This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make cpan/CGI/t/http.t (hopefully) compatible with VMS
[perl5.git] / cpan / CGI / t / http.t
CommitLineData
deafae52
SH
1#!./perl -w
2
3# Fixes RT 12909
4
5use lib qw(t/lib);
6
7use Test::More tests => 7;
8use CGI;
9
10my $cgi = CGI->new();
11
12{
13 # http() without arguments should not cause warnings
14 local $SIG{__WARN__} = sub { die @_ };
15 ok eval { $cgi->http(); 1 }, "http() without arguments doesn't warn";
16 ok eval { $cgi->https(); 1 }, "https() without arguments doesn't warn";
17}
18
19{
20 # Capitalization and the use of hyphens versus underscores are not significant.
21 local $ENV{'HTTP_HOST'} = 'foo';
22 is $cgi->http('Host'), 'foo', 'http("Host") returns $ENV{HTTP_HOST}';
23 is $cgi->http('http-host'), 'foo', 'http("http-host") returns $ENV{HTTP_HOST}';
24}
25
26{
27 # Called with no arguments returns the list of HTTP environment variables
28 local $ENV{'HTTPS_FOO'} = 'bar';
29 my @http = $cgi->http();
30 is scalar( grep /^HTTPS/, @http), 0, "http() doesn't return HTTPS variables";
31}
32
33{
34 # https()
35 # The same as http(), but operates on the HTTPS environment variables present when the SSL protocol is in
36 # effect. Can be used to determine whether SSL is turned on.
582bd879
FC
37 my @expect = grep /^HTTPS/, keys %ENV;
38 push @expect, 'HTTPS' if not exists $ENV{HTTPS};
39 push @expect, 'HTTPS_KEYSIZE' if not exists $ENV{HTTPS_KEYSIZE};
deafae52
SH
40 local $ENV{'HTTPS'} = 'ON';
41 local $ENV{'HTTPS_KEYSIZE'} = 512;
42 is $cgi->https(), 'ON', 'scalar context to check SSL is on';
582bd879 43 ok eq_set( [$cgi->https()], \@expect), 'list context returns https keys';
deafae52 44}