Skip to content

Commit f19338b

Browse files
spacewanderagentzh
authored andcommitted
tests: corrected the handshake flag setting positions.
We should set the handshake done flag when the handshake is totally finished, not just right before the first handshake begins. The incorrect handshake flag caused some random test failures. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent e9fb2a8 commit f19338b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

t/ssl-session-fetch.t

+10-7
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,6 @@ $/s,
414414
415415
local sid = ssl.get_session_id()
416416
print("session id: ", sid)
417-
418-
ngx.shared.done:set("handshake", true)
419417
}
420418
421419
ssl_session_fetch_by_lua_block {
@@ -430,8 +428,6 @@ $/s,
430428
if not ok or err then
431429
print("failed to resume session: ", err)
432430
end
433-
434-
-- ngx.shared.done:set("handshake", true)
435431
}
436432
437433
server {
@@ -440,6 +436,12 @@ $/s,
440436
ssl_session_tickets off;
441437
ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
442438
ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key;
439+
440+
location / {
441+
content_by_lua_block {
442+
ngx.shared.done:set("handshake", true)
443+
}
444+
}
443445
}
444446
--- config
445447
lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt;
@@ -451,12 +453,13 @@ $/s,
451453
ngx.shared.done:delete("handshake")
452454
local addr = ngx.var.addr;
453455
local sess = ngx.var.sess_file
456+
local req = "'GET / HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n'"
454457
local f, err
455458
if not package.loaded.session then
456-
f, err = io.popen("echo 'Q' | timeout 3s openssl s_client -connect " .. addr .. " -sess_out " .. sess)
459+
f, err = io.popen("echo -n " .. req .. " | timeout 3s openssl s_client -connect " .. addr .. " -sess_out " .. sess)
457460
package.loaded.session = true
458461
else
459-
f, err = io.popen("echo 'Q' | timeout 3s openssl s_client -connect " .. addr .. " -sess_in " .. sess)
462+
f, err = io.popen("echo -n " .. req .. " | timeout 3s openssl s_client -connect " .. addr .. " -sess_in " .. sess)
460463
end
461464
462465
if not f then
@@ -465,7 +468,7 @@ $/s,
465468
end
466469
467470
local step = 0.001
468-
while step < 1 do
471+
while step < 2 do
469472
ngx.sleep(step)
470473
step = step * 2
471474

t/ssl.t

+5-6
Original file line numberDiff line numberDiff line change
@@ -2211,13 +2211,11 @@ client ip: 127.0.0.1
22112211
ngx.log(ngx.ERR, "failed to set DER cert: ", err)
22122212
return
22132213
end
2214-
2215-
ngx.shared.done:set("handshake", true)
22162214
}
22172215
2218-
location /foo {
2216+
location / {
22192217
content_by_lua_block {
2220-
ngx.exit(201)
2218+
ngx.shared.done:set("handshake", true)
22212219
}
22222220
}
22232221
}
@@ -2228,14 +2226,15 @@ client ip: 127.0.0.1
22282226
content_by_lua_block {
22292227
ngx.shared.done:delete("handshake")
22302228
local addr = ngx.var.addr;
2231-
local f, err = io.popen("echo 'Q' | timeout 3s openssl s_client -connect 127.0.0.1:$TEST_NGINX_SERVER_SSL_PORT")
2229+
local req = "'GET / HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n'"
2230+
local f, err = io.popen("echo -n " .. req .. " | timeout 3s openssl s_client -connect 127.0.0.1:$TEST_NGINX_SERVER_SSL_PORT")
22322231
if not f then
22332232
ngx.say(err)
22342233
return
22352234
end
22362235
22372236
local step = 0.001
2238-
while step < 1 do
2237+
while step < 2 do
22392238
ngx.sleep(step)
22402239
step = step * 2
22412240

0 commit comments

Comments
 (0)