Skip to content

Commit 8c7f9bf

Browse files
authored
tests: t/129-ssl-socket.t: use the same IP to ensure that the ssl session can be reused. (#2267)
1 parent 0d054a5 commit 8c7f9bf

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

t/129-ssl-socket.t

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ 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("openresty.org", $ENV{TEST_NGINX_RESOLVER});
2528

2629
my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
2730
my $openssl_version = eval { `$NginxBinary -V 2>&1` };
@@ -44,6 +47,19 @@ sub read_file {
4447
$cert;
4548
}
4649

50+
sub resolve ($$) {
51+
my ($domain, $resolver) = @_;
52+
my $ips = qx/dig \@$resolver +short $domain/;
53+
54+
my $exit_code = $? >> 8;
55+
if (!$ips || $exit_code != 0) {
56+
die "failed to resolve '$domain' using '$resolver' as resolver";
57+
}
58+
59+
my ($ip) = split /\n/, $ips;
60+
return $ip;
61+
}
62+
4763
our $DSTRootCertificate = read_file("t/cert/dst-ca.crt");
4864
our $EquifaxRootCertificate = read_file("t/cert/equifax.crt");
4965
our $TestCertificate = read_file("t/cert/test.crt");
@@ -1397,6 +1413,7 @@ SSL reused session
13971413
location /t {
13981414
#set $port 5000;
13991415
set $port $TEST_NGINX_MEMCACHED_PORT;
1416+
set $openresty_org_ip $TEST_NGINX_OPENRESTY_ORG_IP;
14001417
14011418
content_by_lua '
14021419
local sock = ngx.socket.tcp()
@@ -1406,7 +1423,8 @@ SSL reused session
14061423
14071424
local session
14081425
for i = 1, 3 do
1409-
local ok, err = sock:connect("openresty.org", 443)
1426+
-- Use the same IP to ensure that the connection can be reused
1427+
local ok, err = sock:connect(ngx.var.openresty_org_ip, 443)
14101428
if not ok then
14111429
ngx.say("failed to connect: ", err)
14121430
return
@@ -1473,6 +1491,7 @@ SSL reused session
14731491
lua_ssl_verify_depth 2;
14741492
location /t {
14751493
#set $port 5000;
1494+
set $openresty_org_ip $TEST_NGINX_OPENRESTY_ORG_IP;
14761495
set $port $TEST_NGINX_MEMCACHED_PORT;
14771496
14781497
content_by_lua '
@@ -1482,7 +1501,8 @@ SSL reused session
14821501
do
14831502
14841503
for i = 1, 3 do
1485-
local ok, err = sock:connect("openresty.org", 443)
1504+
-- Use the same IP to ensure that the connection can be reused
1505+
local ok, err = sock:connect(ngx.var.openresty_org_ip, 443)
14861506
if not ok then
14871507
ngx.say("failed to connect: ", err)
14881508
return

0 commit comments

Comments
 (0)