Skip to content

Commit 3a3982a

Browse files
committed
Tests: more corner cases for secure_link module.
1 parent 7b90061 commit 3a3982a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

secure_link.t

+33-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use Test::Nginx;
2424
select STDERR; $| = 1;
2525
select STDOUT; $| = 1;
2626

27-
my $t = Test::Nginx->new()->has(qw/http secure_link rewrite/)->plan(10);
27+
my $t = Test::Nginx->new()->has(qw/http secure_link rewrite/)->plan(19);
2828

2929
$t->write_file_expand('nginx.conf', <<'EOF');
3030
@@ -111,6 +111,10 @@ http {
111111
return 403;
112112
}
113113
}
114+
115+
location /stub {
116+
return 200 x$secure_link${secure_link_expires}x;
117+
}
114118
}
115119
}
116120
@@ -128,6 +132,22 @@ like(http_get('/test.html?hash=q-5vpkjBkRXXtkUMXiJVHA=='),
128132
qr/PASSED/, 'request md5');
129133
like(http_get('/test.html?hash=q-5vpkjBkRXXtkUMXiJVHA'),
130134
qr/PASSED/, 'request md5 no padding');
135+
136+
TODO: {
137+
todo_skip 'stack-buffer-overflow', 1 unless $ENV{TEST_NGINX_UNSAFE}
138+
or $t->has_version('1.13.5');
139+
140+
like(http_get('/test.html?hash=q-5vpkjBkRXXtkUMXiJVHAQQ'),
141+
qr/^HTTP.*403/, 'request md5 too long');
142+
143+
}
144+
145+
like(http_get('/test.html?hash=q-5vpkjBkRXXtkUMXiJVHA-TOOLONG'),
146+
qr/^HTTP.*403/, 'request md5 too long encoding');
147+
like(http_get('/test.html?hash=BADHASHLENGTH'),
148+
qr/^HTTP.*403/, 'request md5 decode error');
149+
like(http_get('/test.html?hash=q-5vpkjBkRXXtkUMXiJVHX=='),
150+
qr/^HTTP.*403/, 'request md5 mismatch');
131151
like(http_get('/test.html'), qr/^HTTP.*403/, 'request no hash');
132152

133153
# new style with expires
@@ -146,15 +166,27 @@ $hash = encode_base64url(md5("secret/expires.html$expires"));
146166
like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires),
147167
qr/^HTTP.*403/, 'request md5 expired');
148168

169+
$expires = 0;
170+
$hash = encode_base64url(md5("secret/expires.html$expires"));
171+
like(http_get('/expires.html?hash=' . $hash . '&expires=' . $expires),
172+
qr/^HTTP.*403/, 'request md5 invalid expiration');
173+
149174
# old style
150175

151176
like(http_get('/p/' . md5_hex('test.html' . 'secret') . '/test.html'),
152177
qr/PASSED/, 'request old style');
153178
like(http_get('/p/' . md5_hex('fake') . '/test.html'), qr/^HTTP.*403/,
154179
'request old style fake hash');
180+
like(http_get('/p/' . 'foo' . '/test.html'), qr/^HTTP.*403/,
181+
'request old style short hash');
182+
like(http_get('/p/' . 'x' x 32 . '/test.html'), qr/^HTTP.*403/,
183+
'request old style corrupt hash');
184+
like(http_get('/p%2f'), qr/^HTTP.*403/, 'request old style bad uri');
155185
like(http_get('/p/test.html'), qr/^HTTP.*403/, 'request old style no hash');
156186
like(http_get('/inheritance/test'), qr/PASSED/, 'inheritance');
157187

188+
like(http_get('/stub'), qr/xx/, 'secure_link not found');
189+
158190
###############################################################################
159191

160192
sub encode_base64url {

0 commit comments

Comments
 (0)