annotate proxy_cookie.t @ 1585:bff287fbf347

Tests: added proxy_cookie_domain/path tests with "off" parameter.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 23 Jul 2020 12:17:39 +0300
parents 882267679006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
1585
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
54
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
55 location /off/ {
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
56 proxy_pass http://127.0.0.1:8081;
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
57
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
58 proxy_cookie_domain off;
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
59 proxy_cookie_path off;
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
60 }
200
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
61 }
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
62 }
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
63
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
64 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
65 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
66 server_name localhost;
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 location / {
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
69 if ($arg_domain) {
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
70 set $sc_domain "; Domain=$arg_domain";
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 if ($arg_path) {
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
73 set $sc_path "; Path=$arg_path";
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
74 }
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
75 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
76 return 200 OK;
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 }
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
80
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
81 EOF
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
82
1585
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
83 $t->run()->plan(9);
200
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
84
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
85 ###############################################################################
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
86
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
87 my $port = port(8080);
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 397
diff changeset
88
200
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
89 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
90 '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
91 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
92 '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
93 'domain rewrite with vars');
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
94 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
95 '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
96
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=/path/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=/new/test.html', 'path rewrite');
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
99 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
100 '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
101 'path rewrite with vars');
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
102 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
103 '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
104 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
105 '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
106
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
107 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
108 '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
109 'domain and path rewrite');
1585
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
110 is(http_get_set_cookie('/off/?domain=www.example.org&path=/path/test.html'),
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
111 'v=path=domain=; Domain=www.example.org; Path=/path/test.html',
bff287fbf347 Tests: added proxy_cookie_domain/path tests with "off" parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
112 'domain and path rewrite off');
200
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
113
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
114 ###############################################################################
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
115
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
116 sub http_get_set_cookie {
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
117 my ($uri) = @_;
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 397
diff changeset
118 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
119 return $1;
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
120 }
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
121
0ca8725e5958 Tests: proxy_cookie_domain and proxy_cookie_path tests.
Valentin Bartenev <ne@vbart.ru>
parents:
diff changeset
122 ###############################################################################