forked from argoproj-labs/argocd-vault-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for github, k8s and iam auth types
- Loading branch information
Showing
13 changed files
with
294 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
package ibmsecretsmanager_test | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/IBM/argocd-vault-plugin/pkg/auth/ibmsecretsmanager" | ||
"github.com/IBM/argocd-vault-plugin/pkg/helpers" | ||
) | ||
|
||
// MockClient is the mock client | ||
type MockClient struct{} | ||
|
||
// Do is the mock client's `Do` func | ||
func (m *MockClient) Do(req *http.Request) (*http.Response, error) { | ||
json := `{"access_token":"123"}` | ||
|
||
// create a new reader with that JSON | ||
r := ioutil.NopCloser(bytes.NewReader([]byte(json))) | ||
return &http.Response{ | ||
StatusCode: 200, | ||
Body: r, | ||
}, nil | ||
} | ||
|
||
// Need to find a way to mock GitHub Auth within Vault | ||
func TestIBMAuth(t *testing.T) { | ||
cluster := helpers.CreateTestAuthVault(t) | ||
defer cluster.Cleanup() | ||
|
||
c := &MockClient{} | ||
ibm := ibmsecretsmanager.NewIAMAuth("abc", c) | ||
|
||
err := ibm.Authenticate(cluster.Cores[0].Client) | ||
if err != nil { | ||
t.Fatalf("expected no errors but got: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
package vault_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/IBM/argocd-vault-plugin/pkg/auth/vault" | ||
"github.com/IBM/argocd-vault-plugin/pkg/helpers" | ||
) | ||
|
||
// Need to find a way to mock GitHub Auth within Vault | ||
// func TestGithubLogin(t *testing.T) { | ||
// cluster, role, secret := helpers.CreateTestVault(t) | ||
// defer cluster.Cleanup() | ||
// | ||
// github := auth.Github{ | ||
// AccessToken: "test", | ||
// } | ||
// | ||
// err := github.Authenticate(cluster.Cores[0].Client) | ||
// if err != nil { | ||
// t.Fatalf("expected no errors but got: %s", err) | ||
// } | ||
// } | ||
func TestGithubLogin(t *testing.T) { | ||
cluster := helpers.CreateTestAuthVault(t) | ||
defer cluster.Cleanup() | ||
|
||
github := vault.NewGithubAuth("123") | ||
|
||
err := github.Authenticate(cluster.Cores[0].Client) | ||
if err != nil { | ||
t.Fatalf("expected no errors but got: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,59 @@ | ||
package vault_test | ||
|
||
// Need to find a way to mock k8s Auth within Vault | ||
// func TestGithubLogin(t *testing.T) { | ||
// cluster, role, secret := helpers.CreateTestVault(t) | ||
// defer cluster.Cleanup() | ||
// | ||
// k8s := vault.NewK8sAuth("", "", "") | ||
// | ||
// err := k8s.Authenticate(cluster.Cores[0].Client) | ||
// if err != nil { | ||
// t.Fatalf("expected no errors but got: %s", err) | ||
// } | ||
// } | ||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/IBM/argocd-vault-plugin/pkg/auth/vault" | ||
"github.com/IBM/argocd-vault-plugin/pkg/helpers" | ||
) | ||
|
||
const saPath = "/tmp/avp/kubernetes.io/serviceaccount" | ||
|
||
func writeK8sToken() error { | ||
err := os.MkdirAll(saPath, os.ModePerm) | ||
if err != nil { | ||
return fmt.Errorf("Could not create directory: %s", err.Error()) | ||
} | ||
|
||
data := []byte("123456") | ||
err = ioutil.WriteFile(filepath.Join(saPath, "token"), data, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func removeK8sToken() error { | ||
err := os.RemoveAll("/tmp/avp") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Need to find a way to mock GitHub Auth within Vault | ||
func TestKubernetesAuth(t *testing.T) { | ||
cluster := helpers.CreateTestAuthVault(t) | ||
defer cluster.Cleanup() | ||
|
||
err := writeK8sToken() | ||
if err != nil { | ||
t.Fatalf("error writing token: %s", err) | ||
} | ||
|
||
k8s := vault.NewK8sAuth("role", "", string(filepath.Join(saPath, "token"))) | ||
|
||
err = k8s.Authenticate(cluster.Cores[0].Client) | ||
if err != nil { | ||
t.Fatalf("expected no errors but got: %s", err) | ||
} | ||
|
||
err = removeK8sToken() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.