File: lint_wrong_header_info.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 (48 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download | duplicates (5)
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
use strict;
use Plack::Test;
use Test::More;
use HTTP::Request::Common;

use Plack::Builder;
use Plack::Middleware::Lint;

my @CASES = (
    {
        app => sub { return [ 200, [ foo => "bar" ], [ 'OK' ] ]; },
        die => undef,
    },
    {
        app => sub { return [ 200, [ foo => undef ], [ 'OK' ] ]; },
        die => qr/Response headers MUST be a defined string. Header: foo/,
    },
    {
        app => sub { return [ 200, [ "foo\nbar" => "baz" ], [ 'OK' ] ]; },
        die => qr/Response headers MUST NOT contain a key with.+Header: foo\nbar/,
    },
    {
        app => sub { return [ 200, [ foo => "\021bar" ], [ 'OK' ] ]; },
        die => qr/Response headers MUST NOT contain characters below octal.+Header: foo/,
    },
    {
        app => sub { return [ 200, [ "foo\021" => "bar" ], [ 'OK' ] ]; },
        die => qr/Response headers MUST consist only of letters, digits, _ or.+Header: foo\021/,
    },
);

for my $case ( @CASES ) {
    my $linted_app = Plack::Middleware::Lint->wrap( $case->{app} );
    my $die_reason = $case->{die};
    test_psgi $linted_app, sub {
        my $cb = shift;
        my $res = $cb->(GET "/");
        if ( $die_reason ) {
            is $res->code, 500, "Code of ". $res->content;
            like $res->content, $die_reason, "Text of ". $res->content;
        }
        else {
            is $res->code, 200, $res->content;
        }
    };
}

done_testing;