forked from mch1307/vaultlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth_test.go
71 lines (69 loc) · 1.49 KB
/
auth_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package vaultlib
import (
"net/http"
"net/url"
"testing"
)
func TestVaultClient_setTokenFromAppRole(t *testing.T) {
rightURL, _ := url.Parse("http://localhost:8200")
badURL, _ := url.Parse("https://localhost:8200")
conf := NewConfig()
anyMountPoint := "anyMountPoint"
anyCreds := NewConfig().AppRoleCredentials
anyCreds.MountPoint = anyMountPoint
htCli := new(http.Client)
type fields struct {
Address *url.URL
HTTPClient *http.Client
AppRoleCredentials *AppRoleCredentials
//Config *Config
Token string
Status string
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{"tokenKO",
fields{
rightURL,
htCli,
conf.AppRoleCredentials,
"bad-token",
""},
true},
{"badUrl",
fields{
badURL,
htCli,
conf.AppRoleCredentials,
"bad-token",
""},
true},
{"anyMountPoint",
fields{
rightURL,
htCli,
anyCreds,
"bad-token",
""},
true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Client{
address: tt.fields.Address,
httpClient: tt.fields.HTTPClient,
appRoleCredentials: tt.fields.AppRoleCredentials,
//config: tt.fields.Config,
token: &VaultTokenInfo{ID: tt.fields.Token},
status: tt.fields.Status,
}
if err := c.setTokenFromAppRole(); (err != nil) != tt.wantErr {
t.Errorf("Client.setTokenFromAppRole() error = %v, wantErr %v", c.token.ID, tt.fields.Token)
//err, tt.wantErr)
}
})
}
}