Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,23 @@ _M.ssl = {
sni = {
type = "string",
pattern = [[^\*?[0-9a-zA-Z-.]+$]],
}
},
snis = {
type = "array",
items = {
type = "string",
pattern = [[^\*?[0-9a-zA-Z-.]+$]],
}
},
exptime = {
type = "integer",
minimum = 1588262400, -- 2020/5/1 0:0:0
},
},
oneOf = {
{required = {"sni", "key", "cert"}},
{required = {"snis", "key", "cert"}}
},
required = {"sni", "key", "cert"},
additionalProperties = false,
}

Expand Down
18 changes: 16 additions & 2 deletions t/admin/schema.t
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,23 @@ location /t {
sni = {
type = "string",
pattern = [[^\*?[0-9a-zA-Z-.]+$]],
}
},
snis = {
type = "array",
items = {
type = "string",
pattern = [[^\*?[0-9a-zA-Z-.]+$]],
}
},
exptime = {
type = "integer",
minimum = 1588262400, -- 2020/5/1 0:0:0
},
},
oneOf = {
{required = {"sni", "key", "cert"}},
{required = {"snis", "key", "cert"}}
},
required = {"sni", "key", "cert"},
additionalProperties = false,
}
)
Expand Down
86 changes: 85 additions & 1 deletion t/admin/ssl.t
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"cert\" is required"}
{"error_msg":"invalid configuration: value should match only one schema, but matches none"}
--- no_error_log
[error]

Expand Down Expand Up @@ -269,3 +269,87 @@ GET /t
passed
--- no_error_log
[error]



=== TEST 8: store sni in `snis`
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin")

local ssl_cert = t.read_file("conf/cert/apisix.crt")
local ssl_key = t.read_file("conf/cert/apisix.key")
local data = {
cert = ssl_cert, key = ssl_key,
snis = {"*.foo.com", "bar.com"},
}

local code, body = t.test('/apisix/admin/ssl/1',
ngx.HTTP_PUT,
core.json.encode(data),
[[{
"node": {
"value": {
"snis": ["*.foo.com", "bar.com"]
},
"key": "/apisix/ssl/1"
},
"action": "set"
}]]
)

ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 9: store exptime
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin")

local ssl_cert = t.read_file("conf/cert/apisix.crt")
local ssl_key = t.read_file("conf/cert/apisix.key")
local data = {
cert = ssl_cert, key = ssl_key,
sni = "bar.com",
exptime = 1588262400 + 60 * 60 * 24 * 365,
}

local code, body = t.test('/apisix/admin/ssl/1',
ngx.HTTP_PUT,
core.json.encode(data),
[[{
"node": {
"value": {
"sni": "bar.com",
"exptime": 1619798400
},
"key": "/apisix/ssl/1"
},
"action": "set"
}]]
)

ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
4 changes: 3 additions & 1 deletion t/lib/test_admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ end


function _M.comp_tab(left_tab, right_tab)
dir_names = {}

if type(left_tab) == "string" then
left_tab = json.decode(left_tab)
end
Expand All @@ -110,7 +112,7 @@ function _M.comp_tab(left_tab, right_tab)

local ok, err = com_tab(left_tab, right_tab)
if not ok then
return 500, "failed, " .. err
return false, err
end

return true
Expand Down