Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhawa Gunasekara authored and Madhawa Gunasekara committed May 14, 2024
1 parent 7e78961 commit bab158f
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 89 deletions.
90 changes: 1 addition & 89 deletions t/plugin/multi-auth.t
Original file line number Diff line number Diff line change
Expand Up @@ -468,98 +468,10 @@ passed



=== TEST 15: verify key-auth with same authorization header
=== TEST 15: verify key-auth using the same authorization header for jwt-auth
--- request
GET /echo
--- more_headers
Authorization: auth-one
--- response_headers
Authorization: auth-one



=== TEST 16: verify multi auth plugin (in header) with hiding credentials
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"multi-auth": {
"auth_plugins": [
{
"basic-auth": {}
},
{
"key-auth": {
"query": "apikey",
"header": "authorization"
}
},
{
"jwt-auth": {
"cookie": "jwt",
"query": "jwt",
"header": "authorization"
}
}
],
"hide_credentials": true
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/echo"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /echo
--- more_headers
Authorization: auth-one
--- response_headers
!Authorization



=== TEST 17: verify jwt-auth with same header
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, err, sign = t('/apisix/plugin/jwt/sign?key=user-key',
ngx.HTTP_GET
)

if code > 200 then
ngx.status = code
ngx.say(err)
return
end

-- verify JWT token
local http = require("resty.http")
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/echo"
local httpc = http.new()
local res, err = httpc:request_uri(uri, {headers={authorization=sign}})

ngx.status = res.status
ngx.print(res.body)
}
}
--- request
GET /t
--- response_headers
!Authorization
157 changes: 157 additions & 0 deletions t/plugin/multi-auth2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use t::APISIX 'no_plan';

repeat_each(2);
no_long_string();
no_root_location();
no_shuffle();
run_tests;

__DATA__

=== TEST 1: add consumer with basic-auth and key-auth plugins
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "foo",
"plugins": {
"basic-auth": {
"username": "foo",
"password": "bar"
},
"key-auth": {
"key": "auth-one"
},
"jwt-auth": {
"key": "user-key",
"secret": "my-secret-key"
}
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed



=== TEST 2: verify multi auth plugin (in header) with hiding credentials
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"multi-auth": {
"auth_plugins": [
{
"basic-auth": {}
},
{
"key-auth": {
"query": "apikey",
"header": "authorization"
}
},
{
"jwt-auth": {
"cookie": "jwt",
"query": "jwt",
"header": "authorization"
}
}
],
"hide_credentials": true
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/echo"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /echo
--- more_headers
Authorization: auth-one
--- response_headers
!Authorization



=== TEST 3: verify key auth with same header with hiding credentials
--- request
GET /echo
--- more_headers
apikey: auth-one
--- response_headers
!Authorization



=== TEST 4: verify jwt-auth with same header
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, err, sign = t('/apisix/plugin/jwt/sign?key=user-key',
ngx.HTTP_GET
)

if code > 200 then
ngx.status = code
ngx.say(err)
return
end

-- verify JWT token
local http = require("resty.http")
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/echo"
local httpc = http.new()
local res, err = httpc:request_uri(uri, {headers={authorization=sign}})

ngx.status = res.status
ngx.print(res.body)
}
}
--- request
GET /t
--- response_headers
!Authorization

0 comments on commit bab158f

Please sign in to comment.