@@ -382,7 +382,67 @@ passed
382
382
383
383
384
384
385
- === TEST 15 : add consumer with 0 clock skew
385
+ === TEST 15 : verify: ok (multiple duplicates X -HMAC-SIGNATURE header)
386
+ -- - config
387
+ location / t {
388
+ content_by_lua_block {
389
+ local ngx_time = ngx. time
390
+ local ngx_http_time = ngx. http_time
391
+ local core = require (" apisix.core" )
392
+ local t = require (" lib.test_admin" )
393
+ local hmac = require (" resty.hmac" )
394
+ local ngx_encode_base64 = ngx. encode_base64
395
+
396
+ local secret_key = " my-secret-key"
397
+ local timestamp = ngx_time()
398
+ local gmt = ngx_http_time(timestamp)
399
+ local access_key = " my-access-key"
400
+ local custom_header_a = " asld$% dfasf"
401
+ local custom_header_b = " 23879fmsldfk"
402
+
403
+ local signing_string = {
404
+ " GET" ,
405
+ " /hello" ,
406
+ " " ,
407
+ access_key,
408
+ gmt,
409
+ " x-custom-header-a:" .. custom_header_a,
410
+ " x-custom-header-b:" .. custom_header_b
411
+ }
412
+ signing_string = core. table. concat(signing_string, " \n " ) .. " \n "
413
+ core. log . info(" signing_string:" , signing_string)
414
+
415
+ local signature = hmac: new(secret_key, hmac. ALGOS. SHA256): final(signing_string)
416
+ core. log . info(" signature:" , ngx_encode_base64(signature ))
417
+ local headers = {}
418
+ local encoded_signature = ngx_encode_base64(signature )
419
+ headers[" X-HMAC-SIGNATURE" ] = {encoded_signature, " another-signature" }
420
+ headers[" X-HMAC-ALGORITHM" ] = " hmac-sha256"
421
+ headers[" Date" ] = gmt
422
+ headers[" X-HMAC-ACCESS-KEY" ] = access_key
423
+ headers[" X-HMAC-SIGNED-HEADERS" ] = " x-custom-header-a;x-custom-header-b"
424
+ headers[" x-custom-header-a" ] = custom_header_a
425
+ headers[" x-custom-header-b" ] = custom_header_b
426
+
427
+ local code, body = t. test(' /hello' ,
428
+ ngx. HTTP_GET,
429
+ " " ,
430
+ nil,
431
+ headers
432
+ )
433
+
434
+ ngx. status = code
435
+ ngx. say (body )
436
+ }
437
+ }
438
+ -- - request
439
+ GET / t
440
+ -- - response_body
441
+ passed
442
+
443
+
444
+
445
+ === TEST 16 : add consumer with 0 clock skew
386
446
-- - config
387
447
location / t {
388
448
content_by_lua_block {
@@ -413,11 +473,12 @@ passed
413
473
414
474
415
475
416
- === TEST 16 : verify: invalid signature
476
+ === TEST 17 : verify: invalid signature
417
477
-- - request
418
478
GET / hello
419
479
-- - more_headers
420
480
X -HMAC-SIGNATURE: asdf
481
+ X -HMAC-SIGNATURE: asdf
421
482
X -HMAC-ALGORITHM: hmac-sha256
422
483
Date : Thu, 24 Sep 2020 06 : 39 : 52 GMT
423
484
X -HMAC-ACCESS-KEY: my-access-key3
@@ -431,7 +492,7 @@ client request can't be validated: Invalid signature
431
492
432
493
433
494
434
- === TEST 17 : add consumer with 1 clock skew
495
+ === TEST 18 : add consumer with 1 clock skew
435
496
-- - config
436
497
location / t {
437
498
content_by_lua_block {
@@ -463,7 +524,7 @@ passed
463
524
464
525
465
526
466
- === TEST 18 : verify: Invalid GMT format time
527
+ === TEST 19 : verify: Invalid GMT format time
467
528
-- - config
468
529
location / t {
469
530
content_by_lua_block {
@@ -520,7 +581,7 @@ client request can't be validated: Clock skew exceeded
520
581
521
582
522
583
523
- === TEST 19 : verify: put ok
584
+ === TEST 20 : verify: put ok
524
585
-- - config
525
586
location / t {
526
587
content_by_lua_block {
@@ -583,7 +644,7 @@ passed
583
644
584
645
585
646
586
- === TEST 20 : verify: put ok (pass auth data by header `Authorization`)
647
+ === TEST 21 : verify: put ok (pass auth data by header `Authorization`)
587
648
-- - config
588
649
location / t {
589
650
content_by_lua_block {
@@ -645,7 +706,7 @@ passed
645
706
646
707
647
708
648
- === TEST 21 : hit route without auth info
709
+ === TEST 22 : hit route without auth info
649
710
-- - request
650
711
GET / hello
651
712
-- - error_code: 401
@@ -658,7 +719,7 @@ client request can't be validated: access key or signature missing
658
719
659
720
660
721
661
- === TEST 22 : add consumer with signed_headers
722
+ === TEST 23 : add consumer with signed_headers
662
723
-- - config
663
724
location / t {
664
725
content_by_lua_block {
@@ -690,7 +751,7 @@ passed
690
751
691
752
692
753
693
- === TEST 23 : verify with invalid signed header
754
+ === TEST 24 : verify with invalid signed header
694
755
-- - config
695
756
location / t {
696
757
content_by_lua_block {
@@ -745,7 +806,7 @@ client request can't be validated: Invalid signed header x-custom-header-c
745
806
746
807
747
808
748
- === TEST 24 : verify ok with signed headers
809
+ === TEST 25 : verify ok with signed headers
749
810
-- - config
750
811
location / t {
751
812
content_by_lua_block {
@@ -800,7 +861,7 @@ passed
800
861
801
862
802
863
803
- === TEST 25 : add consumer with plugin hmac-auth - empty configuration
864
+ === TEST 26 : add consumer with plugin hmac-auth - empty configuration
804
865
-- - config
805
866
location / t {
806
867
content_by_lua_block {
0 commit comments