Mercurial > hg > nginx-tests
annotate http_location_auto.t @ 1564:fe938b5daf80
Tests: more grpc tests with discarded request body.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 28 Apr 2020 18:44:29 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
330
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for location selection, an auto_redirect edge case. |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4) |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 daemon off; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 listen 127.0.0.1:8080; |
330
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 proxy_hide_header X-Location; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 add_header X-Location unset; |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 # As of nginx 1.5.4, this results in the following |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 # location tree: |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 # |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 # "/a-b" |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 # "/a-a" "/a/" |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 # |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 # A request to "/a" is expected to match "/a/" with auto_redirect, |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 # but with such a tree it tests locations "/a-b", "/a-a" and then |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 # falls back to null location. |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 # |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 # Key factor is that "-" is less than "/". |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 location /a/ { proxy_pass http://127.0.0.1:8080/a-a; } |
330
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 location /a-a { add_header X-Location a-a; return 204; } |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 location /a-b { add_header X-Location a-b; return 204; } |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 } |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 EOF |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 $t->run(); |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 ############################################################################### |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 like(http_get('/a'), qr/301 Moved/, 'auto redirect'); |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 like(http_get('/a/'), qr/X-Location: unset/, 'match a'); |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 like(http_get('/a-a'), qr/X-Location: a-a/, 'match a-a'); |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 like(http_get('/a-b'), qr/X-Location: a-b/, 'match a-b'); |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
617f72beba8d
Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 ############################################################################### |