Completed
Push — master ( 630401...3eb757 )
by Oleg
02:43
created

InvalidateTokensCest::invalidateTokesWrongUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
rs 9.7
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace codecept;
5
6
use Codeception\Util\HttpCode;
7
use SlayerBirden\DataFlowServer\Authentication\Entities\Grant;
8
use SlayerBirden\DataFlowServer\Authentication\Entities\Token;
9
use SlayerBirden\DataFlowServer\Domain\Entities\User;
10
11
class InvalidateTokensCest
12
{
13
    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...
14
    {
15
        $userId = $I->haveInRepository(User::class, [
16
            'first' => 'Tester2',
17
            'last' => 'Tester2',
18
            'email' => '[email protected]',
19
        ]);
20
21
        $user = $I->grabEntityFromRepository(User::class, ['id' => $userId]);
22
23
        $tokenId = $I->haveInRepository(Token::class, [
24
            'owner' => $user,
25
            'active' => true,
26
            'token' => 'yyy',
27
            'due' => new \DateTime('+1 year'),
28
            'createdAt' => new \DateTime(),
29
        ]);
30
31
        $token = $I->grabEntityFromRepository(Token::class, ['id' => $tokenId]);
32
33
        $I->haveInRepository(Grant::class, [
34
            'token' => $token,
35
            'resource' => 'invalidate_tokens',
36
        ]);
37
38
        $I->amBearerAuthenticated('yyy');
39
    }
40
41
    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...
42
    {
43
        $I->wantTo('invalidate other user\'s token');
44
45
        $I->haveHttpHeader('Content-Type', 'application/json');
46
        $I->sendPost('/invalidatetokens', [
47
            'users' => [1]
48
        ]);
49
        $I->seeResponseCodeIs(HttpCode::OK);
50
        $I->seeResponseContainsJson([
51
            'success' => true,
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
            'success' => true,
75
            'data' => [
76
                'count' => 2
77
            ],
78
        ]);
79
    }
80
81
    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...
82
    {
83
        $I->wantTo('invalidate wrong user\'s token');
84
85
        $I->haveHttpHeader('Content-Type', 'application/json');
86
        $I->sendPost('/invalidatetokens', [
87
            'users' => [10]
88
        ]);
89
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
90
        $I->seeResponseContainsJson([
91
            'success' => false,
92
            'data' => [
93
                'tokens' => [],
94
                'count' => 0
95
            ],
96
        ]);
97
    }
98
}
99