Skip to content

Commit c83c9e2

Browse files
catbro666pintsized
authored andcommitted
add test
1 parent 7598cbe commit c83c9e2

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

t/20-mtls.t

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,101 @@ GET /t
209209
--- response_body
210210
hello, CN=foo@example.com,O=OpenResty,ST=California,C=US
211211

212+
213+
=== TEST 4: users with different client certs should not share the same pool.
214+
--- SKIP
215+
--- http_config eval: $::mtls_http_config
216+
--- config eval
217+
"
218+
lua_ssl_trusted_certificate $::HtmlDir/test.crt;
219+
220+
location /t {
221+
content_by_lua_block {
222+
local f = assert(io.open('$::HtmlDir/mtls_client.crt'))
223+
local cert_data = f:read('*a')
224+
f:close()
225+
226+
f = assert(io.open('$::HtmlDir/mtls_client.key'))
227+
local key_data = f:read('*a')
228+
f:close()
229+
230+
local ssl = require('ngx.ssl')
231+
232+
local cert = assert(ssl.parse_pem_cert(cert_data))
233+
local key = assert(ssl.parse_pem_priv_key(key_data))
234+
235+
f = assert(io.open('$::HtmlDir/test.crt'))
236+
local invalid_cert_data = f:read('*a')
237+
f:close()
238+
239+
f = assert(io.open('$::HtmlDir/test.key'))
240+
local invalid_key_data = f:read('*a')
241+
f:close()
242+
243+
local invalid_cert = assert(ssl.parse_pem_cert(invalid_cert_data))
244+
local invalid_key = assert(ssl.parse_pem_priv_key(invalid_key_data))
245+
246+
local httpc = assert(require('resty.http').new())
247+
248+
local ok, err = httpc:connect {
249+
scheme = 'https',
250+
host = 'unix:$::HtmlDir/mtls.sock',
251+
ssl_client_cert = cert,
252+
ssl_client_priv_key = key,
253+
}
254+
255+
if ok and not err then
256+
local res, err = assert(httpc:request {
257+
method = 'GET',
258+
path = '/',
259+
headers = {
260+
['Host'] = 'example.com',
261+
},
262+
})
263+
264+
ngx.say(res:read_body())
265+
end
266+
267+
httpc:set_keepalive()
268+
269+
local httpc = assert(require('resty.http').new())
270+
271+
local ok, err = httpc:connect {
272+
scheme = 'https',
273+
host = 'unix:$::HtmlDir/mtls.sock',
274+
ssl_client_cert = invalid_cert,
275+
ssl_client_priv_key = invalid_key,
276+
}
277+
278+
ngx.say(httpc:get_reused_times())
279+
ngx.say(ok)
280+
ngx.say(err)
281+
282+
if ok and not err then
283+
local res, err = assert(httpc:request {
284+
method = 'GET',
285+
path = '/',
286+
headers = {
287+
['Host'] = 'example.com',
288+
},
289+
})
290+
291+
ngx.say(res.status) -- expect 400
292+
end
293+
294+
httpc:close()
295+
}
296+
}
297+
"
298+
--- user_files eval: $::mtls_user_files
299+
--- request
300+
GET /t
301+
--- no_error_log
302+
[error]
303+
[warn]
304+
--- response_body
305+
hello, CN=foo@example.com,O=OpenResty,ST=California,C=US
306+
0
307+
true
308+
nil
309+
400

0 commit comments

Comments
 (0)