Mercurial > hg > nginx-tests
comparison realip.t @ 216:f2f37a52e42e
Tests: basic tests for geo and realip modules.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 12 May 2012 04:54:01 +0400 |
parents | |
children | ea574aae77cb |
comparison
equal
deleted
inserted
replaced
215:7f5095965c88 | 216:f2f37a52e42e |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for nginx realip module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 my $t = Test::Nginx->new()->has(qw/http realip/)->plan(3); | |
25 | |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 set_real_ip_from 127.0.0.1/32; | |
39 real_ip_header X-Forwarded-For; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080; | |
43 server_name localhost; | |
44 | |
45 location / { | |
46 add_header X-IP $remote_addr; | |
47 } | |
48 } | |
49 } | |
50 | |
51 EOF | |
52 | |
53 $t->write_file('1', ''); | |
54 $t->run(); | |
55 | |
56 ############################################################################### | |
57 | |
58 like(http_get('/1'), qr/^X-IP: 127.0.0.1/m, 'realip no ip'); | |
59 | |
60 like(http_xff('192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip'); | |
61 like(http_xff('10.0.0.1, 192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip multi'); | |
62 | |
63 ############################################################################### | |
64 | |
65 sub http_xff { | |
66 my ($xff) = @_; | |
67 return http(<<EOF); | |
68 GET /1 HTTP/1.0 | |
69 Host: localhost | |
70 X-Forwarded-For: $xff | |
71 | |
72 EOF | |
73 } | |
74 | |
75 ############################################################################### |