Skip to content

Commit

Permalink
fix: fix and optimize tls in upstream_schema (apache#10269)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzy0618 authored and Revolyssup committed Oct 15, 2023
1 parent 982eefb commit f3180c8
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 9 deletions.
12 changes: 3 additions & 9 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,10 @@ local upstream_schema = {
},
},
dependencies = {
client_cert = {
required = {"client_key"},
["not"] = {required = {"client_cert_id"}}
},
client_key = {
required = {"client_cert"},
["not"] = {required = {"client_cert_id"}}
},
client_cert = {required = {"client_key"}},
client_key = {required = {"client_cert"}},
client_cert_id = {
["not"] = {required = {"client_client", "client_key"}}
["not"] = {required = {"client_cert", "client_key"}}
}
}
},
Expand Down
98 changes: 98 additions & 0 deletions t/core/schema_def.t
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,101 @@ qr/ok: false err: property "(id|plugins)" is required/
GET /t
--- response_body
passed
=== TEST 4: sanity check upstream_schema
--- config
location /t {
content_by_lua_block {
local schema_def = require("apisix.schema_def")
local core = require("apisix.core")
local t = require("lib.test_admin")
local ssl_cert = t.read_file("t/certs/apisix.crt")
local ssl_key = t.read_file("t/certs/apisix.key")
local upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert_id = 1,
client_cert = ssl_cert,
client_key = ssl_key
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(not ok)
assert(err ~= nil)
upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert_id = 1
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(ok)
assert(err == nil, err)
upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert = ssl_cert,
client_key = ssl_key
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(ok)
assert(err == nil, err)
upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(ok)
assert(err == nil, err)
upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert = ssl_cert
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(not ok)
assert(err ~= nil)
upstream = {
nodes = {
["127.0.0.1:8080"] = 1
},
type = "roundrobin",
tls = {
client_cert_id = 1,
client_key = ssl_key
}
}
local ok, err = core.schema.check(schema_def.upstream, upstream)
assert(not ok)
assert(err ~= nil)
ngx.say("passed")
}
}
--- response_body
passed

0 comments on commit f3180c8

Please sign in to comment.