annotate proxy_cookie_flags.t @ 1625:a140cab489e8

Tests: added js buffer tests.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 25 Nov 2020 12:25:24 +0000
parents 2083b4f183e7
children 3b8a9f02d141
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1594
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for the proxy_cookie_flags directive.
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/);
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 server {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 listen 127.0.0.1:8080;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server_name localhost;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 location / {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 proxy_pass http://127.0.0.1:8081;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 proxy_cookie_flags a secure httponly samesite=none;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 proxy_cookie_flags b secure httponly samesite=lax;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 proxy_cookie_flags c secure httponly samesite=strict;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 proxy_cookie_flags d nosecure nohttponly nosamesite;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 proxy_cookie_flags $arg_complex secure;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 proxy_cookie_flags ~BAR httponly;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 location /off/ {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 proxy_pass http://127.0.0.1:8081;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 proxy_cookie_flags off;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 server {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 listen 127.0.0.1:8081;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 server_name localhost;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 location / {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 set $c "$arg_v$arg_complex=path=domain=; Domain=example.org$arg_f";
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 add_header Set-Cookie $c;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 return 200 OK;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 EOF
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 $t->try_run('no proxy_cookie_flags')->plan(11);
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 ###############################################################################
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 is(http_get_set_cookie('/?v=a'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 'a=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=None',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 'flags set all');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 is(http_get_set_cookie('/?v=b'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 'b=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=Lax',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 'flags set lax');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 is(http_get_set_cookie('/?v=c'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 'c=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=Strict',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 'flags set strict');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 # edit already set flags
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 is(http_get_set_cookie('/?v=a&f=;Secure;HttpOnly;SameSite=Lax'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 'a=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=None',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 'flags reset all');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 is(http_get_set_cookie('/?v=b&f=;Secure;HttpOnly;SameSite=None'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 'b=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=Lax',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 'flags reset lax');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 is(http_get_set_cookie('/?v=c&f=;Secure;HttpOnly;SameSite=None'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 'c=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=Strict',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 'flags reset strict');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 is(http_get_set_cookie('/?v=d&f=;secure;httponly;samesite=lax'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 'd=path=domain=; Domain=example.org',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 'flags remove');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 is(http_get_set_cookie('/?v=nx&f=;samesite=none'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 'nx=path=domain=; Domain=example.org;samesite=none', 'flags no match');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 is(http_get_set_cookie('/?complex=v'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 'v=path=domain=; Domain=example.org; Secure', 'flags variable');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 is(http_get_set_cookie('/?v=foobarbaz'),
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 'foobarbaz=path=domain=; Domain=example.org; HttpOnly', 'flags regex');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 is(http_get_set_cookie('/off/?v=a'), 'a=path=domain=; Domain=example.org',
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 'flags off');
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 ###############################################################################
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 sub http_get_set_cookie {
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 my ($uri) = @_;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 http_get($uri) =~ /^Set-Cookie:\s(.+?)\x0d?$/mi;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 return $1;
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 }
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123
2083b4f183e7 Tests: proxy_cookie_flags tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 ###############################################################################