GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RS256Test::testCanVerifySignatureOfGivenData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Gandung\JWT\Tests\Algorithm\RSA;
4
5
use PHPUnit\Framework\TestCase;
6
use Gandung\JWT\Algorithm\RSA\RS256;
7
use Gandung\JWT\Manager\KeyManager;
8
use Gandung\JWT\Tests\Exception\ConstantFromExternalModuleNotFoundException;
9
10
/**
11
 * @author Paulus Gandung Prakosa <[email protected]>
12
 */
13
class RS256Test extends TestCase
14
{
15
    public function testIfConstantValueExistsFromOpensslDependency()
16
    {
17
        if (!defined('OPENSSL_ALGO_SHA256') ||
18
            !defined('OPENSSL_ALGO_SHA384') ||
19
            !defined('OPENSSL_ALGO_SHA512')) {
20
            throw new ConstantFromExternalModuleNotFoundException(
21
                "Install 'openssl' module first."
22
            );
23
        }
24
25
        $this->assertTrue(true);
26
    }
27
28
    public function testCanGetInstance()
29
    {
30
        $this->assertInstanceOf(RS256::class, new RS256());
31
    }
32
33
    public function testCanSignGivenData()
34
    {
35
        $key = new KeyManager;
36
        $key->setContentFromCertFile('cert/dummy256.pem');
37
        $key->setPassphrase('umar123');
38
        $rs256 = new RS256;
39
        $signature = $rs256->sign('this is a text.', $key);
40
        $this->assertInternalType('string', $signature);
41
        $this->assertNotEmpty($signature);
42
    }
43
44
    /**
45
     * @expectedException \RuntimeException
46
     */
47
    public function testCanRaiseExceptionWhenSignDataWithBadKey()
48
    {
49
        $key = new KeyManager;
50
        $key->setContentFromCertFile('cert/dummy256.pem');
51
        $rs256 = new RS256;
52
        $signature = $rs256->sign('this is a text.', $key);
0 ignored issues
show
Unused Code introduced by
$signature is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53
    }
54
55
    public function testCanVerifySignatureOfGivenData()
56
    {
57
        $key = new KeyManager;
58
        $key->setContentFromCertFile('cert/dummy256.pem');
59
        $key->setPassphrase('umar123');
60
        $rs256 = new RS256;
61
        $signature = $rs256->sign('this is a text.', $key);
62
        $this->assertInternalType('string', $signature);
63
        $this->assertNotEmpty($signature);
64
        $isSignatureMatched = $rs256->verify($signature, 'this is a text.', $key);
65
        $this->assertInternalType('boolean', $isSignatureMatched);
66
        $this->assertTrue($isSignatureMatched);
67
    }
68
69
    /**
70
     * @expectedException \RuntimeException
71
     */
72
    public function testCanRaiseExceptionWhenVerifySignatureOfGivenDataWithBadKey()
73
    {
74
        $key = new KeyManager;
75
        $key->setContentFromCertFile('cert/dummy256.pem');
76
        $key->setPassphrase('umar123');
77
        $rs256 = new RS256;
78
        $signature = $rs256->sign('this is a text.', $key);
79
        $this->assertInternalType('string', $signature);
80
        $this->assertNotEmpty($signature);
81
        $key->setPassphrase(null);
82
        $isSignatureMatched = $rs256->verify($signature, 'this is a text.', $key);
0 ignored issues
show
Unused Code introduced by
$isSignatureMatched is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
83
    }
84
85
    public function testCanGetAlgorithmAlias()
86
    {
87
        $rs256 = new RS256;
88
        $this->assertEquals(\Gandung\JWT\Token\Algorithm::RS256, $rs256->getAlgorithmAlias());
89
    }
90
}
91