SlayerBirden /
dataflow-server
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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\Authorization\Entities\Permission; |
||
| 9 | use SlayerBirden\DataFlowServer\Domain\Entities\User; |
||
| 10 | |||
| 11 | class GenerateTmpTokenCest |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var int |
||
| 15 | */ |
||
| 16 | private $userId; |
||
| 17 | |||
| 18 | public function _before(ApiTester $I) |
||
|
0 ignored issues
–
show
|
|||
| 19 | { |
||
| 20 | $this->userId = $I->haveInRepository(User::class, [ |
||
| 21 | 'first' => 'Tester2', |
||
| 22 | 'last' => 'Tester2', |
||
| 23 | 'email' => '[email protected]', |
||
| 24 | ]); |
||
| 25 | |||
| 26 | $user = $I->grabEntityFromRepository(User::class, ['id' => $this->userId]); |
||
| 27 | $resources = [ |
||
| 28 | 'create_password', |
||
| 29 | 'get_tmp_token', |
||
| 30 | ]; |
||
| 31 | foreach ($resources as $key => $resource) { |
||
| 32 | $I->haveInRepository(Permission::class, [ |
||
| 33 | 'id' => ++$key, |
||
| 34 | 'user' => $user, |
||
| 35 | 'resource' => $resource, |
||
| 36 | ]); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param ApiTester $I |
||
| 42 | * @throws \Exception |
||
| 43 | */ |
||
| 44 | public function createTmpTokenSuccess(ApiTester $I) |
||
|
0 ignored issues
–
show
|
|||
| 45 | { |
||
| 46 | $I->wantTo('create tmp token'); |
||
| 47 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
| 48 | $I->sendPOST('/gettmptoken/' . (string)$this->userId, [ |
||
| 49 | 'resources' => [ |
||
| 50 | 'create_password' |
||
| 51 | ], |
||
| 52 | ]); |
||
| 53 | $I->seeResponseCodeIs(HttpCode::OK); |
||
| 54 | $I->seeResponseContainsJson([ |
||
| 55 | 'data' => [ |
||
| 56 | 'token' => [ |
||
| 57 | 'owner' => [ |
||
| 58 | 'email' => '[email protected]', |
||
| 59 | ], |
||
| 60 | 'active' => 1, |
||
| 61 | ], |
||
| 62 | ], |
||
| 63 | ]); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param ApiTester $I |
||
| 68 | * @throws \Exception |
||
| 69 | */ |
||
| 70 | public function createTmpTokenForNonExistingUser(ApiTester $I) |
||
|
0 ignored issues
–
show
|
|||
| 71 | { |
||
| 72 | $I->wantTo('create tmp token for non existing user'); |
||
| 73 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
| 74 | $I->sendPOST('/gettmptoken/' . (string)($this->userId + 100), [ |
||
| 75 | 'resources' => [ |
||
| 76 | 'create_password' |
||
| 77 | ], |
||
| 78 | ]); |
||
| 79 | $I->seeResponseCodeIs(HttpCode::NOT_FOUND); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param ApiTester $I |
||
| 84 | * @throws \Exception |
||
| 85 | */ |
||
| 86 | public function createTmpTokenNotPermitted(ApiTester $I) |
||
|
0 ignored issues
–
show
|
|||
| 87 | { |
||
| 88 | $I->wantTo('create tmp token for resource without granted permission'); |
||
| 89 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
| 90 | $I->sendPOST('/gettmptoken/' . (string)$this->userId, [ |
||
| 91 | 'resources' => [ |
||
| 92 | 'update_password' |
||
| 93 | ], |
||
| 94 | ]); |
||
| 95 | $I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param ApiTester $I |
||
| 100 | * @throws \Exception |
||
| 101 | */ |
||
| 102 | public function createTmpTokenValidationError(ApiTester $I) |
||
|
0 ignored issues
–
show
|
|||
| 103 | { |
||
| 104 | $I->wantTo('create tmp token wrong input'); |
||
| 105 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
| 106 | $I->sendPOST('/gettmptoken/' . (string)$this->userId, [ |
||
| 107 | 'bar' => 'baz', |
||
| 108 | ]); |
||
| 109 | $I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
||
| 110 | $I->seeResponseContainsJson([ |
||
| 111 | 'data' => [ |
||
| 112 | 'validation' => [ |
||
| 113 | [ |
||
| 114 | 'field' => 'resources' |
||
| 115 | ] |
||
| 116 | ] |
||
| 117 | ] |
||
| 118 | ]); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param ApiTester $I |
||
| 123 | * @throws \Exception |
||
| 124 | */ |
||
| 125 | public function createTmpTokenValidationErrorNonExistingResource(ApiTester $I) |
||
|
0 ignored issues
–
show
|
|||
| 126 | { |
||
| 127 | $I->wantTo('create tmp token for non existing resource'); |
||
| 128 | $I->haveHttpHeader('Content-Type', 'application/json'); |
||
| 129 | $I->sendPOST('/gettmptoken/' . (string)$this->userId, [ |
||
| 130 | 'resources' => [ |
||
| 131 | 'bar' |
||
| 132 | ], |
||
| 133 | ]); |
||
| 134 | $I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
||
| 135 | } |
||
| 136 | } |
||
| 137 |
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.