Files
mesh-host/packaging/operator_keys_test.go
T
jschoubben dc3765bb7c Ask the packet filter's holder allowed at every compose of the filter
The node-engine stays the one renderer of the filter file: at each compose of
a converged node's filter it asks the holder of node-packet-filter its verb
allowed within the setting compose-ask-bound (10 s) and renders the answer.
When allowed does not answer, or answers what is not its answer, no filter file
is composed: the one loaded is kept as it runs, the holder's module is not held
(an old holder must stay replaceable), and the part withheld is said once in
the journal until an answer comes between. The node hears allowances-changed
on its own node's subject and composes again. The manifest invokes
seat:node-packet-filter.allowed and consumes node-packet-filter.allowances-changed.

Builds: design 08 control-verbs §1, §3, §4, §5, §7, §8; ADR 0683; H-A-305, H-A-307 (1), (2), H-A-314 (3), (5), (7), H-A-315 (2), (6), H-A-321
2026-11-21 22:32:36 +01:00

139 lines
7.6 KiB
Go

package packaging_test
import (
"encoding/json"
"os"
"reflect"
"slices"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
)
// The operator's public keys reach every node as a file beside the state file, fed by a setting of the node-engine
// (novox/hq ADR 0539 clauses 3 and 11): the node agent reads it, and a composition made by hand is applied only when one
// of these keys signed it. The setting may be empty, and then no operator key is trusted.
func TestTheManifestDeclaresTheOperatorKeysFileFedByASetting(t *testing.T) {
raw, err := os.ReadFile("../module.json")
if err != nil {
t.Fatal(err)
}
if _, err := catalogue.Decode(raw); err != nil {
t.Fatalf("the manifest no longer parses: %v", err)
}
var m struct {
Config map[string]struct {
Type string `json:"type"`
Default any `json:"default"`
} `json:"config"`
Resources []struct {
ID string `json:"id"`
Type string `json:"type"`
Path string `json:"path"`
Mode string `json:"mode"`
Content string `json:"content"`
} `json:"resources"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
setting, ok := m.Config["operator-signers"]
if !ok || setting.Type != "string" || setting.Default != "" {
t.Fatalf("the setting operator-signers is %+v: a string that may be empty", setting)
}
for _, r := range m.Resources {
if r.ID != "operator-keys" {
continue
}
if r.Type != "file" || r.Path != "/var/lib/mesh-host/operator-keys" || r.Mode != "0644" ||
!strings.Contains(r.Content, "${config:operator-signers}") {
t.Fatalf("the file is %+v: it is declared beside the state file, 0644, its content the setting", r)
}
return
}
t.Fatal("module.json declares no operator-keys file")
}
// The node agent hears the end of a backup on the event of node-backup's holder, so the manifest consumes it.
func TestTheManifestConsumesTheBackupEvent(t *testing.T) {
raw, err := os.ReadFile("../module.json")
if err != nil {
t.Fatal(err)
}
var m struct {
Consumes []string `json:"consumes"`
Uses []string `json:"uses"`
Invokes []any `json:"invokes"` // a verb, or the long form {verb, fields} (§558)
Config map[string]struct {
Default any `json:"default"`
} `json:"config"`
}
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
// Design 47 G §630, §633, A-77: the recovery module's three verbs it asks, and its bound as a config key of 90.
// §635, §558, §617: it invokes `withheld` and names no `uses`; the catalog's revision in the long form with the field none-yet.
if len(m.Uses) != 0 {
t.Errorf("uses is %v, want none: the invoke of seat:mesh-grants.withheld is the edge (§635, A-307)", m.Uses)
}
for _, v := range []any{"seat:mesh-recovery.kept-points", "seat:mesh-recovery.restore-kept", "seat:mesh-recovery.snapshot-kept",
"seat:mesh-grants.withheld", "seat:mesh-catalog.module", map[string]any{"verb": "seat:mesh-catalog.revision", "fields": []any{"none-yet"}}} {
if !slices.ContainsFunc(m.Invokes, func(have any) bool { return reflect.DeepEqual(have, v) }) {
t.Errorf("invokes %v lacks %v", m.Invokes, v)
}
}
if !strings.Contains(string(raw), `"content": "${config:view-waits-minutes}\n"`) || m.Config["view-waits-minutes"].Default != float64(5) {
t.Errorf("module.json declares no file with the content ${config:view-waits-minutes} or its default is not 5 (§633)")
}
if !strings.Contains(string(raw), `"content": "${config:recovery-wait-minutes}\n"`) {
t.Errorf("module.json declares no file with the content ${config:recovery-wait-minutes} (design 47 G A-112)")
}
if !strings.Contains(string(raw), `"content": "${config:entry-asks}\n"`) || m.Config["entry-asks"].Default != float64(5) {
t.Errorf("module.json declares no file with the content ${config:entry-asks} or its default is not 5 (design 47 H, H-A-60)")
}
if !strings.Contains(string(raw), `"content": "${config:resolve-again-minutes}\n"`) || m.Config["resolve-again-minutes"].Default != float64(1) {
t.Errorf("module.json declares no file with the content ${config:resolve-again-minutes} or its default is not 1 (design 47 H, H-A-146)")
}
// Design 08 control-verbs §1, H-A-314 (3), (5): the compose-ask bound, ten seconds by default, fed into its file; allowed invoked.
if !strings.Contains(string(raw), `"content": "${config:compose-ask-bound}\n"`) || m.Config["compose-ask-bound"].Default != float64(10) ||
!strings.Contains(string(raw), `"seat:node-packet-filter.allowed"`) {
t.Errorf("module.json declares no file with the content ${config:compose-ask-bound}, its default is not 10, or it invokes no seat:node-packet-filter.allowed")
}
if m.Config["recovery-wait-minutes"].Default != float64(90) {
t.Errorf("config recovery-wait-minutes is %+v, want default 90", m.Config["recovery-wait-minutes"])
}
// The backup event, the status view's settled, and the two events of the seat that serves the seat list (ADR 0636 §4), the keeper's ask (design 47 G §387), the seat's running (§199) and the builder's build ends (A-293).
if want := []string{"mesh-catalog.catalog-revision", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-builder.build.ended.**", "mesh-delivery-view.settled", "mesh-recovery.ended", "mesh-recovery.restored", "node-engine.running", "node-packet-filter.allowances-changed", "restic.backed-up"}; !slices.Equal(m.Consumes, want) {
t.Fatalf("consumes %v, want %v", m.Consumes, want)
}
// 774: the acts bucket mesh-host_acts is not declared as state for now: a declared state of a module with no account
// of its own is carried by every node's tool runner, which would be a second writer of the engine's own keys and
// has the grants part refuse the whole user list (2026-10-30). It comes back once the runtime never carries the engine.
parsed, err := catalogue.Decode(raw)
if err != nil {
t.Fatal(err)
}
// ADR 0614 §4: the node-engine's own manifest uses only words every running engine reads (the baseline, what an engine
// stating none is read as), so its new build is never held for a word only it reads.
if needs, err := catalogue.ManifestNeeds(raw); err != nil || len(needs) == 0 {
t.Fatalf("the manifest's needs: %v, %v", needs, err)
} else if missing := catalogue.MissingManifestReads(needs, nil); len(missing) != 0 {
t.Errorf("the manifest needs %v, which an engine stating nothing does not read: its new build would be held", missing)
}
// 774 (the alert table): the state health, one key per node, the node's own health report, kept until
// written again (no TTL: a node that stops writing keeps its last word, which the watchman reads with its time).
// ADR 0577 clause 1: and the state data, one key per module placed on the node that declares data items, kept until
// the module leaves the node; created by the grants part from this manifest as health is.
// ADR 0565 clause 6: and the state packages, one key per node, its compositions' declared packages, read by pacman.
// ADR 0564 §2, ADR 0636 §1: and the state findings, the node's finding that it waits for the seat list (no TTL: the
// finding stays until the first full read deletes its key).
// Design 47 G A-92: and the state bounds, each key a wait's bound with its own lifetime (packaging/bounds_state_test.go).
if len(parsed.State) != 5 || parsed.State[0].Name != "health" || parsed.State[0].TTLSeconds != 0 ||
parsed.State[1].Name != "findings" || parsed.State[1].TTLSeconds != 0 ||
parsed.State[2].Name != "data" || parsed.State[2].TTLSeconds != 0 || parsed.State[3].Name != "packages" ||
parsed.State[3].TTLSeconds != 0 || parsed.State[4].Name != "bounds" {
t.Fatalf("the manifest declares the state %+v", parsed.State)
}
}