1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
use strict;
use Plack::Test;
use Test::More;
use HTTP::Request::Common;
use Plack::App::File;
use FindBin qw($Bin);
my $app = Plack::App::File->new(file => 'README');
test_psgi $app, sub {
my $cb = shift;
my $res = $cb->(GET "/");
is $res->code, 200;
like $res->content, qr/Plack/;
$res = $cb->(GET "/whatever");
is $res->content_type, 'text/plain';
is $res->code, 200;
};
my $app_content_type = Plack::App::File->new(
file => 'README',
content_type => 'text/x-readme'
);
test_psgi $app_content_type, sub {
my $cb = shift;
my $res = $cb->(GET "/");
is $res->code, 200;
like $res->content, qr/Plack/;
$res = $cb->(GET "/whatever");
is $res->content_type, 'text/x-readme';
is $res->code, 200;
};
my $app_secure = Plack::App::File->new(root => $Bin);
test_psgi $app_secure, sub {
my $cb = shift;
my $res = $cb->(GET "/file.t");
is $res->code, 200;
like $res->content, qr/We will find for this literal string/;
my $res = $cb->(GET "/../Plack-Middleware/file.t");
is $res->code, 403;
is $res->content, 'forbidden';
for my $i (1..100) {
$res = $cb->(GET "/file.t" . ("/" x $i));
is $res->code, 404;
is $res->content, 'not found';
}
};
done_testing;
|