Files
mesh-catalog/modules/mesh-provisioner-client/cmd/mesh-provisioner-client/whole_plan_test.go
T

44 lines
2.4 KiB
Go

package main
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
// A plan provision carries everything the controller's PlanProvision writes (issue 954): what the consumer
// contributes, where the provider is and who the consumer is at its end (issue 788), the names the mesh calls it
// (issue 792), for a software-issued offer, the tool the vault asks (issue 928), and what the consumer contributes as
// one opaque payload, carried unread (issue 774: route-proxy serves its routes from it, read with its own contract).
// The client still refuses a field nobody writes, but never looks inside the payload.
func TestAPlanProvisionWithEveryFieldTheControllerWritesIsRead(t *testing.T) {
p, err := json.Marshal(contributor(t, "shell:zsh:normal", "alias nox=mesh-cli"))
if err != nil {
t.Fatal(err)
}
provision := `"provisions":[{"provision":"route","local":"web","provider":"novox","provider-module":"route-proxy",` +
`"credential-form":"pair","contributes":{"label":"git"},"at":"10.10.0.1","from":"novox","as":"gitea",` +
`"names":{"name-web":"git.example.org"},` +
`"contributed":{"v":1,"at":"10.10.0.2","each":[{"local":"web","values":{"name":"git.example.org","anything":1}}]}},` +
`{"name":"gitea-read","provision":"gitea-read","provider":"novox",` +
`"provider-module":"gitea","credential-form":"issued","credential-tool":"gitea_agent_token",` +
`"path":"/var/lib/claude-code/gitea-read.secret"}],"items":`
value := fmt.Sprintf(`{"node":"g14","module":"mesh-cli","provisioning":%s}`,
strings.Replace(string(p), `"items":`, provision, 1))
_, got, err := planOf("g14", "g14.mesh-cli", []byte(value))
if err != nil {
t.Fatalf("a plan with the controller's fields is refused: %v", err)
}
if len(got.Provisions) != 2 || got.Provisions[0].At != "10.10.0.1" || got.Provisions[0].From != "novox" ||
got.Provisions[0].As != "gitea" || got.Provisions[0].Names["name-web"] != "git.example.org" ||
got.Provisions[1].CredentialTool != "gitea_agent_token" || string(got.Provisions[0].Contributed) !=
`{"v":1,"at":"10.10.0.2","each":[{"local":"web","values":{"name":"git.example.org","anything":1}}]}` {
t.Fatalf("the plan's provisions read as %+v", got.Provisions)
}
spoilt := strings.Replace(value, `"at":`, `"surprise":1,"at":`, 1)
if _, _, err := planOf("g14", "g14.mesh-cli", []byte(spoilt)); err == nil {
t.Fatalf("a provision with a field nobody writes is read: %s", spoilt)
}
}