Files
mesh-catalog/modules/mesh-vault/cmd/mesh-vault/named_pair_test.go
T

45 lines
2.1 KiB
Go

package main
// A consumer's own login, kept by the vault as its pair row, is named on the consumer's plan entry when the
// controller hands the consumer's secrets file to its machine's client (issue 779): the client asks for the row, and
// the rule hands it to that consumer's machine alone.
import "testing"
func TestANamedPairEntryHandsTheConsumersMachineItsOwnLoginAndNoOtherConsumers(t *testing.T) {
const pg = "provision/novox/postgres-database"
mirror := assignments{
"novox.postgres": handedWith("novox", "postgres"),
"g14.gitea": handedWith("g14", "gitea", "postgres-database@novox/postgres=database+pair"),
"ace.umami": handedWith("ace", "umami", "postgres-database@novox/postgres#stats=database-stats+pair"),
"shanks.other": handedWith("shanks", "other", "postgres-database@novox/postgres=database+pair"),
}
v := pairVault(t, mirror)
if o := pass(t, v, pg); o.Outcome != PairMade {
t.Fatalf("a named pair entry held the provider back: %+v", o)
}
gitea, umami := "pair/novox/postgres-database/g14/gitea", "pair/novox/postgres-database/ace/umami/stats"
ofGitea, _, err := asks(v, "provisioner.g14", gitea)
if err != nil || ofGitea == "" {
t.Fatalf("the consumer's machine was refused its own login: %v", err)
}
if ofUmami, _, err := asks(v, "provisioner.ace", umami); err != nil || ofUmami == "" || ofUmami == ofGitea {
t.Fatalf("the second consumer's login: %q (%v)", ofUmami, err)
}
if _, _, err := asks(v, "provisioner.g14", umami); err == nil {
t.Fatal("a consumer's machine was handed another consumer's login")
}
if _, _, err := asks(v, "provisioner.shanks", gitea); err == nil {
t.Fatal("a machine was handed the login of a module that is not its own")
}
// A named entry of another form is still not a pair row's.
other := assignments{
"novox.postgres": handedWith("novox", "postgres"),
"g14.gitea": handedWith("g14", "gitea", "postgres-database@novox/postgres=database+issued"),
}
w := pairVault(t, other)
if _, _, err := asks(w, "provisioner.g14", gitea); err == nil {
t.Fatal("a named entry of the issued form was handed a pair row")
}
}