Completed
Push — master ( 19902b...129fa7 )
by Anton
03:10
created

CredentialsSha256Test::testInvalidCredentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
class CredentialsSha256Test extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function invalidTokens() {
6
        return array(
7
            array(null, null),
8
            array("12345678901234567890123456789012", null),
9
            array(null, "12345678901234567890123456789012"),
10
            array("12345678901234567890123456789012", "12345"),
11
            array("12345", "12345678901234567890123456789012"),
12
        );
13
    }
14
15
    /**
16
     * @dataProvider invalidTokens
17
     * @expectedException \InvalidArgumentException
18
     */
19
    public function testInvalidCredentials($token, $secret)
20
    {
21
        new \Covery\Client\Credentials\Sha256($token, $secret);
22
    }
23
24
    public function testSign()
25
    {
26
        $maker = new \Covery\Client\Credentials\Sha256(
27
            '12345678901234567890123456789012',
28
            'asjdh283ysfjhbkjKHGV^7ra/adf2145'
29
        );
30
31
        $req = new \GuzzleHttp\Psr7\Request('POST', 'http://localhost/foo', [], "Hello, world");
32
        $signed = $maker->signRequest($req);
33
34
        self::assertNotSame($req, $signed);
35
        self::assertEquals($req->getMethod(), $signed->getMethod());
36
        self::assertEquals($req->getUri(), $signed->getUri());
37
        self::assertEquals($req->getBody()->getContents(), $signed->getBody()->getContents());
38
        self::assertFalse($req->hasHeader('X-Auth-Token'));
39
        self::assertFalse($req->hasHeader('X-Auth-Signature'));
40
        self::assertFalse($req->hasHeader('X-Auth-Nonce'));
41
        self::assertTrue($signed->hasHeader('X-Auth-Token'));
42
        self::assertTrue($signed->hasHeader('X-Auth-Signature'));
43
        self::assertTrue($signed->hasHeader('X-Auth-Nonce'));
44
45
        self::assertEquals(
46
            hash('sha256', $signed->getHeaderLine('X-Auth-Nonce') . 'Hello, world' .  'asjdh283ysfjhbkjKHGV^7ra/adf2145'),
47
            $signed->getHeaderLine('X-Auth-Signature')
48
        );
49
    }
50
}