The legacy key form placement.<node> is gone from the client, so the readers and their fixtures lose it. The check noplacement now also refuses the assigner's retired names in a manifest. Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
507 lines
25 KiB
Go
507 lines
25 KiB
Go
package main
|
|
|
|
import (
|
|
"crypto/ecdh"
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"crypto/x509"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"encoding/pem"
|
|
"fmt"
|
|
assignerclient "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
|
placing "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
|
enrollerclient "git.novox.be/novox/mesh-contracts/identity-and-access/go/clients/meshnodeenrollerclient"
|
|
vaultclient "git.novox.be/novox/mesh-contracts/identity-and-access/go/clients/meshvaultclient"
|
|
"slices"
|
|
"sort"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshvault"
|
|
"golang.org/x/crypto/bcrypt"
|
|
"golang.org/x/crypto/nacl/box"
|
|
)
|
|
|
|
// loginsState is the vault's state node-logins in memory; like the runtime it refuses a value naming a credential.
|
|
type loginsState struct {
|
|
mu sync.Mutex
|
|
keys map[string]NodeLogin
|
|
}
|
|
|
|
func (l *loginsState) Get(node string) (*NodeLogin, error) {
|
|
l.mu.Lock()
|
|
defer l.mu.Unlock()
|
|
n, ok := l.keys[node]
|
|
if !ok {
|
|
return nil, nil
|
|
}
|
|
return &n, nil
|
|
}
|
|
|
|
func (l *loginsState) Put(n NodeLogin) error {
|
|
l.mu.Lock()
|
|
defer l.mu.Unlock()
|
|
raw, err := vaultclient.EncodeNodeLogin(n)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if field := credentialField(raw); field != "" {
|
|
return fmt.Errorf("%s carries a field %q, which names a credential", n.Node, field)
|
|
}
|
|
if l.keys == nil {
|
|
l.keys = map[string]NodeLogin{}
|
|
}
|
|
l.keys[n.Node] = n
|
|
return nil
|
|
}
|
|
|
|
func (l *loginsState) Delete(node string) error {
|
|
l.mu.Lock()
|
|
defer l.mu.Unlock()
|
|
delete(l.keys, node)
|
|
return nil
|
|
}
|
|
|
|
func (l *loginsState) Keys() ([]string, error) {
|
|
l.mu.Lock()
|
|
defer l.mu.Unlock()
|
|
var out []string
|
|
for k := range l.keys {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return out, nil
|
|
}
|
|
|
|
// enrolling is a vault that mints, with no lease heard (issue 1126), a loaded user list at revision 570, the bus on novox, the
|
|
// nodes g14, ace and novox placed, their existing logins adopted, and hand acts of person.jochen's.
|
|
type enrolling struct {
|
|
testVault
|
|
accounts *fakeAccounts
|
|
logins *loginsState
|
|
acts map[string]HandActSeen
|
|
}
|
|
|
|
func newEnrolling(t *testing.T) *enrolling {
|
|
t.Helper()
|
|
v := newVault(t, nil)
|
|
e := &enrolling{testVault: v, accounts: &fakeAccounts{keys: map[string]AccountHash{}}, logins: &loginsState{keys: map[string]NodeLogin{}}, acts: map[string]HandActSeen{}}
|
|
v.Accounts, v.Logins = e.accounts, e.logins
|
|
v.Assigner = assignedNodes(t, map[string][]string{"novox": {"nats"}, "g14": {"web"}, "ace": {"shop"}})
|
|
v.LoadedListHeard(570)
|
|
v.TokenBase = func() (TokenBase, error) {
|
|
return TokenBase{Broker: "tls://10.77.0.1:4222", Fingerprint: "sha256:bus"}, nil
|
|
}
|
|
v.ReadAct = func(id string) (*HandActSeen, error) {
|
|
if a, ok := e.acts[id]; ok {
|
|
return &a, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
for _, n := range []string{"g14", "ace", "novox"} {
|
|
e.accounts.keys["node."+n] = AccountHash{User: "node." + n, Hash: "$2a$04$adopted", Adopted: true, At: time.Now()}
|
|
pub, _ := aSealingKey(t)
|
|
if err := v.recordNodeKey(n, pub, "node."+n); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
return e
|
|
}
|
|
|
|
func (e *enrolling) act(id, by, node string) {
|
|
e.acts[id] = HandActSeen{ID: id, By: by, At: time.Now().Add(time.Hour), Verb: "rotate-node", Args: []string{node}}
|
|
}
|
|
|
|
// 774/S43/AC1-AC3, S44/AC1-AC3, S45/AC1 (novox/hq ADR 0587 §3, §5, §6, §8): the vault's enrolment verbs
|
|
// are called through their real tool handlers with the arguments mesh-enrolment sends, and each wire answer is decoded
|
|
// into mesh-sdk's delivery types the holder decodes (EnrolmentTokenAnswer, NodeAccountAnswer, SignAnswer and the signed
|
|
// parts of RedeemAnswer), with every field the holder reads filled. Only mesh-enrolment is answered; a token is issued
|
|
// only with its first tunnel whole, its hash is bcrypt of the kept secret, `sealed` answers it sealed to the operator key
|
|
// (a token whose Missing() is empty) and issues nothing; the account is the same for the same keys and opens with the
|
|
// sealing key presented, as the node-engine opens it; a joining node's certificate is signed for the serving key presented
|
|
// only when the keys have the digest node-account recorded; a retire and a drop take it all away.
|
|
func TestTheVaultsEnrolmentAnswersAreMeshSDKsWireShapes(t *testing.T) {
|
|
e := newEnrolling(t)
|
|
if _, err := e.EnsureSigning(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// new1 is placed with its private-network address, as mesh-enrolment writes it before it asks for the certificate.
|
|
values := map[string][]byte{}
|
|
for node, p := range map[string]placing.Assignments{"novox": {Node: "novox", Modules: []placing.PlacedModule{{Module: "nats"}}},
|
|
"g14": {Node: "g14"}, "new1": {Node: "new1", Decided: placing.NodeDecided{Address: "10.77.0.9"}}} {
|
|
p.V = vaultclient.Version
|
|
kv, err := assignerclient.AssignmentsValues(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for k, raw := range kv {
|
|
values[k] = raw
|
|
}
|
|
_ = node
|
|
}
|
|
e.Assigner = AssignerReader{Read: func(key string) ([]byte, error) { return values[key], nil },
|
|
Keys: func() ([]string, error) {
|
|
var out []string
|
|
for k := range values {
|
|
out = append(out, k)
|
|
}
|
|
return out, nil
|
|
}}
|
|
defs := definitions(&Env{Vault: e.Vault})
|
|
call := func(verb, caller string, args map[string]any) (json.RawMessage, error) {
|
|
out, err := toolNamed(t, defs, Seat+"."+verb).run(caller, args)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(out)
|
|
}
|
|
const holder = "novox.mesh-enrolment"
|
|
signer, _ := e.keys()
|
|
signerB64 := base64.StdEncoding.EncodeToString(signer.key.Public().(ed25519.PublicKey))
|
|
tunnel := map[string]any{"key": "machine-tunnel-key", "address": "10.77.0.9", "range": "10.77.0.0/24",
|
|
"hub_key": "hub-tunnel-key", "hub_endpoint": "203.0.113.1:51820"}
|
|
without := func(field string) map[string]any {
|
|
out := map[string]any{}
|
|
for k, x := range tunnel {
|
|
if k != field {
|
|
out[k] = x
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
sealingKey, _ := ecdh.X25519().GenerateKey(rand.Reader)
|
|
sealingPub := base64.StdEncoding.EncodeToString(sealingKey.PublicKey().Bytes())
|
|
identity, _, _ := ed25519.GenerateKey(rand.Reader)
|
|
serving, _, _ := ed25519.GenerateKey(rand.Reader)
|
|
keys := map[string]any{"public_key": base64.StdEncoding.EncodeToString(identity), "overlay_key": "overlay-pub",
|
|
"sealing_key": sealingPub, "serving_key": base64.StdEncoding.EncodeToString(serving)}
|
|
digest := enrollerclient.KeysDigest(keys["public_key"].(string), "overlay-pub", sealingPub, keys["serving_key"].(string))
|
|
with := func(base map[string]any, more map[string]any) map[string]any {
|
|
out := map[string]any{}
|
|
for k, x := range base {
|
|
out[k] = x
|
|
}
|
|
for k, x := range more {
|
|
out[k] = x
|
|
}
|
|
return out
|
|
}
|
|
reply := enrollerclient.RedeemAnswer{Node: "new1", Login: "node.new1", Account: "sealed", Certificate: "pem", Signer: signerB64}
|
|
|
|
var issued, sealed, dropped meshvault.EnrolmentTokenAnswer
|
|
var account, accountAgain, retired meshvault.NodeAccountAnswer
|
|
var cert, replySig meshvault.SignAnswer
|
|
var secret, accountHash string
|
|
for _, c := range []struct {
|
|
name, verb, caller string
|
|
args map[string]any
|
|
into any
|
|
filled []string // the json fields the holder reads, which must not be empty
|
|
refused string // a part of the refusal, when refused
|
|
}{
|
|
// Only the seat mesh-node-enroller is answered: not the controller, a node, a person or a caller not proven.
|
|
{"a node asks a token", "enrolment-token", "node.g14", map[string]any{"node": "new1", "tunnel": tunnel}, nil, nil, "mesh-enrolment"},
|
|
{"the controller asks a token", "enrolment-token", "controller", map[string]any{"node": "new1", "tunnel": tunnel}, nil, nil, "mesh-enrolment"},
|
|
{"a person asks an account", "node-account", "person.jochen", map[string]any{"node": "new1"}, nil, nil, "mesh-enrolment"},
|
|
{"unproven asks an enrolment signed", "sign", "", map[string]any{"kind": vaultclient.KindEnrolment, "node": "new1", "reply": "AAEC"}, nil, nil, "proved"},
|
|
{"a grants part asks an enrolment signed", "sign", "novox.mesh-grants", map[string]any{"kind": vaultclient.KindEnrolment, "node": "new1", "reply": "AAEC"}, nil, nil, "mesh-enrolment"},
|
|
// Insight 2026-11-02: the first tunnel is whole at issue, or nothing is issued.
|
|
{"no tunnel", "enrolment-token", holder, map[string]any{"node": "new1"}, nil, nil, "first tunnel"},
|
|
{"a tunnel without the hub's key", "enrolment-token", holder, map[string]any{"node": "new1", "tunnel": without("hub_key")}, nil, nil, "hub's tunnel key"},
|
|
{"a tunnel without the hub's endpoint", "enrolment-token", holder, map[string]any{"node": "new1", "tunnel": without("hub_endpoint")}, nil, nil, "where the hub's tunnel is dialled"},
|
|
{"a tunnel without the address", "enrolment-token", holder, map[string]any{"node": "new1", "tunnel": without("address")}, nil, nil, "this machine's address"},
|
|
{"a tunnel without the machine's tunnel key", "enrolment-token", holder, map[string]any{"node": "new1", "tunnel": without("key")}, nil, nil, "the tunnel key it was issued for"},
|
|
{"a tunnel without the range", "enrolment-token", holder, map[string]any{"node": "new1", "tunnel": without("range")}, nil, nil, "the private network's range"},
|
|
{"a tunnel with a field it has not", "enrolment-token", holder, map[string]any{"node": "new1", "tunnel": with(tunnel, map[string]any{"port": 1})}, nil, nil, "not a first tunnel"},
|
|
// Issue answers what the machine must trust; sealed and drop as the holder sends them, the switch as a word.
|
|
{"issue", "enrolment-token", holder, map[string]any{"node": "new1", "expires": "2026-11-02T12:00:00Z", "tunnel": tunnel}, &issued, []string{"node", "broker", "fingerprint", "signer"}, ""},
|
|
{"sealed", "enrolment-token", holder, map[string]any{"node": "new1", "sealed": "true"}, &sealed, []string{"node", "sealed"}, ""},
|
|
// The account at the redeem, twice with the same keys; other keys and an adopted node's are refused.
|
|
{"node-account", "node-account", holder, map[string]any{"node": "new1", "sealing_key": sealingPub, "keys_digest": digest}, &account, []string{"node", "login", "account"}, ""},
|
|
{"node-account again", "node-account", holder, map[string]any{"node": "new1", "sealing_key": sealingPub, "keys_digest": digest}, &accountAgain, []string{"node", "login", "account"}, ""},
|
|
{"node-account for other keys", "node-account", holder, map[string]any{"node": "new1", "sealing_key": sealingPub, "keys_digest": "sha256:other"}, nil, nil, "another set of keys"},
|
|
{"node-account of an adopted node", "node-account", holder, map[string]any{"node": "g14", "sealing_key": sealingPub, "keys_digest": digest}, nil, nil, "never minted anew"},
|
|
// The certificate for the serving key presented, checked against node-account's digest; the reply signed.
|
|
{"a certificate without the keys", "sign", holder, map[string]any{"kind": vaultclient.KindNodeCertificate, "node": "new1", "serving_key": keys["serving_key"]}, nil, nil, "keys it presented"},
|
|
{"a certificate for another serving key", "sign", holder, with(keys, map[string]any{"kind": vaultclient.KindNodeCertificate, "node": "new1", "serving_key": base64.StdEncoding.EncodeToString(identity)}), nil, nil, "not the ones its account was made for"},
|
|
{"a certificate", "sign", holder, with(keys, map[string]any{"kind": vaultclient.KindNodeCertificate, "node": "new1"}), &cert, []string{"kind", "node", "certificate", "authority", "signer", "digest"}, ""},
|
|
{"the reply signed", "sign", holder, map[string]any{"kind": vaultclient.KindEnrolment, "node": "new1", "reply": base64.StdEncoding.EncodeToString(reply.SignedBytes())}, &replySig, []string{"kind", "node", "signature", "signer", "digest"}, ""},
|
|
{"a reply of a node with no token", "sign", holder, map[string]any{"kind": vaultclient.KindEnrolment, "node": "g14", "reply": "AAEC"}, nil, nil, "no enrolment token"},
|
|
// A revoke: the account retired, the token and its hash dropped.
|
|
{"retire", "node-account", holder, map[string]any{"node": "new1", "retire": "true"}, &retired, []string{"node", "retired"}, ""},
|
|
{"drop", "enrolment-token", holder, map[string]any{"node": "new1", "drop": "true"}, &dropped, []string{"node", "dropped"}, ""},
|
|
} {
|
|
raw, err := call(c.verb, c.caller, c.args)
|
|
if c.refused != "" {
|
|
if err == nil || !strings.Contains(err.Error(), c.refused) {
|
|
t.Errorf("%s: answered %s, %v; want a refusal saying %q", c.name, raw, err, c.refused)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", c.name, err)
|
|
}
|
|
if err := json.Unmarshal(raw, c.into); err != nil {
|
|
t.Fatalf("%s: %s does not decode as mesh-sdk's shape: %v", c.name, raw, err)
|
|
}
|
|
var fields map[string]any
|
|
back, _ := json.Marshal(c.into)
|
|
_ = json.Unmarshal(back, &fields)
|
|
for _, f := range c.filled {
|
|
if x, ok := fields[f]; !ok || x == "" || x == false {
|
|
t.Errorf("%s: the wire answer %s leaves %q empty", c.name, raw, f)
|
|
}
|
|
}
|
|
if c.name == "issue" {
|
|
// What was kept: the secret, whose bcrypt hash is enrol.new1; listed, never handed out, never answered.
|
|
rec, held, _ := e.Store.Read("enrol/new1/token")
|
|
secret, _ = openAtRest(rec, e.Vault)
|
|
key := e.accounts.keys["enrol.new1"]
|
|
if !held || secret == "" || strings.Contains(string(raw), secret) || strings.Contains(strings.Join(e.bus.raw, " "), secret) ||
|
|
key.Kept != KeptEnrolment || bcrypt.CompareHashAndPassword([]byte(key.Hash), []byte(secret)) != nil {
|
|
t.Fatalf("the token is held %v, its hash %+v, or its secret is in an answer or an event: %s", held, key, raw)
|
|
}
|
|
if held, _ := e.EnrolmentsHeld(); len(held) != 1 || held[0].User != "enrol.new1" {
|
|
t.Errorf("secret_holders names %+v", held)
|
|
}
|
|
}
|
|
if c.name == "node-account" {
|
|
accountHash = e.accounts.keys["node.new1"].Hash
|
|
if _, err := e.Get(holder, "enrol/new1/token", pemOf(t, mustPub(t))); err == nil {
|
|
t.Error("an enrolment token was handed out by get")
|
|
}
|
|
}
|
|
}
|
|
if issued.Broker != "tls://10.77.0.1:4222" || issued.Fingerprint != "sha256:bus" || issued.Signer != signerB64 || issued.Sealed != "" {
|
|
t.Errorf("issue answered %+v", issued)
|
|
}
|
|
// sealed issued nothing new: the token it seals is the one whose hash is enrol.new1, with its tunnel, and usable whole.
|
|
tok, err := enrollerclient.ParseToken(openOperator(t, e.operatorPublic, e.operatorPrivate, sealed.Sealed))
|
|
if err != nil || len(tok.Missing()) != 0 || tok.Node != "new1" || tok.Broker != issued.Broker || tok.Tunnel == nil ||
|
|
tok.Tunnel.HubEndpoint != "203.0.113.1:51820" || base64.StdEncoding.EncodeToString(tok.Signer) != signerB64 ||
|
|
tok.Secret != secret {
|
|
t.Errorf("the sealed token is %+v, %v", tok, err)
|
|
}
|
|
// The account opens with the sealing key presented, as the node-engine opens it, and is the same both times.
|
|
open := func(a meshvault.NodeAccountAnswer) string {
|
|
blob, _ := base64.StdEncoding.DecodeString(a.Account)
|
|
var pub, priv [32]byte
|
|
copy(pub[:], sealingKey.PublicKey().Bytes())
|
|
copy(priv[:], sealingKey.Bytes())
|
|
out, _ := box.OpenAnonymous(nil, blob, &pub, &priv)
|
|
return string(out)
|
|
}
|
|
if p := open(account); p == "" || p != open(accountAgain) || account.Login != "node.new1" ||
|
|
bcrypt.CompareHashAndPassword([]byte(accountHash), []byte(p)) != nil {
|
|
t.Errorf("the account is %+v / %+v", account, accountAgain)
|
|
}
|
|
// The certificate certifies the serving key presented, for new1's internal name.
|
|
block, _ := pem.Decode([]byte(cert.Certificate))
|
|
if block == nil {
|
|
t.Fatalf("the certificate is %q", cert.Certificate)
|
|
}
|
|
parsed, err := x509.ParseCertificate(block.Bytes)
|
|
if err != nil || !ed25519.PublicKey(serving).Equal(parsed.PublicKey) {
|
|
t.Errorf("the certificate is of another key: %v", err)
|
|
}
|
|
ctx, _ := vaultclient.SignContext(vaultclient.KindEnrolment)
|
|
sig, _ := base64.StdEncoding.DecodeString(replySig.Signature)
|
|
if !ed25519.Verify(signer.key.Public().(ed25519.PublicKey), append([]byte(ctx), reply.SignedBytes()...), sig) {
|
|
t.Error("the redeem answer's signature does not verify under the enrolment context")
|
|
}
|
|
// After the retire and the drop nothing of the enrolment remains.
|
|
if _, ok := e.accounts.keys["node.new1"]; ok || e.logins.keys["new1"].Node != "" {
|
|
t.Error("the retired account's hash or node-logins key remains")
|
|
}
|
|
for _, name := range []string{"own/new1/mesh-host/node.new1", "enrol/new1/token", "enrol/new1/tunnel"} {
|
|
if _, held, _ := e.Store.Read(name); held {
|
|
t.Errorf("%s remains after the retire and the drop", name)
|
|
}
|
|
}
|
|
if _, ok := e.accounts.keys["enrol.new1"]; ok {
|
|
t.Error("the token's hash remains after a drop")
|
|
}
|
|
}
|
|
|
|
func mustPub(t *testing.T) string {
|
|
t.Helper()
|
|
pub, _ := aSealingKey(t)
|
|
return pub
|
|
}
|
|
|
|
// 774/S46/AC1-AC3, S47/AC1-AC2, S48/AC1, S49/AC1 (novox/hq ADR 0583 §1 to §7): a rotation is answered only for a hand act
|
|
// read back by its id; one runs at a time and the bus node waits for the rest; the new login is ready only when the loaded
|
|
// list holds it; a confirm from any caller but the new login retires nothing; a proven confirm removes the old hash and the
|
|
// rotation is done once the loaded list lacks it; an abandon keeps the old hash; and a node's login is its engine's alone.
|
|
func TestANodesLoginRotatesOneAtATimeAndEndsWithTheListWithoutTheOldOne(t *testing.T) {
|
|
e := newEnrolling(t)
|
|
ask := func(node, act string) (RotateNodeAnswer, error) {
|
|
return e.RotateNode("person.jochen", RotateNodeArgs{Node: node, Why: "a rotation under test", Act: act})
|
|
}
|
|
// AC1: no recorded act, another caller's act, and an old act are all refused.
|
|
e.acts["theirs"] = HandActSeen{ID: "theirs", By: "person.other", At: time.Now().Add(time.Hour), Verb: "rotate-node", Args: []string{"g14"}}
|
|
e.acts["old"] = HandActSeen{ID: "old", By: "person.jochen", At: time.Unix(0, 0), Verb: "rotate-node", Args: []string{"g14"}}
|
|
e.acts["elsewhere"] = HandActSeen{ID: "elsewhere", By: "person.jochen", At: time.Now().Add(time.Hour), Verb: "rotate-node", Args: []string{"ace"}}
|
|
e.acts["restart"] = HandActSeen{ID: "restart", By: "person.jochen", At: time.Now().Add(time.Hour), Verb: "restart", Args: []string{"g14"}}
|
|
for _, act := range []string{"", "missing", "theirs", "old", "elsewhere", "restart"} {
|
|
if _, err := ask("g14", act); err == nil {
|
|
t.Errorf("act %q warranted a rotation", act)
|
|
}
|
|
}
|
|
if len(e.logins.keys) != 0 {
|
|
t.Fatalf("a refused rotation wrote %+v", e.logins.keys)
|
|
}
|
|
e.act("a1", "person.jochen", "g14")
|
|
e.act("a2", "person.jochen", "ace")
|
|
e.act("a3", "person.jochen", "novox")
|
|
first, err := ask("g14", "a1")
|
|
if err != nil || first.Queued || first.Rotating != "node.g14--b" || first.Stage != StageBegun {
|
|
t.Fatalf("g14 began as %+v, %v", first, err)
|
|
}
|
|
// The second login has a hash of its own value, the first is marked rotating, and the value waits for the engine.
|
|
second := e.accounts.keys["node.g14--b"]
|
|
rec, held, _ := e.Store.Read("own/g14/mesh-host/node.g14--b")
|
|
value, _ := openAtRest(rec, e.Vault)
|
|
var acct struct{ User, Password string }
|
|
if !held || json.Unmarshal([]byte(value), &acct) != nil || acct.User != "node.g14--b" ||
|
|
bcrypt.CompareHashAndPassword([]byte(second.Hash), []byte(acct.Password)) != nil || e.accounts.keys["node.g14"].Rotating == nil {
|
|
t.Fatalf("g14's second login is held %v as %s, keyed %+v", held, value, second)
|
|
}
|
|
// AC2: one at a time, the bus node last.
|
|
ace, err := ask("ace", "a2")
|
|
if err != nil || !ace.Queued || strings.Join(ace.Behind, ",") != "g14" {
|
|
t.Fatalf("ace asked while g14 runs: %+v, %v", ace, err)
|
|
}
|
|
bus, err := ask("novox", "a3")
|
|
if err != nil || !bus.Queued || strings.Join(bus.Behind, ",") != "g14,ace" {
|
|
t.Fatalf("novox, the bus node, asked: %+v, %v", bus, err)
|
|
}
|
|
if _, err := ask("g14", "a1"); err == nil {
|
|
t.Error("g14 began a rotation twice")
|
|
}
|
|
// AC3: the loaded list lacks the second login, so nothing is ready; once it holds it, node-account-ready is said.
|
|
e.loadedListHeld("sha256:l1", map[string]string{"node.g14": "$2a$04$adopted"})
|
|
e.advanceRotations()
|
|
if said(e.bus, NodeAccountReadyEvent) != 0 || e.logins.keys["g14"].Stage != StageBegun {
|
|
t.Fatalf("ready without the login in the loaded list: %+v", e.logins.keys["g14"])
|
|
}
|
|
e.loadedListHeld("sha256:l2", map[string]string{"node.g14": "$2a$04$adopted", "node.g14--b": second.Hash})
|
|
e.advanceRotations()
|
|
if said(e.bus, NodeAccountReadyEvent) != 1 || e.logins.keys["g14"].Stage != StageReady {
|
|
t.Fatalf("not ready with the login in the loaded list: %+v", e.logins.keys["g14"])
|
|
}
|
|
// S49/AC1: the new login's value is g14's engine's alone, sealed to the key it stated.
|
|
stated, _, _ := e.Store.NodeKey("g14")
|
|
statedPEM, _ := publicPEM(stated)
|
|
if a, err := e.Get("node.g14", "own/g14/mesh-host/node.g14--b", statedPEM); err != nil || a.Sealed.Ct == "" {
|
|
t.Errorf("g14's engine was answered %+v, %v", a, err)
|
|
}
|
|
if _, err := e.Get("node.ace", "own/g14/mesh-host/node.g14--b", statedPEM); err == nil || !strings.Contains(err.Error(), "engine") {
|
|
t.Errorf("ace's engine asked for g14's login: %v", err)
|
|
}
|
|
if _, err := e.Get("node.g14", "own/g14/mesh-host/node.g14--b", pemOf(t, mustPub(t))); err == nil {
|
|
t.Error("g14's login was sealed to a key its engine did not state")
|
|
}
|
|
if own, err := e.OwnOfNode("node.ace"); err != nil || len(own.Own) != 0 {
|
|
t.Errorf("ace's engine was handed %+v, %v", own, err)
|
|
}
|
|
// S47/AC1: a confirm from the old login, from another node's login or from a person retires nothing.
|
|
for _, caller := range []string{"node.g14", "node.ace--b", "person.jochen", "controller"} {
|
|
if _, err := e.NodeAccountConfirm(caller); err == nil {
|
|
t.Errorf("%q confirmed g14's rotation", caller)
|
|
}
|
|
}
|
|
if _, ok := e.accounts.keys["node.g14"]; !ok || e.logins.keys["g14"].Stage != StageReady {
|
|
t.Fatalf("a refused confirm retired something: %+v", e.logins.keys["g14"])
|
|
}
|
|
// S47/AC2: the proven confirm removes the old hash; done only when the loaded list lacks it.
|
|
if c, err := e.NodeAccountConfirm("node.g14--b"); err != nil || c.Stage != StageConfirmed {
|
|
t.Fatalf("the confirm answered %+v, %v", c, err)
|
|
}
|
|
if _, ok := e.accounts.keys["node.g14"]; ok || said(e.bus, RotationDoneEvent) != 0 {
|
|
t.Fatal("the old hash remains, or the rotation was done while the loaded list still held it")
|
|
}
|
|
e.loadedListHeld("sha256:l3", map[string]string{"node.g14--b": second.Hash})
|
|
e.advanceRotations()
|
|
if nl := e.logins.keys["g14"]; said(e.bus, RotationDoneEvent) != 1 || nl.Login != "node.g14--b" || nl.Rotating != "" || nl.Stage != "" {
|
|
t.Fatalf("after the loaded list lacks the old login g14 is %+v", nl)
|
|
}
|
|
if _, held, _ := e.Store.Read("own/g14/mesh-host/node.g14"); held {
|
|
t.Error("the old login's value remains after the rotation is done")
|
|
}
|
|
if _, err := e.AbandonRotation("person.jochen", "g14"); err == nil {
|
|
t.Error("a finished rotation was abandoned")
|
|
}
|
|
// Blocker 5 (ADR 0583 §2): the act is recorded in g14's key and warrants no second rotation.
|
|
if acts := e.logins.keys["g14"].Acts; !slices.Equal(acts, []string{"a1"}) {
|
|
t.Errorf("g14's key records the acts %v", acts)
|
|
}
|
|
if _, err := ask("g14", "a1"); err == nil || !strings.Contains(err.Error(), "already") {
|
|
t.Errorf("a used hand act warranted another rotation: %v", err)
|
|
}
|
|
// The queue moves on, the bus node after every other: ace first; novox only once ace is done.
|
|
e.RotationPass()
|
|
if e.logins.keys["ace"].Rotating == "" || e.logins.keys["novox"].Rotating != "" {
|
|
t.Fatalf("after g14 the queue began ace=%+v novox=%+v", e.logins.keys["ace"], e.logins.keys["novox"])
|
|
}
|
|
e.RotationPass()
|
|
if e.logins.keys["novox"].Rotating != "" {
|
|
t.Fatal("the bus node began while ace still rotated")
|
|
}
|
|
// S48/AC1: an abandon drops the new login and its value, keeps the old hash and clears the rotating part.
|
|
if _, err := e.AbandonRotation("person.jochen", "ace"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := e.accounts.keys["node.ace--b"]; ok || e.accounts.keys["node.ace"].Rotating != nil || e.accounts.keys["node.ace"].Hash == "" ||
|
|
e.logins.keys["ace"].Rotating != "" || e.logins.keys["ace"].Login != "node.ace" {
|
|
t.Errorf("an abandon left ace as %+v / %+v", e.accounts.keys["node.ace"], e.logins.keys["ace"])
|
|
}
|
|
if _, held, _ := e.Store.Read("own/ace/mesh-host/node.ace--b"); held {
|
|
t.Error("an abandoned login's value remains")
|
|
}
|
|
e.RotationPass()
|
|
if e.logins.keys["novox"].Rotating == "" {
|
|
t.Fatal("the bus node did not begin once every other was done")
|
|
}
|
|
}
|
|
|
|
// said counts the events of a kind the vault said.
|
|
func said(p *published, event string) int {
|
|
p.mu.Lock()
|
|
defer p.mu.Unlock()
|
|
n := 0
|
|
for _, e := range p.events {
|
|
if e["event"] == event {
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
// 774/S48/AC2 (novox/hq ADR 0583 §1 insight): the key of a node that leaves the assignments is deleted, heard from the
|
|
// the assignments' watch or found by the minute pass; one that cannot be read deletes nothing.
|
|
func TestANodesLoginsKeyGoesWhenItLeavesTheAssignments(t *testing.T) {
|
|
e := newEnrolling(t)
|
|
for _, n := range []string{"g14", "gone", "gone2"} {
|
|
e.logins.keys[n] = NodeLogin{Node: n, Login: "node." + n}
|
|
}
|
|
e.NodeLeft("g14")
|
|
if _, ok := e.logins.keys["g14"]; !ok {
|
|
t.Error("g14 is placed, and its key was deleted")
|
|
}
|
|
e.NodeLeft("gone")
|
|
e.LoginsPass()
|
|
if len(e.logins.keys) != 1 || e.logins.keys["g14"].Node == "" {
|
|
t.Errorf("the keys after a node left and a pass: %+v", e.logins.keys)
|
|
}
|
|
e.logins.keys["gone"] = NodeLogin{Node: "gone"}
|
|
e.Assigner = AssignerReader{}
|
|
e.LoginsPass()
|
|
if _, ok := e.logins.keys["gone"]; !ok {
|
|
t.Error("an assignment that is not read deleted a key")
|
|
}
|
|
}
|