20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
35 'Simple Case - Empty' => [
39 'Simple Case - Single Value' => [
43 'Simple Case - Two Values' => [
51 [
'field1',
'field[subfield1]',
'field[subfield2]'],
60 'recursion with duplicated field name' => [
61 [
'field1',
'field[subfield1]',
'field[subfield2]',
'field1'],
70 'Recursion with un-named fields at the end (...[]). There, they should be made explicit by increasing the counter' => [
71 [
'field1',
'field[subfield1][]',
'field[subfield1][]',
'field[subfield2]'],
95 'Overriding form fields (string overridden by array) - 1' => [
96 [
'field1',
'field2',
'field2[bla]',
'field2[blubb]'],
99 'Overriding form fields (string overridden by array) - 2' => [
100 [
'field1',
'field2[bla]',
'field2[bla][blubb][blubb]'],
103 'Overriding form fields (array overridden by string) - 1' => [
104 [
'field1',
'field2[bla]',
'field2[blubb]',
'field2'],
107 'Overriding form fields (array overridden by string) - 2' => [
108 [
'field1',
'field2[bla][blubb][blubb]',
'field2[bla]'],
111 'Empty [] not as last argument' => [
112 [
'field1',
'field2[][bla]'],
125 $requestHashService = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class)
126 ->setMethods([
'serializeAndHashFormFieldArray'])
128 $requestHashService->expects($this->once())->method(
'serializeAndHashFormFieldArray')->with($expected);
129 $requestHashService->generateTrustedPropertiesToken($input);
140 $this->expectException(InvalidArgumentForHashGenerationException::class);
141 $this->expectExceptionCode($expectExceptionCode);
142 $requestHashService = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class)
143 ->setMethods([
'serializeAndHashFormFieldArray'])
145 $requestHashService->generateTrustedPropertiesToken($input);
161 $hashService = $this->getMockBuilder($this->buildAccessibleProxy(\
TYPO3\CMS\
Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class))
162 ->setMethods([
'appendHmac'])
164 $hashService->expects($this->once())->method(
'appendHmac')->with(serialize($formFieldArray))->will($this->returnValue(serialize($formFieldArray) . $mockHash));
166 $requestHashService = $this->getMockBuilder($this->buildAccessibleProxy(\
TYPO3\CMS\
Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class))
167 ->setMethods([
'dummy'])
169 $requestHashService->_set(
'hashService', $hashService);
171 $expected = serialize($formFieldArray) . $mockHash;
172 $actual = $requestHashService->_call(
'serializeAndHashFormFieldArray', $formFieldArray);
173 $this->assertEquals($expected, $actual);
181 $request = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Mvc\Request::class)->setMethods([
'getInternalArgument'])->disableOriginalConstructor()->getMock();
182 $request->expects($this->any())->method(
'getInternalArgument')->with(
'__trustedProperties')->will($this->returnValue(
null));
183 $arguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
185 $requestHashService = new \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService;
186 $requestHashService->initializePropertyMappingConfigurationFromRequest($request, $arguments);
194 $this->expectException(BadRequestException::class);
195 $this->expectExceptionCode(1581862822);
197 $request = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Mvc\Request::class)->setMethods([
'getInternalArgument'])->disableOriginalConstructor()->getMock();
198 $request->expects(self::any())->method(
'getInternalArgument')->with(
'__trustedProperties')->willReturn(
'string with less than 40 characters');
199 $arguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
201 $hashService = new \TYPO3\CMS\Extbase\Security\Cryptography\HashService();
204 $requestHashService->initializePropertyMappingConfigurationFromRequest($request, $arguments);
212 $trustedProperties = [
223 $trustedProperties = [
224 'nonExistingArgument' => 1
227 $this->assertFalse($arguments->hasArgument(
'nonExistingArgument'));
235 $trustedProperties = [
244 $propertyMappingConfiguration = $arguments->getArgument(
'foo')->getPropertyMappingConfiguration();
245 $this->assertTrue($propertyMappingConfiguration->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED),
'ConfigurationValue is not CONFIGURATION_MODIFICATION_ALLOWED at line ' . __LINE__);
246 $this->assertNull($propertyMappingConfiguration->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED),
'ConfigurationValue is not NULL at line ' . __LINE__);
247 $this->assertFalse($propertyMappingConfiguration->shouldMap(
'someProperty'),
'Value is not FALSE at line ' . __LINE__);
249 $this->assertTrue($propertyMappingConfiguration->forProperty(
'nested')->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED),
'ConfigurationValue is not CONFIGURATION_MODIFICATION_ALLOWED at line ' . __LINE__);
250 $this->assertNull($propertyMappingConfiguration->forProperty(
'nested')->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED),
'ConfigurationValue is not NULL at line ' . __LINE__);
251 $this->assertFalse($propertyMappingConfiguration->forProperty(
'nested')->shouldMap(
'someProperty'),
'Value is not FALSE at line ' . __LINE__);
259 $trustedProperties = [
265 $propertyMappingConfiguration = $arguments->getArgument(
'foo')->getPropertyMappingConfiguration();
266 $this->assertNull($propertyMappingConfiguration->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));
267 $this->assertTrue($propertyMappingConfiguration->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED));
268 $this->assertFalse($propertyMappingConfiguration->shouldMap(
'someProperty'));
270 $this->assertNull($propertyMappingConfiguration->forProperty(
'bar')->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));
271 $this->assertTrue($propertyMappingConfiguration->forProperty(
'bar')->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED));
272 $this->assertFalse($propertyMappingConfiguration->forProperty(
'bar')->shouldMap(
'someProperty'));
280 $trustedProperties = [
286 $propertyMappingConfiguration = $arguments->getArgument(
'foo')->getPropertyMappingConfiguration();
287 $this->assertFalse($propertyMappingConfiguration->shouldMap(
'someProperty'));
288 $this->assertTrue($propertyMappingConfiguration->shouldMap(
'bar'));
296 $trustedProperties = [
304 $propertyMappingConfiguration = $arguments->getArgument(
'foo')->getPropertyMappingConfiguration();
305 $this->assertFalse($propertyMappingConfiguration->shouldMap(
'someProperty'));
306 $this->assertTrue($propertyMappingConfiguration->shouldMap(
'bar'));
307 $this->assertTrue($propertyMappingConfiguration->forProperty(
'bar')->shouldMap(
'foo'));
319 $request = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Mvc\Request::class)->setMethods([
'getInternalArgument'])->disableOriginalConstructor()->getMock();
320 $request->expects($this->any())->method(
'getInternalArgument')->with(
'__trustedProperties')->will($this->returnValue(
'fooTrustedProperties'));
322 $mockHashService = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Security\Cryptography\HashService::class)
323 ->setMethods([
'validateAndStripHmac'])
325 $mockHashService->expects($this->once())->method(
'validateAndStripHmac')->with(
'fooTrustedProperties')->will($this->returnValue(serialize($trustedProperties)));
327 $requestHashService = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService::class, [
'dummy']);
328 $requestHashService->_set(
'hashService', $mockHashService);
330 $mockObjectManager = $this->createMock(\
TYPO3\CMS\
Extbase\Object\ObjectManagerInterface::class);
331 $mockArgument = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\Argument::class, [
'getName'], [],
'',
false);
333 $propertyMappingConfiguration = new \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfiguration();
335 $mockArgument->_set(
'propertyMappingConfiguration', $propertyMappingConfiguration);
336 $mockArgument->expects($this->any())->method(
'getName')->will($this->returnValue(
'foo'));
337 $mockObjectManager->expects($this->once())->method(
'get')->with(\
TYPO3\CMS\
Extbase\Mvc\Controller\Argument::class)->will($this->returnValue($mockArgument));
339 $arguments = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\Arguments::class, [
'dummy']);
340 $arguments->_set(
'objectManager', $mockObjectManager);
341 $arguments->addNewArgument(
'foo');
343 $requestHashService->initializePropertyMappingConfigurationFromRequest($request, $arguments);