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
|
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest qw/GET_BODY/;
BEGIN { plan tests => 7; }
my $head; # expected page header
my $foot; # expected page footer
my @body; # sections of page body
mkdir 't/htdocs/subdir' if ! -d 't/htdocs/subdir';
# Read contents of header and footer
open my $h, '<', 't/htdocs/head.html'
or die "Could not open < t/htdocs/head.html: $!";
open my $f, '<', 't/htdocs/foot.html'
or die "Could not open < t/htdocs/foot.html: $!";
$head = do { local $/; <$h> };
$foot = do { local $/; <$f> };
close $h; close $f;
# Helper for replacing file contents
sub set {
my $file = shift;
open my $fh, '>', $file or die "Could not open > $file: $!";
print $fh join('', @_);
close $fh;
}
# Run tests
set 't/htdocs/.htaccess', <<CONF;
Inject " "
CONF
@body = ("This is a test page.\n");
set 't/htdocs/test.html', @body;
set 't/htdocs/ ', 'whatever';
ok GET_BODY('/test.html'), ${body[0]}, # should not include 'whatever'
'single-space argument should fail';
set 't/htdocs/.htaccess', <<CONF;
Inject head.html foot.html
CONF
@body = ("<title>Test</title>\n", "This is a test page.\n");
set 't/htdocs/test.html', @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
'<head>-less head';
@body = ("<head>...</head>\n", "This is a test page.\n");
set 't/htdocs/test.html', @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
'<head>-ful head';
set 't/htdocs/subdir/.htaccess', <<CONF;
Inject head.html
CONF
@body = ("This is a test page.\n");
set 't/htdocs/subdir/test.html', @body;
ok GET_BODY('/subdir/test.html'), "$head${body[0]}",
'different injection in subdirectory';
@body = ("<html>\n", "This is a test page.\n", "</html>\n");
set 't/htdocs/test.html', @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot${body[2]}",
'<html>-wrapped document';
@body = ("<!doctype html>\n", "This is a test page.\n");
set 't/htdocs/test.html', @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
'<!doctype>';
@body = ("\n<!doctype html>\n", "This is a test page.\n");
set 't/htdocs/test.html', @body;
ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot",
'<!doctype> with leading newline';
unlink 't/htdocs/.htaccess';
unlink 't/htdocs/test.html';
unlink 't/htdocs/subdir/.htaccess';
unlink 't/htdocs/subdir/test.html';
unlink 't/htdocs/ ';
|