Raised DBAL version from 1.1.5 to 1.1.6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Security / Cryptography / HashService_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Sebastian Kurfürst <sebastian@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the Hash Service
27 *
28 * @version $Id: HashService_testcase.php 1729 2009-11-25 21:37:20Z stucki $
29 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser Public License, version 3 or later
30 */
31 class Tx_Extbase_Security_Cryptography_HashService_testcase extends Tx_Extbase_BaseTestCase {
32
33 protected $hashService;
34
35 public function setUp() {
36 $this->hashService = new Tx_Extbase_Security_Cryptography_HashService();
37 }
38
39 /**
40 * @test
41 * @author Sebastian Kurfürst
42 */
43 public function generateHashReturnsHashStringIfStringIsGiven() {
44 $hash = $this->hashService->generateHash('asdf');
45 $this->assertTrue(is_string($hash));
46 }
47
48 /**
49 * @test
50 * @author Sebastian Kurfürst
51 */
52 public function generateHashReturnsHashStringWhichContainsSomeSalt() {
53 $hash = $this->hashService->generateHash('asdf');
54 $this->assertNotEquals(sha1('asdf'), $hash);
55 }
56
57 /**
58 * @test
59 * @author Sebastian Kurfürst
60 */
61 public function generateHashReturnsDifferentHashStringsForDifferentInputStrings() {
62 $hash1 = $this->hashService->generateHash('asdf');
63 $hash2 = $this->hashService->generateHash('blubb');
64 $this->assertNotEquals($hash1, $hash2);
65 }
66
67 /**
68 * @test
69 * @expectedException Tx_Extbase_Security_Exception_InvalidArgumentForHashGeneration
70 * @author Sebastian Kurfürst
71 */
72 public function generateHashThrowsExceptionIfNoStringGiven() {
73 $hash = $this->hashService->generateHash(NULL);
74 }
75
76 /**
77 * @test
78 * @author Sebastian Kurfürst <sebastian@typo3.org>
79 */
80 public function generatedHashCanBeValidatedAgain() {
81 $string = 'asdf';
82 $hash = $this->hashService->generateHash($string);
83 $this->assertTrue($this->hashService->validateHash($string, $hash));
84 }
85
86 /**
87 * @test
88 * @author Sebastian Kurfürst <sebastian@typo3.org>
89 */
90 public function generatedHashWillNotBeValidatedIfHashHasBeenChanged() {
91 $string = 'asdf';
92 $hash = 'myhash';
93 $this->assertFalse($this->hashService->validateHash($string, $hash));
94 }
95 }
96 ?>