@@ -109,73 +109,97 @@ spec:
109109 s .ResourceApplied ("httproute" , "httpbin" , defaultHTTPRoute , 1 )
110110 }
111111
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
114114kind: Consumer
115115metadata:
116116 name: consumer-sample
117117spec:
118118 gatewayRef:
119119 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
122128 config:
123129 key: sample-key
130+ - type: key-auth
131+ name: key-auth-sample2
132+ config:
133+ key: sample-key2
124134`
125- var basicAuthConsumer = `apiVersion: gateway.apisix.io/v1alpha1
135+ var updateCredential = `apiVersion: gateway.apisix.io/v1alpha1
126136kind: Consumer
127137metadata:
128138 name: consumer-sample
129139spec:
130140 gatewayRef:
131141 name: api7ee
132- plugins:
133- - name: basic-auth
142+ credentials:
143+ - type: basic-auth
144+ name: basic-auth-sample
134145 config:
135146 username: sample-user
136147 password: sample-password
148+ plugins:
149+ - name: key-auth
150+ config:
151+ key: consumer-key
137152`
138-
139153 BeforeEach (beforeEachHTTP )
140154
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 )
143157
144158 s .NewAPISIXClient ().
145159 GET ("/get" ).
160+ WithHeader ("apikey" , "sample-key" ).
146161 WithHost ("httpbin.org" ).
147162 Expect ().
148- Status (401 )
163+ Status (200 )
149164
150165 s .NewAPISIXClient ().
151166 GET ("/get" ).
152- WithHeader ("apikey" , "sample-key " ).
167+ WithHeader ("apikey" , "sample-key2 " ).
153168 WithHost ("httpbin.org" ).
154169 Expect ().
155170 Status (200 )
156171
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 )
161181
162182 s .NewAPISIXClient ().
163183 GET ("/get" ).
164184 WithHeader ("apikey" , "sample-key" ).
165185 WithHost ("httpbin.org" ).
166186 Expect ().
167187 Status (401 )
168- })
169-
170- It ("basic-auth" , func () {
171- s .ResourceApplied ("Consumer" , "consumer-sample" , basicAuthConsumer , 1 )
172188
173189 s .NewAPISIXClient ().
174190 GET ("/get" ).
191+ WithHeader ("apikey" , "sample-key2" ).
175192 WithHost ("httpbin.org" ).
176193 Expect ().
177194 Status (401 )
178195
196+ s .NewAPISIXClient ().
197+ GET ("/get" ).
198+ WithHeader ("apikey" , "consumer-key" ).
199+ WithHost ("httpbin.org" ).
200+ Expect ().
201+ Status (200 )
202+
179203 s .NewAPISIXClient ().
180204 GET ("/get" ).
181205 WithBasicAuth ("sample-user" , "sample-password" ).
@@ -184,7 +208,7 @@ spec:
184208 Status (200 )
185209
186210 By ("delete Consumer" )
187- err := s .DeleteResourceFromString (basicAuthConsumer )
211+ err := s .DeleteResourceFromString (updateCredential )
188212 Expect (err ).NotTo (HaveOccurred (), "deleting Consumer" )
189213 time .Sleep (5 * time .Second )
190214
@@ -197,8 +221,26 @@ spec:
197221 })
198222 })
199223
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
202244kind: Consumer
203245metadata:
204246 name: consumer-sample
@@ -208,40 +250,25 @@ spec:
208250 credentials:
209251 - type: basic-auth
210252 name: basic-auth-sample
211- config:
212- username: sample-user
213- password: sample-password
253+ secretRef:
254+ name: basic-auth-secret
214255 - type: key-auth
215256 name: key-auth-sample
216- config :
217- key: sample- key
257+ secretRef :
258+ name: key-auth-secret
218259 - type: key-auth
219260 name: key-auth-sample2
220261 config:
221262 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
240263`
241264 BeforeEach (beforeEachHTTP )
242265
243266 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 )
245272
246273 s .NewAPISIXClient ().
247274 GET ("/get" ).
@@ -250,22 +277,17 @@ spec:
250277 Expect ().
251278 Status (200 )
252279
253- s .NewAPISIXClient ().
254- GET ("/get" ).
255- WithHeader ("apikey" , "sample-key2" ).
256- WithHost ("httpbin.org" ).
257- Expect ().
258- Status (200 )
259-
260280 s .NewAPISIXClient ().
261281 GET ("/get" ).
262282 WithBasicAuth ("sample-user" , "sample-password" ).
263283 WithHost ("httpbin.org" ).
264284 Expect ().
265285 Status (200 )
266286
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 )
269291
270292 s .NewAPISIXClient ().
271293 GET ("/get" ).
@@ -274,32 +296,6 @@ spec:
274296 Expect ().
275297 Status (401 )
276298
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-
303299 s .NewAPISIXClient ().
304300 GET ("/get" ).
305301 WithBasicAuth ("sample-user" , "sample-password" ).
@@ -308,7 +304,4 @@ spec:
308304 Status (401 )
309305 })
310306 })
311-
312- PContext ("SecretRef" , func () {
313- })
314307})
0 commit comments