Skip to content

Commit 5f706e5

Browse files
filters/auth: add tokeninfo test cases (zalando#2789)
Add test cases and update messages for consistency. Signed-off-by: Alexander Yastrebov <[email protected]>
1 parent 3dc744e commit 5f706e5

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

filters/auth/tokeninfo_test.go

+45-17
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,28 @@ func TestOAuth2Tokeninfo(t *testing.T) {
4545
expected int
4646
expectRequests int32
4747
}{{
48-
msg: "invalid token",
48+
msg: "oauthTokeninfoAnyScope: invalid token",
4949
authType: filters.OAuthTokeninfoAnyScopeName,
5050
args: []interface{}{"not-matching-scope"},
5151
auth: "invalid-token",
5252
expected: http.StatusUnauthorized,
5353
expectRequests: N,
5454
}, {
55-
msg: "invalid scope",
55+
msg: "oauthTokeninfoAnyScope: one invalid scope",
5656
authType: filters.OAuthTokeninfoAnyScopeName,
5757
args: []interface{}{"not-matching-scope"},
5858
auth: testToken,
5959
expected: http.StatusForbidden,
6060
expectRequests: N,
6161
}, {
62-
msg: "missing token",
62+
msg: "oauthTokeninfoAnyScope: two invalid scopes",
63+
authType: filters.OAuthTokeninfoAnyScopeName,
64+
args: []interface{}{"not-matching-scope1", "not-matching-scope2"},
65+
auth: testToken,
66+
expected: http.StatusForbidden,
67+
expectRequests: N,
68+
}, {
69+
msg: "oauthTokeninfoAnyScope: missing token",
6370
authType: filters.OAuthTokeninfoAnyScopeName,
6471
args: []interface{}{testScope},
6572
auth: "",
@@ -73,98 +80,119 @@ func TestOAuth2Tokeninfo(t *testing.T) {
7380
expected: http.StatusOK,
7481
expectRequests: N,
7582
}, {
76-
msg: "OAuthTokeninfoAnyScopeName: valid token, one valid scope, one invalid scope",
83+
msg: "oauthTokeninfoAnyScope: valid token, one valid scope, one invalid scope",
7784
authType: filters.OAuthTokeninfoAnyScopeName,
7885
args: []interface{}{testScope, "other-scope"},
7986
auth: testToken,
8087
expected: http.StatusOK,
8188
expectRequests: N,
8289
}, {
83-
msg: "oauthTokeninfoAllScope(): valid token, valid scopes",
90+
msg: "oauthTokeninfoAnyScope: valid token, one invalid scope, one valid scope",
91+
authType: filters.OAuthTokeninfoAnyScopeName,
92+
args: []interface{}{"other-scope", testScope},
93+
auth: testToken,
94+
expected: http.StatusOK,
95+
expectRequests: N,
96+
}, {
97+
msg: "oauthTokeninfoAllScope: valid token, all valid scopes",
8498
authType: filters.OAuthTokeninfoAllScopeName,
8599
args: []interface{}{testScope, testScope2, testScope3},
86100
auth: testToken,
87101
expected: http.StatusOK,
88102
expectRequests: N,
89103
}, {
90-
msg: "oauthTokeninfoAllScope(): valid token, one valid scope, one invalid scope",
104+
msg: "oauthTokeninfoAllScope: valid token, two valid scopes",
105+
authType: filters.OAuthTokeninfoAllScopeName,
106+
args: []interface{}{testScope, testScope2},
107+
auth: testToken,
108+
expected: http.StatusOK,
109+
expectRequests: N,
110+
}, {
111+
msg: "oauthTokeninfoAllScope: valid token, one valid scope",
112+
authType: filters.OAuthTokeninfoAllScopeName,
113+
args: []interface{}{testScope},
114+
auth: testToken,
115+
expected: http.StatusOK,
116+
expectRequests: N,
117+
}, {
118+
msg: "oauthTokeninfoAllScope: valid token, one valid scope, one invalid scope",
91119
authType: filters.OAuthTokeninfoAllScopeName,
92120
args: []interface{}{testScope, "other-scope"},
93121
auth: testToken,
94122
expected: http.StatusForbidden,
95123
expectRequests: N,
96124
}, {
97-
msg: "anyKV(): valid token, one valid key, wrong value",
125+
msg: "oauthTokeninfoAnyKV: valid token, one valid key, wrong value",
98126
authType: filters.OAuthTokeninfoAnyKVName,
99127
args: []interface{}{testKey, "other-value"},
100128
auth: testToken,
101129
expected: http.StatusForbidden,
102130
expectRequests: N,
103131
}, {
104-
msg: "anyKV(): valid token, one valid key value pair",
132+
msg: "oauthTokeninfoAnyKV: valid token, one valid key value pair",
105133
authType: filters.OAuthTokeninfoAnyKVName,
106134
args: []interface{}{testKey, testValue},
107135
auth: testToken,
108136
expected: http.StatusOK,
109137
expectRequests: N,
110138
}, {
111-
msg: "anyKV(): valid token, one valid kv, multiple key value pairs1",
139+
msg: "oauthTokeninfoAnyKV: valid token, one valid kv, multiple key value pairs1",
112140
authType: filters.OAuthTokeninfoAnyKVName,
113141
args: []interface{}{testKey, testValue, "wrongKey", "wrongValue"},
114142
auth: testToken,
115143
expected: http.StatusOK,
116144
expectRequests: N,
117145
}, {
118-
msg: "anyKV(): valid token, one valid kv, multiple key value pairs2",
146+
msg: "oauthTokeninfoAnyKV: valid token, one valid kv, multiple key value pairs2",
119147
authType: filters.OAuthTokeninfoAnyKVName,
120148
args: []interface{}{"wrongKey", "wrongValue", testKey, testValue},
121149
auth: testToken,
122150
expected: http.StatusOK,
123151
expectRequests: N,
124152
}, {
125-
msg: "anyKV(): valid token, one valid kv, same key multiple times should pass",
153+
msg: "oauthTokeninfoAnyKV: valid token, one valid kv, same key multiple times should pass",
126154
authType: filters.OAuthTokeninfoAnyKVName,
127155
args: []interface{}{testKey, testValue, testKey, "someValue"},
128156
auth: testToken,
129157
expected: http.StatusOK,
130158
expectRequests: N,
131159
}, {
132-
msg: "allKV(): valid token, one valid key, wrong value",
160+
msg: "oauthTokeninfoAllKV: valid token, one valid key, wrong value",
133161
authType: filters.OAuthTokeninfoAllKVName,
134162
args: []interface{}{testKey, "other-value"},
135163
auth: testToken,
136164
expected: http.StatusForbidden,
137165
expectRequests: N,
138166
}, {
139-
msg: "allKV(): valid token, one valid key value pair",
167+
msg: "oauthTokeninfoAllKV: valid token, one valid key value pair",
140168
authType: filters.OAuthTokeninfoAllKVName,
141169
args: []interface{}{testKey, testValue},
142170
auth: testToken,
143171
expected: http.StatusOK,
144172
expectRequests: N,
145173
}, {
146-
msg: "allKV(): valid token, one valid key value pair, check realm",
174+
msg: "oauthTokeninfoAllKV: valid token, one valid key value pair, check realm",
147175
authType: filters.OAuthTokeninfoAllKVName,
148176
args: []interface{}{testRealmKey, testRealm, testKey, testValue},
149177
auth: testToken,
150178
expected: http.StatusOK,
151179
expectRequests: N,
152180
}, {
153-
msg: "allKV(): valid token, valid key value pairs",
181+
msg: "oauthTokeninfoAllKV: valid token, valid key value pairs",
154182
authType: filters.OAuthTokeninfoAllKVName,
155183
args: []interface{}{testKey, testValue, testKey, testValue},
156184
auth: testToken,
157185
expected: http.StatusOK,
158186
expectRequests: N,
159187
}, {
160-
msg: "allKV(): valid token, one valid kv, multiple key value pairs1",
188+
msg: "oauthTokeninfoAllKV: valid token, one valid kv, multiple key value pairs1",
161189
authType: filters.OAuthTokeninfoAllKVName,
162190
args: []interface{}{testKey, testValue, "wrongKey", "wrongValue"},
163191
auth: testToken,
164192
expected: http.StatusForbidden,
165193
expectRequests: N,
166194
}, {
167-
msg: "allKV(): valid token, one valid kv, multiple key value pairs2",
195+
msg: "oauthTokeninfoAllKV: valid token, one valid kv, multiple key value pairs2",
168196
authType: filters.OAuthTokeninfoAllKVName,
169197
args: []interface{}{"wrongKey", "wrongValue", testKey, testValue},
170198
auth: testToken,

0 commit comments

Comments
 (0)