TYPO3 CMS  TYPO3_6-2
InstallToolFormProtectionTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $fixture;
28 
32  public function setUp() {
33  $this->fixture = $this->getAccessibleMock(
34  'TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection',
35  array('dummy')
36  );
37  }
38 
40  // Tests concerning the reading and saving of the tokens
42 
47  $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
48  $formName = 'foo';
49  $action = 'edit';
50  $formInstanceName = '42';
51 
52  $tokenId = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
53 
54  $_SESSION['installToolFormToken'] = $sessionToken;
55 
56  $this->fixture->_call('retrieveSessionToken');
57 
58  $this->assertTrue(
59  $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
60  );
61  }
62 
67  $_SESSION['installToolFormToken'] = 'foo';
68 
69  $this->fixture->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
70 
71  $this->fixture->persistSessionToken();
72 
73  $this->assertEquals(
74  '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
75  $_SESSION['installToolFormToken']
76  );
77  }
78 
79 
81  // Tests concerning createValidationErrorMessage
83 
89  $installTool = $this->getMock(
90  'stdClass', array('addErrorMessage'), array(), '', FALSE
91  );
92  $installTool->expects($this->once())->method('addErrorMessage')
93  ->with(
94  'Validating the security token of this form has failed. ' .
95  'Please reload the form and submit it again.'
96  );
97  $this->fixture->injectInstallTool($installTool);
98 
99  $this->fixture->_call('createValidationErrorMessage');
100  }
101 }
static hmac($input, $additionalSecret='')
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)