8652e7494ed78137ebe88faf3f85e0b4969b7e0d
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Service / SilentConfigurationUpgradeServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Install\Controller\Exception\RedirectException;
18
19 /**
20 * Test case
21 */
22 class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject
26 */
27 protected $configurationManager;
28
29 /**
30 * @param array $methods
31 */
32 protected function createConfigurationManagerWithMockedMethods(array $methods) {
33 $this->configurationManager = $this->getMock(
34 \TYPO3\CMS\Core\Configuration\ConfigurationManager::class,
35 $methods
36 );
37 }
38
39 /**
40 * @test
41 */
42 public function configureSaltedPasswordsWithDefaultConfiguration() {
43 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
44 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
45 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
46 array('dummy'),
47 array(),
48 '',
49 FALSE
50 );
51 $config = 'a:2:{s:3:"BE.";a:3:{s:11:"forceSalted";i:0;s:15:"onlyAuthService";i:0;s:12:"updatePasswd";i:1;}s:3:"FE.";a:4:{s:7:"enabled";i:0;s:11:"forceSalted";i:0;s:15:"onlyAuthService";i:0;s:12:"updatePasswd";i:1;}}';
52 $defaultConfiguration = array();
53 $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
54
55 $closure = function () {
56 throw new \RuntimeException('Path does not exist in array', 1341397869);
57 };
58
59 $this->createConfigurationManagerWithMockedMethods(
60 array(
61 'getDefaultConfiguration',
62 'getLocalConfigurationValueByPath',
63 'setLocalConfigurationValueByPath',
64 )
65 );
66 $this->configurationManager->expects($this->exactly(1))
67 ->method('getDefaultConfiguration')
68 ->will($this->returnValue($defaultConfiguration));
69 $this->configurationManager->expects($this->exactly(1))
70 ->method('getLocalConfigurationValueByPath')
71 ->will($this->returnCallback($closure));
72 $this->configurationManager->expects($this->once())
73 ->method('setLocalConfigurationValueByPath')
74 ->with($this->equalTo('EXT/extConf/saltedpasswords'), $this->equalTo($config));
75
76 $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class);
77
78 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
79
80 $silentConfigurationUpgradeServiceInstance->_call('configureSaltedPasswords');
81 }
82
83 /**
84 * @test
85 */
86 public function configureSaltedPasswordsWithExtensionConfigurationBeEnabled() {
87 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
88 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
89 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
90 array('dummy'),
91 array(),
92 '',
93 FALSE
94 );
95 $config = 'a:2:{s:3:"BE.";a:1:{s:21:"saltedPWHashingMethod";}s:3:"FE.";a:2:{s:7:"enabled";i:0;s:11:"forceSalted";i:0;}}';
96 $defaultConfiguration = array();
97 $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
98
99 $currentLocalConfiguration = array(
100 array('EXT/extConf/saltedpasswords', 'a:2:{s:3:"BE.";a:1:{s:7:"enabled";i:1;}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}')
101 );
102 $newConfig = 'a:2:{s:3:"BE.";a:0:{}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}';
103 $this->createConfigurationManagerWithMockedMethods(
104 array(
105 'getDefaultConfiguration',
106 'getLocalConfigurationValueByPath',
107 'setLocalConfigurationValueByPath',
108 )
109 );
110 $this->configurationManager->expects($this->exactly(1))
111 ->method('getDefaultConfiguration')
112 ->will($this->returnValue($defaultConfiguration));
113 $this->configurationManager->expects($this->exactly(1))
114 ->method('getLocalConfigurationValueByPath')
115 ->will($this->returnValueMap($currentLocalConfiguration));
116 $this->configurationManager->expects($this->once())
117 ->method('setLocalConfigurationValueByPath')
118 ->with($this->equalTo('EXT/extConf/saltedpasswords'), $this->equalTo($newConfig));
119
120 $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class);
121
122 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
123
124 $silentConfigurationUpgradeServiceInstance->_call('configureSaltedPasswords');
125 }
126
127 /**
128 * @test
129 */
130 public function configureSaltedPasswordsWithExtensionConfigurationBeNotEnabled() {
131 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
132 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
133 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
134 array('dummy'),
135 array(),
136 '',
137 FALSE
138 );
139 $config = 'a:2:{s:3:"BE.";a:1:{s:15:"onlyAuthService";i:0;}s:3:"FE.";a:2:{s:7:"enabled";i:0;s:11:"forceSalted";i:0;}}';
140 $defaultConfiguration = array();
141 $defaultConfiguration['EXT']['extConf']['saltedpasswords'] = $config;
142
143 $currentLocalConfiguration = array(
144 array('EXT/extConf/saltedpasswords', 'a:2:{s:3:"BE.";a:2:{s:7:"enabled";i:0;s:12:"updatePasswd";i:1;}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}')
145 );
146 $newConfig = 'a:2:{s:3:"BE.";a:1:{s:15:"onlyAuthService";i:0;}s:3:"FE.";a:1:{s:7:"enabled";i:0;}}';
147 $this->createConfigurationManagerWithMockedMethods(
148 array(
149 'getDefaultConfiguration',
150 'getLocalConfigurationValueByPath',
151 'setLocalConfigurationValueByPath',
152 )
153 );
154 $this->configurationManager->expects($this->exactly(1))
155 ->method('getDefaultConfiguration')
156 ->will($this->returnValue($defaultConfiguration));
157 $this->configurationManager->expects($this->exactly(1))
158 ->method('getLocalConfigurationValueByPath')
159 ->will($this->returnValueMap($currentLocalConfiguration));
160 $this->configurationManager->expects($this->once())
161 ->method('setLocalConfigurationValueByPath')
162 ->with($this->equalTo('EXT/extConf/saltedpasswords'), $this->equalTo($newConfig));
163
164 $this->setExpectedException(\TYPO3\CMS\Install\Controller\Exception\RedirectException::class);
165
166 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
167
168 $silentConfigurationUpgradeServiceInstance->_call('configureSaltedPasswords');
169 }
170
171 /**
172 * Dataprovider for transferDeprecatedCurlSettings
173 *
174 * @return array
175 */
176 public function curlProxySettingsToHttpSettingsMapping() {
177 return array(
178 array('http://proxy:3128/', 'proxy', '3128'),
179 array('http://proxy:3128', 'proxy', '3128'),
180 array('proxy:3128', 'proxy', '3128'),
181 array('https://proxy:3128/', 'proxy', '3128'),
182 );
183 }
184
185 /**
186 * @test
187 * @dataProvider curlProxySettingsToHttpSettingsMapping
188 */
189 public function transferDeprecatedCurlSettings($curlProxyServer, $proxyHost, $proxyPort) {
190 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
191 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
192 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
193 array('dummy'),
194 array(),
195 '',
196 FALSE
197 );
198
199 $currentLocalConfiguration = array(
200 array('SYS/curlProxyServer', $curlProxyServer),
201 array('HTTP/proxy_host', ''),
202 array('SYS/curlProxyUserPass', ''),
203 array('HTTP/proxy_user', ''),
204 array('SYS/curlUse', FALSE)
205 );
206 $this->createConfigurationManagerWithMockedMethods(
207 array(
208 'getLocalConfigurationValueByPath',
209 'setLocalConfigurationValueByPath',
210 'getConfigurationValueByPath'
211 )
212 );
213 $this->configurationManager->expects($this->exactly(5))
214 ->method('getLocalConfigurationValueByPath')
215 ->will($this->returnValueMap($currentLocalConfiguration));
216 $this->configurationManager->expects($this->exactly(2))
217 ->method('setLocalConfigurationValueByPath')
218 ->withConsecutive(
219 array('HTTP/proxy_host', $proxyHost),
220 array('HTTP/proxy_port', $proxyPort)
221 );
222
223 $this->setExpectedException('\TYPO3\CMS\Install\Controller\Exception\RedirectException');
224
225 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
226
227 $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
228 }
229
230 /**
231 * @test
232 */
233 public function curlProxyServerDoesNotOverwriteHttpSettings() {
234 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
235 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
236 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
237 array('dummy'),
238 array(),
239 '',
240 FALSE
241 );
242
243 $currentLocalConfiguration = array(
244 array('SYS/curlProxyServer', 'http://proxyOld:3128/'),
245 array('SYS/curlProxyUserPass', 'userOld:passOld'),
246 array('HTTP/proxy_host', 'proxyNew'),
247 array('HTTP/proxy_port', '3128'),
248 array('HTTP/proxy_user', 'userNew'),
249 array('HTTP/proxy_pass', 'passNew'),
250 array('SYS/curlUse', FALSE)
251 );
252 $this->createConfigurationManagerWithMockedMethods(
253 array(
254 'getLocalConfigurationValueByPath',
255 'setLocalConfigurationValueByPath',
256 'getConfigurationValueByPath'
257 )
258 );
259 $this->configurationManager->expects($this->exactly(5))
260 ->method('getLocalConfigurationValueByPath')
261 ->will($this->returnValueMap($currentLocalConfiguration));
262 $this->configurationManager->expects($this->never())
263 ->method('setLocalConfigurationValueByPath');
264
265 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
266
267 $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
268 }
269
270 /**
271 * @test
272 */
273 public function curlAdapterUsedIfCurlUse() {
274 /** @var $silentConfigurationUpgradeServiceInstance \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
275 $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
276 \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService::class,
277 array('dummy'),
278 array(),
279 '',
280 FALSE
281 );
282
283 $currentLocalConfiguration = array(
284 array('SYS/curlProxyServer', ''),
285 array('SYS/curlProxyUserPass', ''),
286 array('HTTP/proxy_host', 'proxyNew'),
287 array('HTTP/proxy_user', 'userNew'),
288 array('SYS/curlUse', TRUE)
289 );
290 $this->createConfigurationManagerWithMockedMethods(
291 array(
292 'getLocalConfigurationValueByPath',
293 'getConfigurationValueByPath',
294 'setLocalConfigurationValueByPath',
295 )
296 );
297 $this->configurationManager->expects($this->exactly(5))
298 ->method('getLocalConfigurationValueByPath')
299 ->will($this->returnValueMap($currentLocalConfiguration));
300 $this->configurationManager->expects($this->once())
301 ->method('setLocalConfigurationValueByPath')
302 ->withConsecutive(
303 array('HTTP/adapter', 'curl')
304 );
305
306 $this->setExpectedException('\TYPO3\CMS\Install\Controller\Exception\RedirectException');
307
308 $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
309
310 $silentConfigurationUpgradeServiceInstance->_call('transferDeprecatedCurlSettings');
311 }
312
313 }