|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HtaccessCapabilityTester\Testers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class for testing if RequestHeader works |
|
7
|
|
|
* |
|
8
|
|
|
* @package HtaccessCapabilityTester |
|
9
|
|
|
* @author Bjørn Rosell <[email protected]> |
|
10
|
|
|
* @since Class available since 0.7 |
|
11
|
|
|
*/ |
|
12
|
|
|
class RequestHeaderTester extends CustomTester |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Constructor. |
|
17
|
|
|
* |
|
18
|
|
|
* @return void |
|
19
|
|
|
*/ |
|
20
|
7 |
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$htaccessFile = <<<'EOD' |
|
23
|
7 |
|
<IfModule mod_headers.c> |
|
24
|
|
|
# Certain hosts seem to strip non-standard request headers, |
|
25
|
|
|
# so we use a standard one to avoid a false negative |
|
26
|
|
|
RequestHeader set User-Agent "request-header-test" |
|
27
|
|
|
</IfModule> |
|
28
|
|
|
EOD; |
|
29
|
|
|
|
|
30
|
|
|
$phpFile = <<<'EOD' |
|
31
|
7 |
|
<?php |
|
32
|
|
|
if (isset($_SERVER['HTTP_USER_AGENT'])) { |
|
33
|
|
|
echo (($_SERVER['HTTP_USER_AGENT'] == 'request-header-test') ? "1" : "0"); |
|
34
|
|
|
} else { |
|
35
|
|
|
echo "0"; |
|
36
|
|
|
} |
|
37
|
|
|
EOD; |
|
38
|
|
|
|
|
39
|
|
|
// PS: |
|
40
|
|
|
// There is a little edge case: When .htaccess is disabled AND phps are either not processed |
|
41
|
|
|
// or access is denied. This ought to return *failure*, but it currently returns *inconclusive*. |
|
42
|
|
|
|
|
43
|
|
|
$test = [ |
|
44
|
7 |
|
'subdir' => 'request-header', |
|
45
|
|
|
'files' => [ |
|
46
|
7 |
|
['.htaccess', $htaccessFile], |
|
47
|
7 |
|
['test.php', $phpFile], |
|
48
|
|
|
], |
|
49
|
7 |
|
'request' => 'test.php', |
|
50
|
|
|
'interpretation' => [ |
|
51
|
|
|
['success', 'body', 'equals', '1'], |
|
52
|
|
|
['failure', 'body', 'equals', '0'], |
|
53
|
|
|
['inconclusive', 'body', 'begins-with', '<' . '?php'], |
|
54
|
|
|
] |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
7 |
|
parent::__construct($test); |
|
58
|
7 |
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|