Skip to content

Commit

Permalink
update integration tests to pass in the existing environment. necessa…
Browse files Browse the repository at this point in the history
…ry for DBUS secret-service in some scenarios
  • Loading branch information
joemiller committed Jun 3, 2021
1 parent aca9e24 commit 68914db
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ func TestMain(m *testing.M) {
}
}

// getEnv returns a copy of the process's current environment with any VAULT_*
// env vars removed. This function exists because we need a copy of the processes
// environment on certain platforms. For example, to run these tests on Linux
// we need a copy of the DBUS_SESSION_BUS_ADDRESS env var in order to access the
// gnome keyring.
func getEnv() []string {
env := os.Environ()
newEnv := []string{}
for _, i := range env {
if !strings.HasPrefix(i, "VAULT_") {
newEnv = append(newEnv, i)
}
}
return newEnv
}

// execCmd executes the vault-token-helper with the provides args and returns
// stdout, stderr, and error.
// execCommand("list", "--debug") would be similar to executing the compiled program "vault-token-helper list --debug"
Expand All @@ -47,7 +63,7 @@ func TestGetCmd_MissingVAULT_ADDR(t *testing.T) {
}

stdin := ""
env := []string{}
env := getEnv()
stdout, stderr, err := execCmd(env, stdin, "get")

assert.NotNil(t, err) // vault-token-helper should exit non-zero when VAULT_ADDR is not set
Expand All @@ -62,7 +78,8 @@ func TestGetCmd_NoMatch(t *testing.T) {
}

stdin := ""
env := []string{"VAULT_ADDR=https://foo.bar:8200"}
env := getEnv()
env = append(env, "VAULT_ADDR=https://foo.bar:8200")
stdout, stderr, err := execCmd(env, stdin, "get")

assert.Nil(t, err) // vault-token-helper should exit 0 if no token is stored for the $VAULT_ADDR
Expand All @@ -77,7 +94,8 @@ func TestGetCmd_Match(t *testing.T) {
}

stdin := ""
env := []string{"VAULT_ADDR=https://foo.bar:8200"}
env := getEnv()
env = append(env, "VAULT_ADDR=https://foo.bar:8200")
stdout, stderr, err := execCmd(env, stdin, "get")
assert.Nil(t, err) // vault-token-helper should exit 0 if no token is stored for the $VAULT_ADDR
assert.Equal(t, "", stdout)
Expand Down

0 comments on commit 68914db

Please sign in to comment.