Skip to content

Commit

Permalink
Using the correct env prefix for env settings (gopasspw#2617)
Browse files Browse the repository at this point in the history
Signed-off-by: Yolan Romailler <[email protected]>
  • Loading branch information
AnomalRoil authored Jul 30, 2023
1 parent acc8049 commit 5b7e558
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var (
envPrefix = "GOPASS_CONFIG_"
envPrefix = "GOPASS_CONFIG"
systemConfig = "/etc/gopass/config"
)

Expand Down
44 changes: 44 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,47 @@ func TestConfig(t *testing.T) {
assert.Equal(t, "foo", String(ctx, "core.string"))
assert.Equal(t, 42, Int(ctx, "core.int"))
}

func TestEnvConfig(t *testing.T) {
envs := map[string]string{
"GOPASS_CONFIG_CONFIG_COUNT": "1",
"GOPASS_CONFIG_CONFIG_KEY_0": "core.autosync",
"GOPASS_CONFIG_CONFIG_VALUE_0": "false",
}
for k, v := range envs {
t.Setenv(k, v)
}

u := gptest.NewUnitTester(t)
assert.NotNil(t, u)

td := t.TempDir()
t.Setenv("GOPASS_HOMEDIR", td)

// this will write to the tempdir
cfg := New()

assert.Equal(t, "false", cfg.Get("core.autosync"))
}

func TestInvalidEnvConfig(t *testing.T) {
envs := map[string]string{
"GOPASS_CONFIG__CONFIG_COUNT": "1",
"GOPASS_CONFIG__CONFIG_KEY_0": "core.autosync",
"GOPASS_CONFIG__CONFIG_VALUE_0": "false",
}
for k, v := range envs {
t.Setenv(k, v)
}

u := gptest.NewUnitTester(t)
assert.NotNil(t, u)

td := t.TempDir()
t.Setenv("GOPASS_HOMEDIR", td)

// this will write to the tempdir
cfg := New()

assert.Equal(t, "true", cfg.Get("core.autosync"))
}

0 comments on commit 5b7e558

Please sign in to comment.