- 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)
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package pact
|
|
|
|
import "testing"
|
|
|
|
// tokenScopeNames is the name table of TestFrontendTokenScopes; cabana's
|
|
// TestTokenScopeNameParity checks its own validation against the same
|
|
// names.
|
|
var tokenScopeNames = []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},
|
|
}
|
|
|
|
// sampleScopesPlugin declares member token scopes, as an application's
|
|
// plugin does for E-2.
|
|
type sampleScopesPlugin struct{}
|
|
|
|
func (sampleScopesPlugin) FrontendTokenScopes() []FrontendTokenScope {
|
|
return []FrontendTokenScope{{Name: "servers:write", Label: "Report servers", Description: "Lets an agent report server components."}}
|
|
}
|
|
|
|
// TestFrontendTokenScopes pins plan 07's member token scope seam (E-2,
|
|
// P-30): ValidTokenScopeName accepts and refuses the table's names, and a
|
|
// plugin declaring FrontendTokenScopes is discovered through
|
|
// HasFrontendTokenScopes (and not as an admin HasTokenScopes plugin).
|
|
func TestFrontendTokenScopes(t *testing.T) {
|
|
t.Run("ValidTokenScopeName", func(t *testing.T) {
|
|
for _, c := range tokenScopeNames {
|
|
if got := ValidTokenScopeName(c.name); got != c.ok {
|
|
t.Errorf("ValidTokenScopeName(%q) = %v, want %v", c.name, got, c.ok)
|
|
}
|
|
}
|
|
})
|
|
t.Run("a sample plugin is discovered", func(t *testing.T) {
|
|
var plugin any = sampleScopesPlugin{}
|
|
src, ok := plugin.(HasFrontendTokenScopes)
|
|
if !ok {
|
|
t.Fatal("the sample plugin is not a HasFrontendTokenScopes")
|
|
}
|
|
scopes := src.FrontendTokenScopes()
|
|
if len(scopes) != 1 || scopes[0].Name != "servers:write" || !ValidTokenScopeName(scopes[0].Name) {
|
|
t.Fatalf("scopes = %+v", scopes)
|
|
}
|
|
if _, admin := plugin.(HasTokenScopes); admin {
|
|
t.Fatal("a member token scope plugin is also an admin token scope plugin")
|
|
}
|
|
})
|
|
}
|