|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Sebastian Kurfürst <sebastian@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Testcase for the Hash Service 00027 * 00028 * @version $Id: HashService_testcase.php 1729 2009-11-25 21:37:20Z stucki $ 00029 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser Public License, version 3 or later 00030 */ 00031 class Tx_Extbase_Tests_Unit_Security_Cryptography_HashServiceTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00032 00033 protected $hashService; 00034 00035 public function setUp() { 00036 $this->hashService = new Tx_Extbase_Security_Cryptography_HashService(); 00037 } 00038 00039 /** 00040 * @test 00041 * @author Sebastian Kurfürst 00042 */ 00043 public function generateHashReturnsHashStringIfStringIsGiven() { 00044 $hash = $this->hashService->generateHash('asdf'); 00045 $this->assertTrue(is_string($hash)); 00046 } 00047 00048 /** 00049 * @test 00050 * @author Sebastian Kurfürst 00051 */ 00052 public function generateHashReturnsHashStringWhichContainsSomeSalt() { 00053 $hash = $this->hashService->generateHash('asdf'); 00054 $this->assertNotEquals(sha1('asdf'), $hash); 00055 } 00056 00057 /** 00058 * @test 00059 * @author Sebastian Kurfürst 00060 */ 00061 public function generateHashReturnsDifferentHashStringsForDifferentInputStrings() { 00062 $hash1 = $this->hashService->generateHash('asdf'); 00063 $hash2 = $this->hashService->generateHash('blubb'); 00064 $this->assertNotEquals($hash1, $hash2); 00065 } 00066 00067 /** 00068 * @test 00069 * @expectedException Tx_Extbase_Security_Exception_InvalidArgumentForHashGeneration 00070 * @author Sebastian Kurfürst 00071 */ 00072 public function generateHashThrowsExceptionIfNoStringGiven() { 00073 $hash = $this->hashService->generateHash(NULL); 00074 } 00075 00076 /** 00077 * @test 00078 * @author Sebastian Kurfürst <sebastian@typo3.org> 00079 */ 00080 public function generatedHashCanBeValidatedAgain() { 00081 $string = 'asdf'; 00082 $hash = $this->hashService->generateHash($string); 00083 $this->assertTrue($this->hashService->validateHash($string, $hash)); 00084 } 00085 00086 /** 00087 * @test 00088 * @author Sebastian Kurfürst <sebastian@typo3.org> 00089 */ 00090 public function generatedHashWillNotBeValidatedIfHashHasBeenChanged() { 00091 $string = 'asdf'; 00092 $hash = 'myhash'; 00093 $this->assertFalse($this->hashService->validateHash($string, $hash)); 00094 } 00095 } 00096 ?>
1.8.0