Files
archie/modules/connectors/credentials_test.go
T
sam f24c2b4455 feat(connectors): separate packages from scoped installations (#2027)
Packages are accepted once by the instance. Installations configure them at the instance, an organisation or a person; bindings and credentials resolve the person's, then their organisation's, then the instance's. Decisions, approval requests and held chat actions record the installation and scope that acted.

The dashboard lists packages separately from installations, shows every installation's scope, and creates, edits and disables installations at their scope.
2026-11-24 03:05:27 +11:00

72 lines
2.0 KiB
Go

package connectors
import (
"context"
json "encoding/json/v2"
"log/slog"
"strings"
"testing"
"filippo.io/age"
"github.com/samcharles93/archie-core/internal/platform/seal"
"github.com/samcharles93/archie-core/modules/connectors/internal/store"
"github.com/samcharles93/archie-core/modules/governance"
)
// TestCredentialRoutesNeverReturnASecret guards the credential boundary: a
// list or a read says where each field comes from and never what it holds.
func TestCredentialRoutesNeverReturnASecret(t *testing.T) {
id, err := age.GenerateX25519Identity()
if err != nil {
t.Fatal(err)
}
sealer, err := seal.New(id.String(), nil)
if err != nil {
t.Fatal(err)
}
const secret = "plainly-fake-value-the-route-must-not-return"
plain, err := json.Marshal(map[string]Field{"token": {Value: secret}})
if err != nil {
t.Fatal(err)
}
sealed, err := sealer.Seal("instance:/ops/bearer", plain)
if err != nil {
t.Fatal(err)
}
module := &Module{
log: slog.New(slog.DiscardHandler),
store: &fakeRegistry{creds: []store.Credential{
{Scope: store.ScopeInstance, Name: "ops", Kind: "bearer", Sealed: sealed},
}},
sealer: sealer,
}
for _, tt := range []struct {
name string
call func(context.Context) (any, error)
}{
{name: "list", call: func(ctx context.Context) (any, error) { return module.listCredentials(ctx, nil) }},
{name: "read", call: func(ctx context.Context) (any, error) { return module.getCredential(ctx, &nameInput{Name: "ops"}) }},
} {
t.Run(tt.name, func(t *testing.T) {
ctx := governance.WithPrincipal(t.Context(), governance.Principal{IdentityID: "admin", Kind: governance.KindUser, Org: governance.DefaultOrgID})
reply, err := tt.call(ctx)
if err != nil {
t.Fatalf("read: %v", err)
}
raw, err := json.Marshal(reply)
if err != nil {
t.Fatal(err)
}
body := string(raw)
if strings.Contains(body, secret) {
t.Fatalf("the route returned the secret: %s", body)
}
if !strings.Contains(body, "stored") {
t.Fatalf("the route didn't say the field is stored: %s", body)
}
})
}
}