Completed
Push — master ( 178a08...5c0b6f )
by Oleg
05:22
created

GenerateTmpTokenCest::createTmpTokenNotPermitted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
use Codeception\Util\HttpCode;
5
use SlayerBirden\DataFlowServer\Authorization\Entities\Permission;
6
use SlayerBirden\DataFlowServer\Domain\Entities\User;
7
8
class GenerateTmpTokenCest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * @var int
12
     */
13
    private $userId;
14
15
    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...
16
    {
17
        $this->userId = $I->haveInRepository(User::class, [
18
            'first' => 'Tester2',
19
            'last' => 'Tester2',
20
            'email' => '[email protected]',
21
        ]);
22
23
        $user = $I->grabEntityFromRepository(User::class, ['id' => $this->userId]);
24
        $resources = [
25
            'create_password',
26
            'get_tmp_token',
27
        ];
28
        foreach ($resources as $key => $resource) {
29
            $I->haveInRepository(Permission::class, [
30
                'id' => ++$key,
31
                'user' => $user,
32
                'resource' => $resource,
33
            ]);
34
        }
35
    }
36
37
    /**
38
     * @param ApiTester $I
39
     * @throws Exception
40
     */
41
    public function createTmpTokenSuccess(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('create tmp token');
44
        $I->haveHttpHeader('Content-Type', 'application/json');
45
        $I->sendPOST('/gettmptoken/' . (string)$this->userId, [
46
            'resources' => [
47
                'create_password'
48
            ],
49
        ]);
50
        $I->seeResponseCodeIs(HttpCode::OK);
51
        $I->seeResponseContainsJson([
52
            'success' => true,
53
            'data' => [
54
                'token' => [
55
                    'owner' => [
56
                        'email' => '[email protected]',
57
                    ],
58
                    'active' => 1,
59
                ],
60
            ],
61
        ]);
62
    }
63
64
    /**
65
     * @param ApiTester $I
66
     * @throws Exception
67
     */
68
    public function createTmpTokenForNonExistingUser(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...
69
    {
70
        $I->wantTo('create tmp token for non existing user');
71
        $I->haveHttpHeader('Content-Type', 'application/json');
72
        $I->sendPOST('/gettmptoken/' . (string)($this->userId + 100), [
73
            'resources' => [
74
                'create_password'
75
            ],
76
        ]);
77
        $I->seeResponseCodeIs(HttpCode::NOT_FOUND);
78
        $I->seeResponseContainsJson([
79
            'success' => false,
80
        ]);
81
    }
82
83
    /**
84
     * @param ApiTester $I
85
     * @throws Exception
86
     */
87
    public function createTmpTokenNotPermitted(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...
88
    {
89
        $I->wantTo('create tmp token for resource without granted permission');
90
        $I->haveHttpHeader('Content-Type', 'application/json');
91
        $I->sendPOST('/gettmptoken/' . (string)$this->userId, [
92
            'resources' => [
93
                'update_password'
94
            ],
95
        ]);
96
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
97
        $I->seeResponseContainsJson([
98
            'success' => false,
99
        ]);
100
    }
101
102
    /**
103
     * @param ApiTester $I
104
     * @throws Exception
105
     */
106
    public function createTmpTokenValidationError(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...
107
    {
108
        $I->wantTo('create tmp token wrong input');
109
        $I->haveHttpHeader('Content-Type', 'application/json');
110
        $I->sendPOST('/gettmptoken/' . (string)$this->userId, [
111
            'bar' => 'baz',
112
        ]);
113
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
114
        $I->seeResponseContainsJson([
115
            'success' => false,
116
            'data' => [
117
                'validation' => [
118
                    [
119
                        'field' => 'resources'
120
                    ]
121
                ]
122
            ]
123
        ]);
124
    }
125
126
    /**
127
     * @param ApiTester $I
128
     * @throws Exception
129
     */
130
    public function createTmpTokenValidationErrorNonExistingResource(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...
131
    {
132
        $I->wantTo('create tmp token for non existing resource');
133
        $I->haveHttpHeader('Content-Type', 'application/json');
134
        $I->sendPOST('/gettmptoken/' . (string)$this->userId, [
135
            'resources' => [
136
                'bar'
137
            ],
138
        ]);
139
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
140
        $I->seeResponseContainsJson([
141
            'success' => false,
142
        ]);
143
    }
144
}
145