forked from argoproj-labs/argocd-vault-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserpass_test.go
More file actions
62 lines (48 loc) · 1.86 KB
/
userpass_test.go
File metadata and controls
62 lines (48 loc) · 1.86 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package vault_test
import (
"bytes"
"fmt"
"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"
)
func TestUserPassLogin(t *testing.T) {
cluster, username, password := helpers.CreateTestUserPassVault(t)
defer cluster.Cleanup()
userpass := vault.NewUserPassAuth(username, password, "")
if err := userpass.Authenticate(cluster.Cores[0].Client); err != nil {
t.Fatalf("expected no errors but got: %s", err)
}
cachedToken, err := utils.ReadExistingToken(fmt.Sprintf("userpass_%s", username))
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
err = userpass.Authenticate(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected no errors but got: %s", err)
}
newCachedToken, err := utils.ReadExistingToken(fmt.Sprintf("userpass_%s", username))
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)
}
// We create a new connection with a different approle and create a different cache
secondCluster, secondUsername, secondPassword := helpers.CreateTestUserPassVault(t)
defer secondCluster.Cleanup()
secondUserpass := vault.NewUserPassAuth(secondUsername, secondPassword, "")
err = secondUserpass.Authenticate(secondCluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected no errors but got: %s", err)
}
secondCachedToken, err := utils.ReadExistingToken(fmt.Sprintf("userpass_%s", secondUsername))
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
// Both cache should be different
if bytes.Compare(cachedToken, secondCachedToken) == 0 {
t.Fatalf("expected different tokens but got %s", secondCachedToken)
}
}