Mercurial > hg > nginx-tests
annotate proxy_cookie.t @ 1282:fd281e3a3df5
Tests: better test names in h2_server_push.t.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 12 Feb 2018 14:46:40 +0300 |
parents | 882267679006 |
children | bff287fbf347 |
rev | line source |
---|---|
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
2 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
4 # (C) Valentin Bartenev |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
5 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
6 # Tests for the proxy_cookie_domain and proxy_cookie_path directives. |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
7 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
8 ############################################################################### |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
9 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
10 use warnings; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
11 use strict; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
12 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
13 use Test::More; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
14 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
16 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
19 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
20 ############################################################################### |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
21 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
24 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
26 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
28 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
30 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
31 daemon off; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
32 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
33 events { |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
34 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
35 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
36 http { |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
38 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
39 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen 127.0.0.1:8080; |
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
41 server_name localhost; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
42 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
43 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 proxy_pass http://127.0.0.1:8081; |
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
45 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
46 proxy_cookie_domain www.example.org .example.com; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
47 proxy_cookie_domain .$server_name.com en.$server_name.org; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
48 proxy_cookie_domain ~^(.+)\.com$ $1.org; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
49 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
50 proxy_cookie_path /path/ /new/; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
51 proxy_cookie_path /$server_name/ /new/$server_name/; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
52 proxy_cookie_path ~^/regex/(.+)$ /$1; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
53 proxy_cookie_path ~*^/caseless/(.+)$ /$1; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
54 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
55 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
56 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
57 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 listen 127.0.0.1:8081; |
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
59 server_name localhost; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
60 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
61 location / { |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
62 if ($arg_domain) { |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
63 set $sc_domain "; Domain=$arg_domain"; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
64 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
65 if ($arg_path) { |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
66 set $sc_path "; Path=$arg_path"; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
67 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
68 add_header Set-Cookie v=path=domain=$sc_domain$sc_path; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
69 return 200 OK; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
70 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
71 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
72 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
73 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
74 EOF |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
75 |
397
847ea345becb
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
392
diff
changeset
|
76 $t->run()->plan(8); |
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
77 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
78 ############################################################################### |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
79 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
80 my $port = port(8080); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
397
diff
changeset
|
81 |
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
82 is(http_get_set_cookie('/?domain=www.Example.org'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
83 'v=path=domain=; Domain=example.com', 'domain rewrite'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
84 is(http_get_set_cookie('/?domain=.LocalHost.com'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
85 'v=path=domain=; Domain=.en.localhost.org', |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
86 'domain rewrite with vars'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
87 is(http_get_set_cookie('/?domain=www.example.COM'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
88 'v=path=domain=; Domain=www.example.org', 'domain regex rewrite'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
89 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
90 is(http_get_set_cookie('/?path=/path/test.html'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
91 'v=path=domain=; Path=/new/test.html', 'path rewrite'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
92 is(http_get_set_cookie('/?path=/localhost/test.html'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
93 'v=path=domain=; Path=/new/localhost/test.html', |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
94 'path rewrite with vars'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
95 is(http_get_set_cookie('/?path=/regex/test.html'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
96 'v=path=domain=; Path=/test.html', 'path regex rewrite'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
97 is(http_get_set_cookie('/?path=/CASEless/test.html'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
98 'v=path=domain=; Path=/test.html', 'path caseless regex rewrite'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
99 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
100 is(http_get_set_cookie('/?domain=www.example.org&path=/path/test.html'), |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
101 'v=path=domain=; Domain=example.com; Path=/new/test.html', |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
102 'domain and path rewrite'); |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
103 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
104 ############################################################################### |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
105 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
106 sub http_get_set_cookie { |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
107 my ($uri) = @_; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
397
diff
changeset
|
108 http_get("http://127.0.0.1:$port$uri") =~ /^Set-Cookie:\s(.+?)\x0d?$/mi; |
200
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
109 return $1; |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
110 } |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
111 |
0ca8725e5958
Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
112 ############################################################################### |