Skip to content

Commit f7a24f3

Browse files
committed
Tests: revised tests for listen port ranges.
Renumbered testing ports to get more chance to execute when run in parallel. Relaxed condition to skip tests only when the port range is out of sequence. Adjacent port numbers out of a specified range aren't crucial to skip tests: if not in sequence, statistically this will be caught in subsequent runs. Unsafe tests that use wildcard addresses are moved to a separate file.
1 parent c85a9d0 commit f7a24f3

File tree

2 files changed

+99
-25
lines changed

2 files changed

+99
-25
lines changed

http_listen.t

+17-25
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ http {
3838
3939
server {
4040
listen 127.0.0.1:8080;
41-
listen 127.0.0.1:%%PORT_8082%%-%%PORT_8083%%;
42-
listen %%PORT_8085%%-%%PORT_8086%%;
43-
listen [::1]:%%PORT_8085%%-%%PORT_8086%%;
41+
listen 127.0.0.1:%%PORT_8182%%-%%PORT_8183%%;
42+
listen [::1]:%%PORT_8182%%-%%PORT_8183%%;
4443
server_name localhost;
4544
4645
location / {
@@ -55,43 +54,36 @@ http {
5554
# catch out of range
5655
5756
server {
58-
listen 127.0.0.1:8081;
59-
listen 127.0.0.1:8084;
60-
listen 127.0.0.1:8087;
61-
listen [::1]:%%PORT_8084%%;
62-
listen [::1]:%%PORT_8087%%;
57+
listen 127.0.0.1:8181;
58+
listen 127.0.0.1:8184;
59+
listen [::1]:%%PORT_8181%%;
60+
listen [::1]:%%PORT_8184%%;
6361
server_name localhost;
6462
}
6563
}
6664
6765
EOF
6866

69-
my $p0 = port(8080); my $p3 = port(8083); my $p6 = port(8086);
70-
my $p1 = port(8081); my $p4 = port(8084); my $p7 = port(8087);
71-
my $p2 = port(8082); my $p5 = port(8085);
72-
73-
plan(skip_all => 'listen on wildcard address')
74-
unless $ENV{TEST_NGINX_UNSAFE};
67+
my $p0 = port(8080); my $p3 = port(8183);
68+
my $p1 = port(8181); my $p4 = port(8184);
69+
my $p2 = port(8182);
7570

7671
plan(skip_all => 'no requested ranges')
77-
if "$p0$p1$p2$p3$p4$p5$p6$p7" ne "80808081808280838084808580868087";
72+
if "$p2$p3" ne "81828183";
7873

79-
$t->run()->plan(12);
74+
$t->run()->plan(9);
8075

8176
###############################################################################
8277

8378
like(http_get("/?b=127.0.0.1:$p0"), qr/127.0.0.1:$p0/, 'single');
8479
unlike(http_get("/?b=127.0.0.1:$p1"), qr/127.0.0.1:$p1/, 'out of range 1');
8580
like(http_get("/?b=127.0.0.1:$p2"), qr/127.0.0.1:$p2/, 'range 1');
8681
like(http_get("/?b=127.0.0.1:$p3"), qr/127.0.0.1:$p3/, 'range 2');
87-
unlike(http_get("/?b=127.0.0.1:$p4"), qr/127.0.0.$p4/, 'out of range 2');
88-
like(http_get("/?b=127.0.0.1:$p5"), qr/127.0.0.1:$p5/, 'wildcard range 1');
89-
like(http_get("/?b=127.0.0.1:$p6"), qr/127.0.0.1:$p6/, 'wildcard range 2');
90-
unlike(http_get("/?b=127.0.0.1:$p7"), qr/127.0.0.1:$p7/, 'out of range 3');
91-
92-
unlike(http_get("/?b=[::1]:$p4"), qr/::1:$p4/, 'out of range 4');
93-
like(http_get("/?b=[::1]:$p5"), qr/::1:$p5/, 'ipv6 range 1');
94-
like(http_get("/?b=[::1]:$p6"), qr/::1:$p6/, 'ipv6 range 2');
95-
unlike(http_get("/?b=[::1]:$p7"), qr/::1:$p7/, 'out of range 5');
82+
unlike(http_get("/?b=127.0.0.1:$p4"), qr/127.0.0.1:$p4/, 'out of range 2');
83+
84+
unlike(http_get("/?b=[::1]:$p1"), qr/::1:$p1/, 'inet6 out of range 1');
85+
like(http_get("/?b=[::1]:$p2"), qr/::1:$p2/, 'inet6 range 1');
86+
like(http_get("/?b=[::1]:$p3"), qr/::1:$p3/, 'inet6 range 2');
87+
unlike(http_get("/?b=[::1]:$p4"), qr/::1:$p4/, 'inet6 out of range 2');
9688

9789
###############################################################################

http_listen_wildcard.t

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Sergey Kandaurov
4+
# (C) Nginx, Inc.
5+
6+
# Tests for listen port ranges with a wildcard address.
7+
8+
###############################################################################
9+
10+
use warnings;
11+
use strict;
12+
13+
use Test::More;
14+
15+
BEGIN { use FindBin; chdir($FindBin::Bin); }
16+
17+
use lib 'lib';
18+
use Test::Nginx;
19+
20+
###############################################################################
21+
22+
select STDERR; $| = 1;
23+
select STDOUT; $| = 1;
24+
25+
my $t = Test::Nginx->new()->has(qw/http proxy rewrite/);
26+
27+
plan(skip_all => 'listen on wildcard address')
28+
unless $ENV{TEST_NGINX_UNSAFE};
29+
30+
$t->write_file_expand('nginx.conf', <<'EOF');
31+
32+
%%TEST_GLOBALS%%
33+
34+
daemon off;
35+
36+
events {
37+
}
38+
39+
http {
40+
%%TEST_GLOBALS_HTTP%%
41+
42+
server {
43+
listen 127.0.0.1:8080;
44+
listen %%PORT_8186%%-%%PORT_8187%%;
45+
server_name localhost;
46+
47+
location / {
48+
proxy_pass http://$arg_b/t;
49+
}
50+
51+
location /t {
52+
return 200 $server_addr:$server_port;
53+
}
54+
}
55+
56+
# catch out of range
57+
58+
server {
59+
listen 127.0.0.1:8185;
60+
listen 127.0.0.1:8188;
61+
server_name localhost;
62+
}
63+
}
64+
65+
EOF
66+
67+
my $p5 = port(8185); my $p7 = port(8187);
68+
my $p6 = port(8186); my $p8 = port(8188);
69+
70+
plan(skip_all => 'no requested ranges')
71+
if "$p6$p7" ne "81868187";
72+
73+
$t->run()->plan(4);
74+
75+
###############################################################################
76+
77+
unlike(http_get("/?b=127.0.0.1:$p5"), qr/127.0.0.1:$p5/, 'out of range 1');
78+
like(http_get("/?b=127.0.0.1:$p6"), qr/127.0.0.1:$p6/, 'wildcard range 1');
79+
like(http_get("/?b=127.0.0.1:$p7"), qr/127.0.0.1:$p7/, 'wildcard range 2');
80+
unlike(http_get("/?b=127.0.0.1:$p8"), qr/127.0.0.1:$p8/, 'out of range 2');
81+
82+
###############################################################################

0 commit comments

Comments
 (0)