|
|
|
@@ -9,7 +9,9 @@ import (
|
|
|
|
|
"sync"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/provider"
|
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/provisions"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// bucketBus is the helper's bus over in-memory buckets.
|
|
|
|
@@ -44,33 +46,60 @@ func (b *bucketBus) Delete(_ context.Context, bucket, key string) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A consumer of a route is answered with the names its plan's entry carries, and nothing of a credential (issue 792):
|
|
|
|
|
// the entry's values are the controller's composition, copied unchanged, and no vault is asked.
|
|
|
|
|
// A consumer of a route is answered with the names its plan's entry carries, and nothing of a credential (issue 792),
|
|
|
|
|
// from the seat mesh-provisioner's plans and keys (novox/hq ADR 0570 clause 2), never the controller's assignments: a
|
|
|
|
|
// module not handed whose route the seat keys (grafana, issue 774) has a plan of provisions alone, and a helper that
|
|
|
|
|
// read only the assignments left its key asked for good, so the assigner withheld every new build of 38 such modules.
|
|
|
|
|
func TestAConsumerOfARouteIsToldItsNamesFromItsPlanEntry(t *testing.T) {
|
|
|
|
|
bus := &bucketBus{buckets: map[string]map[string][]byte{}}
|
|
|
|
|
plan, _ := json.Marshal(map[string]any{"node": "g14", "module": "gitea", "provisioning": map[string]any{
|
|
|
|
|
"provisions": []any{map[string]any{"provision": ProvisionName, "provider": "novox",
|
|
|
|
|
"provider-module": ModuleName, "at": "10.7.0.1", "from": "novox", "as": "mesh_g14_gitea",
|
|
|
|
|
"names": map[string]any{"name": "git.example.org", "internal-name": "git.novox.internal",
|
|
|
|
|
"name-web": "git.example.org"}}}}})
|
|
|
|
|
if err := bus.Put(context.Background(), provider.AssignmentsBucket, "g14.gitea", plan); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
for module, names := range map[string]map[string]string{
|
|
|
|
|
"gitea": {"name": "git.example.org", "internal-name": "git.novox.internal", "name-web": "git.example.org"},
|
|
|
|
|
"grafana": {"name": "grafana.example.org"},
|
|
|
|
|
} {
|
|
|
|
|
plan, err := provisions.EncodePlan(provisions.Plan{Node: "g14", Module: module, Plan: catalogue.Plan{
|
|
|
|
|
Provisions: []catalogue.PlanProvision{{Provision: ProvisionName, Provider: "novox", ProviderModule: ModuleName,
|
|
|
|
|
At: "10.7.0.1", From: "novox", As: "mesh_g14_" + module, Names: names}}}})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
key := "g14." + module
|
|
|
|
|
if err := bus.Put(context.Background(), provisions.PlansBucket, key, plan); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
asked, err := json.Marshal(provisions.Provision{V: provisions.Version, Provision: ProvisionName,
|
|
|
|
|
Consumer: provisions.End{Node: "g14", Module: module}, Provider: provisions.End{Node: "novox", Module: ModuleName},
|
|
|
|
|
State: provisions.Asked})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if err := bus.Put(context.Background(), provisions.ProvisionsBucket, key+"."+ProvisionName, asked); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
p := newProvider("novox", bus, t.Logf)
|
|
|
|
|
out, err := p.Pass(context.Background())
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if len(out) != 1 || out[0].Status != provider.Answered {
|
|
|
|
|
if len(out) != 2 || out[0].Status != provider.Answered || out[1].Status != provider.Answered {
|
|
|
|
|
t.Fatalf("the pass did %+v", out)
|
|
|
|
|
}
|
|
|
|
|
var e provider.Entry
|
|
|
|
|
if err := json.Unmarshal(bus.buckets[provider.BucketOf(ModuleName)]["g14.gitea.route"], &e); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if e.Values["name-web"] != "git.example.org" || e.Values["name"] != "git.example.org" ||
|
|
|
|
|
e.Values["internal-name"] != "git.novox.internal" || e.VaultName != "" || e.User != "" || e.Refused != "" {
|
|
|
|
|
t.Fatalf("the entry is %+v", e)
|
|
|
|
|
for key, want := range map[string]map[string]string{
|
|
|
|
|
"g14.gitea.route": {"name-web": "git.example.org", "name": "git.example.org", "internal-name": "git.novox.internal"},
|
|
|
|
|
"g14.grafana.route": {"name": "grafana.example.org"},
|
|
|
|
|
} {
|
|
|
|
|
var e provider.Entry
|
|
|
|
|
if err := json.Unmarshal(bus.buckets[provider.BucketOf(ModuleName)][key], &e); err != nil {
|
|
|
|
|
t.Fatalf("%s: %v", key, err)
|
|
|
|
|
}
|
|
|
|
|
for k, v := range want {
|
|
|
|
|
if e.Values[k] != v {
|
|
|
|
|
t.Errorf("%s says %s %v, want %s", key, k, e.Values[k], v)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if e.State != provisions.Provided || e.VaultName != "" || e.User != "" || e.Refused != "" {
|
|
|
|
|
t.Errorf("the entry %s is %+v", key, e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|