Files
mesh-controller/internal/link/seat_as_test.go
T
mesh-tools 97a2d841c7 Land feature 57's controller work on its release branch
The controller plans config, templates and moved providers' provisions,
hands bus accounts to the vault and judges the new manifest words, on the
feature's SDK and node-engine validator (feature 57, config and provisioning).
2026-10-15 21:27:33 +00:00

48 lines
1.6 KiB
Go

package link
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
"github.com/nats-io/nats.go"
"github.com/novox/mesh-controller/internal/broker"
"github.com/novox/mesh-controller/internal/testbus"
)
// A mesh seat's verb asked in the caller's own name goes on the subject that names its caller (novox/hq issue
// 365), so the holder knows who asks from the subject alone: how the vault takes a value from the controller
// and nobody else (design 57's V2, issue 675).
func TestAMeshSeatsVerbIsAskedInTheCallersOwnName(t *testing.T) {
conn, err := nats.Connect(testbus.URL(t))
if err != nil {
t.Fatal(err)
}
defer conn.Close()
heard := make(chan string, 1)
sub, err := conn.Subscribe(broker.CalledPattern(SeatToolSubject("mesh-vault", "accept")), func(m *nats.Msg) {
heard <- m.Subject
raw, _ := json.Marshal(Answer{Result: json.RawMessage(`{"call":"c1"}`)})
_ = m.Respond(raw)
})
if err != nil {
t.Fatal(err)
}
defer sub.Unsubscribe()
answer, err := AskMeshSeatToolAs(context.Background(), conn, broker.ControllerName, "mesh-vault", "accept",
map[string]any{"provider": "novox", "provision": "postgres"}, 5*time.Second)
if err != nil || string(answer.Result) != `{"call":"c1"}` {
t.Fatalf("%+v %v", answer, err)
}
subject := <-heard
if subject != "mesh.seat.mesh-vault.call.accept.controller" || !strings.HasSuffix(subject, "."+broker.ControllerName) {
t.Errorf("asked on %s", subject)
}
if _, err := AskMeshSeatToolAs(context.Background(), conn, "not a user!", "mesh-vault", "accept", nil, time.Second); err == nil {
t.Error("a caller that is no bus user was asked in")
}
}