package main // 1426/AC4: the trusted setting callers, per shape, and an unproven caller. import "testing" func TestCallersAllowsEachShape(t *testing.T) { c := Callers{"mesh-mail-web", "novox.mesh-knowledge", "person.jochen"} cases := []struct { caller string want bool }{ {"mesh-mail-web", true}, // a bare module name {"shanks.mesh-mail-web", true}, // ... on any machine {"novox.mesh-knowledge", true}, // exactly . {"shanks.mesh-knowledge", false}, // ... but not on another machine {"person.jochen", true}, // exactly person. {"person.someoneelse", false}, // ... but not another person {"mesh-mail-notifier", false}, // not named at all {"", false}, {Unproven, false}, // 1426/AC4: unproven never } for _, c2 := range cases { if got := c.Allows(c2.caller); got != c2.want { t.Errorf("Allows(%q) = %v, want %v", c2.caller, got, c2.want) } } } // 1426/AC4: a wildcard entry is no entry (mirrors mesh-mail's own Grants.Allows). func TestCallersWildcardEntryIsNoEntry(t *testing.T) { c := Callers{"*", "mesh-mail.>"} if c.Allows("anything") { t.Fatal("a wildcard entry granted a caller") } } func TestParseCallersDefault(t *testing.T) { c, err := ParseCallers([]byte(`{"callers": ["mesh-mail-web"]}`)) if err != nil { t.Fatal(err) } if len(c) != 1 || c[0] != "mesh-mail-web" { t.Fatalf("callers = %v", c) } } func TestReadCallersEmptyPath(t *testing.T) { if _, err := ReadCallers(""); err == nil { t.Fatal("no error reading callers with no path") } }