prep for release
[catagits/Catalyst-Runtime.git] / t / live_redirect_body.t
CommitLineData
d67d5f87 1use FindBin;
13e3699a 2use lib "$FindBin::Bin/lib";
d67d5f87 3use Catalyst::Test 'TestApp', {default_host => 'default.com'};
4use Catalyst::Request;
5
9bdde4de 6use Test::More;
7
8# test redirect
9{
10 my $request =
11 HTTP::Request->new( GET => 'http://localhost:3000/test_redirect' );
12
13 ok( my $response = request($request), 'Request' );
14 is( $response->code, 302, 'Response Code' );
15
16 # When no body and no content_type has been set, redirecting should set both.
17 is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
18 like( $response->content, qr/<body>/, 'Content contains HTML body' );
19}
20
21# test redirect without a body and but with a content_type set explicitly by the developer
22{
23 my $request =
24 HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_contenttype' );
25
26 ok( my $response = request($request), 'Request' );
27 is( $response->code, 302, 'Response Code' );
28
29 # When the developer has not set content body, we set it. The content type must always match the body, so it should be overwritten.
30 is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
31 like( $response->content, qr/<body>/, 'Content contains HTML body' );
32}
33
34# test redirect without a body and but with a content_type set explicitly by the developer
35{
36 my $request =
37 HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_with_content' );
38
39 ok( my $response = request($request), 'Request' );
40 is( $response->code, 302, 'Response Code' );
41
42 # When the developer sets both the content body and content type, the set content body and content_type should get through.
55046410 43 like( $response->header( 'Content-Type' ), qr{text/plain}, 'Content Type' );
9bdde4de 44 like( $response->content, qr/kind sir/, 'Content contains content set by the Controller' );
45}
46
7af54927 47# test redirect with dodgy host
48{
49 local $Catalyst::Test::default_host = "-->\">'>'\"<sfi000003v407412>";
50 my $request =
51 HTTP::Request->new( GET => 'http://localhost:3000/test_redirect_uri_for');
52
53 ok( my $response = request($request), 'Request' );
54 is( $response->code, 302, 'Response Code' );
55
56 # When no body and no content_type has been set, redirecting should set both.
57 is( $response->header( 'Content-Type' ), 'text/html; charset=utf-8', 'Content Type' );
58 like( $response->content, qr/<body>/, 'Content contains HTML body' );
59 like( $response->content, qr/href="[^"]+">here<\/a>/, 'link doesn\'t have xss' );
60}
61
9bdde4de 62done_testing;
63