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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<?php
namespace PhpConsole\Test\Remote;
class Evaluate extends Test {
protected function setUp() { parent::setUp(); $this->randomOutputMustPresentInResponse = false; }
protected function setUpConnector() { parent::setUpConnector(); $this->request->addScript('init_default_handler'); }
protected function setRequestEval($code, $signature = null, \PhpConsole\Auth $auth = null) { if(!$auth) { $auth = $this->setRequestAuth(); } $this->request->postData[\PhpConsole\Connector::POST_VAR_NAME]['eval'] = array( 'data' => $code, 'signature' => $signature ? : $auth->getSignature($code), ); }
public function testIsEvalNotEnabledInResponse() { $this->sendRequest(); $this->assertEmpty($this->response->package->isEvalEnabled); }
public function testIsEvalEnabledInResponse() { $this->setConnectorAuth(); $this->setRequestAuth(); $this->request->addScript('set_connector_eval_enabled'); $this->sendRequest(); $this->assertTrue($this->response->package->isEvalEnabled); }
public function testEnableEvalInNotAuthModeThrowsException() { $this->request->addScript('set_connector_eval_enabled'); $this->sendRequest(); $this->assertMessageInResponse(array( 'type' => 'error', 'class' => 'Exception', 'data' => 'Eval dispatcher is allowed only in password protected mode. See PhpConsole\Connector::getInstance()->setPassword(...)', )); }
public function testEvalResultInResponse() { $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled'); $this->setRequestEval('echo 321; return 123;');
$this->sendRequest();
$this->assertMessageInResponse(array( 'type' => 'eval_result', 'return' => 123, 'output' => '321', ));
$this->assertEmpty($this->findMessagesInResponse(array( 'type' => 'error' ))); }
public function testFlushDebugMessagesEnabled() { $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled'); $this->setRequestEval('return 123'); $this->sendRequest(); $this->assertRandomMessageInResponse(false); }
public function testFlushDebugMessagesDisabled() { $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled', array( 'flushDebugMessages' => false )); $this->setRequestEval('return 123'); $this->sendRequest(); $this->assertRandomMessageInResponse(); }
public function testExitOnEvalDisabled() { $this->randomOutputMustPresentInResponse = true; $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled', array( 'exitOnEval' => false )); $this->setRequestEval('return 123'); $this->sendRequest(); }
public function testNoEvalIfAuthFails() { $this->setConnectorAuth('oops'); $this->request->addScript('set_connector_eval_enabled'); $this->setRequestEval('echo 321; return 123;');
$this->sendRequest();
$this->assertEmpty($this->findMessageInResponse(array( 'type' => 'eval_result', ))); }
public function testEvalErrorIsHandled() { $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled'); $this->setRequestEval('oops()'); $this->sendRequest(); $this->assertMessageInResponse(array( 'type' => 'error', 'code' => E_ERROR, 'data' => 'Call to undefined function oops()' )); }
public function testEvalExceptionIsHandled() { $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled'); $this->setRequestEval('throw new Exception(123)'); $this->sendRequest(); $this->assertMessageInResponse(array( 'type' => 'error', 'class' => 'Exception', )); }
public function testDisableFileAccessByOpenBaseDir() { $evalProvider = new \PhpConsole\EvalProvider(); $evalProvider->disableFileAccessByOpenBaseDir(); $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled', array( 'evalProvider' => $evalProvider )); $this->setRequestEval('echo file_get_contents("' . __FILE__ . '");'); $this->sendRequest();
$this->assertMessageInResponse(array( 'type' => 'eval_result', 'return' => null, 'output' => '', ));
$this->assertMessageInResponse(array( 'type' => 'error', 'code' => E_WARNING, )); }
public function tesSetOpenBaseDirs() { $evalProvider = new \PhpConsole\EvalProvider(); $evalProvider->setOpenBaseDirs(__DIR__); $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled', array( 'evalProvider' => $evalProvider )); $this->setRequestEval('return file_get_contents("' . __FILE__ . '");'); $this->sendRequest();
$this->assertMessageInResponse(array( 'type' => 'eval_result', 'return' => __FILE__, 'output' => '', )); }
public function testEvalWithCustomServerEncoding() { $string = 'Ёпрст'; $encoding = 'Windows-1251'; $this->request->addScript('set_connector_encoding', array('encoding' => $encoding)); $this->setConnectorAuth(); $this->request->addScript('set_connector_eval_enabled'); $this->setRequestEval("return mb_convert_encoding(mb_convert_encoding('$string', 'utf-8', '$encoding'), '$encoding', 'utf-8')"); $this->sendRequest(); $this->assertMessageInResponse(array( 'type' => 'eval_result', 'return' => $string, )); } }
|