-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path00-phases.t
132 lines (102 loc) · 6.33 KB
/
00-phases.t
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
use strict;
use Apache::Test;
use Apache::TestRequest;
require "t/find_string_in_file.pl";
plan tests => 5, have_lwp;
my $audit_log = Apache::Test::config()->{vars}->{t_logs} . "/audit_logs.txt";
###############################################################################
# Test phases
# phase 1 (request headers)
###############################################################################
{
# Remember position in audit log file before our test
my $audit_log_start_size = -s $audit_log or die "Failed to access file: " . $audit_log;
my $url = "/00-phases/00-phases_01.html";
my $ct_header_name = "Content-Type";
my $ct_header_val = "application/x-www-form-urlencoded";
my $content = "arg1=val1&arg2=val2";
my $res1 = POST $url, $ct_header_name => $ct_header_val, content => $content;
# Expected results
my $status_code_expected = 200;
my $audit_log_expected = 'Matched "Operator \`Rx\' with parameter \`\^POST\' against variable \`REQUEST_LINE';
my $audit_log_missing = 'Matched [\s\S]*(ARGS|RESPONSE)';
my $audit_found_expected = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_expected);
my $audit_found_missing = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_missing);
ok (($res1->code == $status_code_expected) && ($audit_found_expected) && (not $audit_found_missing));
}
###############################################################################
# Test phases
# phase 2 (request body)
###############################################################################
{
# Remember position in audit log file before our test
my $audit_log_start_size = -s $audit_log or die "Failed to access file: " . $audit_log;
my $url = "/00-phases/00-phases_02.html";
my $ct_header_name = "Content-Type";
my $ct_header_val = "application/x-www-form-urlencoded";
my $content = "arg1=val1&arg2=val2";
my $res1 = POST $url, $ct_header_name => $ct_header_val, content => $content;
# Expected results
my $status_code_expected = 200;
my $audit_log_expected = 'Matched "Operator \`Rx\' with parameter \`\^POST\' against variable \`REQUEST_LINE[\s\S]*Matched "Operator \`Rx\' with parameter \`val1\' against variable \`ARGS';
my $audit_log_missing = 'Matched [\s\S]*RESPONSE';
my $audit_found_expected = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_expected);
my $audit_found_missing = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_missing);
ok (($res1->code == $status_code_expected) && ($audit_found_expected) && (not $audit_found_missing));
}
###############################################################################
# Test phases
# phase 3 (response headers)
###############################################################################
{
# Remember position in audit log file before our test
my $audit_log_start_size = -s $audit_log or die "Failed to access file: " . $audit_log;
my $url = "/00-phases/00-phases_03.html";
my $ct_header_name = "Content-Type";
my $ct_header_val = "application/x-www-form-urlencoded";
my $content = "arg1=val1&arg2=val2";
my $res1 = POST $url, $ct_header_name => $ct_header_val, content => $content;
# Expected results
my $status_code_expected = 200;
my $audit_log_expected = 'Matched "Operator \`Rx\' with parameter \`\^POST\' against variable \`REQUEST_LINE[\s\S]*Matched "Operator \`Rx\' with parameter \`val1\' against variable \`ARGS[\s\S]*Matched "Operator \`Rx\' with parameter \`.\' against variable \`RESPONSE_HEADERS';
my $audit_log_missing = 'Matched [\s\S]*RESPONSE_BODY';
my $audit_found_expected = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_expected);
my $audit_found_missing = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_missing);
ok (($res1->code == $status_code_expected) && ($audit_found_expected) && (not $audit_found_missing));
}
###############################################################################
# Test phases
# phase 4 (response body)
###############################################################################
{
# Remember position in audit log file before our test
my $audit_log_start_size = -s $audit_log or die "Failed to access file: " . $audit_log;
my $url = "/00-phases/00-phases_04.html";
my $ct_header_name = "Content-Type";
my $ct_header_val = "application/x-www-form-urlencoded";
my $content = "arg1=val1&arg2=val2";
my $res1 = POST $url, $ct_header_name => $ct_header_val, content => $content;
# Expected results
my $status_code_expected = 200;
my $audit_log_expected = 'Matched "Operator \`Rx\' with parameter \`\^POST\' against variable \`REQUEST_LINE[\s\S]*Matched "Operator \`Rx\' with parameter \`val1\' against variable \`ARGS[\s\S]*Matched "Operator \`Rx\' with parameter \`.\' against variable \`RESPONSE_HEADERS[\s\S]*Matched "Operator \`Rx\' with parameter \`TEST\' against variable \`RESPONSE_BODY';
my $audit_found_expected = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_expected);
ok (($res1->code == $status_code_expected) && ($audit_found_expected));
}
###############################################################################
# Test phases
# phase 5 (logging)
###############################################################################
{
# Remember position in audit log file before our test
my $audit_log_start_size = -s $audit_log or die "Failed to access file: " . $audit_log;
my $url = "/00-phases/00-phases_05.html";
my $ct_header_name = "Content-Type";
my $ct_header_val = "application/x-www-form-urlencoded";
my $content = "arg1=val1&arg2=val2";
my $res1 = POST $url, $ct_header_name => $ct_header_val, content => $content;
# Expected results
my $status_code_expected = 200;
my $audit_log_expected = 'Matched "Operator \`Rx\' with parameter \`\^POST\' against variable \`REQUEST_LINE[\s\S]*Matched "Operator \`Rx\' with parameter \`val1\' against variable \`ARGS[\s\S]*Matched "Operator \`Rx\' with parameter \`.\' against variable \`RESPONSE_HEADERS[\s\S]*Matched "Operator \`Rx\' with parameter \`TEST\' against variable \`RESPONSE_BODY';
my $audit_found_expected = find_string_in_file($audit_log, $audit_log_start_size, $audit_log_expected);
ok (($res1->code == $status_code_expected) && ($audit_found_expected));
}