File: file.t

package info (click to toggle)
libplack-perl 1.0048-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,480 kB
  • sloc: perl: 5,288; python: 7; makefile: 4; javascript: 1
file content (59 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (3)
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 => 'Changes');

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 => 'Changes',
    content_type => 'text/x-changes'
);

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-changes';
    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/;

    $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;