File: allowmethods.t

package info (click to toggle)
apache2 2.4.66-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 59,324 kB
  • sloc: ansic: 212,315; python: 13,830; perl: 11,307; sh: 7,254; php: 1,320; javascript: 1,314; awk: 749; makefile: 715; lex: 374; yacc: 161; xml: 2
file content (64 lines) | stat: -rw-r--r-- 1,480 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
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;

my $r;
my $get = "Get";
my $head = "Head";
my $post = "Post";
my $options = "Options";

##
## mod_allowmethods test
##
my @test_cases = (
    [ $get, $get, 200 ],
    [ $head, $get, 200 ],
    [ $post, $get, 405 ],
    [ $get, $head, 200 ],
    [ $head, $head, 200 ],
    [ $post, $head, 405 ],
    [ $get, $post, 405 ],
    [ $head, $post, 405 ],
    [ $post, $post, 200 ],
);

my @new_test_cases = (
    [ $get, $post . '/reset', 200 ],
    [ $post, $get . '/post', 200 ],
    [ $get, $get . '/post', 200 ],
    [ $options, $get . '/post', 405 ],
    [ $get, $get . '/none', 405 ],
    [ $get, "NoPost", 200 ],
    [ $post, "NoPost", 405 ],
    [ $options, "NoPost" , 200 ],
);

if (have_min_apache_version('2.5.1')) { 
    push(@test_cases, @new_test_cases);
}

plan tests => (scalar @test_cases), have_module 'allowmethods';

foreach my $case (@test_cases) {
    my ($fct, $allowed, $rc) = @{$case};

    if ($fct eq $get) {
        $r = GET('/modules/allowmethods/' . $allowed . '/');
    }
    elsif ($fct eq $head) {
        $r = HEAD('/modules/allowmethods/' . $allowed . '/');
    }
    elsif ($fct eq $post) {
        $r = POST('/modules/allowmethods/' . $allowed . '/foo.txt');
    }
    elsif ($fct eq $options) {
        $r = OPTIONS('/modules/allowmethods/' . $allowed . '/');
    }

    ok t_cmp($r->code, $rc, "$fct request to /$allowed responds $rc");
}