Drop the bot_user-derived root identity and the empty-identity sentinel. System polls forge connections and owns instance-level work; a polled task stores the polling identity, task_queued and work_request_submitted carry task id, actor and principal, and an empty task identity is refused. Migration 0072 moves empty tasks.identity, the identity-grants root key and the old root's connection permits to System so a re-poll dedups.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package controlplanestore
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/identity"
|
|
)
|
|
|
|
// TestIdentityGrantsReplaceTheFiles pins that the stored grants replace the
|
|
// file's: a listed identity gets exactly its list, an unlisted one is left to
|
|
// inherit System's (nil), and an empty list grants nothing.
|
|
func TestIdentityGrantsReplaceTheFiles(t *testing.T) {
|
|
fileList := []string{"from-file"}
|
|
cfg := config.Config{
|
|
GrantedCredentials: []string{"file-root"},
|
|
Identities: []config.IdentityConfig{
|
|
{Name: "listed", GrantedCredentials: &fileList},
|
|
{Name: "unlisted", GrantedCredentials: &fileList},
|
|
{Name: "none"},
|
|
},
|
|
}
|
|
applyIdentityGrants(&cfg, identityGrants{
|
|
Identities: map[string][]string{string(identity.SystemID): {"github"}, "listed": {"anthropic"}, "none": {}},
|
|
})
|
|
if !slices.Equal(cfg.GrantedCredentials, []string{"github"}) {
|
|
t.Fatalf("System granted %v", cfg.GrantedCredentials)
|
|
}
|
|
tests := []struct {
|
|
identity string
|
|
want []string // nil means inherit System
|
|
}{
|
|
{"listed", []string{"anthropic"}},
|
|
{"unlisted", nil},
|
|
{"none", []string{}},
|
|
}
|
|
for i, tt := range tests {
|
|
t.Run(tt.identity, func(t *testing.T) {
|
|
got := cfg.Identities[i].GrantedCredentials
|
|
if (got == nil) != (tt.want == nil) || (got != nil && !slices.Equal(*got, tt.want)) {
|
|
t.Fatalf("granted %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|