2022-01-18 17:39:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-01-27 09:30:00 +01:00
|
|
|
namespace App\Test\TestCase\Api\AuthKeys;
|
2022-01-18 17:39:41 +01:00
|
|
|
|
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
use App\Test\Fixture\AuthKeysFixture;
|
|
|
|
use App\Test\Fixture\UsersFixture;
|
|
|
|
use App\Test\Helper\ApiTestTrait;
|
|
|
|
|
|
|
|
class AddAuthKeyApiTest extends TestCase
|
|
|
|
{
|
|
|
|
use ApiTestTrait;
|
|
|
|
|
2022-01-19 16:22:44 +01:00
|
|
|
protected const ENDPOINT = '/authKeys/add';
|
2022-01-18 17:39:41 +01:00
|
|
|
|
|
|
|
protected $fixtures = [
|
|
|
|
'app.Organisations',
|
|
|
|
'app.Individuals',
|
|
|
|
'app.Roles',
|
|
|
|
'app.Users',
|
|
|
|
'app.AuthKeys'
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testAddAdminAuthKey(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
|
|
|
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$uuid = $faker->uuid;
|
|
|
|
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'authkey' => $faker->sha1,
|
|
|
|
'expiration' => 0,
|
|
|
|
'user_id' => UsersFixture::USER_ADMIN_ID,
|
|
|
|
'comment' => $faker->text
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseOk();
|
|
|
|
$this->assertResponseContains(sprintf('"uuid": "%s"', $uuid));
|
|
|
|
$this->assertDbRecordExists('AuthKeys', ['uuid' => $uuid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddAdminAuthKeyNotAllowedAsRegularUser(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
|
|
|
|
|
|
|
$faker = \Faker\Factory::create();
|
|
|
|
$uuid = $faker->uuid;
|
|
|
|
|
|
|
|
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'authkey' => $faker->sha1,
|
|
|
|
'expiration' => 0,
|
|
|
|
'user_id' => UsersFixture::USER_ADMIN_ID,
|
|
|
|
'comment' => $faker->text
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2022-02-20 14:48:29 +01:00
|
|
|
$this->assertResponseCode(405);
|
2022-01-18 17:39:41 +01:00
|
|
|
$this->assertDbRecordNotExists('AuthKeys', ['uuid' => $uuid]);
|
|
|
|
}
|
|
|
|
}
|