Mercurial > hg > nginx-tests
comparison proxy_upstream_cookie.t @ 396:5eb0df61f371
Tests: added tests for the "$upstream_cookie_<name>" variables.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 30 Apr 2014 18:04:50 +0400 |
parents | |
children | 907e89fba9c3 |
comparison
equal
deleted
inserted
replaced
395:d7d9b4367bab | 396:5eb0df61f371 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Nginx, Inc. | |
4 | |
5 # Tests for the $upstream_cookie_<name> variables. | |
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/); | |
25 | |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 server { | |
39 listen 127.0.0.1:8080; | |
40 server_name localhost; | |
41 | |
42 location / { | |
43 add_header X-Upstream-Cookie $upstream_cookie_tc; | |
44 proxy_pass http://127.0.0.1:8081; | |
45 } | |
46 } | |
47 | |
48 server { | |
49 listen 127.0.0.1:8081; | |
50 server_name localhost; | |
51 | |
52 location / { | |
53 add_header Set-Cookie $http_x_test_cookie; | |
54 return 204; | |
55 } | |
56 | |
57 # embed multiline cookie with add_header | |
58 location /mcomma { | |
59 add_header Set-Cookie "tc=one,two,three"; | |
60 add_header Set-Cookie "tc=four,five,six"; | |
61 return 204; | |
62 } | |
63 location /msemicolon { | |
64 add_header Set-Cookie "tc=one;two;three"; | |
65 add_header Set-Cookie "tc=four;five;six"; | |
66 return 204; | |
67 } | |
68 } | |
69 } | |
70 | |
71 EOF | |
72 | |
73 $t->try_run('no upstream_cookie_<name>')->plan(19); | |
74 | |
75 ############################################################################### | |
76 | |
77 is(http_get_uc('tc='), undef, 'value_none'); | |
78 is(http_get_uc('tc=;'), undef, 'semicolon'); | |
79 is(http_get_uc('tc= ;'), undef, 'space_semicolon'); | |
80 is(http_get_uc('tc = ; Domain=example.com;'), undef, 'space_semicolon_more'); | |
81 | |
82 is(http_get_uc('tc=x'), 'x', 'onechar'); | |
83 is(http_get_uc('tc=,'), ',', 'comma'); | |
84 is(http_get_uc('tc = content ;'), undef, 'tabbed'); | |
85 is(http_get_uc('tc="content"'), '"content"', 'dquoted'); | |
86 is(http_get_uc('tc=content'), 'content', 'normal'); | |
87 is(http_get_uc('tc=con tent; Domain=example.com'), 'con tent', | |
88 'internal_space'); | |
89 is(http_get_uc('tc = content'), 'content', 'separated'); | |
90 | |
91 is(http_get_uc('tc=1.2.3'), '1.2.3', 'dots'); | |
92 is(http_get_uc('tc==abc'), '=abc', 'deq'); | |
93 is(http_get_uc('tc==;abc'), '=', 'deqsemi'); | |
94 is(http_get_uc('=tc=content'), undef, 'eqfirst'); | |
95 is(http_get_uc('tc=first,tc=second'), 'first,tc=second', 'two_comma'); | |
96 is(http_get_uc('tc=first;tc=second'), 'first', 'two_semicolon'); | |
97 | |
98 like(http_get('/mcomma'), qr/^X-Upstream-Cookie: one,two,three\x0d?$/mi, | |
99 'multiline comma'); | |
100 like(http_get('/msemicolon'), qr/^X-Upstream-Cookie: one\x0d?$/mi, | |
101 'multiline semicolon'); | |
102 | |
103 ############################################################################### | |
104 | |
105 sub http_get_uc { | |
106 my ($cookie) = @_; | |
107 | |
108 http(<<EOF) =~ qr/^X-Upstream-Cookie:\s(.+?)\x0d?$/mi; | |
109 GET / HTTP/1.1 | |
110 Host: localhost | |
111 Connection: close | |
112 X-Test-Cookie: $cookie | |
113 | |
114 EOF | |
115 | |
116 return $1; | |
117 } | |
118 | |
119 ############################################################################### |