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.
69 lines
2.9 KiB
Go
69 lines
2.9 KiB
Go
package config
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/identity"
|
|
"github.com/samcharles93/archie-core/internal/domain/org"
|
|
)
|
|
|
|
func TestCredentialOrgBoundary(t *testing.T) {
|
|
tests := []struct {
|
|
name, binding, requested, identity, root string
|
|
bound bool
|
|
want string
|
|
}{
|
|
{name: "empty binding matches dashboard default", requested: string(org.DefaultOrgID), bound: true, want: string(org.DefaultOrgID)},
|
|
{name: "explicit default matches root", binding: string(org.DefaultOrgID), bound: true, want: string(org.DefaultOrgID)},
|
|
{name: "empty binding and root", bound: true, want: string(org.DefaultOrgID)},
|
|
{name: "named tenant remains isolated", binding: "acme", requested: "other", identity: "acme", root: "other", want: "acme"},
|
|
{name: "identity inherits root tenant", binding: "acme", requested: "acme", root: "acme", bound: true, want: "acme"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cfg := Config{Org: tt.root, GrantedCredentials: []string{"codex"}, Identities: []IdentityConfig{{Name: "bot", Org: tt.identity}}, Containers: ContainerConfig{Credentials: []CredentialBinding{{Service: "codex", Org: tt.binding}}}}
|
|
got, granted := cfg.CredentialAccess("bot")
|
|
if got != tt.want {
|
|
t.Fatalf("run org %q, want %q", got, tt.want)
|
|
}
|
|
bindings := cfg.Containers.BoundCredentials(tt.requested, granted, []string{"codex"})
|
|
b, ok := bindings["codex"]
|
|
if ok != tt.bound {
|
|
t.Fatalf("bound=%v, want %v", ok, tt.bound)
|
|
}
|
|
if ok && b.Org == "" {
|
|
t.Fatal("returned binding retains empty org")
|
|
}
|
|
})
|
|
}
|
|
cfg := ContainerConfig{Credentials: []CredentialBinding{{Service: "codex"}, {Service: "codex", Org: string(org.DefaultOrgID)}}}
|
|
if err := cfg.ValidateCredentialBindings(); err == nil {
|
|
t.Fatal("empty and explicit default bindings must be duplicates")
|
|
}
|
|
}
|
|
|
|
func TestCredentialAccessGrants(t *testing.T) {
|
|
cfg := Config{
|
|
GrantedCredentials: []string{"root-service"},
|
|
Identities: []IdentityConfig{{Name: "bot"}},
|
|
IdentityGrants: map[string][]string{"6f129e29-0e26-5246-99bd-74cb4496203b": {"github"}},
|
|
}
|
|
tests := []struct {
|
|
name, identity string
|
|
want []string
|
|
}{
|
|
{name: "System", identity: string(identity.SystemID), want: []string{"root-service"}},
|
|
{name: "configured identity without its own grant inherits the root's", identity: "bot", want: []string{"root-service"}},
|
|
{name: "dashboard identity gets its grant", identity: "6f129e29-0e26-5246-99bd-74cb4496203b", want: []string{"github"}},
|
|
{name: "unknown identity gets none", identity: "11111111-1111-5111-8111-111111111111", want: nil},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if _, got := cfg.CredentialAccess(tt.identity); !slices.Equal(got, tt.want) {
|
|
t.Fatalf("granted %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|