3 # add current source dir to the include-path
4 # we need this for make distcheck
5 (my $srcdir = $0) =~ s
,/[^/]+$,/,;
11 use Test
::More tests
=> 16;
13 use Digest
::MD5
qw(md5_hex);
14 use Digest
::SHA
qw(hmac_sha1 hmac_sha256);
15 use MIME
::Base64
qw(encode_base64url);
17 my $tf = LightyTest
->new();
20 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
22 my $secret = "verysecret";
25 $t->{REQUEST
} = ( <<EOF
26 GET /index.html HTTP/1.0
30 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
32 ok
($tf->handle_http($t) == 0, 'skipping secdownload - direct access');
36 $thex = sprintf("%08x", time);
37 $m = md5_hex
($secret.$f.$thex);
39 $t->{REQUEST
} = ( <<EOF
40 GET /sec/$m/$thex$f HTTP/1.0
44 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
46 ok
($tf->handle_http($t) == 0, 'secdownload (md5)');
48 $thex = sprintf("%08x", time - 1800);
49 $m = md5_hex
($secret.$f.$thex);
51 $t->{REQUEST
} = ( <<EOF
52 GET /sec/$m/$thex$f HTTP/1.0
56 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
58 ok
($tf->handle_http($t) == 0, 'secdownload - gone (timeout) (md5)');
60 $t->{REQUEST
} = ( <<EOF
65 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
67 ok
($tf->handle_http($t) == 0, 'secdownload - direct access (md5)');
70 $thex = sprintf("%08x", time);
71 $m = md5_hex
($secret.$f.$thex);
73 $t->{REQUEST
} = ( <<EOF
74 GET /sec/$m/$thex$f HTTP/1.0
78 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
80 ok
($tf->handle_http($t) == 0, 'secdownload - timeout (md5)');
84 $thex = sprintf("%08x", time);
85 $m = encode_base64url
(hmac_sha1
("/$thex$f", $secret));
87 $t->{REQUEST
} = ( <<EOF
88 GET /sec/$m/$thex$f HTTP/1.0
89 Host: vvv-sha1.example.org
92 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
94 ok
($tf->handle_http($t) == 0, 'secdownload (hmac-sha1)');
96 $thex = sprintf("%08x", time - 1800);
97 $m = encode_base64url
(hmac_sha1
("/$thex$f", $secret));
99 $t->{REQUEST
} = ( <<EOF
100 GET /sec/$m/$thex$f HTTP/1.0
101 Host: vvv-sha1.example.org
104 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
106 ok
($tf->handle_http($t) == 0, 'secdownload - gone (timeout) (hmac-sha1)');
108 $t->{REQUEST
} = ( <<EOF
110 Host: vvv-sha1.example.org
113 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
115 ok
($tf->handle_http($t) == 0, 'secdownload - direct access (hmac-sha1)');
119 $thex = sprintf("%08x", time);
120 $m = encode_base64url
(hmac_sha1
("/$thex$f", $secret));
122 $t->{REQUEST
} = ( <<EOF
123 GET /sec/$m/$thex$f HTTP/1.0
124 Host: vvv-sha1.example.org
127 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
129 ok
($tf->handle_http($t) == 0, 'secdownload - timeout (hmac-sha1)');
133 $thex = sprintf("%08x", time);
134 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
136 $t->{REQUEST
} = ( <<EOF
137 GET /sec/$m/$thex$f HTTP/1.0
138 Host: vvv-sha256.example.org
141 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
143 ok
($tf->handle_http($t) == 0, 'secdownload (hmac-sha256)');
146 $f = "/index.html?qs=1";
147 $thex = sprintf("%08x", time);
148 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
150 $t->{REQUEST
} = ( <<EOF
151 GET /sec/$m/$thex$f HTTP/1.0
152 Host: vvv-sha256.example.org
155 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
157 ok
($tf->handle_http($t) == 0, 'secdownload (hmac-sha256) with hash-querystr');
159 $thex = sprintf("%08x", time - 1800);
160 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
162 $t->{REQUEST
} = ( <<EOF
163 GET /sec/$m/$thex$f HTTP/1.0
164 Host: vvv-sha256.example.org
167 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
169 ok
($tf->handle_http($t) == 0, 'secdownload - gone (timeout) (hmac-sha256)');
171 $t->{REQUEST
} = ( <<EOF
173 Host: vvv-sha256.example.org
176 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
178 ok
($tf->handle_http($t) == 0, 'secdownload - direct access (hmac-sha256)');
182 $thex = sprintf("%08x", time);
183 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
185 $t->{REQUEST
} = ( <<EOF
186 GET /sec/$m/$thex$f HTTP/1.0
187 Host: vvv-sha256.example.org
190 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
192 ok
($tf->handle_http($t) == 0, 'secdownload - timeout (hmac-sha256)');
196 ok
($tf->stop_proc == 0, "Stopping lighttpd");