InvalidateTokensCest::invalidateTokensSuccess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 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 InvalidateTokensCest
13
{
14
    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...
15
    {
16
        $userId = $I->haveInRepository(User::class, [
17
            'first' => 'Tester2',
18
            'last' => 'Tester2',
19
            'email' => '[email protected]',
20
        ]);
21
22
        $user = $I->grabEntityFromRepository(User::class, ['id' => $userId]);
23
24
        $tokenId = $I->haveInRepository(Token::class, [
25
            'owner' => $user,
26
            'active' => true,
27
            'token' => 'yyy',
28
            'due' => new \DateTime('+1 year'),
29
            'createdAt' => new \DateTime(),
30
        ]);
31
32
        $token = $I->grabEntityFromRepository(Token::class, ['id' => $tokenId]);
33
34
        $I->haveInRepository(Grant::class, [
35
            'token' => $token,
36
            'resource' => 'invalidate_tokens',
37
        ]);
38
39
        $I->amBearerAuthenticated('yyy');
40
    }
41
42
    public function invalidateTokensSuccess(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...
43
    {
44
        $I->wantTo('invalidate other user\'s token');
45
46
        $I->haveHttpHeader('Content-Type', 'application/json');
47
        $I->sendPost('/invalidatetokens', [
48
            'users' => [1]
49
        ]);
50
        $I->seeResponseCodeIs(HttpCode::OK);
51
        $I->seeResponseContainsJson([
52
            'data' => [
53
                'tokens' => [
54
                    [
55
                        'owner' => [
56
                            'email' => '[email protected]',
57
                        ],
58
                        'active' => 0,
59
                    ]
60
                ],
61
                'count' => 1
62
            ],
63
        ]);
64
    }
65
66
    public function invalidateAllTokensSuccess(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...
67
    {
68
        $I->wantTo('invalidate all tokens');
69
70
        $I->haveHttpHeader('Content-Type', 'application/json');
71
        $I->sendPost('/invalidatetokens');
72
        $I->seeResponseCodeIs(HttpCode::OK);
73
        $I->seeResponseContainsJson([
74
            'data' => [
75
                'count' => 2
76
            ],
77
        ]);
78
    }
79
80
    public function invalidateTokesWrongUsers(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 wrong user\'s token');
83
84
        $I->haveHttpHeader('Content-Type', 'application/json');
85
        $I->sendPost('/invalidatetokens', [
86
            'users' => [10]
87
        ]);
88
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
89
        $I->seeResponseContainsJson([
90
            'data' => [
91
                'tokens' => [],
92
                'count' => 0
93
            ],
94
        ]);
95
    }
96
}
97