forked from nette/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest.invalidEncoding.phpt
More file actions
121 lines (100 loc) · 3.48 KB
/
Request.invalidEncoding.phpt
File metadata and controls
121 lines (100 loc) · 3.48 KB
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
<?php
/**
* Test: Nette\Http\Request invalid encoding.
*/
use Nette\Http;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
// Setup environment
define('INVALID', "\xC4\x76\xC5\xBE");
define('CONTROL_CHARACTERS', "A\x01B\x02C");
$_SERVER['REQUEST_URI'] = '/?' . http_build_query([
'invalid' => INVALID,
'control' => CONTROL_CHARACTERS,
INVALID => '1',
CONTROL_CHARACTERS => '1',
'array' => [INVALID => '1'],
]);
$_POST = [
'invalid' => INVALID,
'control' => CONTROL_CHARACTERS,
INVALID => '1',
CONTROL_CHARACTERS => '1',
'array' => [INVALID => '1'],
];
$_COOKIE = [
'invalid' => INVALID,
'control' => CONTROL_CHARACTERS,
INVALID => '1',
CONTROL_CHARACTERS => '1',
'array' => [INVALID => '1'],
];
$_FILES = [
INVALID => [
'name' => 'readme.txt',
'type' => 'text/plain',
'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp',
'error' => 0,
'size' => 209,
],
CONTROL_CHARACTERS => [
'name' => 'readme.txt',
'type' => 'text/plain',
'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp',
'error' => 0,
'size' => 209,
],
'file1' => [
'name' => INVALID,
'type' => 'text/plain',
'tmp_name' => 'C:\\PHP\\temp\\php1D5B.tmp',
'error' => 0,
'size' => 209,
],
];
test(function () { // unfiltered data
$factory = new Http\RequestFactory;
$factory->setBinary();
$request = $factory->createHttpRequest();
Assert::same($request->getQuery('invalid'), INVALID);
Assert::same($request->getQuery('control'), CONTROL_CHARACTERS);
Assert::same('1', $request->getQuery(INVALID));
Assert::same('1', $request->getQuery(CONTROL_CHARACTERS));
Assert::same('1', $request->query['array'][INVALID]);
Assert::same($request->getPost('invalid'), INVALID);
Assert::same($request->getPost('control'), CONTROL_CHARACTERS);
Assert::same('1', $request->getPost(INVALID));
Assert::same('1', $request->getPost(CONTROL_CHARACTERS));
Assert::same('1', $request->post['array'][INVALID]);
Assert::same($request->getCookie('invalid'), INVALID);
Assert::same($request->getCookie('control'), CONTROL_CHARACTERS);
Assert::same('1', $request->getCookie(INVALID));
Assert::same('1', $request->getCookie(CONTROL_CHARACTERS));
Assert::same('1', $request->cookies['array'][INVALID]);
Assert::type(Nette\Http\FileUpload::class, $request->getFile(INVALID));
Assert::type(Nette\Http\FileUpload::class, $request->getFile(CONTROL_CHARACTERS));
Assert::type(Nette\Http\FileUpload::class, $request->files['file1']);
});
test(function () { // filtered data
$factory = new Http\RequestFactory;
$request = $factory->createHttpRequest();
Assert::same('', $request->getQuery('invalid'));
Assert::same('ABC', $request->getQuery('control'));
Assert::null($request->getQuery(INVALID));
Assert::null($request->getQuery(CONTROL_CHARACTERS));
Assert::false(isset($request->query['array'][INVALID]));
Assert::same('', $request->getPost('invalid'));
Assert::same('ABC', $request->getPost('control'));
Assert::null($request->getPost(INVALID));
Assert::null($request->getPost(CONTROL_CHARACTERS));
Assert::false(isset($request->post['array'][INVALID]));
Assert::same('', $request->getCookie('invalid'));
Assert::same('ABC', $request->getCookie('control'));
Assert::null($request->getCookie(INVALID));
Assert::null($request->getCookie(CONTROL_CHARACTERS));
Assert::false(isset($request->cookies['array'][INVALID]));
Assert::null($request->getFile(INVALID));
Assert::null($request->getFile(CONTROL_CHARACTERS));
Assert::type(Nette\Http\FileUpload::class, $request->files['file1']);
Assert::same('', $request->files['file1']->name);
});