Mercurial > hg > nginx-tests
annotate stream_geo_unix.t @ 1553:01867708af95
Tests: adjusted todo_alerts() in js_subrequest.t.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 02 Mar 2020 19:46:52 +0300 |
parents | 144c6ce732e4 |
children | f3ba4c74de31 |
rev | line source |
---|---|
1418
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream geo module with unix socket. |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_geo stream_return unix/) |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->plan(4); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 geo $geo { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 default default; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 255.255.255.255 none; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 geo $remote_addr $geora { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 default default; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 255.255.255.255 none; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 geo $geor { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 ranges; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 0.0.0.0-255.255.255.254 test; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 default none; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 geo $remote_addr $georra { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 ranges; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 0.0.0.0-255.255.255.254 test; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 default none; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 listen unix:%%TESTDIR%%/unix.sock; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 return "geo:$geo geora:$geora geor:$geor georra:$georra"; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 server { |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 listen 127.0.0.1:8080; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_pass unix:%%TESTDIR%%/unix.sock; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 EOF |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t->write_file('index.html', ''); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $t->run(); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 my %data = stream('127.0.0.1:' . port(8080))->read() =~ /(\w+):(\w+)/g; |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 is($data{geo}, 'none', 'geo unix'); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 is($data{geor}, 'none', 'geo unix ranges'); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 is($data{geora}, 'none', 'geo unix remote addr'); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 is($data{georra}, 'none', 'geo unix ranges remote addr'); |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
f3422a4fe349
Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |