Mercurial > hg > nginx-tests
comparison http_location_auto.t @ 330:617f72beba8d
Tests: location auto_redirect edge case test.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 14 Sep 2013 03:48:56 +0400 |
parents | |
children | b86d60e4cb96 |
comparison
equal
deleted
inserted
replaced
329:98c6af2a5138 | 330:617f72beba8d |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for location selection, an auto_redirect edge case. | |
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 proxy rewrite/)->plan(4) | |
25 ->write_file_expand('nginx.conf', <<'EOF'); | |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
29 daemon off; | |
30 | |
31 events { | |
32 } | |
33 | |
34 http { | |
35 %%TEST_GLOBALS_HTTP%% | |
36 | |
37 server { | |
38 listen 127.0.0.1:8080; | |
39 server_name localhost; | |
40 | |
41 proxy_hide_header X-Location; | |
42 add_header X-Location unset; | |
43 | |
44 # As of nginx 1.5.4, this results in the following | |
45 # location tree: | |
46 # | |
47 # "/a-b" | |
48 # "/a-a" "/a/" | |
49 # | |
50 # A request to "/a" is expected to match "/a/" with auto_redirect, | |
51 # but with such a tree it tests locations "/a-b", "/a-a" and then | |
52 # falls back to null location. | |
53 # | |
54 # Key factor is that "-" is less than "/". | |
55 | |
56 location /a/ { proxy_pass http://127.0.0.1:8080/a-a; } | |
57 location /a-a { add_header X-Location a-a; return 204; } | |
58 location /a-b { add_header X-Location a-b; return 204; } | |
59 } | |
60 } | |
61 | |
62 EOF | |
63 | |
64 $t->run(); | |
65 | |
66 ############################################################################### | |
67 | |
68 TODO: { | |
69 local $TODO = 'not yet'; | |
70 | |
71 like(http_get('/a'), qr/301 Moved/, 'auto redirect'); | |
72 | |
73 } | |
74 | |
75 like(http_get('/a/'), qr/X-Location: unset/, 'match a'); | |
76 like(http_get('/a-a'), qr/X-Location: a-a/, 'match a-a'); | |
77 like(http_get('/a-b'), qr/X-Location: a-b/, 'match a-b'); | |
78 | |
79 ############################################################################### |