File: status.t

package info (click to toggle)
libapache2-mod-perl2 2.0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 12,016 kB
  • sloc: perl: 97,771; ansic: 14,493; makefile: 51; sh: 18
file content (158 lines) | stat: -rw-r--r-- 3,363 bytes parent folder | download | duplicates (7)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil qw(t_cmp t_server_log_error_is_expected);

use Apache2::Const -compile => qw(OK DECLINED
                                 NOT_FOUND SERVER_ERROR FORBIDDEN
                                 HTTP_OK);

plan tests => 15, need 'HTML::HeadParser';

my $base = "/TestModperl__status";

# valid Apache return codes
{
    my $uri = join '?', $base, Apache2::Const::OK;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::HTTP_OK,
             $uri);
}

{
    my $uri = join '?', $base, Apache2::Const::DECLINED;
    my $code = GET_RC $uri;

    # no Alias to map us to DocumentRoot
    ok t_cmp($code,
             Apache2::Const::NOT_FOUND,
             $uri);
}

# standard HTTP status codes
{
    my $uri = join '?', $base, Apache2::Const::NOT_FOUND;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::NOT_FOUND,
             $uri);
}

{
    my $uri = join '?', $base, Apache2::Const::FORBIDDEN;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::FORBIDDEN,
             $uri);
}

{
    my $uri = join '?', $base, Apache2::Const::SERVER_ERROR;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::SERVER_ERROR,
             $uri);
}

# apache translates non-HTTP codes into 500
# see ap_index_of_response
{
    my $uri = join '?', $base, 601;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::SERVER_ERROR,
             $uri);
}

{
    my $uri = join '?', $base, 313;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::SERVER_ERROR,
             $uri);
}

{
    my $uri = join '?', $base, 1;
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::SERVER_ERROR,
             $uri);
}

# HTTP_OK is treated as an error, since it's not
# OK, DECLINED, or DONE.  while apache's lookups
# succeed so the 200 is propagated to the client,
# there's an error beneath that 200 code.
{
    my $uri = join '?', $base, Apache2::Const::HTTP_OK;
    my $response = GET $uri;

    ok t_cmp($response->code,
             Apache2::Const::HTTP_OK,
             $uri);

    ok t_cmp($response->content,
             qr/server encountered an internal error/,
             $uri);
}

# mod_perl-specific implementation tests
{
    # ModPerl::Util::exit - voids return OK
    my $uri = join '?', $base, 'exit';
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::HTTP_OK,
             $uri);
}

{
    # die gets trapped
    my $uri = join '?', $base, 'die';
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::SERVER_ERROR,
             $uri);
}

{
    my $uri = join '?', $base, 'foobar';
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::HTTP_OK,
             $uri);
}

{
    my $uri = join '?', $base, 'foo9bar';
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::HTTP_OK,
             $uri);
}

{
    my $uri = join '?', $base, 'undef';
    my $code = GET_RC $uri;

    ok t_cmp($code,
             Apache2::Const::HTTP_OK,
             $uri);
}