package main import ( "encoding/json" "os" "path/filepath" "testing" "git.novox.be/novox/mesh-sdk/go/delivery" ) // Issue 1126 (ADR 0555 ยง3): the mesh's own certificate a composition carries is kept for the machine's record, and the // record's keys read it; a composition carrying none changes nothing. func TestTheAppliedAuthorityIsKeptForTheRecord(t *testing.T) { state := filepath.Join(t.TempDir(), "state", "state.json") res := func(id, content string) json.RawMessage { raw, _ := json.Marshal(map[string]any{"id": id, "type": "file", "path": "/etc/x", "content": content}) return raw } if err := keepAuthority(state, delivery.Composed{Resources: []json.RawMessage{res("web.conf", "x")}}); err != nil { t.Fatal(err) } if _, err := os.Stat(authorityPath(state)); !os.IsNotExist(err) { t.Fatalf("a composition with no authority kept one: %v", err) } if err := keepAuthority(state, delivery.Composed{Resources: []json.RawMessage{res("ca-trust.certificate-authority", "CA-1")}}); err != nil { t.Fatal(err) } if got := recordKeys(state)(); got.Authority != "CA-1" { t.Errorf("the record's keys read the authority %q", got.Authority) } }