annotate proxy_upstream_cookie.t @ 1957:c544b7120a6d default tip

Tests: removed dependencies on 405 error text. It is going to be changed from "405 Not Allowed" to "405 Method Not Allowed" to match RFC description.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 20 Apr 2024 20:58:42 +0300
parents 882267679006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
396
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Nginx, Inc.
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # Tests for the $upstream_cookie_<name> variables.
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 ###############################################################################
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 use warnings;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use strict;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use Test::More;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 use lib 'lib';
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 ###############################################################################
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 396
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(19);
396
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 $t->write_file_expand('nginx.conf', <<'EOF');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
39 listen 127.0.0.1:8080;
396
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server_name localhost;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 location / {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 add_header X-Upstream-Cookie $upstream_cookie_tc;
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;
396
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
49 listen 127.0.0.1:8081;
396
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 server_name localhost;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 location / {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 add_header Set-Cookie $http_x_test_cookie;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 return 204;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 # embed multiline cookie with add_header
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 location /mcomma {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 add_header Set-Cookie "tc=one,two,three";
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 add_header Set-Cookie "tc=four,five,six";
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 return 204;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 location /msemicolon {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 add_header Set-Cookie "tc=one;two;three";
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 add_header Set-Cookie "tc=four;five;six";
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 return 204;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 EOF
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 396
diff changeset
73 $t->run();
396
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 ###############################################################################
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 is(http_get_uc('tc='), undef, 'value_none');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 is(http_get_uc('tc=;'), undef, 'semicolon');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 is(http_get_uc('tc= ;'), undef, 'space_semicolon');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 is(http_get_uc('tc = ; Domain=example.com;'), undef, 'space_semicolon_more');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 is(http_get_uc('tc=x'), 'x', 'onechar');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 is(http_get_uc('tc=,'), ',', 'comma');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 is(http_get_uc('tc = content ;'), undef, 'tabbed');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 is(http_get_uc('tc="content"'), '"content"', 'dquoted');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 is(http_get_uc('tc=content'), 'content', 'normal');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 is(http_get_uc('tc=con tent; Domain=example.com'), 'con tent',
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 'internal_space');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 is(http_get_uc('tc = content'), 'content', 'separated');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 is(http_get_uc('tc=1.2.3'), '1.2.3', 'dots');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 is(http_get_uc('tc==abc'), '=abc', 'deq');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 is(http_get_uc('tc==;abc'), '=', 'deqsemi');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 is(http_get_uc('=tc=content'), undef, 'eqfirst');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 is(http_get_uc('tc=first,tc=second'), 'first,tc=second', 'two_comma');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 is(http_get_uc('tc=first;tc=second'), 'first', 'two_semicolon');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 like(http_get('/mcomma'), qr/^X-Upstream-Cookie: one,two,three\x0d?$/mi,
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 'multiline comma');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 like(http_get('/msemicolon'), qr/^X-Upstream-Cookie: one\x0d?$/mi,
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 'multiline semicolon');
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 ###############################################################################
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 sub http_get_uc {
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 my ($cookie) = @_;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 http(<<EOF) =~ qr/^X-Upstream-Cookie:\s(.+?)\x0d?$/mi;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 GET / HTTP/1.1
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 Host: localhost
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 Connection: close
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 X-Test-Cookie: $cookie
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 EOF
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 return $1;
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 }
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
5eb0df61f371 Tests: added tests for the "$upstream_cookie_<name>" variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 ###############################################################################