524 lines
24 KiB
PHP
524 lines
24 KiB
PHP
<?php
|
|
|
|
namespace Functional;
|
|
|
|
use App\Entity\BootServer;
|
|
use App\Entity\DhcpServer;
|
|
use App\Entity\OrganizationalUnit;
|
|
use App\Factory\ClientFactory;
|
|
use App\Factory\CommandFactory;
|
|
use App\Factory\ImageRepositoryFactory;
|
|
use App\Factory\OrganizationalUnitFactory;
|
|
use App\Factory\UserFactory;
|
|
use App\Model\OrganizationalUnitTypes;
|
|
use App\Model\UserGroupPermissions;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Verifica que cada rol sólo puede realizar las operaciones permitidas.
|
|
*
|
|
* Cubre la matriz de permisos definida en permisos_opengnsys.xlsx:
|
|
* - Clientes : solo super-admin / ou-admin pueden crear
|
|
* - OUs : solo super-admin / ou-admin pueden crear;
|
|
* ou-admin solo puede borrar sus propias OUs
|
|
* - DHCP Servers : solo super-admin puede escribir
|
|
* - Boot Servers : solo super-admin puede escribir
|
|
* - Image Repos : solo super-admin puede escribir
|
|
* - Commands : solo super-admin puede crear/editar/borrar
|
|
*/
|
|
class PermissionsTest extends AbstractTest
|
|
{
|
|
// Nombres de usuario de prueba (únicos por test, se resetea la BD entre tests)
|
|
private const SA_USER = 'perm-super-admin';
|
|
private const OA_USER = 'perm-ou-admin';
|
|
private const OP_USER = 'perm-ou-operator';
|
|
private const OM_USER = 'perm-ou-minimal';
|
|
|
|
// ── Helpers ───────────────────────────────────────────────────────────────
|
|
|
|
/** Crea un usuario con el rol indicado y devuelve su JWT. */
|
|
private function tokenFor(string $username, string $role): string
|
|
{
|
|
UserFactory::createOne(['username' => $username, 'roles' => [$role]]);
|
|
return $this->getToken([
|
|
'username' => $username,
|
|
'password' => UserFactory::PLAIN_PASSWORD,
|
|
]);
|
|
}
|
|
|
|
/** Cliente HTTP autenticado con el token dado. */
|
|
private function as(string $token): \ApiPlatform\Symfony\Bundle\Test\Client
|
|
{
|
|
return $this->createClientWithCredentials($token);
|
|
}
|
|
|
|
/** Crea un DhcpServer directamente en BD y devuelve su IRI. */
|
|
private function createDhcpServerIri(string $ip = '192.0.2.10', string $name = 'dhcp-test'): string
|
|
{
|
|
$em = static::getContainer()->get('doctrine')->getManager();
|
|
$server = new DhcpServer();
|
|
$server->setIp($ip);
|
|
$server->setName($name);
|
|
$em->persist($server);
|
|
$em->flush();
|
|
return '/dhcp-servers/' . $server->getUuid();
|
|
}
|
|
|
|
/** Crea un BootServer directamente en BD y devuelve su IRI. */
|
|
private function createBootServerIri(string $name = 'boot-test', string $ip = '192.0.2.11'): string
|
|
{
|
|
$em = static::getContainer()->get('doctrine')->getManager();
|
|
$server = new BootServer();
|
|
$server->setName($name);
|
|
$server->setIp($ip);
|
|
$em->persist($server);
|
|
$em->flush();
|
|
return '/boot-servers/' . $server->getUuid();
|
|
}
|
|
|
|
/**
|
|
* Crea una OU directamente en BD con un createdBy específico
|
|
* y opcionalmente la asigna al usuario indicado (para que el filtro
|
|
* de OUs no devuelva 404 cuando intenten borrarla).
|
|
*/
|
|
private function createOuOwnedBy(
|
|
string $createdByUsername,
|
|
string $ouName = 'test-ou',
|
|
?\App\Entity\User $assignToUser = null
|
|
): string {
|
|
$em = static::getContainer()->get('doctrine')->getManager();
|
|
|
|
$ou = new OrganizationalUnit();
|
|
$ou->setName($ouName);
|
|
$ou->setType(OrganizationalUnitTypes::CLASSROOM);
|
|
$ou->setCreatedBy($createdByUsername);
|
|
$em->persist($ou);
|
|
|
|
if ($assignToUser !== null) {
|
|
$assignToUser->addAllowedOrganizationalUnit($ou);
|
|
$em->persist($assignToUser);
|
|
}
|
|
|
|
$em->flush();
|
|
return '/organizational-units/' . $ou->getUuid();
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 1 — CLIENTES: creación
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Super-admin puede crear un cliente (POST → 201). */
|
|
public function testSuperAdminCanCreateClient(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$ouFactory = OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::CLASSROOM]);
|
|
$ouIri = $this->findIriBy(OrganizationalUnit::class, ['name' => $ouFactory->getName()]);
|
|
|
|
$this->as($token)->request('POST', '/clients', ['json' => [
|
|
'name' => 'client-by-super-admin',
|
|
'organizationalUnit' => $ouIri,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
|
}
|
|
|
|
/** OU-admin puede crear un cliente (POST → 201). */
|
|
public function testOuAdminCanCreateClient(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
|
|
// Crear la OU como super-admin y asignarla al ou-admin
|
|
$saToken = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$this->as($saToken)->request('POST', '/organizational-units', ['json' => [
|
|
'name' => 'aula-for-client-test',
|
|
'type' => OrganizationalUnitTypes::CLASSROOM,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(201);
|
|
$ouIri = $this->findIriBy(OrganizationalUnit::class, ['name' => 'aula-for-client-test']);
|
|
|
|
// Asignar la OU al ou-admin directamente en BD
|
|
$em = static::getContainer()->get('doctrine')->getManager();
|
|
$user = $em->getRepository(\App\Entity\User::class)->findOneBy(['username' => self::OA_USER]);
|
|
$ou = $em->getRepository(OrganizationalUnit::class)->findOneBy(['name' => 'aula-for-client-test']);
|
|
$user->addAllowedOrganizationalUnit($ou);
|
|
$em->flush();
|
|
|
|
$this->as($token)->request('POST', '/clients', ['json' => [
|
|
'name' => 'client-by-ou-admin',
|
|
'organizationalUnit' => $ouIri,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
|
}
|
|
|
|
/** OU-operator NO puede crear un cliente (POST → 403). */
|
|
public function testOuOperatorCannotCreateClient(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
|
|
$this->as($token)->request('POST', '/clients', ['json' => [
|
|
'name' => 'forbidden-client',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-minimal NO puede crear un cliente (POST → 403). */
|
|
public function testOuMinimalCannotCreateClient(): void
|
|
{
|
|
$token = $this->tokenFor(self::OM_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_MINIMAL);
|
|
|
|
$this->as($token)->request('POST', '/clients', ['json' => [
|
|
'name' => 'forbidden-client-minimal',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 2 — OUs: creación
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Super-admin puede crear una OU (POST → 201). */
|
|
public function testSuperAdminCanCreateOrganizationalUnit(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$this->as($token)->request('POST', '/organizational-units', ['json' => [
|
|
'name' => 'ou-by-super-admin',
|
|
'type' => OrganizationalUnitTypes::CLASSROOM,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
|
}
|
|
|
|
/** OU-admin puede crear una OU (POST → 201). */
|
|
public function testOuAdminCanCreateOrganizationalUnit(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$this->as($token)->request('POST', '/organizational-units', ['json' => [
|
|
'name' => 'ou-by-ou-admin',
|
|
'type' => OrganizationalUnitTypes::CLASSROOM,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
|
}
|
|
|
|
/** OU-operator NO puede crear una OU (POST → 403). */
|
|
public function testOuOperatorCannotCreateOrganizationalUnit(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$this->as($token)->request('POST', '/organizational-units', ['json' => [
|
|
'name' => 'forbidden-ou',
|
|
'type' => OrganizationalUnitTypes::CLASSROOM,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-minimal NO puede crear una OU (POST → 403). */
|
|
public function testOuMinimalCannotCreateOrganizationalUnit(): void
|
|
{
|
|
$token = $this->tokenFor(self::OM_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_MINIMAL);
|
|
$this->as($token)->request('POST', '/organizational-units', ['json' => [
|
|
'name' => 'forbidden-ou-minimal',
|
|
'type' => OrganizationalUnitTypes::CLASSROOM,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 3 — OUs: borrado con control de autoría
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/**
|
|
* OU-admin puede borrar una OU que él mismo creó.
|
|
* Flujo: POST (crea la OU con createdBy=username) → DELETE → 204.
|
|
*/
|
|
public function testOuAdminCanDeleteOwnOrganizationalUnit(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$client = $this->as($token);
|
|
|
|
// Crear la OU como ou-admin (Gedmo establece createdBy automáticamente)
|
|
$response = $client->request('POST', '/organizational-units', ['json' => [
|
|
'name' => 'ou-to-delete-by-owner',
|
|
'type' => OrganizationalUnitTypes::CLASSROOM,
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(201);
|
|
$iri = $response->toArray()['@id'];
|
|
|
|
// Borrarla → 204
|
|
$client->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT);
|
|
}
|
|
|
|
/**
|
|
* OU-admin NO puede borrar una OU creada por otro usuario.
|
|
* Se crea la OU directamente en BD con createdBy='otro-usuario' y se asigna
|
|
* al ou-admin en allowedOrganizationalUnits para que el filtro no devuelva 404.
|
|
*/
|
|
public function testOuAdminCannotDeleteOtherUsersOrganizationalUnit(): void
|
|
{
|
|
// Crear el ou-admin
|
|
UserFactory::createOne([
|
|
'username' => self::OA_USER,
|
|
'roles' => [UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN],
|
|
]);
|
|
$token = $this->getToken(['username' => self::OA_USER, 'password' => UserFactory::PLAIN_PASSWORD]);
|
|
|
|
// Recuperar la entidad User recién creada para poder asignarle la OU
|
|
$em = static::getContainer()->get('doctrine')->getManager();
|
|
$user = $em->getRepository(\App\Entity\User::class)->findOneBy(['username' => self::OA_USER]);
|
|
|
|
// Crear una OU con createdBy='otro-admin' y asignarla al ou-admin
|
|
$iri = $this->createOuOwnedBy('otro-admin', 'ou-owned-by-other', $user);
|
|
|
|
// Intento de borrado → 403
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/**
|
|
* Super-admin puede borrar cualquier OU, independientemente de quién la creó.
|
|
*/
|
|
public function testSuperAdminCanDeleteAnyOrganizationalUnit(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
|
|
// OU creada por 'otro-usuario', no el super-admin
|
|
$iri = $this->createOuOwnedBy('otro-usuario', 'ou-to-delete-by-sa');
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT);
|
|
}
|
|
|
|
/**
|
|
* OU-operator NO puede borrar ninguna OU (no las crea → createdBy nunca coincide).
|
|
*/
|
|
public function testOuOperatorCannotDeleteOrganizationalUnit(): void
|
|
{
|
|
UserFactory::createOne([
|
|
'username' => self::OP_USER,
|
|
'roles' => [UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR],
|
|
]);
|
|
$token = $this->getToken(['username' => self::OP_USER, 'password' => UserFactory::PLAIN_PASSWORD]);
|
|
|
|
$em = static::getContainer()->get('doctrine')->getManager();
|
|
$user = $em->getRepository(\App\Entity\User::class)->findOneBy(['username' => self::OP_USER]);
|
|
|
|
// OU creada por 'otro-admin' y visible para el operador
|
|
$iri = $this->createOuOwnedBy('otro-admin', 'ou-op-cannot-delete', $user);
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 4 — DHCP SERVERS
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Super-admin puede hacer PATCH en un DhcpServer (→ 200). */
|
|
public function testSuperAdminCanPatchDhcpServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$iri = $this->createDhcpServerIri('192.0.2.20', 'dhcp-sa-test');
|
|
|
|
$this->as($token)->request('PATCH', $iri, ['json' => ['name' => 'dhcp-updated']]);
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
|
|
/** OU-admin NO puede hacer PATCH en un DhcpServer (→ 403). */
|
|
public function testOuAdminCannotPatchDhcpServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$iri = $this->createDhcpServerIri('192.0.2.21', 'dhcp-oa-test');
|
|
|
|
$this->as($token)->request('PATCH', $iri, ['json' => ['name' => 'dhcp-forbidden']]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-operator NO puede hacer PATCH en un DhcpServer (→ 403). */
|
|
public function testOuOperatorCannotPatchDhcpServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$iri = $this->createDhcpServerIri('192.0.2.22', 'dhcp-op-test');
|
|
|
|
$this->as($token)->request('PATCH', $iri, ['json' => ['name' => 'dhcp-forbidden']]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-admin NO puede borrar un DhcpServer (→ 403). */
|
|
public function testOuAdminCannotDeleteDhcpServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$iri = $this->createDhcpServerIri('192.0.2.23', 'dhcp-oa-del-test');
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-operator NO puede borrar un DhcpServer (→ 403). */
|
|
public function testOuOperatorCannotDeleteDhcpServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$iri = $this->createDhcpServerIri('192.0.2.24', 'dhcp-op-del-test');
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 5 — BOOT SERVERS
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Super-admin puede hacer PATCH en un BootServer (→ 200). */
|
|
public function testSuperAdminCanPatchBootServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$iri = $this->createBootServerIri('boot-sa-test', '192.0.2.30');
|
|
|
|
$this->as($token)->request('PATCH', $iri, ['json' => ['name' => 'boot-updated']]);
|
|
$this->assertResponseIsSuccessful();
|
|
}
|
|
|
|
/** OU-admin NO puede hacer PATCH en un BootServer (→ 403). */
|
|
public function testOuAdminCannotPatchBootServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$iri = $this->createBootServerIri('boot-oa-test', '192.0.2.31');
|
|
|
|
$this->as($token)->request('PATCH', $iri, ['json' => ['name' => 'boot-forbidden']]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-operator NO puede hacer PATCH en un BootServer (→ 403). */
|
|
public function testOuOperatorCannotPatchBootServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$iri = $this->createBootServerIri('boot-op-test', '192.0.2.32');
|
|
|
|
$this->as($token)->request('PATCH', $iri, ['json' => ['name' => 'boot-forbidden']]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-admin NO puede borrar un BootServer (→ 403). */
|
|
public function testOuAdminCannotDeleteBootServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$iri = $this->createBootServerIri('boot-oa-del', '192.0.2.33');
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-operator NO puede borrar un BootServer (→ 403). */
|
|
public function testOuOperatorCannotDeleteBootServer(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$iri = $this->createBootServerIri('boot-op-del', '192.0.2.34');
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 6 — IMAGE REPOSITORIES
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Super-admin puede crear un Image Repository (POST → 201). */
|
|
public function testSuperAdminCanCreateImageRepository(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$this->as($token)->request('POST', '/image-repositories', ['json' => [
|
|
'name' => 'repo-by-super-admin',
|
|
'ip' => '192.0.2.40',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
|
}
|
|
|
|
/** OU-admin NO puede crear un Image Repository (POST → 403). */
|
|
public function testOuAdminCannotCreateImageRepository(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$this->as($token)->request('POST', '/image-repositories', ['json' => [
|
|
'name' => 'repo-forbidden',
|
|
'ip' => '192.0.2.41',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-operator NO puede crear un Image Repository (POST → 403). */
|
|
public function testOuOperatorCannotCreateImageRepository(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$this->as($token)->request('POST', '/image-repositories', ['json' => [
|
|
'name' => 'repo-forbidden-op',
|
|
'ip' => '192.0.2.42',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-admin NO puede borrar un Image Repository (DELETE → 403). */
|
|
public function testOuAdminCannotDeleteImageRepository(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$repo = ImageRepositoryFactory::createOne();
|
|
$iri = $this->findIriBy(\App\Entity\ImageRepository::class, ['name' => $repo->getName()]);
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// SECCIÓN 7 — COMMANDS
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** Super-admin puede crear un Command (POST → 201). */
|
|
public function testSuperAdminCanCreateCommand(): void
|
|
{
|
|
$token = $this->tokenFor(self::SA_USER, UserGroupPermissions::ROLE_SUPER_ADMIN);
|
|
$this->as($token)->request('POST', '/commands', ['json' => [
|
|
'name' => 'cmd-by-super-admin',
|
|
'script' => 'echo test',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
|
}
|
|
|
|
/** OU-admin NO puede crear un Command (POST → 403). */
|
|
public function testOuAdminCannotCreateCommand(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$this->as($token)->request('POST', '/commands', ['json' => [
|
|
'name' => 'cmd-forbidden',
|
|
'script' => 'echo test',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-operator NO puede crear un Command (POST → 403). */
|
|
public function testOuOperatorCannotCreateCommand(): void
|
|
{
|
|
$token = $this->tokenFor(self::OP_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_OPERATOR);
|
|
$this->as($token)->request('POST', '/commands', ['json' => [
|
|
'name' => 'cmd-forbidden-op',
|
|
'script' => 'echo test',
|
|
]]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-admin NO puede borrar un Command (DELETE → 403). */
|
|
public function testOuAdminCannotDeleteCommand(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$command = CommandFactory::createOne();
|
|
$iri = $this->findIriBy(\App\Entity\Command::class, ['name' => $command->getName()]);
|
|
|
|
$this->as($token)->request('DELETE', $iri);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
/** OU-admin NO puede editar un Command (PUT → 403). */
|
|
public function testOuAdminCannotEditCommand(): void
|
|
{
|
|
$token = $this->tokenFor(self::OA_USER, UserGroupPermissions::ROLE_ORGANIZATIONAL_UNIT_ADMIN);
|
|
$command = CommandFactory::createOne();
|
|
$iri = $this->findIriBy(\App\Entity\Command::class, ['name' => $command->getName()]);
|
|
|
|
$this->as($token)->request('PUT', $iri, ['json' => ['name' => 'forbidden-edit']]);
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
|
}
|
|
}
|