PBKDF2Test::testEncrypt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace CWP\Core\Tests\PasswordEncryptor;
4
5
use CWP\Core\PasswordEncryptor\PBKDF2;
6
use League\Flysystem\Exception;
7
use SilverStripe\Dev\SapphireTest;
8
9
class PBKDF2Test extends SapphireTest
10
{
11
    public function testGetIterations()
12
    {
13
        $encryptor = new PBKDF2('sha512', 12345);
14
        $this->assertSame(12345, $encryptor->getIterations());
15
    }
16
17
    public function testEncrypt()
18
    {
19
        $encryptor = new PBKDF2('sha512', 10000);
20
        $salt = 'predictablesaltforunittesting';
21
        $result = $encryptor->encrypt('opensesame', $salt);
22
        $this->assertSame(
23
            '6bafcacb90',
24
            substr($result, 0, 10),
25
            'Hashed password with predictable salt did not match fixtured expectation'
26
        );
27
    }
28
29
    /**
30
     * @expectedException Exception
31
     * @expectedExceptionMessage Hash algorithm "foobar" not found
32
     */
33
    public function testThrowsExceptionWhenInvalidAlgorithmIsProvided()
34
    {
35
        new PBKDF2('foobar');
36
    }
37
}
38