75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// ADR 0394 §2: the holder runs as the tool runner's account, the node's operator account: it declares no
|
|
// runs-as and makes no account, claims node-files once on each node and serves every verb of the seat, keeps
|
|
// a state directory for the trash and the act log, and may tell the operator's channel of an override.
|
|
func TestTheHolderRunsAsTheToolRunnersAccount(t *testing.T) {
|
|
raw, err := os.ReadFile("../../module.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
RunsAs string `json:"runs-as"`
|
|
Invokes []string `json:"invokes"`
|
|
Claims []struct {
|
|
Name, Scope string
|
|
Serves []string
|
|
} `json:"claims"`
|
|
Resources []map[string]any `json:"resources"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m.RunsAs != "" {
|
|
t.Errorf("runs as %q", m.RunsAs)
|
|
}
|
|
if len(m.Claims) != 1 || m.Claims[0].Name != Seat || m.Claims[0].Scope != "node" {
|
|
t.Fatalf("claims %v", m.Claims)
|
|
}
|
|
served := map[string]bool{}
|
|
for _, v := range m.Claims[0].Serves {
|
|
served[v] = true
|
|
}
|
|
for _, tool := range tools(testFiles(t).Files) {
|
|
name := tool.Name[len(Seat)+1:]
|
|
if !served[name] {
|
|
t.Errorf("the manifest does not serve %s", name)
|
|
}
|
|
delete(served, name)
|
|
}
|
|
if len(served) > 0 {
|
|
t.Errorf("the manifest serves what the module does not: %v", served)
|
|
}
|
|
state := false
|
|
for _, r := range m.Resources {
|
|
if r["type"] == "user" {
|
|
t.Errorf("the module makes an account: %v", r)
|
|
}
|
|
if r["id"] == "state" && r["type"] == "directory" {
|
|
state = true
|
|
}
|
|
}
|
|
if !state {
|
|
t.Error("no state directory for the trash and the act log")
|
|
}
|
|
// 1597/AC7: the tell verb, and the object store's link verb that upload and download ask for.
|
|
if len(m.Invokes) != 2 || m.Invokes[0] != "seat:operator-channel.tell" || m.Invokes[1] != "seat:object-store.link" {
|
|
t.Errorf("invokes %v", m.Invokes)
|
|
}
|
|
for _, v := range []string{"upload", "download"} {
|
|
found := false
|
|
for _, s := range m.Claims[0].Serves {
|
|
found = found || s == v
|
|
}
|
|
if !found {
|
|
t.Errorf("1597/AC7: the manifest does not serve %s", v)
|
|
}
|
|
}
|
|
}
|