Completed
Push — master ( 3eb757...3bc7c8 )
by Oleg
03:46
created

InvalidateTokenCest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 83
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 27 1
A invalidateTokenSuccess() 0 19 1
A invalidateTokenNoPermissions() 0 12 1
A invalidateTokenCanNotFindToken() 0 14 1
1
<?php
2
declare(strict_types=1);
3
4
namespace codecept\authentication;
5
6
use codecept\ApiTester;
7
use Codeception\Util\HttpCode;
8
use SlayerBirden\DataFlowServer\Authentication\Entities\Grant;
9
use SlayerBirden\DataFlowServer\Authentication\Entities\Token;
10
use SlayerBirden\DataFlowServer\Domain\Entities\User;
11
12
class InvalidateTokenCest
13
{
14
    /**
15
     * @var int
16
     */
17
    private $tokenId;
18
19
    public function _before(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
20
    {
21
        $userId = $I->haveInRepository(User::class, [
22
            'first' => 'Tester2',
23
            'last' => 'Tester2',
24
            'email' => '[email protected]',
25
        ]);
26
27
        $user = $I->grabEntityFromRepository(User::class, ['id' => $userId]);
28
29
        $this->tokenId = $I->haveInRepository(Token::class, [
30
            'owner' => $user,
31
            'active' => true,
32
            'token' => 'yyy',
33
            'due' => new \DateTime('+1 year'),
34
            'createdAt' => new \DateTime(),
35
        ]);
36
37
        $token = $I->grabEntityFromRepository(Token::class, ['id' => $this->tokenId]);
38
39
        $I->haveInRepository(Grant::class, [
40
            'token' => $token,
41
            'resource' => 'invalidate_token',
42
        ]);
43
44
        $I->amBearerAuthenticated('yyy');
45
    }
46
47
    public function invalidateTokenSuccess(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
48
    {
49
        $I->wantTo('invalidate my token');
50
51
        $I->haveHttpHeader('Content-Type', 'application/json');
52
        $I->sendPut('/invalidatetoken/' . (string)$this->tokenId);
53
        $I->seeResponseCodeIs(HttpCode::OK);
54
        $I->seeResponseContainsJson([
55
            'success' => true,
56
            'data' => [
57
                'token' => [
58
                    'owner' => [
59
                        'email' => '[email protected]',
60
                    ],
61
                    'active' => 0,
62
                ],
63
            ],
64
        ]);
65
    }
66
67
    public function invalidateTokenNoPermissions(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
68
    {
69
        $I->wantTo('invalidate someone elses token');
70
71
        $I->haveHttpHeader('Content-Type', 'application/json');
72
        $I->sendPut('/invalidatetoken/1');
73
        $I->seeResponseCodeIs(HttpCode::FORBIDDEN);
74
        $I->seeResponseContainsJson([
75
            'success' => false,
76
            'data' => [],
77
        ]);
78
    }
79
80
    public function invalidateTokenCanNotFindToken(ApiTester $I)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $I. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
81
    {
82
        $I->wantTo('invalidate token that doesn\'t exist');
83
84
        $I->haveHttpHeader('Content-Type', 'application/json');
85
        $I->sendPut('/invalidatetoken/100');
86
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
87
        $I->seeResponseContainsJson([
88
            'success' => false,
89
            'data' => [
90
                'token' => null,
91
            ],
92
        ]);
93
    }
94
}
95