|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace KochTest\Security; |
|
4
|
|
|
|
|
5
|
|
|
use Koch\Security\Security; |
|
6
|
|
|
|
|
7
|
|
|
class SecurityTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function setUp() |
|
10
|
|
|
{ |
|
11
|
|
|
parent::setUp(); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* testMethodgenerate_salt(). |
|
16
|
|
|
*/ |
|
17
|
|
|
public function testMethodgenerateSalt() |
|
18
|
|
|
{ |
|
19
|
|
|
// generate a salt with length |
|
20
|
|
|
$salt = Security::generateSalt(12); |
|
21
|
|
|
|
|
22
|
|
|
// ensure $salt is a string |
|
23
|
|
|
$this->assertTrue(is_string($salt), true); |
|
24
|
|
|
|
|
25
|
|
|
// ensure $salt has correct length |
|
26
|
|
|
$this->assertEquals(strlen($salt), 12); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testMethodgenerateHash() |
|
30
|
|
|
{ |
|
31
|
|
|
$hash_md5 = \Koch\Security\Security::generateHash('md5', 'admin'); |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
$this->assertSame('21232f297a57a5a743894a0e4a801fc3', $hash_md5); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$hash_sha1 = \Koch\Security\Security::generateHash('sha1', 'admin'); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$this->assertSame('d033e22ae348aeb5660fc2140aec35850c4da997', $hash_sha1); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testMethodbuildSaltedHash() |
|
41
|
|
|
{ |
|
42
|
|
|
$salted_hash = \Koch\Security\Security::buildSaltedHash('admin', 'md5'); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$this->assertTrue(is_array($salted_hash), true); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testMethodcheckSaltedHash() |
|
48
|
|
|
{ |
|
49
|
|
|
// md5('admin'); from form input |
|
50
|
|
|
$passwordhash = '21232f297a57a5a743894a0e4a801fc3'; |
|
51
|
|
|
// expected, from db |
|
52
|
|
|
$databasehash = '7ff3adfa18a8ad7f115e90ce2c44a0ec'; |
|
53
|
|
|
// from db |
|
54
|
|
|
$salt = 'Sko5ie'; |
|
55
|
|
|
$hash_algorithm = 'md5'; |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$bool = \Koch\Security\Security::checkSaltedHash($passwordhash, $databasehash, $salt, $hash_algorithm); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$this->assertTrue($bool, true); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.