Skip to content

Commit e521741

Browse files
tests: added test cases to cover the ngx.ctx created in ssl_client_hello_by_lua.
tests: removed openssl 1.1.0 from ci since it was not maintained for two years.
1 parent 061e1fb commit e521741

File tree

4 files changed

+195
-3
lines changed

4 files changed

+195
-3
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
sudo: required
22
dist: trusty
33

4+
branches:
5+
only:
6+
- "master"
7+
48
os: linux
59

610
language: c
@@ -40,7 +44,6 @@ env:
4044
- TEST_NGINX_RANDOMIZE=1
4145
- LUACHECK_VER=0.21.1
4246
matrix:
43-
- NGINX_VERSION=1.19.9 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d
4447
- NGINX_VERSION=1.19.9 OPENSSL_VER=1.1.1l OPENSSL_PATCH_VER=1.1.1f
4548

4649
services:

t/ctx.t

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ log_level('debug');
1010
#repeat_each(120);
1111
repeat_each(2);
1212

13-
plan tests => repeat_each() * (blocks() * 3 + 11);
13+
plan tests => repeat_each() * (blocks() * 3 + 13);
1414

1515
#no_diff();
1616
#no_long_string();
@@ -929,3 +929,112 @@ reused
929929
reused again
930930
--- no_error_log
931931
[error]
932+
933+
934+
935+
=== TEST 14: ngx.ctx in ssl_client_hello_by_lua
936+
--- http_config
937+
server {
938+
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
939+
server_name test.com;
940+
ssl_client_hello_by_lua_block {
941+
ngx.ctx.answer = 42
942+
ngx.log(ngx.WARN, "ngx.ctx.answer = ", ngx.ctx.answer)
943+
944+
ngx.ctx.count = 0
945+
}
946+
ssl_certificate ../../cert/test.crt;
947+
ssl_certificate_key ../../cert/test.key;
948+
949+
server_tokens off;
950+
location /foo {
951+
content_by_lua_block {
952+
ngx.say(ngx.ctx.answer)
953+
ngx.ctx.count = ngx.ctx.count + 1
954+
ngx.say(ngx.ctx.count)
955+
}
956+
}
957+
}
958+
--- config
959+
lua_ssl_trusted_certificate ../../cert/test.crt;
960+
961+
location /t {
962+
content_by_lua_block {
963+
do
964+
local sock = ngx.socket.tcp()
965+
966+
sock:settimeout(3000)
967+
968+
local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
969+
if not ok then
970+
ngx.say("failed to connect: ", err)
971+
return
972+
end
973+
974+
local sess, err = sock:sslhandshake(nil, "test.com", true)
975+
if not sess then
976+
ngx.say("failed to do SSL handshake: ", err)
977+
return
978+
end
979+
980+
for i = 1, 2 do
981+
local req = "GET /foo HTTP/1.1\r\nHost: test.com\r\n\r\n"
982+
local bytes, err = sock:send(req)
983+
if not bytes then
984+
ngx.say("failed to send http request: ", err)
985+
return
986+
end
987+
988+
local body_seen = false
989+
while true do
990+
local line, err = sock:receive()
991+
if not line then
992+
break
993+
end
994+
995+
if body_seen then
996+
if line == "0" then
997+
assert(sock:receive())
998+
break
999+
end
1000+
local line, err = sock:receive(line)
1001+
ngx.print("received: ", line)
1002+
assert(sock:receive())
1003+
1004+
elseif line == "" then
1005+
body_seen = true
1006+
end
1007+
end
1008+
end
1009+
1010+
sock:close()
1011+
end -- do
1012+
-- collectgarbage()
1013+
}
1014+
}
1015+
1016+
--- request
1017+
GET /t
1018+
--- response_body
1019+
received: 42
1020+
received: 1
1021+
received: 42
1022+
received: 1
1023+
--- error_log
1024+
ngx.ctx.answer = 42
1025+
--- grep_error_log eval
1026+
qr/lua release ngx.ctx at ref \d+/
1027+
--- grep_error_log_out eval
1028+
["lua release ngx.ctx at ref 2
1029+
lua release ngx.ctx at ref 2
1030+
lua release ngx.ctx at ref 1
1031+
",
1032+
"lua release ngx.ctx at ref 2
1033+
lua release ngx.ctx at ref 2
1034+
lua release ngx.ctx at ref 1
1035+
lua release ngx.ctx at ref 2
1036+
lua release ngx.ctx at ref 2
1037+
lua release ngx.ctx at ref 1
1038+
"]
1039+
--- no_error_log
1040+
[error]

t/ssl.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,7 @@ qr/subject=\/?C(?<eq>\s?=\s?)US(?<sep>\/|,\s)ST\k<eq>California\k<sep>L\k<eq>San
22642264
--- timeout: 4
22652265
22662266
2267+
22672268
=== TEST 22: tls version - TLSv1.3
22682269
--- skip_openssl: 6: < 1.1.1
22692270
--- http_config

t/stream/ctx.t

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use t::TestCore::Stream;
44

55
repeat_each(2);
66

7-
plan tests => repeat_each() * (blocks() * 3 + 2);
7+
plan tests => repeat_each() * (blocks() * 3 + 4);
88

99
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
1010
no_long_string();
@@ -201,3 +201,82 @@ qr/lua release ngx.ctx at ref \d+/
201201
"lua release ngx.ctx at ref 1
202202
lua release ngx.ctx at ref 1
203203
"]
204+
205+
206+
207+
=== TEST 4: ngx.ctx in ssl_client_hello_by_lua
208+
--- stream_config
209+
server {
210+
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
211+
ssl_client_hello_by_lua_block {
212+
ngx.ctx.answer = 42
213+
ngx.log(ngx.WARN, "ngx.ctx.answer = ", ngx.ctx.answer)
214+
215+
ngx.ctx.count = 0
216+
}
217+
ssl_certificate ../../cert/test.crt;
218+
ssl_certificate_key ../../cert/test.key;
219+
220+
content_by_lua_block {
221+
ngx.say(ngx.ctx.answer)
222+
ngx.ctx.count = ngx.ctx.count + 1
223+
ngx.say(ngx.ctx.count)
224+
}
225+
}
226+
--- stream_server_config
227+
lua_ssl_trusted_certificate ../../cert/test.crt;
228+
229+
content_by_lua_block {
230+
do
231+
local sock = ngx.socket.tcp()
232+
233+
sock:settimeout(3000)
234+
235+
local function run()
236+
local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
237+
if not ok then
238+
ngx.say("failed to connect: ", err)
239+
return
240+
end
241+
242+
local sess, err = sock:sslhandshake(nil, "test.com", true)
243+
if not sess then
244+
ngx.say("failed to do SSL handshake: ", err)
245+
return
246+
end
247+
248+
while true do
249+
local line, err = sock:receive()
250+
if not line then
251+
break
252+
end
253+
254+
ngx.say("received: ", line)
255+
end
256+
257+
sock:close()
258+
end
259+
260+
run()
261+
end -- do
262+
-- collectgarbage()
263+
}
264+
265+
--- stream_response
266+
received: 42
267+
received: 1
268+
--- error_log
269+
ngx.ctx.answer = 42
270+
--- grep_error_log eval
271+
qr/lua release ngx.ctx at ref \d+/
272+
--- grep_error_log_out eval
273+
["lua release ngx.ctx at ref 2
274+
lua release ngx.ctx at ref 1
275+
",
276+
"lua release ngx.ctx at ref 2
277+
lua release ngx.ctx at ref 1
278+
lua release ngx.ctx at ref 2
279+
lua release ngx.ctx at ref 1
280+
"]
281+
--- no_error_log
282+
[error]

0 commit comments

Comments
 (0)