1#!/usr/bin/env perl
2BEGIN {
3	# add current source dir to the include-path
4	# we need this for make distcheck
5	(my $srcdir = $0) =~ s,/[^/]+$,/,;
6	unshift @INC, $srcdir;
7}
8
9use strict;
10use IO::Socket;
11use Test::More tests => 7;
12use LightyTest;
13use Digest::MD5 qw(md5_hex);
14
15my $tf = LightyTest->new();
16my $t;
17
18ok($tf->start_proc == 0, "Starting lighttpd") or die();
19
20my $secret = "verysecret";
21my $f = "/index.html";
22my $thex = sprintf("%08x", time);
23my $m = md5_hex($secret.$f.$thex);
24
25$t->{REQUEST}  = ( <<EOF
26GET /sec/$m/$thex$f HTTP/1.0
27Host: vvv.example.org
28EOF
29 );
30$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
31
32ok($tf->handle_http($t) == 0, 'secdownload');
33
34$thex = sprintf("%08x", time - 1800);
35$m = md5_hex($secret.$f.$thex);
36
37$t->{REQUEST}  = ( <<EOF
38GET /sec/$m/$thex$f HTTP/1.0
39Host: vvv.example.org
40EOF
41 );
42$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
43
44ok($tf->handle_http($t) == 0, 'secdownload - gone (timeout)');
45
46$t->{REQUEST}  = ( <<EOF
47GET /sec$f HTTP/1.0
48Host: vvv.example.org
49EOF
50 );
51$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
52
53ok($tf->handle_http($t) == 0, 'secdownload - direct access');
54
55$t->{REQUEST}  = ( <<EOF
56GET $f HTTP/1.0
57Host: www.example.org
58EOF
59 );
60$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
61
62ok($tf->handle_http($t) == 0, 'secdownload - conditional access');
63
64
65$f = "/noexists";
66$thex = sprintf("%08x", time);
67$m = md5_hex($secret.$f.$thex);
68
69$t->{REQUEST}  = ( <<EOF
70GET /sec/$m/$thex$f HTTP/1.0
71Host: vvv.example.org
72EOF
73 );
74$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
75
76ok($tf->handle_http($t) == 0, 'secdownload - timeout');
77
78ok($tf->stop_proc == 0, "Stopping lighttpd");
79
80