tokers commented on a change in pull request #2830:
URL: https://github.com/apache/apisix/pull/2830#discussion_r530066963



##########
File path: t/plugin/hmac-auth.t
##########
@@ -1633,3 +1633,125 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 42: verify: ok, the request parameter is missing `=<value>`.
+--- config
+location /t {
+    content_by_lua_block {
+        local ngx_time   = ngx.time

Review comment:
       Style: too many spaces before `=`.

##########
File path: t/plugin/hmac-auth.t
##########
@@ -1633,3 +1633,125 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 42: verify: ok, the request parameter is missing `=<value>`.
+--- config
+location /t {
+    content_by_lua_block {
+        local ngx_time   = ngx.time
+        local ngx_http_time = ngx.http_time
+        local core = require("apisix.core")
+        local t = require("lib.test_admin")
+        local hmac = require("resty.hmac")
+        local ngx_encode_base64 = ngx.encode_base64
+
+        local secret_key = "my-secret-key6"
+        local timestamp = ngx_time()
+        local gmt = ngx_http_time(timestamp)
+        local access_key = "my-access-key6"
+        local custom_header_a = "asld$%dfasf"
+        local custom_header_b = "23879fmsldfk"
+
+        local signing_string = {
+            "GET",
+            "/hello",
+            "age=&name=jack",
+            access_key,
+            gmt,
+            "x-custom-header-a:" .. custom_header_a,
+            "x-custom-header-b:" .. custom_header_b
+        }
+        signing_string = core.table.concat(signing_string, "\n") .. "\n"
+        core.log.info("signing_string:", signing_string)
+
+        local signature = hmac:new(secret_key, 
hmac.ALGOS.SHA256):final(signing_string)
+        core.log.info("signature:", ngx_encode_base64(signature))
+        local headers = {}
+        headers["X-HMAC-SIGNATURE"] = ngx_encode_base64(signature)
+        headers["X-HMAC-ALGORITHM"] = "hmac-sha256"
+        headers["Date"] = gmt
+        headers["X-HMAC-ACCESS-KEY"] = access_key
+        headers["X-HMAC-SIGNED-HEADERS"] = 
"x-custom-header-a;x-custom-header-b"
+        headers["x-custom-header-a"] = custom_header_a
+        headers["x-custom-header-b"] = custom_header_b
+
+        local code, body = t.test('/hello?name=jack&age',
+            ngx.HTTP_GET,
+            "",
+            nil,
+            headers
+        )
+
+        ngx.status = code
+        ngx.say(body)
+    }
+}
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 43: verify: ok, the value of the request parameter is true.
+--- config
+location /t {
+    content_by_lua_block {
+        local ngx_time   = ngx.time

Review comment:
       Ditto, too many spaces before `=`.

##########
File path: t/plugin/hmac-auth.t
##########
@@ -1633,3 +1633,125 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 42: verify: ok, the request parameter is missing `=<value>`.
+--- config
+location /t {
+    content_by_lua_block {
+        local ngx_time   = ngx.time
+        local ngx_http_time = ngx.http_time
+        local core = require("apisix.core")
+        local t = require("lib.test_admin")
+        local hmac = require("resty.hmac")
+        local ngx_encode_base64 = ngx.encode_base64
+
+        local secret_key = "my-secret-key6"
+        local timestamp = ngx_time()
+        local gmt = ngx_http_time(timestamp)
+        local access_key = "my-access-key6"
+        local custom_header_a = "asld$%dfasf"
+        local custom_header_b = "23879fmsldfk"
+
+        local signing_string = {
+            "GET",
+            "/hello",
+            "age=&name=jack",
+            access_key,
+            gmt,
+            "x-custom-header-a:" .. custom_header_a,
+            "x-custom-header-b:" .. custom_header_b
+        }
+        signing_string = core.table.concat(signing_string, "\n") .. "\n"
+        core.log.info("signing_string:", signing_string)
+
+        local signature = hmac:new(secret_key, 
hmac.ALGOS.SHA256):final(signing_string)
+        core.log.info("signature:", ngx_encode_base64(signature))
+        local headers = {}
+        headers["X-HMAC-SIGNATURE"] = ngx_encode_base64(signature)
+        headers["X-HMAC-ALGORITHM"] = "hmac-sha256"
+        headers["Date"] = gmt
+        headers["X-HMAC-ACCESS-KEY"] = access_key
+        headers["X-HMAC-SIGNED-HEADERS"] = 
"x-custom-header-a;x-custom-header-b"
+        headers["x-custom-header-a"] = custom_header_a
+        headers["x-custom-header-b"] = custom_header_b
+
+        local code, body = t.test('/hello?name=jack&age',
+            ngx.HTTP_GET,
+            "",
+            nil,
+            headers
+        )
+
+        ngx.status = code
+        ngx.say(body)
+    }
+}
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 43: verify: ok, the value of the request parameter is true.

Review comment:
       Why checking it when value is literal `true` string? It makes no sense 
for your fixing, the process of literal string `true` is same with other non 
empty values, you should test arguments with form of "id=123&name".

##########
File path: t/plugin/hmac-auth.t
##########
@@ -1633,3 +1633,125 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 42: verify: ok, the request parameter is missing `=<value>`.
+--- config
+location /t {
+    content_by_lua_block {
+        local ngx_time   = ngx.time
+        local ngx_http_time = ngx.http_time
+        local core = require("apisix.core")
+        local t = require("lib.test_admin")
+        local hmac = require("resty.hmac")
+        local ngx_encode_base64 = ngx.encode_base64
+
+        local secret_key = "my-secret-key6"
+        local timestamp = ngx_time()
+        local gmt = ngx_http_time(timestamp)
+        local access_key = "my-access-key6"
+        local custom_header_a = "asld$%dfasf"
+        local custom_header_b = "23879fmsldfk"
+
+        local signing_string = {
+            "GET",
+            "/hello",
+            "age=&name=jack",
+            access_key,
+            gmt,
+            "x-custom-header-a:" .. custom_header_a,
+            "x-custom-header-b:" .. custom_header_b
+        }
+        signing_string = core.table.concat(signing_string, "\n") .. "\n"
+        core.log.info("signing_string:", signing_string)

Review comment:
       It this your debug logging? You don't check it by `grep_error_log`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to