Skip to content

Commit 85a0a1f

Browse files
committed
tests: t/129-ssl-socket.t: use the same IP to ensure that the ssl session can be reused.
1 parent ff96d75 commit 85a0a1f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

t/129-ssl-socket.t

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ use File::Basename;
1515

1616
repeat_each(2);
1717

18+
sub resolve($$);
19+
1820
plan tests => repeat_each() * (blocks() * 7 - 3);
1921

2022
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
2123
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
2224
$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
2325
$ENV{TEST_NGINX_SERVER_SSL_PORT} ||= 12345;
2426
$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__)));
27+
$ENV{TEST_NGINX_OPENRESTY_ORG_IP} ||= resolve($ENV{TEST_NGINX_RESOLVER},
28+
"openresty.org");
2529

2630
my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
2731
my $openssl_version = eval { `$NginxBinary -V 2>&1` };
@@ -44,6 +48,19 @@ sub read_file {
4448
$cert;
4549
}
4650

51+
sub resolve ($$) {
52+
my ($resolver, $domain) = @_;
53+
my $ips = qx/dig \@$resolver +short $domain/;
54+
55+
my $exit_code = $? >> 8;
56+
if (!$ips || $exit_code != 0) {
57+
die "failed to resolve '$domain' using '$resolver' as resolver";
58+
}
59+
60+
my ($ip) = split /\n/, $ips;
61+
return $ip;
62+
}
63+
4764
our $DSTRootCertificate = read_file("t/cert/dst-ca.crt");
4865
our $EquifaxRootCertificate = read_file("t/cert/equifax.crt");
4966
our $TestCertificate = read_file("t/cert/test.crt");
@@ -1397,6 +1414,7 @@ SSL reused session
13971414
location /t {
13981415
#set $port 5000;
13991416
set $port $TEST_NGINX_MEMCACHED_PORT;
1417+
set $openresty_org_ip $TEST_NGINX_OPENRESTY_ORG_IP;
14001418
14011419
content_by_lua '
14021420
local sock = ngx.socket.tcp()
@@ -1406,7 +1424,8 @@ SSL reused session
14061424
14071425
local session
14081426
for i = 1, 3 do
1409-
local ok, err = sock:connect("openresty.org", 443)
1427+
-- Use the same IP to ensure that the connection can be reused
1428+
local ok, err = sock:connect(ngx.var.openresty_org_ip, 443)
14101429
if not ok then
14111430
ngx.say("failed to connect: ", err)
14121431
return
@@ -1473,6 +1492,7 @@ SSL reused session
14731492
lua_ssl_verify_depth 2;
14741493
location /t {
14751494
#set $port 5000;
1495+
set $openresty_org_ip $TEST_NGINX_OPENRESTY_ORG_IP;
14761496
set $port $TEST_NGINX_MEMCACHED_PORT;
14771497
14781498
content_by_lua '
@@ -1482,7 +1502,8 @@ SSL reused session
14821502
do
14831503
14841504
for i = 1, 3 do
1485-
local ok, err = sock:connect("openresty.org", 443)
1505+
-- Use the same IP to ensure that the connection can be reused
1506+
local ok, err = sock:connect(ngx.var.openresty_org_ip, 443)
14861507
if not ok then
14871508
ngx.say("failed to connect: ", err)
14881509
return

0 commit comments

Comments
 (0)