File: live_redirect_body.t

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (63 lines) | stat: -rw-r--r-- 2,509 bytes parent folder | download | duplicates (6)
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
60
61
62
63
use FindBin;
use lib "$FindBin::Bin/lib";
use Catalyst::Test 'TestApp', {default_host => 'default.com'};
use Catalyst::Request;

use Test::More;

# test redirect
{
    my $request  =
      HTTP::Request->new( GET => 'http://localhost:3000/test_redirect' );

    ok( my $response = request($request), 'Request' );
    is( $response->code, 302, 'Response Code' );

    # When no body and no content_type has been set, redirecting should set both.
    is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
    like( $response->content, qr/<body>/, 'Content contains HTML body' );
}

# test redirect without a body and but with a content_type set explicitly by the developer
{
    my $request  =
        HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_contenttype' );

    ok( my $response = request($request), 'Request' );
    is( $response->code, 302, 'Response Code' );

    # When the developer has not set content body, we set it. The content type must always match the body, so it should be overwritten.
    is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
    like( $response->content, qr/<body>/, 'Content contains HTML body' );
}

# test redirect without a body and but with a content_type set explicitly by the developer
{
    my $request  =
        HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_content' );

    ok( my $response = request($request), 'Request' );
    is( $response->code, 302, 'Response Code' );

    # When the developer sets both the content body and content type, the set content body and content_type should get through.
    like( $response->header( 'Content-Type' ), qr{text/plain}, 'Content Type' );
    like( $response->content, qr/kind sir/, 'Content contains content set by the Controller' );
}

# test redirect with dodgy host
{
    local $Catalyst::Test::default_host = "-->\">'>'\"<sfi000003v407412>";
    my $request  =
      HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_uri_for');

    ok( my $response = request($request), 'Request' );
    is( $response->code, 302, 'Response Code' );

    # When no body and no content_type has been set, redirecting should set both.
    is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
    like( $response->content, qr/<body>/, 'Content contains HTML body' );
    like( $response->content, qr/href="[^"]+">here<\/a>/, 'link doesn\'t have xss' );
}

done_testing;