-
Notifications
You must be signed in to change notification settings - Fork 21
/
path_config_user_token_test.go
149 lines (122 loc) · 4.84 KB
/
path_config_user_token_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package artifactory
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAcceptanceBackend_PathConfigUserToken(t *testing.T) {
if !runAcceptanceTests {
t.SkipNow()
}
accTestEnv := NewConfiguredAcceptanceTestEnv(t)
t.Run("update access_token", accTestEnv.PathConfigAccessTokenUpdate)
t.Run("update default_description", accTestEnv.PathConfigDefaultDescriptionUpdate)
t.Run("update audience", accTestEnv.PathConfigAudienceUpdate)
t.Run("update refreshable", accTestEnv.PathConfigRefreshableUpdate)
t.Run("update include_reference_token", accTestEnv.PathConfigIncludeReferenceTokenUpdate)
t.Run("update use_expiring_tokens", accTestEnv.PathConfigUseExpiringTokensUpdate)
t.Run("update default_ttl", accTestEnv.PathConfigDefaultTTLUpdate)
t.Run("update max_ttl", accTestEnv.PathConfigMaxTTLUpdate)
t.Run("update force_revocable", accTestEnv.PathConfigForceRevocableTokens)
}
func (e *accTestEnv) PathConfigAccessTokenUpdate(t *testing.T) {
e.UpdateConfigUserToken(t, "", testData{
"access_token": "test123",
})
data := e.ReadConfigUserToken(t, "")
accessTokenHash := data["access_token_sha256"]
assert.NotEmpty(t, "access_token_sha256")
e.UpdateConfigUserToken(t, "", testData{
"access_token": "test456",
})
data = e.ReadConfigUserToken(t, "")
assert.NotEqual(t, data["access_token_sha256"], accessTokenHash)
}
func (e *accTestEnv) PathConfigDefaultDescriptionUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateStringField(t, "default_description")
}
func (e *accTestEnv) PathConfigAudienceUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateStringField(t, "audience")
}
func (e *accTestEnv) PathConfigRefreshableUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateBoolField(t, "refreshable")
}
func (e *accTestEnv) PathConfigIncludeReferenceTokenUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateBoolField(t, "include_reference_token")
}
func (e *accTestEnv) PathConfigUseExpiringTokensUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateBoolField(t, "use_expiring_tokens")
}
func (e *accTestEnv) PathConfigForceRevocableUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateBoolField(t, "force_revocable")
}
func (e *accTestEnv) PathConfigDefaultTTLUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateDurationField(t, "default_ttl")
}
func (e *accTestEnv) PathConfigMaxTTLUpdate(t *testing.T) {
e.pathConfigUserTokenUpdateDurationField(t, "max_ttl")
}
func (e *accTestEnv) pathConfigUserTokenUpdateStringField(t *testing.T, fieldName string) {
e.UpdateConfigUserToken(t, "", testData{
fieldName: "test123",
})
data := e.ReadConfigUserToken(t, "")
assert.Equal(t, "test123", data[fieldName])
e.UpdateConfigUserToken(t, "", testData{
fieldName: "test456",
})
data = e.ReadConfigUserToken(t, "")
assert.Equal(t, "test456", data[fieldName])
}
func (e *accTestEnv) pathConfigUserTokenUpdateBoolField(t *testing.T, fieldName string) {
e.UpdateConfigUserToken(t, "", testData{
fieldName: true,
})
data := e.ReadConfigUserToken(t, "")
assert.Equal(t, true, data[fieldName])
e.UpdateConfigUserToken(t, "", testData{
fieldName: false,
})
data = e.ReadConfigUserToken(t, "")
assert.Equal(t, false, data[fieldName])
}
func (e *accTestEnv) pathConfigUserTokenUpdateDurationField(t *testing.T, fieldName string) {
e.UpdateConfigUserToken(t, "", testData{
fieldName: 1.0,
})
data := e.ReadConfigUserToken(t, "")
assert.Equal(t, 1.0, data[fieldName])
e.UpdateConfigUserToken(t, "", testData{
fieldName: 4.0,
})
data = e.ReadConfigUserToken(t, "")
assert.Equal(t, 4.0, data[fieldName])
}
func TestAcceptanceBackend_PathConfigUserToken_UseUserDefault(t *testing.T) {
if !runAcceptanceTests {
t.SkipNow()
}
accTestEnv := NewConfiguredAcceptanceTestEnv(t)
accTestEnv.UpdateConfigUserToken(t, "", testData{
"default_ttl": time.Duration(2) * time.Hour,
"max_ttl": time.Duration(4) * time.Hour,
})
data := accTestEnv.ReadConfigUserToken(t, "")
assert.Equal(t, (time.Duration(2) * time.Hour).Seconds(), data["default_ttl"])
assert.Equal(t, (time.Duration(4) * time.Hour).Seconds(), data["max_ttl"])
data = accTestEnv.ReadConfigUserToken(t, "test-user")
assert.Equal(t, (time.Duration(2) * time.Hour).Seconds(), data["default_ttl"])
assert.Equal(t, (time.Duration(4) * time.Hour).Seconds(), data["max_ttl"])
}
func TestAcceptanceBackend_PathConfigUserToken_UseSystemDefault(t *testing.T) {
if !runAcceptanceTests {
t.SkipNow()
}
accTestEnv := NewConfiguredAcceptanceTestEnv(t)
data := accTestEnv.ReadConfigUserToken(t, "")
assert.Equal(t, accTestEnv.Backend.System().DefaultLeaseTTL().Seconds(), data["default_ttl"])
assert.Equal(t, accTestEnv.Backend.System().MaxLeaseTTL().Seconds(), data["max_ttl"])
data = accTestEnv.ReadConfigUserToken(t, "test-user")
assert.Equal(t, accTestEnv.Backend.System().DefaultLeaseTTL().Seconds(), data["default_ttl"])
assert.Equal(t, accTestEnv.Backend.System().MaxLeaseTTL().Seconds(), data["max_ttl"])
}