49 lines
2.1 KiB
Go
49 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// A rotation asked through the seat carries why to the command, which records it in the hand-act
|
|
// log (novox/hq ADR 0228); and with a provision too, since the vault asks why of every rotation of a
|
|
// credential it holds (issue 767).
|
|
func TestARotationThroughTheSeatCarriesWhy(t *testing.T) {
|
|
argv, err := argvFor("rotate", map[string]any{"node": "anchor", "module": "letta",
|
|
"secret": "server-password", "why": "leaked into logs", "cause": "leaked"})
|
|
if err != nil || strings.Join(argv, " ") != "secret rotate anchor letta server-password --why leaked into logs --cause leaked" {
|
|
t.Fatalf("%v %v", argv, err)
|
|
}
|
|
argv, err = argvFor("rotate", map[string]any{"node": "anchor", "module": "letta", "secret": "server-password"})
|
|
if err != nil || strings.Join(argv, " ") != "secret rotate anchor letta server-password" {
|
|
t.Fatalf("without why: %v %v", argv, err)
|
|
}
|
|
argv, err = argvFor("rotate", map[string]any{"provision": "postgres-database", "consumer": "ace", "why": "leaked",
|
|
"cause": "leaked"})
|
|
if err != nil || strings.Join(argv, " ") != "rotate postgres-database --consumer ace --why leaked --cause leaked" {
|
|
t.Fatalf("why beside a provision: %v %v", argv, err)
|
|
}
|
|
}
|
|
|
|
// Only a clean account of a declaration is a good start; a refusal, a failure or a bare word that
|
|
// the machine is there is not (novox/hq ADR 0228).
|
|
func TestAGoodStartIsACleanAccountOfADeclaration(t *testing.T) {
|
|
for _, c := range []struct {
|
|
report link.Report
|
|
good bool
|
|
}{
|
|
{link.Report{Node: "anchor", Declared: "d", Applied: []string{"container:letta"}}, true},
|
|
{link.Report{Node: "anchor", Declared: "d", Applied: []string{}}, true},
|
|
{link.Report{Node: "anchor"}, false},
|
|
{link.Report{Node: "anchor", Applied: []string{"x"}}, false},
|
|
{link.Report{Node: "anchor", Declared: "d", Applied: []string{"x"}, Failed: map[string]string{"y": "no"}}, false},
|
|
{link.Report{Node: "anchor", Declared: "d", Refused: "older"}, false},
|
|
} {
|
|
if got := startedWell(c.report); got != c.good {
|
|
t.Errorf("%+v: a good start = %v, want %v", c.report, got, c.good)
|
|
}
|
|
}
|
|
}
|