diff --git a/pkg/auth/vault/approle_test.go b/pkg/auth/vault/approle_test.go index 9937253f..c86db654 100644 --- a/pkg/auth/vault/approle_test.go +++ b/pkg/auth/vault/approle_test.go @@ -20,7 +20,7 @@ func TestAppRoleLogin(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - cachedToken, err := utils.ReadExistingToken() + cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } @@ -30,7 +30,7 @@ func TestAppRoleLogin(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - newCachedToken, err := utils.ReadExistingToken() + newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } diff --git a/pkg/auth/vault/github_test.go b/pkg/auth/vault/github_test.go index ecedb197..a1a6017a 100644 --- a/pkg/auth/vault/github_test.go +++ b/pkg/auth/vault/github_test.go @@ -21,7 +21,7 @@ func TestGithubLogin(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - cachedToken, err := utils.ReadExistingToken() + cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } @@ -31,7 +31,7 @@ func TestGithubLogin(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - newCachedToken, err := utils.ReadExistingToken() + newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } diff --git a/pkg/auth/vault/kubernetes_test.go b/pkg/auth/vault/kubernetes_test.go index 77396dd5..bad173af 100644 --- a/pkg/auth/vault/kubernetes_test.go +++ b/pkg/auth/vault/kubernetes_test.go @@ -53,7 +53,7 @@ func TestKubernetesAuth(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - cachedToken, err := utils.ReadExistingToken() + cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } @@ -63,7 +63,7 @@ func TestKubernetesAuth(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - newCachedToken, err := utils.ReadExistingToken() + newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } diff --git a/pkg/auth/vault/userpass_test.go b/pkg/auth/vault/userpass_test.go index 0e67d76d..10696f75 100644 --- a/pkg/auth/vault/userpass_test.go +++ b/pkg/auth/vault/userpass_test.go @@ -19,7 +19,7 @@ func TestUserPassLogin(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - cachedToken, err := utils.ReadExistingToken() + cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } @@ -29,7 +29,7 @@ func TestUserPassLogin(t *testing.T) { t.Fatalf("expected no errors but got: %s", err) } - newCachedToken, err := utils.ReadExistingToken() + newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client) if err != nil { t.Fatalf("expected cached vault token but got: %s", err) } diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index f4da370d..b3e64f4c 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -11,11 +11,12 @@ import ( "testing" "time" + "github.com/hashicorp/vault/api" "github.com/argoproj-labs/argocd-vault-plugin/pkg/helpers" "github.com/argoproj-labs/argocd-vault-plugin/pkg/utils" ) -func writeToken(token string) error { +func writeToken(token string, client *api.Client) error { home, err := os.UserHomeDir() if err != nil { return err @@ -28,7 +29,7 @@ func writeToken(token string) error { "vault_token": token, } file, _ := json.MarshalIndent(data, "", " ") - err = os.WriteFile(filepath.Join(path, utils.GetConfigFileName()), file, 0644) + err = os.WriteFile(filepath.Join(path, utils.GetConfigFileName(client)), file, 0644) if err != nil { return err } @@ -45,9 +46,9 @@ func removeToken() error { return nil } -func readToken() interface{} { +func readToken(client *api.Client) interface{} { home, _ := os.UserHomeDir() - path := filepath.Join(home, ".avp", utils.GetConfigFileName()) + path := filepath.Join(home, ".avp", utils.GetConfigFileName(client)) dat, _ := os.ReadFile(path) var result map[string]interface{} json.Unmarshal([]byte(dat), &result) @@ -59,7 +60,7 @@ func TestCheckExistingToken(t *testing.T) { defer ln.Close() t.Run("will set token if valid", func(t *testing.T) { - err := writeToken(roottoken) + err := writeToken(roottoken, client) if err != nil { t.Fatal(err) } @@ -90,7 +91,7 @@ func TestCheckExistingToken(t *testing.T) { } dir, _ := os.UserHomeDir() - expected := fmt.Sprintf("stat %s/.avp/%s: no such file or directory", dir, utils.GetConfigFileName()) + expected := fmt.Sprintf("stat %s/.avp/%s: no such file or directory", dir, utils.GetConfigFileName(client)) if err.Error() != expected { t.Errorf("expected: %s, got: %s.", expected, err.Error()) }