Skip to content

Commit 9cc21da

Browse files
committed
tests: t/proxy-ssl-verify.t
1 parent dcef919 commit 9cc21da

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

t/proxy-ssl-verify.t

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# vim:set ft= ts=4 sw=4 et fdm=marker:
2+
use lib '.';
3+
use t::TestCore;
4+
5+
#worker_connections(10140);
6+
#workers(1);
7+
#log_level('warn');
8+
9+
repeat_each(2);
10+
11+
# All these tests need to have new openssl
12+
my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
13+
my $openssl_version = eval { `$NginxBinary -V 2>&1` };
14+
15+
if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
16+
plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
17+
} else {
18+
plan tests => repeat_each() * (blocks() * 6 - 2) - 4;
19+
}
20+
21+
no_long_string();
22+
#no_diff();
23+
24+
env_to_nginx("PATH=" . $ENV{'PATH'});
25+
$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = "$t::TestCore::lua_package_path";
26+
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
27+
28+
run_tests();
29+
30+
__DATA__
31+
32+
=== TEST 1: ssl.proxysslverify.set_verify_result & ssl.proxysslverify.get_verify_result
33+
--- http_config
34+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
35+
36+
server {
37+
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
38+
39+
ssl_certificate ../../cert/mtls_server.crt;
40+
ssl_certificate_key ../../cert/mtls_server.key;
41+
42+
location / {
43+
default_type 'text/plain';
44+
45+
content_by_lua_block {
46+
ngx.say("hello world")
47+
}
48+
49+
more_clear_headers Date;
50+
}
51+
}
52+
--- config
53+
location /t {
54+
proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
55+
proxy_ssl_verify on;
56+
proxy_ssl_name example.com;
57+
proxy_ssl_certificate ../../cert/mtls_client.crt;
58+
proxy_ssl_certificate_key ../../cert/mtls_client.key;
59+
proxy_ssl_trusted_certificate ../../cert/mtls_ca.crt;
60+
proxy_ssl_session_reuse off;
61+
proxy_ssl_conf_command VerifyMode Peer;
62+
63+
proxy_ssl_verify_by_lua_block {
64+
local proxy_ssl_vfy = require "ngx.ssl.proxysslverify"
65+
66+
local ok, err = proxy_ssl_vfy.set_verify_result(23)
67+
if not ok then
68+
ngx.log(ngx.ERR, "proxy ssl verify set_verify_result failed: ", err)
69+
ngx.exit(ngx.ERROR)
70+
end
71+
72+
local result, err = proxy_ssl_vfy.get_verify_result()
73+
if not result then
74+
ngx.log(ngx.ERR, "proxy ssl verify get_verify_result failed: ", err)
75+
end
76+
77+
ngx.log(ngx.INFO, "proxy ssl verify result: ", result)
78+
}
79+
}
80+
--- request
81+
GET /t
82+
--- error_code: 502
83+
--- response_body_like: 502 Bad Gateway
84+
--- error_log
85+
proxy ssl verify result: 23
86+
--- no_error_log
87+
[alert]
88+
89+
90+
91+
=== TEST 2: ssl.proxysslverify.get_verify_cert
92+
--- http_config
93+
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
94+
95+
server {
96+
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
97+
98+
ssl_certificate ../../cert/mtls_server.crt;
99+
ssl_certificate_key ../../cert/mtls_server.key;
100+
101+
location / {
102+
default_type 'text/plain';
103+
104+
content_by_lua_block {
105+
ngx.say("hello world")
106+
}
107+
108+
more_clear_headers Date;
109+
}
110+
}
111+
--- config
112+
location /t {
113+
proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock;
114+
proxy_ssl_verify on;
115+
proxy_ssl_name example.com;
116+
proxy_ssl_certificate ../../cert/mtls_client.crt;
117+
proxy_ssl_certificate_key ../../cert/mtls_client.key;
118+
proxy_ssl_trusted_certificate ../../cert/mtls_ca.crt;
119+
proxy_ssl_session_reuse off;
120+
proxy_ssl_conf_command VerifyMode Peer;
121+
122+
proxy_ssl_verify_by_lua_block {
123+
local proxy_ssl_vfy = require "ngx.ssl.proxysslverify"
124+
125+
local cert, err = proxy_ssl_vfy.get_verify_cert()
126+
if not cert then
127+
ngx.log(ngx.ERR, "proxy ssl verify get_verify_cert failed: ", err)
128+
end
129+
130+
-- more functions to take care of the returned cert
131+
}
132+
}
133+
--- request
134+
GET /t
135+
--- error_code: 200
136+
--- response_body
137+
hello world
138+
--- no_error_log
139+
proxy ssl verify get_verify_cert failed
140+
[alert]

0 commit comments

Comments
 (0)