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

invalidateTokenCanNotFindToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
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 InvalidateTokenCest
12
{
13
    /**
14
     * @var int
15
     */
16
    private $tokenId;
17
18
    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...
19
    {
20
        $userId = $I->haveInRepository(User::class, [
21
            'first' => 'Tester2',
22
            'last' => 'Tester2',
23
            'email' => '[email protected]',
24
        ]);
25
26
        $user = $I->grabEntityFromRepository(User::class, ['id' => $userId]);
27
28
        $this->tokenId = $I->haveInRepository(Token::class, [
29
            'owner' => $user,
30
            'active' => true,
31
            'token' => 'yyy',
32
            'due' => new \DateTime('+1 year'),
33
            'createdAt' => new \DateTime(),
34
        ]);
35
36
        $token = $I->grabEntityFromRepository(Token::class, ['id' => $this->tokenId]);
37
38
        $I->haveInRepository(Grant::class, [
39
            'token' => $token,
40
            'resource' => 'invalidate_token',
41
        ]);
42
43
        $I->amBearerAuthenticated('yyy');
44
    }
45
46
    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...
47
    {
48
        $I->wantTo('invalidate my token');
49
50
        $I->haveHttpHeader('Content-Type', 'application/json');
51
        $I->sendPut('/invalidatetoken/' . (string)$this->tokenId);
52
        $I->seeResponseCodeIs(HttpCode::OK);
53
        $I->seeResponseContainsJson([
54
            'success' => true,
55
            'data' => [
56
                'token' => [
57
                    'owner' => [
58
                        'email' => '[email protected]',
59
                    ],
60
                    'active' => 0,
61
                ],
62
            ],
63
        ]);
64
    }
65
66
    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...
67
    {
68
        $I->wantTo('invalidate someone elses token');
69
70
        $I->haveHttpHeader('Content-Type', 'application/json');
71
        $I->sendPut('/invalidatetoken/1');
72
        $I->seeResponseCodeIs(HttpCode::FORBIDDEN);
73
        $I->seeResponseContainsJson([
74
            'success' => false,
75
            'data' => [],
76
        ]);
77
    }
78
79
    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...
80
    {
81
        $I->wantTo('invalidate token that doesn\'t exist');
82
83
        $I->haveHttpHeader('Content-Type', 'application/json');
84
        $I->sendPut('/invalidatetoken/100');
85
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
86
        $I->seeResponseContainsJson([
87
            'success' => false,
88
            'data' => [
89
                'token' => null,
90
            ],
91
        ]);
92
    }
93
}
94