comparison secure_link.t @ 695:da20b4389038

Tests: added secure_link_expires variable test.
author Andrey Zelenkov <zelenkov@nginx.com>
date Mon, 14 Sep 2015 19:34:25 +0300
parents dc2f8aac0553
children e9064d691790
comparison
equal deleted inserted replaced
694:3eba6e1b8313 695:da20b4389038
22 ############################################################################### 22 ###############################################################################
23 23
24 select STDERR; $| = 1; 24 select STDERR; $| = 1;
25 select STDOUT; $| = 1; 25 select STDOUT; $| = 1;
26 26
27 my $t = Test::Nginx->new()->has(qw/http secure_link rewrite/)->plan(9); 27 my $t = Test::Nginx->new()->has(qw/http secure_link rewrite/)->plan(10);
28 28
29 $t->write_file_expand('nginx.conf', <<'EOF'); 29 $t->write_file_expand('nginx.conf', <<'EOF');
30 30
31 %%TEST_GLOBALS%% 31 %%TEST_GLOBALS%%
32 32
63 } 63 }
64 64
65 location = /expires.html { 65 location = /expires.html {
66 # new style with expires 66 # new style with expires
67 # /test.html?hash=BASE64URL&expires=12345678 67 # /test.html?hash=BASE64URL&expires=12345678
68
69 add_header X-Expires $secure_link_expires;
68 70
69 secure_link $arg_hash,$arg_expires; 71 secure_link $arg_hash,$arg_expires;
70 secure_link_md5 secret$uri$arg_expires; 72 secure_link_md5 secret$uri$arg_expires;
71 73
72 # invalid hash 74 # invalid hash
134 136
135 $expires = time() + 86400; 137 $expires = time() + 86400;
136 $hash = encode_base64url(md5("secret/expires.html$expires")); 138 $hash = encode_base64url(md5("secret/expires.html$expires"));
137 like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires), 139 like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires),
138 qr/PASSED/, 'request md5 not expired'); 140 qr/PASSED/, 'request md5 not expired');
141 like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires),
142 qr/X-Expires: $expires/, 'secure_link_expires variable');
139 143
140 $expires = time() - 86400; 144 $expires = time() - 86400;
141 $hash = encode_base64url(md5("secret/expires.html$expires")); 145 $hash = encode_base64url(md5("secret/expires.html$expires"));
142 like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires), 146 like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires),
143 qr/^HTTP.*403/, 'request md5 expired'); 147 qr/^HTTP.*403/, 'request md5 expired');