mesh/delivery merged: source.main moved to novox/mesh-catalog@6d000647de2d
mesh/check being carried to cff1005422c1 on 6d000647de2d | from f9dcbc295723
The one bundle that did everything becomes the manager bundle, which runs long and answers the seat's ten verbs and the three acting tools, and a tools bundle of its own that answers the four reading tools and writes nothing, so they answer while the manager fails to load or stops. Both import the module's one package for the layouts of the kept data and the log entries, the key form, the entries' names and the settings with their validity; the settings file and the account with its directory stay as they are. Builds: design 39 parts §1, §2, §3, §4, §5, §6, §7, §8
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
. "claude-licence-manager/internal/licences"
|
|
)
|
|
|
|
// design 39 bus-and-switch §10: an adoption whose key another licence has is refused, in the audit and as an event.
|
|
func TestAnAdoptionWhoseKeyIsTakenIsRefused(t *testing.T) {
|
|
ctx := context.Background()
|
|
t.Run("an API key", func(t *testing.T) {
|
|
mm := newMesh(t)
|
|
_ = mm.store.SaveLicence(ctx, Licence{Name: "Ops-Key", Kind: "api-key"})
|
|
_, err := mm.m.adoptKey(ctx, "ops-key", "sk-ant-"+strings.Repeat("a", 40), "a test")
|
|
if err == nil || !strings.Contains(err.Error(), "Ops-Key") {
|
|
t.Fatalf("adopted a key whose key form is taken: %v", err)
|
|
}
|
|
if l, _ := mm.store.Licence(ctx, "ops-key"); l != nil {
|
|
t.Fatal("the clashing licence was kept")
|
|
}
|
|
assertRefused(t, mm)
|
|
})
|
|
t.Run("a login", func(t *testing.T) {
|
|
mm := newMesh(t)
|
|
_ = mm.store.SaveLicence(ctx, Licence{Name: "ACCT-1@example.org", Kind: "api-key"})
|
|
r := mm.login("laptop", "rt-laptop", true, t0.Add(-time.Minute))
|
|
adopted, err := mm.m.Consider(ctx, []Holdings{r})
|
|
if err != nil || len(adopted) != 0 {
|
|
t.Fatalf("adopted %v (%v), want none", adopted, err)
|
|
}
|
|
if len(mm.vendor.exchanged) != 0 {
|
|
t.Fatalf("a refused login was exchanged: %v", mm.vendor.exchanged)
|
|
}
|
|
if o, _ := mm.store.Outcome(ctx, Fingerprint("rt-laptop")); o != Refused {
|
|
t.Fatalf("outcome %q, want refused", o)
|
|
}
|
|
assertRefused(t, mm)
|
|
})
|
|
}
|
|
|
|
func assertRefused(t *testing.T, mm *miniMesh) {
|
|
t.Helper()
|
|
said := false
|
|
for _, e := range mm.events {
|
|
said = said || strings.HasPrefix(e, "licence.refused ")
|
|
}
|
|
audited := false
|
|
for _, a := range mm.audit.under("") {
|
|
audited = audited || a["what"] == "refused"
|
|
}
|
|
if !said || !audited {
|
|
t.Fatalf("refusal said %v, audited %v: %v", said, audited, mm.events)
|
|
}
|
|
}
|