"Fossies" - the Fresh Open Source Software Archive

Member "mod_perl-2.0.11/t/modperl/cookie.t" (5 Oct 2019, 1879 Bytes) of package /linux/www/apache_httpd_modules/mod_perl-2.0.11.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "cookie.t": 2.0.8_vs_2.0.9.

    1 # please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
    2 use strict;
    3 use warnings FATAL => 'all';
    4 
    5 # The Cookie HTTP header can be accessed via $r->headers_in and in certain
    6 # situations via $ENV{HTTP_COOKIE}.
    7 #
    8 # 'SetHandler perl-script', combined with 'PerlOptions -SetupEnv', or
    9 # 'SetHandler modperl' do not populate %ENV with CGI variables.  So in
   10 # this test we call $r->subprocess_env, which adds them on demand, and
   11 # we are able to get the cookie via %ENV.
   12 #
   13 # the last sub-test makes sure that mod_cgi env vars don't persist
   14 # and are properly re-set at the end of each request.
   15 #
   16 # since the test is run against the same interpreter we also test that
   17 # the cookie value doesn't persist if it makes it to %ENV.
   18 
   19 
   20 use Apache::Test;
   21 use Apache::TestUtil;
   22 use Apache::TestRequest;
   23 Apache::TestRequest::user_agent(keep_alive => 1);
   24 
   25 plan tests => 3, need 'HTML::HeadParser';
   26 
   27 my $module   = 'TestModperl::cookie';
   28 my $location = '/' . Apache::TestRequest::module2path($module);
   29 
   30 my $cookie = 'foo=bar';
   31 my %cookies = (
   32      header   => $cookie,
   33      env      => $cookie,
   34      nocookie => '',
   35 );
   36 
   37 # 'nocookie' must be run last, server-side shouldn't find a cookie
   38 # (testing that %ENV is reset to its original values for vars set by
   39 # $r->subprocess_env, which is run internally for 'perl-script')
   40 # this requires that all the tests are run against the same interpter
   41 
   42 my @tests_ordered = qw(header env nocookie);
   43 
   44 GET $location;
   45 
   46 for my $test (@tests_ordered) {
   47     my $expected = $test eq 'nocookie' ? '' : "bar";
   48     my @headers = ();
   49     push @headers, (Cookie => $cookies{$test}) unless $test eq 'nocookie';
   50 
   51     my $received = GET "$location?$test", @headers;
   52     
   53     ok t_cmp(
   54         $received->content,
   55         $expected,
   56         "perl-script+SetupEnv/cookie: $test"
   57     );
   58 }