mesh/delivery-group group feat/774-l3-reland rejected: composed together: the checker's verdict at the members' heads (b48c90fea31f): integration: mesh-self-ch…
mesh/delivery closed: a newer head of the same pull request
mesh/check failed: integration: mesh-self-check/cmd/mesh-self-check.TestTheSelfCheckWholeRunsOnTheBus: the run answered {Run:doctor-1793351737-1 At:20…
One commit with exactly the tree of the reviewed head35b4509c0a, on main12c2574c9d, so two compiled programs added and removed on the branch leave no trace in history (issue 1577).
123 lines
4.8 KiB
Go
123 lines
4.8 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The vault says each credential's outcome in its own state `bound`, by its own name for the value and its generation,
|
|
// never the value: held is provided, an issued or given value not yet held waits, one not made yet has no entry, an
|
|
// offer of form none has none, the vault's own offer is provided; an entry no plan names goes only once its key is gone
|
|
// or retiring with the operator's Approve (novox/hq ADR 0570 clauses 3, 5-7; issue 1954 V1).
|
|
func TestTheVaultSaysEachCredentialsOutcome(t *testing.T) {
|
|
v := newVault(t, NoAsker{})
|
|
plan := func(node, module string, provisions ...map[string]any) []byte {
|
|
raw, _ := json.Marshal(map[string]any{"node": node, "module": module, "provisioning": map[string]any{"provisions": provisions}})
|
|
return raw
|
|
}
|
|
entry := func(provision, provider, module, form string) map[string]any {
|
|
return map[string]any{"provision": provision, "provider": provider, "provider-module": module, "credential-form": form}
|
|
}
|
|
plans := map[string][]byte{
|
|
"g14.gitea": plan("g14", "gitea",
|
|
entry("postgres-database", "ace", "postgres", "pair"),
|
|
entry("oidc-client", "novox", "keycloak", "shared"),
|
|
entry("media-token", "ace", "jellyfin", "issued"),
|
|
entry("bot-token", "ace", "telegram", "given"),
|
|
entry("route", "novox", "route-adapter", "none"),
|
|
entry("secret", "novox", "mesh-vault", "pair")),
|
|
}
|
|
v.Assignments = Mirror{
|
|
Keys: func() ([]string, error) {
|
|
var k []string
|
|
for key := range plans {
|
|
k = append(k, key)
|
|
}
|
|
return k, nil
|
|
},
|
|
Read: func(key string) ([]byte, error) { return plans[key], nil }}
|
|
bound := map[string][]byte{}
|
|
keys := map[string]string{} // the seat's provisions, by key: a state, or a raw value
|
|
v.Bound = Bound{
|
|
Get: func(key string) ([]byte, error) { return bound[key], nil },
|
|
Put: func(key string, value []byte) error { bound[key] = value; return nil },
|
|
Delete: func(key string) error { delete(bound, key); return nil },
|
|
Keys: func() ([]string, error) {
|
|
var out []string
|
|
for k := range bound {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return out, nil
|
|
},
|
|
Provision: func(key string) ([]byte, error) {
|
|
if raw, ok := keys[key]; ok {
|
|
return []byte(raw), nil
|
|
}
|
|
return nil, nil
|
|
},
|
|
}
|
|
if _, err := v.Put("pair/ace/postgres-database/g14/gitea", "pw", "the test"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := v.OutcomePass(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
read := func(key string) BoundOutcome {
|
|
var o BoundOutcome
|
|
_ = json.Unmarshal(bound[key], &o)
|
|
return o
|
|
}
|
|
for _, row := range []struct {
|
|
key, state, name string
|
|
generation int
|
|
}{
|
|
{"g14.gitea.secret-postgres-database", "provided", "pair/ace/postgres-database/g14/gitea", 1},
|
|
{"g14.gitea.secret-media-token", "waits", "provision/ace/media-token/g14/gitea", 0},
|
|
{"g14.gitea.secret-bot-token", "waits", "provision/ace/bot-token/g14/gitea", 0},
|
|
{"g14.gitea.secret", "provided", "", 0},
|
|
} {
|
|
o := read(row.key)
|
|
if o.State != row.state || o.VaultName != row.name || o.Generation != row.generation || o.ProviderModule != "mesh-vault" {
|
|
t.Errorf("%s: %+v", row.key, o)
|
|
}
|
|
}
|
|
var all []string
|
|
for k := range bound {
|
|
all = append(all, k)
|
|
}
|
|
sort.Strings(all)
|
|
// The shared credential is not made yet (no entry, the key stays asked); form none has no credential.
|
|
if want := []string{"g14.gitea.secret", "g14.gitea.secret-bot-token", "g14.gitea.secret-media-token",
|
|
"g14.gitea.secret-postgres-database"}; !slices.Equal(all, want) {
|
|
t.Errorf("entries %v, want %v", all, want)
|
|
}
|
|
for _, raw := range bound {
|
|
if strings.Contains(string(raw), `"pw"`) {
|
|
t.Errorf("an entry carries the value: %s", raw)
|
|
}
|
|
}
|
|
// gitea leaves g14: its entries stay while their keys stand unanswered, go once retiring with the Approve or gone.
|
|
delete(plans, "g14.gitea")
|
|
keys["g14.gitea.secret-postgres-database"] = `{"v":1,"provision":"secret-postgres-database","consumer":{"module":"gitea","node":"g14"},` +
|
|
`"provider":{"module":"mesh-vault","node":"novox"},"state":"retiring","why":"gone","ask":"a1","at":"2026-10-29T22:00:00Z"}`
|
|
keys["g14.gitea.secret-bot-token"] = keys["g14.gitea.secret-postgres-database"]
|
|
keys["g14.gitea.secret-media-token"] = strings.Replace(keys["g14.gitea.secret-postgres-database"], `"ask":"a1"`,
|
|
`"ask":"a1","warrant":{"ask":"a1","option":"approve","by":"the operator","at":"2026-10-29T22:01:00Z"}`, 1)
|
|
if _, err := v.OutcomePass(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
all = all[:0]
|
|
for k := range bound {
|
|
all = append(all, k)
|
|
}
|
|
sort.Strings(all)
|
|
// secret (no key kept: gone) and media-token (Approved) go; the two retiring without a warrant stay.
|
|
if want := []string{"g14.gitea.secret-bot-token", "g14.gitea.secret-postgres-database"}; !slices.Equal(all, want) {
|
|
t.Errorf("after the plan went: %v, want %v", all, want)
|
|
}
|
|
}
|