SecurityTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 55
rs 10
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testMethodgenerateSalt() 0 11 1
A testMethodgenerateHash() 0 10 1
A testMethodbuildSaltedHash() 0 6 1
A testMethodcheckSaltedHash() 0 14 1
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');
0 ignored issues
show
Coding Style introduced by
$hash_md5 does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
32
33
        $this->assertSame('21232f297a57a5a743894a0e4a801fc3', $hash_md5);
0 ignored issues
show
Coding Style introduced by
$hash_md5 does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
34
35
        $hash_sha1 = \Koch\Security\Security::generateHash('sha1', 'admin');
0 ignored issues
show
Coding Style introduced by
$hash_sha1 does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
36
37
        $this->assertSame('d033e22ae348aeb5660fc2140aec35850c4da997', $hash_sha1);
0 ignored issues
show
Coding Style introduced by
$hash_sha1 does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
38
    }
39
40
    public function testMethodbuildSaltedHash()
41
    {
42
        $salted_hash = \Koch\Security\Security::buildSaltedHash('admin', 'md5');
0 ignored issues
show
Coding Style introduced by
$salted_hash does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
43
44
        $this->assertTrue(is_array($salted_hash), true);
0 ignored issues
show
Coding Style introduced by
$salted_hash does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
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';
0 ignored issues
show
Coding Style introduced by
$hash_algorithm does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
56
57
        $bool = \Koch\Security\Security::checkSaltedHash($passwordhash, $databasehash, $salt, $hash_algorithm);
0 ignored issues
show
Coding Style introduced by
$hash_algorithm does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

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.

Loading history...
58
59
        $this->assertTrue($bool, true);
60
    }
61
}
62