Files
Pulse/pkg/auth/agent_credentials_validation_unicode_test.go
pulse-triage[bot] 44fe4f32cd Avoid building migration data for credential admission
Validate role scopes with a read-only scan instead of constructing canonical and diagnostic collections that admission discards. Reuse the collector vocabulary and preserve Unicode trimming, ordered missing-scope errors, exact error text, legacy behavior and live authority. Keep compatibility, input ownership and benchmark coverage in the normal Go suite.

Contract-Neutral: Internal credential validation cost only; accepted and rejected authority, exact errors, issued values, persistence, live revocation, routes and rendered states are unchanged.
Change-source: pulse-maintainer
2026-11-10 08:49:44 +00:00

47 lines
1.8 KiB
Go

package auth
import "testing"
// Supplement the unchanged before/after matrix with the review's Unicode and
// vocabulary-drift controls. TrimSpace, not ASCII trimming or alias rewriting,
// defines admission at this layer.
func TestValidateRoleScopesUnicodeCompatibility(t *testing.T) {
roles := []string{
"\u00a0" + RuntimeRoleMonitoringCollector + "\u0085",
"\u2003" + RuntimeRoleActionRunner + "\u202f",
"\u0085" + RuntimeRoleLegacyFullTrust + "\u00a0",
"\u2003\u00a0",
"future\"role",
"futuré-role",
"\ufeff" + RuntimeRoleActionRunner,
}
inputs := [][]string{
nil, {},
{"\u00a0" + ScopeAgentReport, ScopeAgentConfigRead + "\u0085"},
{"\u2003" + ScopeAgentExec + "\u202f", ScopeAgentExec},
{ScopeAgentReport, "agent:\u00a0config:read"},
{ScopeAgentExec, "\ufeff" + ScopeAgentExec},
{ScopeAgentReport, ScopeAgentConfigRead, "\u0085" + ScopeDockerReport + "\u00a0", ScopeKubernetesReport},
}
for _, role := range roles {
for _, scopes := range inputs {
if got, want := roleValidationError(ValidateRoleScopes(role, scopes)), referenceRoleValidationError(role, scopes); got != want {
t.Fatalf("role=%q scopes=%q: error=%q, want %q", role, scopes, got, want)
}
}
}
}
func TestValidateRoleScopesCollectorVocabularyStaysAligned(t *testing.T) {
scopes := MonitoringCollectorScopes()
if err := ValidateRoleScopes(RuntimeRoleMonitoringCollector, scopes); err != nil {
t.Fatalf("migration's complete collector vocabulary must be admitted: %v", err)
}
for _, scope := range scopes {
input := []string{ScopeAgentReport, ScopeAgentConfigRead, scope}
if got, want := roleValidationError(ValidateRoleScopes(RuntimeRoleMonitoringCollector, input)), referenceRoleValidationError(RuntimeRoleMonitoringCollector, input); got != want {
t.Fatalf("collector vocabulary scope %q: error=%q, want %q", scope, got, want)
}
}
}