-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecrets_test.go
97 lines (89 loc) · 2.22 KB
/
secrets_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package artifactory
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/hashicorp/vault/sdk/logical"
)
func TestSecretAccessToken_Revoke(t *testing.T) {
tests := []struct {
expectation Expectation
request *logical.Request
handler http.HandlerFunc
}{
{
ExpectedToSucceed,
&logical.Request{
Operation: logical.RevokeOperation,
Secret: &logical.Secret{
InternalData: map[string]interface{}{
"role_name": "test-role",
"secret_type": accessTokenSecretType,
},
},
Data: map[string]interface{}{
"access_token": "fake-token",
},
},
func(w http.ResponseWriter, r *http.Request) {
if r.FormValue("token") != "fake-token" {
t.Fatal("Revoke token request does not contain access token")
}
w.WriteHeader(http.StatusOK)
},
},
{
FailWithError,
&logical.Request{
Operation: logical.RevokeOperation,
Secret: &logical.Secret{
InternalData: map[string]interface{}{
"role_name": "test-role",
"secret_type": accessTokenSecretType,
},
},
Data: map[string]interface{}{
"access_token": "fake-token",
},
},
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
},
},
{
FailWithError,
&logical.Request{
Operation: logical.RevokeOperation,
Secret: &logical.Secret{
InternalData: map[string]interface{}{
"secret_type": "Unknown secret type",
},
},
},
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
},
},
}
for _, test := range tests {
// Mock the api/security/token/revoke endpoint
ts := httptest.NewTLSServer(test.handler)
defer ts.Close()
b, storage := newBackend(t)
resp, err := b.HandleRequest(context.Background(), &logical.Request{
Operation: logical.UpdateOperation,
Path: "config",
Storage: storage,
Data: map[string]interface{}{
"address": ts.URL + "/",
"api_key": "abc123",
"tls_verify": false,
},
})
assertLogicalResponse(t, ExpectedToSucceed, err, resp)
test.request.Storage = storage
resp, err = b.HandleRequest(context.Background(), test.request)
assertLogicalResponse(t, test.expectation, err, resp)
}
}