~ubuntu-branches/ubuntu/precise/perl/precise

« back to all changes in this revision

Viewing changes to cpan/CGI/t/headers.t

  • Committer: Bazaar Package Importer
  • Author(s): Niko Tyni
  • Date: 2011-02-06 11:31:38 UTC
  • mto: (8.2.12 experimental) (1.1.12)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: james.westby@ubuntu.com-20110206113138-lzpm3g6rur7i3eyp
Tags: upstream-5.12.3
ImportĀ upstreamĀ versionĀ 5.12.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# Test that header generation is spec compliant.
 
3
# References:
 
4
#   http://www.w3.org/Protocols/rfc2616/rfc2616.html
 
5
#   http://www.w3.org/Protocols/rfc822/3_Lexical.html
 
6
 
 
7
use strict;
 
8
use warnings;
 
9
 
 
10
use Test::More 'no_plan';
 
11
 
 
12
use CGI;
 
13
 
 
14
my $cgi = CGI->new;
 
15
 
 
16
like $cgi->header( -type => "text/html" ),
 
17
    qr#Type: text/html#, 'known header, basic case: type => "text/html"';
 
18
 
 
19
eval { $cgi->header( -type => "text/html".$CGI::CRLF."evil: stuff" ) };
 
20
like($@,qr/contains a newline/,'invalid header blows up');
 
21
 
 
22
like $cgi->header( -type => "text/html".$CGI::CRLF." evil: stuff " ),
 
23
    qr#Content-Type: text/html evil: stuff#, 'known header, with leading and trailing whitespace on the continuation line';
 
24
 
 
25
eval { $cgi->header( -foobar => "text/html".$CGI::CRLF."evil: stuff" ) };
 
26
like($@,qr/contains a newline/,'unknown header with CRLF embedded blows up');
 
27
 
 
28
eval { $cgi->header( -foobar => $CGI::CRLF."Content-type: evil/header" ) };
 
29
like($@,qr/contains a newline/, 'unknown header with leading newlines blows up');
 
30
 
 
31
eval { $cgi->redirect( -type => "text/html".$CGI::CRLF."evil: stuff" ) };
 
32
like($@,qr/contains a newline/,'redirect with known header with CRLF embedded blows up');
 
33
 
 
34
eval { $cgi->redirect( -foobar => "text/html".$CGI::CRLF."evil: stuff" ) };
 
35
like($@,qr/contains a newline/,'redirect with unknown header with CRLF embedded blows up');
 
36
 
 
37
eval { $cgi->redirect( $CGI::CRLF.$CGI::CRLF."Content-Type: text/html") };
 
38
like($@,qr/contains a newline/,'redirect with leading newlines blows up');
 
39
 
 
40
{
 
41
    my $cgi = CGI->new('t=bogus%0A%0A<html>');
 
42
    my $out;
 
43
    eval { $out = $cgi->redirect( $cgi->param('t') ) };
 
44
    like($@,qr/contains a newline/, "redirect does not allow double-newline injection");
 
45
}
 
46
 
 
47