comparison geo_unix.t @ 1418:f3422a4fe349

Tests: simple geo module tests with unix socket address.
author Sergey Kandaurov <pluknet@nginx.com>
date Sun, 16 Dec 2018 13:06:22 +0300
parents
children 144c6ce732e4
comparison
equal deleted inserted replaced
1417:ea796652fcdc 1418:f3422a4fe349
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for http geo module with unix socket.
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 geo proxy unix/)->plan(5);
26
27 $t->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 geo $geo {
40 default default;
41 255.255.255.255 none;
42 }
43
44 geo $remote_addr $geora {
45 default default;
46 255.255.255.255 none;
47 }
48
49 geo $geor {
50 ranges;
51 0.0.0.0-255.255.255.254 test;
52 default none;
53 }
54
55 geo $remote_addr $georra {
56 ranges;
57 0.0.0.0-255.255.255.254 test;
58 default none;
59 }
60
61 geo $arg_ip $geo_arg {
62 default default;
63 192.0.2.0/24 test;
64 }
65
66 server {
67 listen unix:%%TESTDIR%%/unix.sock;
68 server_name localhost;
69
70 location / {
71 add_header X-Geo $geo;
72 add_header X-Addr $geora;
73 add_header X-Ranges $geor;
74 add_header X-Ranges-Addr $georra;
75 add_header X-Arg $geo_arg;
76 }
77 }
78
79 server {
80 listen 127.0.0.1:8080;
81
82 location / {
83 proxy_pass http://unix:%%TESTDIR%%/unix.sock;
84 }
85 }
86 }
87
88 EOF
89
90 $t->write_file('index.html', '');
91 $t->run();
92
93 ###############################################################################
94
95 my $r = http_get('/');
96
97 TODO: {
98 local $TODO = 'not yet' unless $t->has_version('1.15.8');
99
100 like($r, qr/^X-Geo: none/m, 'geo unix');
101 like($r, qr/^X-Ranges: none/m, 'geo unix ranges');
102
103 }
104
105 like($r, qr/^X-Addr: none/m, 'geo unix remote addr');
106 like($r, qr/^X-Ranges-Addr: none/m, 'geo unix ranges remote addr');
107
108 like(http_get('/?ip=192.0.2.1'), qr/^X-Arg: test/m, 'geo unix variable');
109
110 ###############################################################################