gitea: the Go bundles fall back to the token files in gitea's state directory by default
The binary is placed by hand on novox first, under gitea 0.1.316's composition, which hands the Go bundles neither MESH_GITEA_TOKEN_FILE nor MESH_GITEA_PACKAGES_TOKEN_FILE, nor any variable naming gitea's state directory. Without them the fallback reads token and packages-token in /var/lib/mesh/gitea/state (the manifest's runtime-state directory) and says at start that the path is the default; the manifest's variables still win when handed. Builds: design 47 H2 H-A-564 (hq 1b286366)
This commit is contained in:
@@ -93,13 +93,46 @@ func TestATokenComesFromTheVaultOrWhenTheVaultRefusesTheCallersAccountFromTheFil
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-564: the manifest's file for each account.
|
||||
func TestTheTokenFileOfAnAccountIsTheOneTheManifestNamesForIt(t *testing.T) {
|
||||
t.Setenv("MESH_GITEA_TOKEN_FILE", "/s/token")
|
||||
t.Setenv("MESH_GITEA_PACKAGES_TOKEN_FILE", "/s/packages-token")
|
||||
for account, want := range map[string]string{"mesh-tools": "/s/token", "mesh-packages": "/s/packages-token", "other": ""} {
|
||||
if got := TokenFile(account); got != want {
|
||||
t.Errorf("TokenFile(%s) = %q, want %q", account, got, want)
|
||||
}
|
||||
// H-A-564: the manifest's file for each account wins; without it, the file in gitea's runtime-state directory, said
|
||||
// as the default.
|
||||
func TestTheTokenFileOfAnAccountIsTheOneTheManifestNamesForItElseTheDefault(t *testing.T) {
|
||||
type file struct {
|
||||
path string
|
||||
byDefault bool
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
tools, packs string
|
||||
want map[string]file
|
||||
}{
|
||||
{"named by the manifest", "/s/token", "/s/packages-token", map[string]file{
|
||||
"mesh-tools": {"/s/token", false}, "mesh-packages": {"/s/packages-token", false}, "other": {"", false}}},
|
||||
{"named by none: the default", "", "", map[string]file{
|
||||
"mesh-tools": {"/var/lib/mesh/gitea/state/token", true},
|
||||
"mesh-packages": {"/var/lib/mesh/gitea/state/packages-token", true}, "other": {"", false}}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Setenv("MESH_GITEA_TOKEN_FILE", c.tools)
|
||||
t.Setenv("MESH_GITEA_PACKAGES_TOKEN_FILE", c.packs)
|
||||
for account, want := range c.want {
|
||||
if p, d := TokenFile(account); (file{p, d}) != want {
|
||||
t.Errorf("TokenFile(%s) = %q, %v; want %q, %v", account, p, d, want.path, want.byDefault)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// The start line says the default as such.
|
||||
dir := t.TempDir()
|
||||
p := filepath.Join(dir, "token")
|
||||
_ = os.WriteFile(p, []byte("t\n"), 0o600)
|
||||
_ = os.WriteFile(p+".scopes", []byte("read:user for mesh-tools\n"), 0o600)
|
||||
v, _ := NewVaultToken("mesh-tools", func(string, any) (json.RawMessage, error) {
|
||||
return nil, errors.New("novox.node-tools is no module's account")
|
||||
})
|
||||
v.File, v.FileByDefault = p, true
|
||||
var said string
|
||||
Start(func(f string, a ...any) { said = fmt.Sprintf(f, a...) }, v)
|
||||
if !strings.Contains(said, "the default path") {
|
||||
t.Fatalf("said %q, not that the file is the default", said)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user