TYPO3 CMS  TYPO3_6-2
HashServiceTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $hashService;
26 
27  public function setUp() {
28  $this->hashService = new \TYPO3\CMS\Extbase\Security\Cryptography\HashService();
29  $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'Testing';
30  }
31 
37  $hash = $this->hashService->generateHmac('asdf');
38  $this->assertTrue(is_string($hash));
39  }
40 
46  $hash = $this->hashService->generateHmac('asdf');
47  $this->assertNotEquals(sha1('asdf'), $hash);
48  }
49 
55  $hash1 = $this->hashService->generateHmac('asdf');
56  $hash2 = $this->hashService->generateHmac('blubb');
57  $this->assertNotEquals($hash1, $hash2);
58  }
59 
66  $hash = $this->hashService->generateHmac(NULL);
67  }
68 
74  $string = 'asdf';
75  $hash = $this->hashService->generateHmac($string);
76  $this->assertTrue($this->hashService->validateHmac($string, $hash));
77  }
78 
84  $string = 'asdf';
85  $hash = 'myhash';
86  $this->assertFalse($this->hashService->validateHmac($string, $hash));
87  }
88 
94  $this->hashService->appendHmac(NULL);
95  }
96 
101  $string = 'This is some arbitrary string ';
102  $hashedString = $this->hashService->appendHmac($string);
103  $this->assertSame($string, substr($hashedString, 0, -40));
104  }
105 
111  $this->hashService->validateAndStripHmac(NULL);
112  }
113 
119  $this->hashService->validateAndStripHmac('string with less than 40 characters');
120  }
121 
127  $this->hashService->validateAndStripHmac('string with exactly a length 40 of chars');
128  }
129 
135  $this->hashService->validateAndStripHmac('some Stringac43682075d36592d4cb320e69ff0aa515886eab');
136  }
137 
142  $string = ' Some arbitrary string with special characters: öäüß!"§$ ';
143  $hashedString = $this->hashService->appendHmac($string);
144  $actualResult = $this->hashService->validateAndStripHmac($hashedString);
145  $this->assertSame($string, $actualResult);
146  }
147 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]