File: dir.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 (134 lines) | stat: -rw-r--r-- 3,639 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings FATAL => 'all';

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

## 
## mod_dir tests
##

my @index = qw(1 2 3 4 5 6 7 8 9 0);
my @bad_index = qw(foo goo moo bleh);
my $htdocs = Apache::Test::vars('documentroot');
my $htaccess = "$htdocs/modules/dir/htaccess/.htaccess";
my $url = "/modules/dir/htaccess/";
my ($actual, $expected);

#XXX: this is silly; need a better way to be portable
sub my_chomp {
    $actual =~ s/[\r\n]+$//s;
}

plan tests => @bad_index * @index * 5 + @bad_index + 5 + 3 +1+1, need_module 'dir';

foreach my $bad_index (@bad_index) {

    print "expecting 403 (forbidden) using DirectoryIndex $bad_index\n";
    $expected = (have_module 'autoindex') ? 403 : 404;
    write_htaccess("$bad_index");
    $actual = GET_RC $url;
    ok ($actual == $expected);

    foreach my $index (@index) {

        print "running 5 test gambit for \"$index.html\"\n";
        ## $index will be expected for all
        ## tests at this level
        $expected = $index;

        write_htaccess("$index.html");
        $actual = GET_BODY $url;
        ok ($actual eq $expected);

        write_htaccess("$bad_index $index.html");
        $actual = GET_BODY $url;
        ok ($actual eq $expected);

        write_htaccess("$index.html $bad_index");
        $actual = GET_BODY $url;
        ok ($actual eq $expected);

        write_htaccess("/modules/alias/$index.html");
        $actual = GET_BODY $url;
        ok ($actual eq $expected);

        write_htaccess("$bad_index /modules/alias/$index.html");
        $actual = GET_BODY $url;
        ok ($actual eq $expected);
    }
}

print "DirectoryIndex /modules/alias/index.html\n";
$expected = "alias index";
write_htaccess("/modules/alias/index.html");
$actual = GET_BODY $url;
my_chomp();
ok ($actual eq $expected);

print "expecting 403 for DirectoryIndex @bad_index\n";
$expected = (have_module 'autoindex') ? 403 : 404;
write_htaccess("@bad_index");
$actual = GET_RC $url;
ok ($actual == $expected);

$expected = $index[0];
my @index_html = map { "$_.html" } @index;
print "expecting $expected with DirectoryIndex @index_html\n";
write_htaccess("@index_html");
$actual = GET_BODY $url;
ok ($actual eq $expected);

print "expecting $expected with DirectoryIndex @bad_index @index_html\n";
write_htaccess("@bad_index @index_html");
$actual = GET_BODY $url;
ok ($actual eq $expected);

unlink $htaccess;
print "removed .htaccess (no DirectoryIndex), expecting default (index.html)\n";
$expected = "dir index";
$actual = GET_BODY $url;
my_chomp();
ok ($actual eq $expected);

# DirectorySlash stuff
my $res = GET "/modules/dir", redirect_ok => 0;
ok ($res->code == 301);
$res = GET "/modules/dir/htaccess", redirect_ok => 0;
ok ($res->code == 403);

if (!have_min_apache_version('2.5.1')) { 
    skip("missing DirectorySlash NotFound");
}
else { 
    $res = GET "/modules/dir/htaccess/sub", redirect_ok => 0;
    ok ($res->code == 404);
}


if (!have_min_apache_version('2.4.61') || !have_module('mime') || !have_module('status')) {
    skip("doesn't work");
}
else {
    my $body = GET_BODY "/modules/dir/fallback/";
    ok t_cmp($body, qr/Server Status/, "type->handler wasn't used");

}
if (!have_min_apache_version('2.4.62') || !have_module('negotiation') || !have_module('status')) {
    skip("doesn't work");
}
else {
    my $body = GET_BODY "/modules/dir/fallback/fallback";
    ok t_cmp($body, qr/Server Status/, "type->handler wasn't used w/ multiviews");

}


sub write_htaccess {
    my $string = shift;

    open (HT, ">$htaccess") or die "cannot open $htaccess: $!";
    print HT "DirectoryIndex $string";
    close (HT);
}