forked from argoproj-labs/argocd-vault-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_test.go
42 lines (33 loc) · 1.07 KB
/
github_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package vault_test
import (
"bytes"
"testing"
"github.com/argoproj-labs/argocd-vault-plugin/pkg/auth/vault"
"github.com/argoproj-labs/argocd-vault-plugin/pkg/utils"
"github.com/argoproj-labs/argocd-vault-plugin/pkg/helpers"
)
// Need to find a way to mock GitHub Auth within Vault
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)
}
cachedToken, err := utils.ReadExistingToken("github")
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
err = github.Authenticate(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected no errors but got: %s", err)
}
newCachedToken, err := utils.ReadExistingToken("github")
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
if bytes.Compare(cachedToken, newCachedToken) != 0 {
t.Fatalf("expected same token %s but got %s", cachedToken, newCachedToken)
}
}