@@ -109,73 +109,97 @@ spec:
109
109
s .ResourceApplied ("httproute" , "httpbin" , defaultHTTPRoute , 1 )
110
110
}
111
111
112
- Context ("Consumer plugins " , func () {
113
- var keyAuthConsumer = `apiVersion: gateway.apisix.io/v1alpha1
112
+ Context ("Credential " , func () {
113
+ var defaultCredential = `apiVersion: gateway.apisix.io/v1alpha1
114
114
kind: Consumer
115
115
metadata:
116
116
name: consumer-sample
117
117
spec:
118
118
gatewayRef:
119
119
name: api7ee
120
- plugins:
121
- - name: key-auth
120
+ credentials:
121
+ - type: basic-auth
122
+ name: basic-auth-sample
123
+ config:
124
+ username: sample-user
125
+ password: sample-password
126
+ - type: key-auth
127
+ name: key-auth-sample
122
128
config:
123
129
key: sample-key
130
+ - type: key-auth
131
+ name: key-auth-sample2
132
+ config:
133
+ key: sample-key2
124
134
`
125
- var basicAuthConsumer = `apiVersion: gateway.apisix.io/v1alpha1
135
+ var updateCredential = `apiVersion: gateway.apisix.io/v1alpha1
126
136
kind: Consumer
127
137
metadata:
128
138
name: consumer-sample
129
139
spec:
130
140
gatewayRef:
131
141
name: api7ee
132
- plugins:
133
- - name: basic-auth
142
+ credentials:
143
+ - type: basic-auth
144
+ name: basic-auth-sample
134
145
config:
135
146
username: sample-user
136
147
password: sample-password
148
+ plugins:
149
+ - name: key-auth
150
+ config:
151
+ key: consumer-key
137
152
`
138
-
139
153
BeforeEach (beforeEachHTTP )
140
154
141
- It ("key-auth " , func () {
142
- s .ResourceApplied ("Consumer" , "consumer-sample" , keyAuthConsumer , 1 )
155
+ It ("Create/Update/Delete " , func () {
156
+ s .ResourceApplied ("Consumer" , "consumer-sample" , defaultCredential , 1 )
143
157
144
158
s .NewAPISIXClient ().
145
159
GET ("/get" ).
160
+ WithHeader ("apikey" , "sample-key" ).
146
161
WithHost ("httpbin.org" ).
147
162
Expect ().
148
- Status (401 )
163
+ Status (200 )
149
164
150
165
s .NewAPISIXClient ().
151
166
GET ("/get" ).
152
- WithHeader ("apikey" , "sample-key " ).
167
+ WithHeader ("apikey" , "sample-key2 " ).
153
168
WithHost ("httpbin.org" ).
154
169
Expect ().
155
170
Status (200 )
156
171
157
- By ("delete Consumer" )
158
- err := s .DeleteResourceFromString (keyAuthConsumer )
159
- Expect (err ).NotTo (HaveOccurred (), "deleting Consumer" )
160
- time .Sleep (5 * time .Second )
172
+ s .NewAPISIXClient ().
173
+ GET ("/get" ).
174
+ WithBasicAuth ("sample-user" , "sample-password" ).
175
+ WithHost ("httpbin.org" ).
176
+ Expect ().
177
+ Status (200 )
178
+
179
+ By ("update Consumer" )
180
+ s .ResourceApplied ("Consumer" , "consumer-sample" , updateCredential , 2 )
161
181
162
182
s .NewAPISIXClient ().
163
183
GET ("/get" ).
164
184
WithHeader ("apikey" , "sample-key" ).
165
185
WithHost ("httpbin.org" ).
166
186
Expect ().
167
187
Status (401 )
168
- })
169
-
170
- It ("basic-auth" , func () {
171
- s .ResourceApplied ("Consumer" , "consumer-sample" , basicAuthConsumer , 1 )
172
188
173
189
s .NewAPISIXClient ().
174
190
GET ("/get" ).
191
+ WithHeader ("apikey" , "sample-key2" ).
175
192
WithHost ("httpbin.org" ).
176
193
Expect ().
177
194
Status (401 )
178
195
196
+ s .NewAPISIXClient ().
197
+ GET ("/get" ).
198
+ WithHeader ("apikey" , "consumer-key" ).
199
+ WithHost ("httpbin.org" ).
200
+ Expect ().
201
+ Status (200 )
202
+
179
203
s .NewAPISIXClient ().
180
204
GET ("/get" ).
181
205
WithBasicAuth ("sample-user" , "sample-password" ).
@@ -184,7 +208,7 @@ spec:
184
208
Status (200 )
185
209
186
210
By ("delete Consumer" )
187
- err := s .DeleteResourceFromString (basicAuthConsumer )
211
+ err := s .DeleteResourceFromString (updateCredential )
188
212
Expect (err ).NotTo (HaveOccurred (), "deleting Consumer" )
189
213
time .Sleep (5 * time .Second )
190
214
@@ -197,8 +221,26 @@ spec:
197
221
})
198
222
})
199
223
200
- Context ("Credential" , func () {
201
- var defaultCredential = `apiVersion: gateway.apisix.io/v1alpha1
224
+ Context ("SecretRef" , func () {
225
+ var keyAuthSecret = `
226
+ apiVersion: v1
227
+ kind: Secret
228
+ metadata:
229
+ name: key-auth-secret
230
+ data:
231
+ key: c2FtcGxlLWtleQ==
232
+ `
233
+ var basicAuthSecret = `
234
+ apiVersion: v1
235
+ kind: Secret
236
+ metadata:
237
+ name: basic-auth-secret
238
+ data:
239
+ username: c2FtcGxlLXVzZXI=
240
+ password: c2FtcGxlLXBhc3N3b3Jk
241
+ `
242
+ var defaultConsumer = `
243
+ apiVersion: gateway.apisix.io/v1alpha1
202
244
kind: Consumer
203
245
metadata:
204
246
name: consumer-sample
@@ -208,40 +250,25 @@ spec:
208
250
credentials:
209
251
- type: basic-auth
210
252
name: basic-auth-sample
211
- config:
212
- username: sample-user
213
- password: sample-password
253
+ secretRef:
254
+ name: basic-auth-secret
214
255
- type: key-auth
215
256
name: key-auth-sample
216
- config :
217
- key: sample- key
257
+ secretRef :
258
+ name: key-auth-secret
218
259
- type: key-auth
219
260
name: key-auth-sample2
220
261
config:
221
262
key: sample-key2
222
- `
223
- var updateCredential = `apiVersion: gateway.apisix.io/v1alpha1
224
- kind: Consumer
225
- metadata:
226
- name: consumer-sample
227
- spec:
228
- gatewayRef:
229
- name: api7ee
230
- credentials:
231
- - type: basic-auth
232
- name: basic-auth-sample
233
- config:
234
- username: sample-user
235
- password: sample-password
236
- plugins:
237
- - name: key-auth
238
- config:
239
- key: consumer-key
240
263
`
241
264
BeforeEach (beforeEachHTTP )
242
265
243
266
It ("Create/Update/Delete" , func () {
244
- s .ResourceApplied ("Consumer" , "consumer-sample" , defaultCredential , 1 )
267
+ err := s .CreateResourceFromString (keyAuthSecret )
268
+ Expect (err ).NotTo (HaveOccurred (), "creating key-auth secret" )
269
+ err = s .CreateResourceFromString (basicAuthSecret )
270
+ Expect (err ).NotTo (HaveOccurred (), "creating basic-auth secret" )
271
+ s .ResourceApplied ("Consumer" , "consumer-sample" , defaultConsumer , 1 )
245
272
246
273
s .NewAPISIXClient ().
247
274
GET ("/get" ).
@@ -250,22 +277,17 @@ spec:
250
277
Expect ().
251
278
Status (200 )
252
279
253
- s .NewAPISIXClient ().
254
- GET ("/get" ).
255
- WithHeader ("apikey" , "sample-key2" ).
256
- WithHost ("httpbin.org" ).
257
- Expect ().
258
- Status (200 )
259
-
260
280
s .NewAPISIXClient ().
261
281
GET ("/get" ).
262
282
WithBasicAuth ("sample-user" , "sample-password" ).
263
283
WithHost ("httpbin.org" ).
264
284
Expect ().
265
285
Status (200 )
266
286
267
- By ("update Consumer" )
268
- s .ResourceApplied ("Consumer" , "consumer-sample" , updateCredential , 2 )
287
+ By ("delete consumer" )
288
+ err = s .DeleteResourceFromString (defaultConsumer )
289
+ Expect (err ).NotTo (HaveOccurred (), "deleting consumer" )
290
+ time .Sleep (5 * time .Second )
269
291
270
292
s .NewAPISIXClient ().
271
293
GET ("/get" ).
@@ -274,32 +296,6 @@ spec:
274
296
Expect ().
275
297
Status (401 )
276
298
277
- s .NewAPISIXClient ().
278
- GET ("/get" ).
279
- WithHeader ("apikey" , "sample-key2" ).
280
- WithHost ("httpbin.org" ).
281
- Expect ().
282
- Status (401 )
283
-
284
- s .NewAPISIXClient ().
285
- GET ("/get" ).
286
- WithHeader ("apikey" , "consumer-key" ).
287
- WithHost ("httpbin.org" ).
288
- Expect ().
289
- Status (200 )
290
-
291
- s .NewAPISIXClient ().
292
- GET ("/get" ).
293
- WithBasicAuth ("sample-user" , "sample-password" ).
294
- WithHost ("httpbin.org" ).
295
- Expect ().
296
- Status (200 )
297
-
298
- By ("delete Consumer" )
299
- err := s .DeleteResourceFromString (updateCredential )
300
- Expect (err ).NotTo (HaveOccurred (), "deleting Consumer" )
301
- time .Sleep (5 * time .Second )
302
-
303
299
s .NewAPISIXClient ().
304
300
GET ("/get" ).
305
301
WithBasicAuth ("sample-user" , "sample-password" ).
@@ -308,7 +304,4 @@ spec:
308
304
Status (401 )
309
305
})
310
306
})
311
-
312
- PContext ("SecretRef" , func () {
313
- })
314
307
})
0 commit comments