Merge branch 'feat/r4g-assigner' into feat/r4g
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
@@ -12,11 +13,13 @@ import (
|
||||
|
||||
"github.com/novox/mesh-controller/internal/broker"
|
||||
"github.com/novox/mesh-controller/internal/inventory"
|
||||
"github.com/novox/mesh-controller/internal/link"
|
||||
"github.com/novox/mesh-controller/internal/testbus"
|
||||
)
|
||||
|
||||
// 1394/AC1 of C9 (ADR 0528 clause 2): when the controller has issued mesh-x's credential for fingerprint F (mesh-x
|
||||
// registered at a build of F, its account minted, the bus's user list sent), then grants.mesh-x.F exists on the bus,
|
||||
// registered at a build of F, its account minted, the bus's machine sent its declaration with the user list, through
|
||||
// overTheBus.declare as a push sends it), then grants.mesh-x.F exists on the bus,
|
||||
// and a second pass writes it again as nothing new.
|
||||
func TestTheGrantOfAnIssuedCredentialIsOnTheBus(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
@@ -50,7 +53,22 @@ func TestTheGrantOfAnIssuedCredentialIsOnTheBus(t *testing.T) {
|
||||
if err := broker.OnConn(conn).EnsureControllerBuckets(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
grantsIssued(ctx, inv, js, "")
|
||||
// The live path: a send of the bus's machine's declaration carrying the user list (overTheBus.declare), which records
|
||||
// the list sent and then writes the grants it issued.
|
||||
legacy, err := conn.JetStream()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = js.DeleteStream(ctx, "GRANTS_DECLARED")
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "GRANTS_DECLARED", Subjects: []string{link.DeclareSubject("anchor")}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = js.DeleteStream(context.Background(), "GRANTS_DECLARED") })
|
||||
send := overTheBus{open: open, server: link.SendingOn(link.OverNATS{Conn: conn, JS: legacy}), signer: aSignerOfZeros{}}
|
||||
ready := readyNode{node: "anchor", declared: sendable{BusUsers: "the user list the bus's machine is sent"}}
|
||||
if _, err := send.declare(ctx, ready, []byte(`{}`)); err != nil {
|
||||
t.Fatalf("the send of the bus's machine: %v", err)
|
||||
}
|
||||
kv, err := js.KeyValue(ctx, broker.GrantsBucket)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -64,7 +82,9 @@ func TestTheGrantOfAnIssuedCredentialIsOnTheBus(t *testing.T) {
|
||||
if err != nil || len(g.Accounts) != 1 || g.Accounts[0] != user {
|
||||
t.Fatalf("the grant reads %+v, %v; want the account %s", g, err, user)
|
||||
}
|
||||
grantsIssued(ctx, inv, js, "")
|
||||
if _, err := send.declare(ctx, ready, []byte(`{}`)); err != nil {
|
||||
t.Fatalf("the second send: %v", err)
|
||||
}
|
||||
if again, _ := kv.Get(ctx, key); again.Revision() != e.Revision() {
|
||||
t.Errorf("a second pass wrote the grant again (revision %d, was %d)", again.Revision(), e.Revision())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user