comparison proxy_cookie_flags.t @ 1658:3b8a9f02d141

Tests: proxy_cookie_flags with variables.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 02 Mar 2021 10:05:12 +0300
parents 2083b4f183e7
children 5ac6efbe5552
comparison
equal deleted inserted replaced
1657:22e0133d68b4 1658:3b8a9f02d141
54 location /off/ { 54 location /off/ {
55 proxy_pass http://127.0.0.1:8081; 55 proxy_pass http://127.0.0.1:8081;
56 proxy_cookie_flags off; 56 proxy_cookie_flags off;
57 } 57 }
58 } 58 }
59
60 location /var/ {
61 proxy_pass http://127.0.0.1:8081;
62 proxy_cookie_flags $arg_v $arg_f1 $arg_f2 $arg_f3;
63 }
59 } 64 }
60 65
61 server { 66 server {
62 listen 127.0.0.1:8081; 67 listen 127.0.0.1:8081;
63 server_name localhost; 68 server_name localhost;
70 } 75 }
71 } 76 }
72 77
73 EOF 78 EOF
74 79
75 $t->try_run('no proxy_cookie_flags')->plan(11); 80 $t->try_run('no proxy_cookie_flags')->plan(14);
76 81
77 ############################################################################### 82 ###############################################################################
78 83
79 is(http_get_set_cookie('/?v=a'), 84 is(http_get_set_cookie('/?v=a'),
80 'a=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=None', 85 'a=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=None',
111 'foobarbaz=path=domain=; Domain=example.org; HttpOnly', 'flags regex'); 116 'foobarbaz=path=domain=; Domain=example.org; HttpOnly', 'flags regex');
112 117
113 is(http_get_set_cookie('/off/?v=a'), 'a=path=domain=; Domain=example.org', 118 is(http_get_set_cookie('/off/?v=a'), 'a=path=domain=; Domain=example.org',
114 'flags off'); 119 'flags off');
115 120
121 # variables in flags
122
123 is(http_get_set_cookie('/var/?v=v&f1=secure&f2=httponly&f3=samesite=none'),
124 'v=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=None',
125 'flags set');
126 is(http_get_set_cookie('/var/?v=v&f=;Secure;HttpOnly;SameSite=Lax' .
127 '&f1=secure&f2=httponly&f3=samesite=none'),
128 'v=path=domain=; Domain=example.org; Secure; HttpOnly; SameSite=None',
129 'flags reset');
130 is(http_get_set_cookie('/var/?v=v&f=;secure;httponly;samesite=lax' .
131 '&f1=nosecure&f2=nohttponly&f3=nosamesite'),
132 'v=path=domain=; Domain=example.org',
133 'flags remove');
134
116 ############################################################################### 135 ###############################################################################
117 136
118 sub http_get_set_cookie { 137 sub http_get_set_cookie {
119 my ($uri) = @_; 138 my ($uri) = @_;
120 http_get($uri) =~ /^Set-Cookie:\s(.+?)\x0d?$/mi; 139 http_get($uri) =~ /^Set-Cookie:\s(.+?)\x0d?$/mi;