File: cgi.t

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,048 bytes parent folder | download | duplicates (8)
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
use strict;
use warnings;
use Test::Requires {
    'HTTP::Request::AsCGI' => 1.2,
};
use Test::More;
use FindBin;
use HTTP::Request::AsCGI;
use URI::Escape;
use Plack;
use Plack::Handler::CGI;
use Plack::Test::Suite;

Plack::Test::Suite->runtests(sub {
    my ($name, $test, $handler) = @_;
    local $ENV{PLACK_TEST_HANDLER} = 'CGI';
    local $ENV{PLACK_TEST_SCRIPT_NAME} = '/plack_test.cgi';

    note $name;
    my $cb = sub {
        my $req = shift;

        my $cgi = HTTP::Request::AsCGI->new($req);
        my $c = $cgi->setup;

        # Fix CGI container parameters
        $ENV{SCRIPT_NAME} = '/plack_test.cgi';
        $ENV{REQUEST_URI} = "/plack_test.cgi$ENV{REQUEST_URI}";

        # Apache's CGI implementation does not pass "Authorization" header by untrusted ENV.
        # We bow down to it under this test.
        delete $ENV{HTTP_AUTHORIZATION};

        eval { Plack::Handler::CGI->new->run($handler) };
        my $res = $c->response;
        $res->request($req);

        $res;
    };

    $test->($cb);
});

done_testing;