mesh/delivery merged: source.main moved to novox/mesh-delivery@7c0492b06c37
mesh/delivery-group group feature/1979-zfs-owns-zfs merged: every member is merged
mesh/check being carried to ad7e58091801 on 7c0492b06c37 | from 7221a1e5cd7f, mesh-catalog 117f933dacf0, mesh-host 0193949efe9f, mesh-sdk e42b9491c931…
Builds: design 42 zfs-owns-zfs §25, §26, A-37, A-38
51 lines
2.0 KiB
Go
51 lines
2.0 KiB
Go
package grants
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"mesh-grants/internal/buscompose"
|
|
)
|
|
|
|
// Design 42 zfs-owns-zfs, A-38 (G1): a process whose bus names an event of the events stream its module asks for in
|
|
// `requires` is granted publish on that stream's subjects, and one naming a state asked for there the reads and writes of
|
|
// its bucket; a name in the module's own `emits` is granted as before, and what its bus does not name is granted nothing.
|
|
func TestAProcessBusNamesWhatItsModuleAsksFor(t *testing.T) {
|
|
var m catalogue.Manifest
|
|
raw := `{"module":"zfs","version":"1","emits":["scrub.requested"],"requires":[` +
|
|
`{"name":"events","storage":"stream","template":"events","options":{"events":["config.applied","config.refused"]}},` +
|
|
`{"name":"applied","storage":"key-value","template":"state"},` +
|
|
`{"name":"findings","storage":"key-value","template":"state"}],"resources":[` +
|
|
`{"id":"zfs-keeper","type":"process","run":["./zfs"],"user":"zfs-keeper","bus":` +
|
|
`{"emits":["config.applied","scrub.requested"],"state":["applied"]}}]}`
|
|
if err := json.Unmarshal([]byte(raw), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
users, err := buscompose.Users(buscompose.Records{Nodes: []string{"ace"}, Assigned: map[string][]buscompose.Declared{
|
|
"ace": {{Module: "zfs", Emits: m.EmitsAll(), Processes: processesOf(m)}}}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var perms buscompose.Permissions
|
|
for _, u := range users {
|
|
if u.Kind == buscompose.KindProcess {
|
|
if perms, err = buscompose.PermissionsFor(u); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
for subject, want := range map[string]bool{
|
|
"mesh.bus.zfs.events.config.applied": true,
|
|
"mesh.mod.zfs.event.config.applied": false,
|
|
"mesh.mod.zfs.event.scrub.requested": true,
|
|
"$KV.zfs_applied.pool.tank": true,
|
|
"$KV.zfs_findings.pool.tank": false,
|
|
"mesh.bus.zfs.findings.config.applied": false,
|
|
} {
|
|
if got := buscompose.MayPublish(perms, subject); got != want {
|
|
t.Errorf("publish on %s: %v, want %v", subject, got, want)
|
|
}
|
|
}
|
|
}
|