The read-only TIA Portal connector (pruefwerk epic #1095, #1090/#1094) runs on the customer's machine and uploads a TIA export with a workspace API key: POST /api/v1/targets/{id}/artifacts/upload. The new scope needs the pruefwerk entitlement; integration keys don't get it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
package scopes
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestCatalogueIsWellFormed(t *testing.T) {
|
|
for _, s := range All() {
|
|
if s.Product == "" || s.Description == "" {
|
|
t.Errorf("%s: product and description are required", s.Name)
|
|
}
|
|
if _, ok := Lookup(s.Name); !ok {
|
|
t.Errorf("%s: not found by Lookup", s.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidate(t *testing.T) {
|
|
got, err := Validate([]string{"pruefwerk:scans.run", " pruefwerk:findings.read", "pruefwerk:scans.run"}, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []string{"pruefwerk:findings.read", "pruefwerk:scans.run"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("got %v, want %v", got, want)
|
|
}
|
|
if _, err := Validate([]string{"certifai:read"}, ""); err == nil {
|
|
t.Error("unknown scope accepted")
|
|
}
|
|
if _, err := Validate([]string{"firmwerk:licence"}, "pruefwerk"); err == nil {
|
|
t.Error("scope of another product accepted")
|
|
}
|
|
if _, err := Validate([]string{"werkbank:runner"}, "pruefwerk"); err != nil {
|
|
t.Errorf("werkbank scopes belong to pruefwerk: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestProductsAndEffective(t *testing.T) {
|
|
names := []string{"firmwerk:licence", "pruefwerk:findings.read", "werkbank:runner", "legacy:thing"}
|
|
if got := Products(names); !reflect.DeepEqual(got, []string{"firmwerk", "pruefwerk"}) {
|
|
t.Fatalf("Products = %v", got)
|
|
}
|
|
got := Effective(names, map[string]bool{"pruefwerk": true})
|
|
if want := []string{"pruefwerk:findings.read", "werkbank:runner", "legacy:thing"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("Effective = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestUploadsWrite(t *testing.T) {
|
|
s, ok := Lookup("pruefwerk:uploads.write")
|
|
if !ok || s.Product != "pruefwerk" {
|
|
t.Fatalf("pruefwerk:uploads.write: %+v %v", s, ok)
|
|
}
|
|
got, err := Validate([]string{"pruefwerk:uploads.write", "pruefwerk:scans.run"}, "pruefwerk")
|
|
if err != nil || !reflect.DeepEqual(got, []string{"pruefwerk:scans.run", "pruefwerk:uploads.write"}) {
|
|
t.Fatalf("Validate: %v %v", got, err)
|
|
}
|
|
}
|