File: request.t

package info (click to toggle)
libapreq2-perl 2.04-dev-1sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,700 kB
  • ctags: 1,508
  • sloc: sh: 8,103; ansic: 5,557; perl: 2,842; cpp: 1,052; makefile: 234
file content (132 lines) | stat: -rw-r--r-- 3,743 bytes parent folder | download | duplicates (4)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest qw(GET_BODY UPLOAD_BODY POST_BODY GET_RC);
require File::Copy;

my $num_tests = 18;
$num_tests *= 2 if Apache::Test::have_ssl();
plan tests => $num_tests, have_lwp;
my $scheme = "http";

START_TESTS:
Apache::TestRequest::scheme($scheme);

foreach my $location ('/apreq_request_test', '/apreq_access_test') {

    ok t_cmp(GET_BODY("$location?test=1"), "ARGS:\n\ttest => 1\n", 
             "simple get");

    ok t_cmp(UPLOAD_BODY("$location?test=2", content => "unused"), 
             "ARGS:\n\ttest => 2\nBODY:\n\tHTTPUPLOAD => b\n",
             "simple upload");
}

ok t_cmp(GET_RC("/apreq_access_test"), 403, "access denied");

my $filler = "0123456789" x 6400; # < 64K
my $body = POST_BODY("/apreq_access_test?foo=1;", 
                     content => "bar=2&quux=$filler;test=6&more=$filler");
ok t_cmp($body, <<EOT, "prefetch credentials");
ARGS:
\tfoo => 1
BODY:
\tbar => 2
\tquux => $filler
\ttest => 6
\tmore => $filler
EOT

ok t_cmp(GET_RC("/apreq_redirect_test"), 403, "missing 'test' authorization");

foreach my $location ('/apreq_request_test', '/apreq_access_test') {
    ok t_cmp(GET_BODY("/apreq_redirect_test?test=ok&location=$location%3Ftest=redirect"), 
             "ARGS:\n\ttest => redirect\n", 
             "redirect GET");

    $body = POST_BODY("/apreq_redirect_test?location=$location%3Ffoo=bar", content => 
            "quux=$filler;test=redirect+with+prefetch;more=$filler");

    ok t_cmp($body, <<EOT, "redirect with prefetch");
ARGS:
\tfoo => bar
BODY:
\tquux => $filler
\ttest => redirect with prefetch
\tmore => $filler
EOT
}

# internal redirect to plain text files (which are non-apreq requests)

my $index_html = do {local (@ARGV,$/) = "t/htdocs/index.html"; <> };
my $orig = 't/htdocs/index.html';
my $copy = 't/htdocs/index.txt';
unlink $copy if -f $copy;
File::Copy::copy($orig, $copy)
    or die "Cannot copy $orig to $copy: $!";

$body = GET_BODY("/apreq_redirect_test?test=redirect_index_txt_GET&location=/index.txt");
$body =~ s{\r}{}g;
ok t_cmp($body, $index_html,
        "redirect /index.txt (GET)");
$body = POST_BODY("/apreq_redirect_test?test=redirect_index_txt_POST",
        content => "quux=$filler;location=/index.txt;foo=$filler");
$body =~ s{\r}{}g;
ok t_cmp($body, $index_html, 
        "redirect /index.txt (POST)");

# output filter tests

sub filter_content ($) {
   my $body = shift;      
   $body =~ s/^.*--APREQ OUTPUT FILTER--\s+//s;
   return $body;
}

ok t_cmp(GET_RC("/index.html"), 200, "/index.html");
ok t_cmp(filter_content GET_BODY("/index.html?test=13"),
         "ARGS:\n\ttest => 13\n", "output filter GET");

ok t_cmp(filter_content POST_BODY("/index.html?test=14", content => 
         "post+data=foo;more=$filler;test=output+filter+POST"), 
         <<EOT,
ARGS:
\ttest => 14
BODY:
\tpost data => foo
\tmore => $filler
\ttest => output filter POST
EOT
          "output filter POST");

# internal redirect to html files which are filtered as above

$body = GET_BODY("/apreq_redirect_test?test=redirect_index_html_GET&location=/index.html?foo=bar");
$body =~ s{\r}{}g;
ok t_cmp($body, $index_html . <<EOT, "redirect /index.html (GET)");

--APREQ OUTPUT FILTER--
ARGS:
\tfoo => bar
EOT
$body = POST_BODY("/apreq_redirect_test?test=redirect_index_html_POST",
        content => "quux=$filler;location=/index.html?foo=quux;foo=$filler");
$body =~ s{\r}{}g;
ok t_cmp($body, $index_html . <<EOT, "redirect /index.txt (POST)");

--APREQ OUTPUT FILTER--
ARGS:
\tfoo => quux
BODY:
\tquux => $filler
\tlocation => /index.html?foo=quux
\tfoo => $filler
EOT

if (Apache::Test::have_ssl() and $scheme ne 'https') {    
    $scheme = 'https';
    goto START_TESTS;
}