Annotation of embedaddon/lighttpd/tests/mod-secdownload.t, revision 1.1
1.1 ! misho 1: #!/usr/bin/env perl
! 2: BEGIN {
! 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:
! 9: use strict;
! 10: use IO::Socket;
! 11: use Test::More tests => 7;
! 12: use LightyTest;
! 13: use Digest::MD5 qw(md5_hex);
! 14:
! 15: my $tf = LightyTest->new();
! 16: my $t;
! 17:
! 18: ok($tf->start_proc == 0, "Starting lighttpd") or die();
! 19:
! 20: my $secret = "verysecret";
! 21: my $f = "/index.html";
! 22: my $thex = sprintf("%08x", time);
! 23: my $m = md5_hex($secret.$f.$thex);
! 24:
! 25: $t->{REQUEST} = ( <<EOF
! 26: GET /sec/$m/$thex$f HTTP/1.0
! 27: Host: vvv.example.org
! 28: EOF
! 29: );
! 30: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
! 31:
! 32: ok($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
! 38: GET /sec/$m/$thex$f HTTP/1.0
! 39: Host: vvv.example.org
! 40: EOF
! 41: );
! 42: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 410 } ];
! 43:
! 44: ok($tf->handle_http($t) == 0, 'secdownload - gone (timeout)');
! 45:
! 46: $t->{REQUEST} = ( <<EOF
! 47: GET /sec$f HTTP/1.0
! 48: Host: vvv.example.org
! 49: EOF
! 50: );
! 51: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
! 52:
! 53: ok($tf->handle_http($t) == 0, 'secdownload - direct access');
! 54:
! 55: $t->{REQUEST} = ( <<EOF
! 56: GET $f HTTP/1.0
! 57: Host: www.example.org
! 58: EOF
! 59: );
! 60: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
! 61:
! 62: ok($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
! 70: GET /sec/$m/$thex$f HTTP/1.0
! 71: Host: vvv.example.org
! 72: EOF
! 73: );
! 74: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
! 75:
! 76: ok($tf->handle_http($t) == 0, 'secdownload - timeout');
! 77:
! 78: ok($tf->stop_proc == 0, "Stopping lighttpd");
! 79:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>