TYPO3 CMS  TYPO3_7-6
HashServiceTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
25  protected $hashService;
26 
27  protected function setUp()
28  {
29  $this->hashService = new \TYPO3\CMS\Extbase\Security\Cryptography\HashService();
30  $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'Testing';
31  }
32 
37  {
38  $hash = $this->hashService->generateHmac('asdf');
39  $this->assertTrue(is_string($hash));
40  }
41 
46  {
47  $hash = $this->hashService->generateHmac('asdf');
48  $this->assertNotEquals(sha1('asdf'), $hash);
49  }
50 
55  {
56  $hash1 = $this->hashService->generateHmac('asdf');
57  $hash2 = $this->hashService->generateHmac('blubb');
58  $this->assertNotEquals($hash1, $hash2);
59  }
60 
66  {
67  $hash = $this->hashService->generateHmac(null);
68  }
69 
74  {
75  $string = 'asdf';
76  $hash = $this->hashService->generateHmac($string);
77  $this->assertTrue($this->hashService->validateHmac($string, $hash));
78  }
79 
84  {
85  $string = 'asdf';
86  $hash = 'myhash';
87  $this->assertFalse($this->hashService->validateHmac($string, $hash));
88  }
89 
95  {
96  $this->hashService->appendHmac(null);
97  }
98 
103  {
104  $string = 'This is some arbitrary string ';
105  $hashedString = $this->hashService->appendHmac($string);
106  $this->assertSame($string, substr($hashedString, 0, -40));
107  }
108 
114  {
115  $this->hashService->validateAndStripHmac(null);
116  }
117 
123  {
124  $this->hashService->validateAndStripHmac('string with less than 40 characters');
125  }
126 
132  {
133  $this->hashService->validateAndStripHmac('string with exactly a length 40 of chars');
134  }
135 
141  {
142  $this->hashService->validateAndStripHmac('some Stringac43682075d36592d4cb320e69ff0aa515886eab');
143  }
144 
149  {
150  $string = ' Some arbitrary string with special characters: öäüß!"§$ ';
151  $hashedString = $this->hashService->appendHmac($string);
152  $actualResult = $this->hashService->validateAndStripHmac($hashedString);
153  $this->assertSame($string, $actualResult);
154  }
155 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']