1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Hash;
13:
14: use PHPassLib\Hash\Portable;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class PortableTest extends \PHPUnit_Framework_TestCase
25: {
26:
27: 28: 29: 30: 31:
32: public function validTestVectorProvider()
33: {
34: $vectors = array (
35:
36: array ("test1", '$H$9aaaaaSXBjgypwqm.JsMssPLiS8YQ00'),
37: array ("123456", '$H$9PE8jEklgZhgLmZl5.HYJAzfGCQtzi1'),
38: array ("123456", '$H$9pdx7dbOW3Nnt32sikrjAxYFjX8XoK1'),
39: array ("thisisalongertestPW", '$P$912345678LIjjb6PhecupozNBmDndU0'),
40: array ("JohnRipper", '$P$612345678si5M0DDyPpmRCmcltU/YW/'),
41: array ("JohnRipper", '$H$712345678WhEyvy1YWzT4647jzeOmo0'),
42: array ("JohnRipper", '$P$B12345678L6Lpt4BxNotVIMILOa9u81'),
43: );
44:
45: return $vectors;
46: }
47:
48: 49: 50: 51: 52:
53: public function invalidTestVectorProvider()
54: {
55: $vectors = array (
56: array ("", '*0', '*1'),
57: array ("", '*1', '*0'),
58: );
59:
60: return $vectors;
61: }
62:
63: 64: 65: 66: 67: 68: 69: 70:
71: public function validTestVectorsProduceExpectedResults($password, $hash)
72: {
73: $config = substr($hash, 0, 12);
74: $this->assertEquals($hash, Portable::hash($password, $config));
75: $this->assertTrue(Portable::verify($password, $hash));
76: }
77:
78: 79: 80: 81: 82: 83: 84: 85:
86: public function invalidTestVectorsProduceExpectedResults($password, $hash, $errorString)
87: {
88: $config = substr($hash, 0, 12);
89: $this->assertEquals($errorString, Portable::hash($password, $config));
90: $this->assertFalse(Portable::verify($password, $hash));
91: }
92:
93: 94: 95:
96: public function genconfigAndParseconfigProduceMatchingResults()
97: {
98: $options = array (
99: 'ident' => 'H',
100: 'rounds' => 15,
101: 'salt' => 'CCCCCCC.',
102: );
103: $config = Portable::genConfig($options);
104:
105: $this->assertEquals('$H$DCCCCCCC.', $config, $config);
106: $this->assertSame($options, Portable::parseConfig($config));
107: }
108:
109: }
110: