The fifteen desktop modules' tools tests failed on every manifest with "json: unknown field class": a test helper copied into each module decoded module.json into its own struct, refusing unknown fields. Manifest strictness is the catalog check's alone, and the manifest's form is a contract read through mesh-sdk's catalogue package, so the copied `manifest` struct and its reader go from the fifteen desktop modules and pacman; each test reads module.json with catalogue.Decode and asserts only the module's own promises (claims, files, tools) on catalogue.Manifest. Builds: design 47 H2 H-A-498, H-A-498 addendum
115 lines
4.0 KiB
Go
115 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// gnome-keyring's shape (novox/hq ADR 0208, ADR 0102): it claims node-secret-service, writes its PAM
|
|
// lines into the login and passwd stacks as marked blocks (never over the files), and starts no daemon
|
|
// of its own: PAM and D-Bus do.
|
|
|
|
func TestItClaimsTheSecretServiceSeat(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
if m.Module != "gnome-keyring" || m.DefinesSeats != nil || m.Requires != nil {
|
|
t.Fatalf("module %q, seats %v, requires %v", m.Module, m.DefinesSeats, m.Requires)
|
|
}
|
|
if !reflect.DeepEqual(m.Claims, []catalogue.Claim{{Name: "node-secret-service", Scope: "node"}}) {
|
|
t.Fatalf("claims: %+v", m.Claims)
|
|
}
|
|
if present, absent := packages(m); !reflect.DeepEqual(present, []string{"gnome-keyring", "libsecret", "seahorse"}) || absent != nil {
|
|
t.Fatalf("packages: %v, absent %v", present, absent)
|
|
}
|
|
}
|
|
|
|
func TestThePAMLinesAreBlocksWrittenIntoTheStacks(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
for id, want := range map[string]struct{ path, source string }{
|
|
"pam-login": {"/etc/pam.d/login", "files/pam/login"},
|
|
"pam-passwd": {"/etc/pam.d/passwd", "files/pam/passwd"},
|
|
} {
|
|
fromTemplate(t, m, id, want.source)
|
|
r := resource(t, m, id)
|
|
if r["path"] != want.path || r["into"] != "block" || r["at"] != "end" || r["owner"] != nil {
|
|
t.Errorf("%s: %v", id, r)
|
|
}
|
|
}
|
|
login := templateText(t, m, "pam-login")
|
|
if !strings.Contains(login, "\nauth optional pam_gnome_keyring.so\n") ||
|
|
!strings.Contains(login, "\nsession optional pam_gnome_keyring.so auto_start\n") {
|
|
t.Fatalf("%s", login)
|
|
}
|
|
}
|
|
|
|
func TestItStartsNoDaemonAndOnlyNamesTheAgentsSocket(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
if len(shell(t, m)) != 1 || shell(t, m)[0].For != "xinitrc" || shell(t, m)[0].Slot != "first" {
|
|
t.Fatalf("%+v", shell(t, m))
|
|
}
|
|
code := shell(t, m)[0].Code
|
|
if strings.Contains(code, "gnome-keyring-daemon") || strings.Contains(code, "--unlock") ||
|
|
!strings.Contains(code, `SSH_AUTH_SOCK="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/gcr/ssh"`) {
|
|
t.Fatalf("%q", code)
|
|
}
|
|
if environmentOf(t, m) != nil {
|
|
t.Fatal("SSH_AUTH_SOCK needs the runtime directory, which ADR 0203 forbids in a value; it is not an environment contribution yet")
|
|
}
|
|
}
|
|
|
|
func TestTheToolsAgreeWithTheManifest(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
checkTheToolsAgree(t, m)
|
|
checkNoSecretsOrInstallationNames(t)
|
|
}
|
|
|
|
// No file resource carries its text inline (novox/hq ADR 0349 §2).
|
|
func TestEveryFileTakesItsTextFromATemplate(t *testing.T) {
|
|
manifestJSON, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside.
|
|
m, err := catalogue.Decode(manifestJSON)
|
|
if err != nil {
|
|
t.Fatalf("module.json: %v", err)
|
|
}
|
|
everyFileIsATemplate(t, m)
|
|
}
|