@@ -169,7 +169,87 @@ Existing-Header:
169
169
-- - no_error_log
170
170
[error]
171
171
172
- === TEST 3 : ' set' operation in response headers
172
+ === TEST 3 : ' push' operation in request headers
173
+ We test 3 things:
174
+ 1 ) Push op with a header that does not exist, does not change anything.
175
+ 2 ) Push op with a header that exists , adds a new header with the same name and
176
+ the given value .
177
+ 3 ) Check that the headers are received in the upstream but not in the response
178
+ of the original request.
179
+ -- - configuration
180
+ {
181
+ " services" : [
182
+ {
183
+ " id" : 42 ,
184
+ " backend_version" : 1 ,
185
+ " backend_authentication_type" : " service_token" ,
186
+ " backend_authentication_value" : " token-value" ,
187
+ " proxy" : {
188
+ " policy_chain" : [
189
+ { " name" : " apicast.policy.apicast" },
190
+ {
191
+ " name" : " apicast.policy.headers" ,
192
+ " configuration" :
193
+ {
194
+ " request" :
195
+ [
196
+ { " op" : " push" , " header" : " New-Header" , " value" : " config_value_nh" },
197
+ { " op" : " push" , " header" : " Existing-Header" , " value" : " config_value_eh" }
198
+ ]
199
+ }
200
+ }
201
+ ],
202
+ " api_backend" : " http://test:$ TEST_NGINX_SERVER_PORT /" ,
203
+ " proxy_rules" : [
204
+ { " pattern" : " /" , " http_method" : " GET" , " metric_system_name" : " hits" , " delta" : 2 }
205
+ ]
206
+ }
207
+ }
208
+ ]
209
+ }
210
+ -- - backend
211
+ location / transactions/ authrep. xml {
212
+ content_by_lua_block {
213
+ local expected = " service_token=token-value& service_id =42& usage %5Bhits%5D=2& user_key =value"
214
+ local args = ngx. var. args
215
+ if args == expected then
216
+ ngx. exit(200 )
217
+ else
218
+ ngx. log (ngx. ERR, expected, ' did not match: ' , args)
219
+ ngx. exit(403 )
220
+ end
221
+ }
222
+ }
223
+ -- - upstream
224
+ location / {
225
+ content_by_lua_block {
226
+ local existing_header_values = ngx. req. get_headers()[' Existing-Header' ]
227
+
228
+ if ngx. req. get_headers()[' New-Header' ] then
229
+ ngx. log (ngx. ERR, " Received unexpected header New-Header" )
230
+ elseif existing_header_values[1 ] ~ = ' request_value_eh1' or
231
+ existing_header_values[2 ] ~ = ' request_value_eh2' or
232
+ existing_header_values[3 ] ~ = ' config_value_eh' then
233
+ ngx. log (ngx. ERR, " The header 'Existing-Header' does not have the correct value" )
234
+ else
235
+ ngx. say (' yay, api backend' );
236
+ end
237
+ }
238
+ }
239
+ -- - request
240
+ GET /? user_key= value
241
+ -- - more_headers
242
+ Existing-Header: request_value_eh1
243
+ Existing-Header: request_value_eh2
244
+ -- - response_body
245
+ yay, api backend
246
+ -- - response_headers
247
+ Existing-Header:
248
+ -- - error_code: 200
249
+ -- - no_error_log
250
+ [error]
251
+
252
+ === TEST 4 : ' set' operation in response headers
173
253
We test 3 things:
174
254
1 ) Set op with a header that does not exit creates it with the given value .
175
255
2 ) Set op with a header that exists , clears it and sets the given value .
@@ -239,7 +319,7 @@ Header-To-Delete:
239
319
-- - no_error_log
240
320
[error]
241
321
242
- === TEST 4 : ' add' operation in response headers
322
+ === TEST 5 : ' add' operation in response headers
243
323
We test 2 things:
244
324
1 ) Add op with a header that does not exist creates it with the given value .
245
325
2 ) Add op with a header that exists , creates a new header with the same name
@@ -307,7 +387,76 @@ Header-To-Delete:
307
387
-- - no_error_log
308
388
[error]
309
389
310
- === TEST 5 : headers policy without a configuration
390
+ === TEST 6 : ' push' operation in response headers
391
+ We test 3 things:
392
+ 1 ) Push op with a header that does not exist, does not change anything.
393
+ 2 ) Push op with a header that exists , adds a new header with the same name and
394
+ the given value .
395
+ 3 ) Check that the headers are received in the upstream but not in the response
396
+ of the original request.
397
+ -- - configuration
398
+ {
399
+ " services" : [
400
+ {
401
+ " id" : 42 ,
402
+ " backend_version" : 1 ,
403
+ " backend_authentication_type" : " service_token" ,
404
+ " backend_authentication_value" : " token-value" ,
405
+ " proxy" : {
406
+ " policy_chain" : [
407
+ { " name" : " apicast.policy.apicast" },
408
+ {
409
+ " name" : " apicast.policy.headers" ,
410
+ " configuration" :
411
+ {
412
+ " response" :
413
+ [
414
+ { " op" : " push" , " header" : " New-Header" , " value" : " config_value_nh" },
415
+ { " op" : " push" , " header" : " Existing-Header" , " value" : " config_value_eh" }
416
+ ]
417
+ }
418
+ }
419
+ ],
420
+ " api_backend" : " http://test:$ TEST_NGINX_SERVER_PORT /" ,
421
+ " proxy_rules" : [
422
+ { " pattern" : " /" , " http_method" : " GET" , " metric_system_name" : " hits" , " delta" : 2 }
423
+ ]
424
+ }
425
+ }
426
+ ]
427
+ }
428
+ -- - backend
429
+ location / transactions/ authrep. xml {
430
+ content_by_lua_block {
431
+ local expected = " service_token=token-value& service_id =42& usage %5Bhits%5D=2& user_key =value"
432
+ local args = ngx. var. args
433
+ if args == expected then
434
+ ngx. exit(200 )
435
+ else
436
+ ngx. log (ngx. ERR, expected, ' did not match: ' , args)
437
+ ngx. exit(403 )
438
+ end
439
+ }
440
+ }
441
+ -- - upstream
442
+ location / {
443
+ content_by_lua_block {
444
+ ngx. header[' Existing-Header' ] = ' upstream_value_eh'
445
+ ngx. say (' yay, api backend' )
446
+ }
447
+ }
448
+ -- - request
449
+ GET /? user_key= value
450
+ -- - response_body
451
+ yay, api backend
452
+ -- - response_headers
453
+ Existing-Header: upstream_value_eh, config_value_eh
454
+ New-Header:
455
+ -- - error_code: 200
456
+ -- - no_error_log
457
+ [error]
458
+
459
+ === TEST 7 : headers policy without a configuration
311
460
Just to make sure that APIcast does not crash when the policy does not have a
312
461
configuration.
313
462
-- - configuration
0 commit comments