comparison proxy_cookie.t @ 200:0ca8725e5958

Tests: proxy_cookie_domain and proxy_cookie_path tests.
author Valentin Bartenev <ne@vbart.ru>
date Fri, 10 Feb 2012 17:55:29 +0400
parents
children c28ecaef065f
comparison
equal deleted inserted replaced
199:241b522ce7a5 200:0ca8725e5958
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4 # (C) Valentin Bartenev
5
6 # Tests for the proxy_cookie_domain and proxy_cookie_path directives.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/);
26
27 $t->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 server {
40 listen 127.0.0.1:8080;
41 server_name localhost;
42
43 location / {
44 proxy_pass http://127.0.0.1:8081;
45
46 proxy_cookie_domain www.example.org .example.com;
47 proxy_cookie_domain .$server_name.com en.$server_name.org;
48 proxy_cookie_domain ~^(.+)\.com$ $1.org;
49
50 proxy_cookie_path /path/ /new/;
51 proxy_cookie_path /$server_name/ /new/$server_name/;
52 proxy_cookie_path ~^/regex/(.+)$ /$1;
53 proxy_cookie_path ~*^/caseless/(.+)$ /$1;
54 }
55 }
56
57 server {
58 listen 127.0.0.1:8081;
59 server_name localhost;
60
61 location / {
62 if ($arg_domain) {
63 set $sc_domain "; Domain=$arg_domain";
64 }
65 if ($arg_path) {
66 set $sc_path "; Path=$arg_path";
67 }
68 add_header Set-Cookie v=path=domain=$sc_domain$sc_path;
69 return 200 OK;
70 }
71 }
72 }
73
74 EOF
75
76 eval {
77 open OLDERR, ">&", \*STDERR; close STDERR;
78 $t->run();
79 open STDERR, ">&", \*OLDERR;
80 };
81 plan(skip_all => 'no proxy_cookie') if $@;
82
83 $t->plan(8);
84
85 ###############################################################################
86
87 is(http_get_set_cookie('/?domain=www.Example.org'),
88 'v=path=domain=; Domain=example.com', 'domain rewrite');
89 is(http_get_set_cookie('/?domain=.LocalHost.com'),
90 'v=path=domain=; Domain=.en.localhost.org',
91 'domain rewrite with vars');
92 is(http_get_set_cookie('/?domain=www.example.COM'),
93 'v=path=domain=; Domain=www.example.org', 'domain regex rewrite');
94
95 is(http_get_set_cookie('/?path=/path/test.html'),
96 'v=path=domain=; Path=/new/test.html', 'path rewrite');
97 is(http_get_set_cookie('/?path=/localhost/test.html'),
98 'v=path=domain=; Path=/new/localhost/test.html',
99 'path rewrite with vars');
100 is(http_get_set_cookie('/?path=/regex/test.html'),
101 'v=path=domain=; Path=/test.html', 'path regex rewrite');
102 is(http_get_set_cookie('/?path=/CASEless/test.html'),
103 'v=path=domain=; Path=/test.html', 'path caseless regex rewrite');
104
105 is(http_get_set_cookie('/?domain=www.example.org&path=/path/test.html'),
106 'v=path=domain=; Domain=example.com; Path=/new/test.html',
107 'domain and path rewrite');
108
109 ###############################################################################
110
111 sub http_get_set_cookie {
112 my ($uri) = @_;
113 http_get("http://127.0.0.1:8080$uri") =~ /^Set-Cookie:\s(.+?)\x0d?$/mi;
114 return $1;
115 }
116
117 ###############################################################################