annotate referer.t @ 572:ca54b445d982

Tests: masked nginx bug in proxy next upstream. When iterating through several next upstreams per a worker cycle, a previously reported event about upstream connection error may be improperly applied to the next upstream, thus leading to the invalid connection error. E.g., in kqueue, where the problem is visible, this is caused by "ev->instance" that does not tolerate more than one next upstream at once, and kevents placed on the kqueue separately for read and write events. The change is to limit test case to the only one next upstream.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 14 May 2015 11:54:24 +0300
parents 847ea345becb
children e9064d691790
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # Tests for referer module.
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 ###############################################################################
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 use warnings;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use strict;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use Test::More;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 use lib 'lib';
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 ###############################################################################
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
327
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http referer rewrite/)->plan(54);
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 $t->write_file_expand('nginx.conf', <<'EOF');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 server {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 listen 127.0.0.1:8080;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server_name another;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 valid_referers server_names;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 return 200 "$host value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 listen 127.0.0.1:8080;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 server_name _;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 location / {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 valid_referers server_names;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 return 200 "$host value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server_name below;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 server {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 listen 127.0.0.1:8080;
325
ba212f244288 Tests: more referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 324
diff changeset
59 server_name localhost ~bar ~^anchoredre$;
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 location /blocked {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 valid_referers blocked www.example.org;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 location /none {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 valid_referers none www.example.org;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 location /simple {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 valid_referers www.example.org;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 location /regex {
325
ba212f244288 Tests: more referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 324
diff changeset
74 valid_referers ~example.org ~(?-i)example.net;
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 location /regex2 {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 valid_referers ~example.org/uri;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 location /regex3 {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 valid_referers ~example.org$;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 location /uri {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 valid_referers www.example.org/uri;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 location /sn {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 valid_referers server_names;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 location /sn_blocked {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 valid_referers blocked server_names;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 location /wc {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 valid_referers *.example.com *.example.org www.example.* example.*;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 }
327
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
101 location /long {
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
102 valid_referers ~.*;
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
103 return 200 "value $invalid_referer";
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
104 }
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 location /wc2 {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 valid_referers www.example.*/uri;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 return 200 "value $invalid_referer";
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 EOF
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 $t->run();
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 ###############################################################################
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 ok(valid('/simple', 'http://www.example.org'), 'simple');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 ok(valid('/simple', 'http://www.example.org/uri'), 'simple uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 ok(valid('/simple', 'http://www.example.org:8080/uri'), 'simple port uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 ok(!valid('/simple', 'localhost'), 'simple invalid');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 ok(valid('/simple', 'https://www.example.org'), 'https');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 ok(!valid('/simple', 'example.com'), 'no scheme');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 ok(!valid('/simple'), 'no none');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 ok(valid('/none'), 'none');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 ok(!valid('/none', ''), 'none empty');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 ok(valid('/blocked', 'www.example.org'), 'blocked');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 ok(valid('/blocked', 'www.example.com'), 'blocked 2');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 ok(valid('/blocked', 'http://su'), 'blocked short');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 ok(valid('/blocked', 'foobar'), 'blocked short no scheme');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 ok(valid('/blocked', ''), 'blocked empty');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 ok(!valid('/simple', 'foobar'), 'small');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 ok(valid('/simple', 'http://www.example.org/' . 'a' x 256), 'long uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 ok(!valid('/simple', 'http://www.example.' . 'a' x 256), 'long hostname');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 ok(!valid('/wc', 'http://example.' . 'a' x 256), 'long hostname wildcard');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138
327
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
139 ok(valid('/long', 'http://' . 'a' x 255), 'long hostname 255');
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
140 ok(valid('/long', 'http://' . 'a' x 256), 'long hostname 256');
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
141 ok(!valid('/long', 'http://' . 'a' x 257), 'long hostname 257');
dacd55fa2cde Tests: added edge case tests for long hostname in referer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 325
diff changeset
142
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 ok(valid('/uri', 'http://www.example.org/uri'), 'uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 ok(valid('/uri', 'http://www.example.org/urii'), 'uri prefix');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 ok(!valid('/uri', 'http://www.example.org/uRi'), 'uri case');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 ok(valid('/uri', 'http://www.example.org:8080/urii'), 'uri port');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 ok(!valid('/uri', 'http://www.example.org/ur'), 'uri invalid len');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 ok(!valid('/uri', 'http://www.example.org/urd'), 'uri invalid cmp');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 ok(valid('/regex', 'http://www.example.org'), 'regex');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 ok(valid('/regex', 'http://www.eXample.org'), 'regex caseless');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 ok(valid('/regex', 'http://www.example.org/uri'), 'regex uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 ok(!valid('/regex', 'http://www.example.com'), 'regex mismatch');
325
ba212f244288 Tests: more referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 324
diff changeset
154 ok(!valid('/regex', 'http://www.eXample.net'), 'regex case mismatch');
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 ok(valid('/regex2', 'http://www.example.org/uri'), 'regex 2 uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 ok(!valid('/regex2', 'http://www.example.org'), 'regex 2 no uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 ok(valid('/regex2', 'http://www.example.org/uRI'), 'regex 2 uri caseless');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 ok(valid('/regex3', 'https://www.eXample.org'), 'regex https');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 ok(valid('/sn', 'http://localhost'), 'server_names');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 ok(valid('/sn', 'http://localHost'), 'server_names caseless');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 ok(valid('/sn', 'http://localhost/uri'), 'server_names uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 ok(valid('/sn', 'http://foobar'), 'server_names regex');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 ok(valid('/sn', 'http://foobAr'), 'server_names regex caseless');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 ok(valid('/sn', 'http://foobAr/uri'), 'server_names regex caseless uri');
325
ba212f244288 Tests: more referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 324
diff changeset
167 ok(valid('/sn', 'http://anchoredre/uri'), 'server_names regex anchored');
321
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 ok(valid('/sn', 'http://foobar/uri'), 'server_names regex uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 ok(!valid('/sn', 'localhost'), 'server_names no scheme');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 ok(!valid('/sn', 'foobar'), 'server_names regex no scheme');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 ok(valid('/sn_blocked', 'localhost'), 'server_names no scheme blocked');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 ok(valid('/wc', 'http://www.example.org'), 'wildcard head');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 ok(valid('/wc', 'http://www.example.net'), 'wildcard tail');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 ok(valid('/wc2', 'http://www.example.net/uri'), 'wildcard uri');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 ok(valid('/wc2', 'http://www.example.net/urii'), 'wildcard uri prefix');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 ok(!valid('/wc2', 'http://www.example.net/uRI'), 'wildcard uri case');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 ok(valid('/', 'http://another', 'another'), 'server context');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 # server_name below valid_referers
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 ok(valid('/', 'http://below', 'below'), 'server below');
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 ###############################################################################
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 sub valid {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 my ($uri, $referer, $host) = @_;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 my $text;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 $host = 'localhost' unless defined $host;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 unless (defined $referer) {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 $text = http_get($uri);
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 } else {
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 $text = http(<<EOF);
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 GET $uri HTTP/1.0
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 Host: $host
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 Referer: $referer
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 EOF
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 $text =~ /value 1/ && return 0;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 $text =~ /value/ && return 1;
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 fail("no valid_referers in $uri");
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 }
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208
f98e8674361b Tests: referer tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 ###############################################################################