- pier: TestSessionReserve (A-WR-03), TestLockScope (A-WR-07), TestScopeWidening (A-WR-04), TestStatelessFanOut (A-WR-05, A-WR-06), TestPersonalTokenBinding (A-WR-09), TestDispatchHardening (A-WR-01, A-WR-02, A-WR-08, A-IN-04, A-IN-05, A-IN-08), TestCatalogPathFields (A-WR-02, A-IN-07), TestPromptWriteCeiling (C-IN-01), TestTokenScopedRevoke (B-WR-04, C-IN-02), TestResolveClientAddress (B-IN-04); test seam WrapStore - pact TestFrontendTokenScopes, towel TestClientIP, cabana TestTokenScopeNameParity - cabana TestAccountContributionURL (B-WR-03), TestAccountContributionsIsolation (B-WR-06, B-IN-03), TestRecordActionPromptLocalized (B-IN-02), and the Postgres TestAccountTokenRevokeEvent (B-WR-04) and TestResolveBackendTokenRemote (B-IN-04) - vitest: hotkeysEditing.test.ts (B-WR-01, B-WR-02) and the extended AccountContributions.test.ts (B-WR-03, B-WR-06, B-IN-01) - check-phase19.7.sh requires every name (GO_TESTS, GO_TAGGED_TESTS, DOCKER_TESTS, ADMIN_FILES) and scans the new files (PHASE_TEST_FILES)
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package cabana
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// TestTokenScopeNameParity pins plan 07's shared scope name rule (P-30):
|
|
// cabana's plugin scope validation accepts and refuses exactly the names
|
|
// pact.ValidTokenScopeName does (the table of pact's TestFrontendTokenScopes;
|
|
// "*" is refused by both, by cabana also as reserved).
|
|
func TestTokenScopeNameParity(t *testing.T) {
|
|
names := []struct {
|
|
name string
|
|
ok bool
|
|
}{
|
|
{"read", true},
|
|
{"servers:write", true},
|
|
{"a_b-c:d", true},
|
|
{"", false},
|
|
{"Read", false},
|
|
{"servers:", false},
|
|
{":x", false},
|
|
{"a:b:c", false},
|
|
{"*", false},
|
|
{"with space", false},
|
|
}
|
|
for _, c := range names {
|
|
if got := pact.ValidTokenScopeName(c.name); got != c.ok {
|
|
t.Fatalf("pact.ValidTokenScopeName(%q) = %v, want %v (the table drifted from pact's)", c.name, got, c.ok)
|
|
}
|
|
cat := &tokenScopeCatalog{byName: map[string]*compiledTokenScope{}}
|
|
scope := pact.TokenScope{Name: c.name, Label: "Label", Description: "Description", Permissions: []string{"acme.*"}, Methods: []string{"GET"}}
|
|
reg := &Registry{permissions: map[string]pact.Permission{"acme.read": {Code: "acme.read"}}}
|
|
err := validatePluginTokenScope(reg, "acme.plugin", scope, cat)
|
|
if (err == nil) != c.ok {
|
|
t.Errorf("validatePluginTokenScope(%q) err = %v, want accepted %v", c.name, err, c.ok)
|
|
}
|
|
}
|
|
}
|