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 $tf->{CONFIGFILE
} = 'mod-secdownload.conf';
21 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
23 my $secret = "verysecret";
26 $t->{REQUEST
} = ( <<EOF
27 GET /index.html HTTP/1.0
31 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
33 ok
($tf->handle_http($t) == 0, 'skipping secdownload - direct access');
37 $thex = sprintf("%08x", time);
38 $m = md5_hex
($secret.$f.$thex);
40 $t->{REQUEST
} = ( <<EOF
41 GET /sec/$m/$thex$f HTTP/1.0
45 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
47 ok
($tf->handle_http($t) == 0, 'secdownload (md5)');
49 $thex = sprintf("%08x", time - 1800);
50 $m = md5_hex
($secret.$f.$thex);
52 $t->{REQUEST
} = ( <<EOF
53 GET /sec/$m/$thex$f HTTP/1.0
57 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
59 ok
($tf->handle_http($t) == 0, 'secdownload - gone (timeout) (md5)');
61 $t->{REQUEST
} = ( <<EOF
66 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
68 ok
($tf->handle_http($t) == 0, 'secdownload - direct access (md5)');
71 $thex = sprintf("%08x", time);
72 $m = md5_hex
($secret.$f.$thex);
74 $t->{REQUEST
} = ( <<EOF
75 GET /sec/$m/$thex$f HTTP/1.0
79 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
81 ok
($tf->handle_http($t) == 0, 'secdownload - timeout (md5)');
85 $thex = sprintf("%08x", time);
86 $m = encode_base64url
(hmac_sha1
("/$thex$f", $secret));
88 $t->{REQUEST
} = ( <<EOF
89 GET /sec/$m/$thex$f HTTP/1.0
90 Host: vvv-sha1.example.org
93 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
95 ok
($tf->handle_http($t) == 0, 'secdownload (hmac-sha1)');
97 $thex = sprintf("%08x", time - 1800);
98 $m = encode_base64url
(hmac_sha1
("/$thex$f", $secret));
100 $t->{REQUEST
} = ( <<EOF
101 GET /sec/$m/$thex$f HTTP/1.0
102 Host: vvv-sha1.example.org
105 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
107 ok
($tf->handle_http($t) == 0, 'secdownload - gone (timeout) (hmac-sha1)');
109 $t->{REQUEST
} = ( <<EOF
111 Host: vvv-sha1.example.org
114 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
116 ok
($tf->handle_http($t) == 0, 'secdownload - direct access (hmac-sha1)');
120 $thex = sprintf("%08x", time);
121 $m = encode_base64url
(hmac_sha1
("/$thex$f", $secret));
123 $t->{REQUEST
} = ( <<EOF
124 GET /sec/$m/$thex$f HTTP/1.0
125 Host: vvv-sha1.example.org
128 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
130 ok
($tf->handle_http($t) == 0, 'secdownload - timeout (hmac-sha1)');
134 $thex = sprintf("%08x", time);
135 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
137 $t->{REQUEST
} = ( <<EOF
138 GET /sec/$m/$thex$f HTTP/1.0
139 Host: vvv-sha256.example.org
142 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
144 ok
($tf->handle_http($t) == 0, 'secdownload (hmac-sha256)');
147 $f = "/index.html?qs=1";
148 $thex = sprintf("%08x", time);
149 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
151 $t->{REQUEST
} = ( <<EOF
152 GET /sec/$m/$thex$f HTTP/1.0
153 Host: vvv-sha256.example.org
156 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
158 ok
($tf->handle_http($t) == 0, 'secdownload (hmac-sha256) with hash-querystr');
160 $thex = sprintf("%08x", time - 1800);
161 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
163 $t->{REQUEST
} = ( <<EOF
164 GET /sec/$m/$thex$f HTTP/1.0
165 Host: vvv-sha256.example.org
168 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
170 ok
($tf->handle_http($t) == 0, 'secdownload - gone (timeout) (hmac-sha256)');
172 $t->{REQUEST
} = ( <<EOF
174 Host: vvv-sha256.example.org
177 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
179 ok
($tf->handle_http($t) == 0, 'secdownload - direct access (hmac-sha256)');
183 $thex = sprintf("%08x", time);
184 $m = encode_base64url
(hmac_sha256
("/$thex$f", $secret));
186 $t->{REQUEST
} = ( <<EOF
187 GET /sec/$m/$thex$f HTTP/1.0
188 Host: vvv-sha256.example.org
191 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
193 ok
($tf->handle_http($t) == 0, 'secdownload - timeout (hmac-sha256)');
197 ok
($tf->stop_proc == 0, "Stopping lighttpd");