mirror of https://github.com/MISP/MISP
add: more tests, fix bugs
parent
1b0d05b3bb
commit
ce28fcc54f
|
@ -66,9 +66,9 @@ class SharingGroupsController extends AppController
|
|||
if (empty($sg['roaming']) && empty($sg['SharingGroupServer'])) {
|
||||
$sharingGroupServerEntity = new SharingGroupServer(
|
||||
[
|
||||
'sharing_group_id' => $id,
|
||||
'server_id' => 0,
|
||||
'all_orgs' => 0
|
||||
'sharing_group_id' => $id,
|
||||
'server_id' => 0,
|
||||
'all_orgs' => 0
|
||||
]
|
||||
);
|
||||
$this->SharingGroups->SharingGroupServers->save($sharingGroupServerEntity);
|
||||
|
@ -106,9 +106,9 @@ class SharingGroupsController extends AppController
|
|||
foreach ($sg['Organisation'] as $org) {
|
||||
$sharingGroupOrgEntity = new SharingGroupOrg(
|
||||
[
|
||||
'sharing_group_id' => $sharingGroupEntity->id,
|
||||
'org_id' => $org['id'],
|
||||
'extend' => $org['extend']
|
||||
'sharing_group_id' => $sharingGroupEntity->id,
|
||||
'org_id' => $org['id'],
|
||||
'extend' => $org['extend']
|
||||
]
|
||||
);
|
||||
$this->SharingGroups->SharingGroupOrgs->save($sharingGroupOrgEntity);
|
||||
|
@ -118,9 +118,9 @@ class SharingGroupsController extends AppController
|
|||
foreach ($sg['Server'] as $server) {
|
||||
$sharingGroupServerEntity = new SharingGroupServer(
|
||||
[
|
||||
'sharing_group_id' => $sharingGroupEntity->id,
|
||||
'server_id' => $server['id'],
|
||||
'all_orgs' => $server['all_orgs']
|
||||
'sharing_group_id' => $sharingGroupEntity->id,
|
||||
'server_id' => $server['id'],
|
||||
'all_orgs' => $server['all_orgs']
|
||||
]
|
||||
);
|
||||
$this->SharingGroups->SharingGroupServers->save($sharingGroupServerEntity);
|
||||
|
@ -192,7 +192,7 @@ class SharingGroupsController extends AppController
|
|||
if ($this->ParamHandler->isRest()) {
|
||||
if (!empty($this->request->getData('SharingGroup'))) {
|
||||
$data = $this->request->getData('SharingGroup');
|
||||
}else{
|
||||
} else {
|
||||
$data = $this->request->getData();
|
||||
}
|
||||
$data['uuid'] = $sharingGroup['uuid'];
|
||||
|
@ -392,7 +392,7 @@ class SharingGroupsController extends AppController
|
|||
$response[$k]['deletable'] = $deletable;
|
||||
}
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->RestResponse->viewData(['response' => $response], $this->response->getType()); // 'response' to keep BC
|
||||
return $this->RestResponse->viewData(['response' => $response]); // 'response' to keep BC
|
||||
}
|
||||
$this->set('passive', $passive);
|
||||
$this->set('sharingGroups', $response);
|
||||
|
@ -530,9 +530,9 @@ class SharingGroupsController extends AppController
|
|||
];
|
||||
if (!empty($id)) {
|
||||
if ($type == 'org') {
|
||||
return $this->SharingGroups->SharingGroupOrgs->Organisation->fetchOrg($id);
|
||||
return $this->SharingGroups->SharingGroupOrgs->Organisations->fetchOrg($id);
|
||||
} else {
|
||||
return $this->SharingGroups->SharingGroupServers->Server->fetchServer($id);
|
||||
return $this->SharingGroups->SharingGroupServers->Servers->fetchServer($id);
|
||||
}
|
||||
}
|
||||
if ($type !== 'org' && $type !== 'server') {
|
||||
|
@ -541,9 +541,9 @@ class SharingGroupsController extends AppController
|
|||
foreach ($params[$type] as $param) {
|
||||
if (!empty($request[$param])) {
|
||||
if ($type == 'org') {
|
||||
return $this->SharingGroups->SharingGroupOrgs->Organisation->fetchOrg($request[$param]);
|
||||
return $this->SharingGroups->SharingGroupOrgs->Organisations->fetchOrg($request[$param]);
|
||||
} else {
|
||||
return $this->SharingGroups->SharingGroupServers->Server->fetchServer($request[$param]);
|
||||
return $this->SharingGroups->SharingGroupServers->Servers->fetchServer($request[$param]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -568,18 +568,18 @@ class SharingGroupsController extends AppController
|
|||
}
|
||||
}
|
||||
if (!$addOrg) {
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', $this->action, false, 'Organisation is already in the sharing group.', $this->response->getType());
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', 'addOrg', false, 'Organisation is already in the sharing group.');
|
||||
}
|
||||
$sharingGroupOrgEntity = new SharingGroupOrg(
|
||||
[
|
||||
'org_id' => $org['id'],
|
||||
'sharing_group_id' => $sg['id'],
|
||||
'extend' => $extend ? 1 : 0
|
||||
'org_id' => $org['id'],
|
||||
'sharing_group_id' => $sg['id'],
|
||||
'extend' => $extend ? 1 : 0
|
||||
]
|
||||
);
|
||||
|
||||
$result = $this->SharingGroups->SharingGroupOrgs->save($sharingGroupOrgEntity);
|
||||
return $this->__sendQuickSaveResponse($this->action, $result, 'Organisation');
|
||||
return $this->__sendQuickSaveResponse('addOrg', $result, 'Organisation');
|
||||
}
|
||||
|
||||
public function removeOrg($sg_id = false, $object_id = false)
|
||||
|
@ -599,10 +599,11 @@ class SharingGroupsController extends AppController
|
|||
}
|
||||
}
|
||||
if (false === $removeOrg) {
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', $this->action, false, 'Organisation is not in the sharing group.', $this->response->getType());
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', 'removeOrg', false, 'Organisation is not in the sharing group.');
|
||||
}
|
||||
$result = $this->SharingGroups->SharingGroupOrgs->delete($removeOrg);
|
||||
return $this->__sendQuickSaveResponse($this->action, $result, 'Organisation');
|
||||
$orgEntity = $this->SharingGroups->SharingGroupOrgs->get($removeOrg);
|
||||
$result = $this->SharingGroups->SharingGroupOrgs->delete($orgEntity);
|
||||
return $this->__sendQuickSaveResponse('removeOrg', $result, 'Organisation');
|
||||
}
|
||||
|
||||
public function addServer($sg_id = false, $object_id = false, $all = false)
|
||||
|
@ -621,23 +622,23 @@ class SharingGroupsController extends AppController
|
|||
$addServer = true;
|
||||
if (!empty($sg['SharingGroupServer'])) {
|
||||
foreach ($sg['SharingGroupServer'] as $sgs) {
|
||||
if ($sgs['server_id'] == $server['Server']['id']) {
|
||||
if ($sgs['server_id'] == $server['id']) {
|
||||
$addServer = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$addServer) {
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', $this->action, false, 'Server is already in the sharing group.', $this->response->getType());
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', 'addServer', false, 'Server is already in the sharing group.');
|
||||
}
|
||||
$sharingGroupServerEntity = new SharingGroupServer(
|
||||
[
|
||||
'server_id' => $server['Server']['id'],
|
||||
'sharing_group_id' => $sg['id'],
|
||||
'all_orgs' => $all ? 1 : 0
|
||||
'server_id' => $server['id'],
|
||||
'sharing_group_id' => $sg['id'],
|
||||
'all_orgs' => $all ? 1 : 0
|
||||
]
|
||||
);
|
||||
$result = $this->SharingGroups->SharingGroupServers->save($sharingGroupServerEntity);
|
||||
return $this->__sendQuickSaveResponse($this->action, $result);
|
||||
return $this->__sendQuickSaveResponse('addServer', $result);
|
||||
}
|
||||
|
||||
public function removeServer($sg_id = false, $object_id = false)
|
||||
|
@ -650,17 +651,18 @@ class SharingGroupsController extends AppController
|
|||
$removeServer = false;
|
||||
if (!empty($sg['SharingGroupServer'])) {
|
||||
foreach ($sg['SharingGroupServer'] as $sgs) {
|
||||
if ($sgs['server_id'] == $server['Server']['id']) {
|
||||
$removeServer = $server['Server']['id'];
|
||||
if ($sgs['server_id'] == $server['id']) {
|
||||
$removeServer = $sgs['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (false === $removeServer) {
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', $this->action, false, 'Server is not in the sharing group.', $this->response->getType());
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', 'removeServer', false, 'Server is not in the sharing group.');
|
||||
}
|
||||
$result = $this->SharingGroups->SharingGroupServers->delete($removeServer);
|
||||
return $this->__sendQuickSaveResponse($this->action, $result);
|
||||
$serverEntity = $this->SharingGroups->SharingGroupServers->get($removeServer);
|
||||
$result = $this->SharingGroups->SharingGroupServers->delete($serverEntity);
|
||||
return $this->__sendQuickSaveResponse('removeServer', $result);
|
||||
}
|
||||
|
||||
private function __sendQuickSaveResponse($action, $result, $object_type = 'Server')
|
||||
|
@ -670,9 +672,9 @@ class SharingGroupsController extends AppController
|
|||
$actionType = 'removed from';
|
||||
}
|
||||
if ($result) {
|
||||
return $this->RestResponse->saveSuccessResponse('SharingGroup', $action, false, $this->response->getType(), $object_type . ' ' . $actionType . ' the sharing group.');
|
||||
return $this->RestResponse->saveSuccessResponse('SharingGroup', $action, false, 'json', $object_type . ' ' . $actionType . ' the sharing group.');
|
||||
} else {
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', $action, false, $object_type . ' could not be ' . $actionType . ' the sharing group.', $this->response->getType());
|
||||
return $this->RestResponse->saveFailResponse('SharingGroup', $action, false, $object_type . ' could not be ' . $actionType . ' the sharing group.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
namespace App\Model\Table;
|
||||
|
||||
use App\Model\Table\AppTable;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use Cake\Error\Debugger;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use ArrayObject;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\Validation\Validation;
|
||||
use Cake\Validation\Validator;
|
||||
|
||||
class OrganisationsTable extends AppTable
|
||||
{
|
||||
|
@ -45,17 +44,23 @@ class OrganisationsTable extends AppTable
|
|||
public function captureOrg($org): ?int
|
||||
{
|
||||
if (!empty($org['uuid'])) {
|
||||
$existingOrg = $this->find()->where([
|
||||
$existingOrg = $this->find()->where(
|
||||
[
|
||||
'uuid' => $org['uuid']
|
||||
])->first();
|
||||
]
|
||||
)->first();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (empty($existingOrg)) {
|
||||
$entityToSave = $this->newEmptyEntity();
|
||||
$this->patchEntity($entityToSave, $org, [
|
||||
$this->patchEntity(
|
||||
$entityToSave,
|
||||
$org,
|
||||
[
|
||||
'accessibleFields' => $entityToSave->getAccessibleFieldForNew()
|
||||
]);
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->patchEntity($existingOrg, $org);
|
||||
$entityToSave = $existingOrg;
|
||||
|
@ -67,4 +72,25 @@ class OrganisationsTable extends AppTable
|
|||
}
|
||||
return $savedEntity->id;
|
||||
}
|
||||
|
||||
public function fetchOrg($id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
return false;
|
||||
}
|
||||
$conditions = ['Organisations.id' => $id];
|
||||
if (Validation::uuid($id)) {
|
||||
$conditions = ['Organisations.uuid' => $id];
|
||||
} elseif (!is_numeric($id)) {
|
||||
$conditions = ['LOWER(Organisations.name)' => strtolower($id)];
|
||||
}
|
||||
$org = $this->find(
|
||||
'all',
|
||||
[
|
||||
'conditions' => $conditions,
|
||||
'recursive' => -1
|
||||
]
|
||||
)->disableHydration()->first();
|
||||
return (empty($org)) ? false : $org;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ class ServersTable extends AppTable
|
|||
$existingServer = $this->find(
|
||||
'all',
|
||||
[
|
||||
'recursive' => -1,
|
||||
'conditions' => ['url' => $server['url']]
|
||||
'recursive' => -1,
|
||||
'conditions' => ['url' => $server['url']]
|
||||
]
|
||||
)->disableHydration()->first();
|
||||
// unlike with other capture methods, if we find a server that we don't know
|
||||
|
@ -35,4 +35,26 @@ class ServersTable extends AppTable
|
|||
}
|
||||
return $existingServer['id'];
|
||||
}
|
||||
|
||||
public function fetchServer($id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
return false;
|
||||
}
|
||||
$conditions = ['Servers.id' => $id];
|
||||
if (!is_numeric($id)) {
|
||||
$conditions = ['OR' => [
|
||||
'LOWER(Servers.name)' => strtolower($id),
|
||||
'LOWER(Servers.url)' => strtolower($id)
|
||||
]];
|
||||
}
|
||||
$server = $this->find(
|
||||
'all',
|
||||
[
|
||||
'conditions' => $conditions,
|
||||
'recursive' => -1
|
||||
]
|
||||
)->disableHydration()->first();
|
||||
return (empty($server)) ? false : $server;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,9 +178,9 @@ class SharingGroupsTable extends AppTable
|
|||
[
|
||||
'contain' => ['SharingGroupServers' => ['Servers'], 'SharingGroupOrgs' => ['Organisations'], 'Organisations'],
|
||||
'conditions' => $conditions,
|
||||
'order' => 'SharingGroup.name ASC'
|
||||
'order' => 'SharingGroups.name ASC'
|
||||
]
|
||||
);
|
||||
)->disableHydration()->toArray();
|
||||
return $sgs;
|
||||
} elseif ($scope === 'simplified') {
|
||||
$fieldsOrg = ['id', 'name', 'uuid'];
|
||||
|
@ -217,7 +217,7 @@ class SharingGroupsTable extends AppTable
|
|||
'fields' => $fieldsSharingGroup[$permissionTree]['fields'],
|
||||
'order' => 'SharingGroups.name ASC'
|
||||
]
|
||||
)->toArray();
|
||||
)->disableHydration()->toArray();
|
||||
return $this->appendOrgsAndServers($sgs, $fieldsOrg, $fieldsServer);
|
||||
} elseif ($scope === 'distribution_graph') {
|
||||
// Specific scope that fetch just necessary information for distribution graph
|
||||
|
@ -231,7 +231,7 @@ class SharingGroupsTable extends AppTable
|
|||
'fields' => ['SharingGroups.id', 'SharingGroups.name', 'SharingGroups.org_id'],
|
||||
'order' => 'SharingGroups.name ASC'
|
||||
]
|
||||
)->toArray();
|
||||
)->disableHydration()->toArray();
|
||||
if ($canSeeOrgs) {
|
||||
return $this->appendOrgsAndServers($sgs, ['id', 'name'], []);
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ class SharingGroupsTable extends AppTable
|
|||
'order' => 'SharingGroups.name ASC',
|
||||
'conditions' => $conditions,
|
||||
]
|
||||
);
|
||||
)->disableHydration()->toArray();
|
||||
return $sgs;
|
||||
} elseif ($scope === 'uuid') {
|
||||
$sgs = $this->find(
|
||||
|
@ -258,7 +258,7 @@ class SharingGroupsTable extends AppTable
|
|||
'fields' => ['SharingGroups.id', 'SharingGroups.uuid'],
|
||||
'conditions' => $conditions,
|
||||
]
|
||||
);
|
||||
)->disableHydration()->toArray();
|
||||
return $sgs;
|
||||
}
|
||||
throw new InvalidArgumentException("Invalid scope $scope");
|
||||
|
|
|
@ -16,6 +16,9 @@ class OrganisationsFixture extends TestFixture
|
|||
public const ORGANISATION_B_ID = 2000;
|
||||
public const ORGANISATION_B_UUID = '36d22d9a-851e-4838-a655-9999c1d19497';
|
||||
|
||||
public const ORGANISATION_C_ID = 3000;
|
||||
public const ORGANISATION_C_UUID = '73adc87b-be68-43d4-be8a-be5bdfcb59d2';
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
@ -46,6 +49,19 @@ class OrganisationsFixture extends TestFixture
|
|||
'description' => 'ORGANISATION B',
|
||||
'date_created' => $faker->dateTime()->getTimestamp(),
|
||||
'date_modified' => $faker->dateTime()->getTimestamp()
|
||||
],
|
||||
[
|
||||
'id' => self::ORGANISATION_C_ID,
|
||||
'uuid' => self::ORGANISATION_C_UUID,
|
||||
'name' => 'Organisation C',
|
||||
'url' => $faker->url,
|
||||
'nationality' => $faker->countryCode,
|
||||
'sector' => 'IT',
|
||||
'type' => '',
|
||||
'contacts' => '',
|
||||
'description' => 'ORGANISATION C',
|
||||
'date_created' => $faker->dateTime()->getTimestamp(),
|
||||
'date_modified' => $faker->dateTime()->getTimestamp()
|
||||
]
|
||||
];
|
||||
parent::init();
|
||||
|
|
|
@ -16,6 +16,9 @@ class ServersFixture extends TestFixture
|
|||
public const SERVER_B_ID = 2000;
|
||||
public const SERVER_B_NAME = 'Server B';
|
||||
|
||||
public const SERVER_C_ID = 3000;
|
||||
public const SERVER_C_NAME = 'Server C';
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
@ -68,7 +71,31 @@ class ServersFixture extends TestFixture
|
|||
'remove_missing_tags' => false,
|
||||
'caching_enabled' => false,
|
||||
'priority' => 1,
|
||||
]
|
||||
],
|
||||
[
|
||||
'id' => self::SERVER_C_ID,
|
||||
'org_id' => OrganisationsFixture::ORGANISATION_C_ID,
|
||||
'name' => self::SERVER_C_NAME,
|
||||
'url' => $faker->url,
|
||||
'authkey' => $faker->sha1(),
|
||||
'push' => true,
|
||||
'pull' => true,
|
||||
'push_sightings' => true,
|
||||
'push_galaxy_clusters' => true,
|
||||
'pull_galaxy_clusters' => true,
|
||||
'organization' => 'Org B',
|
||||
'remote_org_id' => $faker->numberBetween(1000, 2000),
|
||||
'publish_without_email' => true,
|
||||
'unpublish_event' => true,
|
||||
'self_signed' => true,
|
||||
'pull_rules' => json_encode([]),
|
||||
'push_rules' => json_encode([]),
|
||||
'internal' => false,
|
||||
'skip_proxy' => false,
|
||||
'remove_missing_tags' => false,
|
||||
'caching_enabled' => false,
|
||||
'priority' => 1,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@ class SharingGroupServersFixture extends TestFixture
|
|||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'server_id' => ServersFixture::SERVER_A_ID,
|
||||
'all_orgs' => false,
|
||||
],
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'server_id' => ServersFixture::SERVER_C_ID,
|
||||
'all_orgs' => false,
|
||||
]
|
||||
];
|
||||
parent::init();
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\SharingGroups;
|
||||
|
||||
use App\Test\Fixture\AuthKeysFixture;
|
||||
use App\Test\Fixture\OrganisationsFixture;
|
||||
use App\Test\Fixture\SharingGroupsFixture;
|
||||
use App\Test\Helper\ApiTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class AddSharingGroupOrgApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
||||
protected const ENDPOINT = '/sharing-groups/add-org';
|
||||
|
||||
protected $fixtures = [
|
||||
'app.Organisations',
|
||||
'app.Users',
|
||||
'app.AuthKeys',
|
||||
'app.Servers',
|
||||
'app.SharingGroups',
|
||||
'app.SharingGroupOrgs',
|
||||
'app.SharingGroupServers',
|
||||
];
|
||||
|
||||
public function testAddSharingGroupOrganisation(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||
|
||||
$this->post(
|
||||
sprintf("%s/%s/%s", self::ENDPOINT, SharingGroupsFixture::SHARING_GROUP_A_ID, OrganisationsFixture::ORGANISATION_C_ID)
|
||||
);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertDbRecordExists(
|
||||
'SharingGroupOrgs',
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'org_id' => OrganisationsFixture::ORGANISATION_C_ID
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\SharingGroups;
|
||||
|
||||
use App\Test\Fixture\AuthKeysFixture;
|
||||
use App\Test\Fixture\ServersFixture;
|
||||
use App\Test\Fixture\SharingGroupsFixture;
|
||||
use App\Test\Helper\ApiTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class AddSharingGroupServerApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
||||
protected const ENDPOINT = '/sharing-groups/add-server';
|
||||
|
||||
protected $fixtures = [
|
||||
'app.Organisations',
|
||||
'app.Users',
|
||||
'app.AuthKeys',
|
||||
'app.Servers',
|
||||
'app.SharingGroups',
|
||||
'app.SharingGroupOrgs',
|
||||
'app.SharingGroupServers',
|
||||
];
|
||||
|
||||
public function testAddSharingGroupServer(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||
|
||||
$this->post(
|
||||
sprintf("%s/%s/%s", self::ENDPOINT, SharingGroupsFixture::SHARING_GROUP_A_ID, ServersFixture::SERVER_B_ID)
|
||||
);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertDbRecordExists(
|
||||
'SharingGroupServers',
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'server_id' => ServersFixture::SERVER_B_ID
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -4,10 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Test\TestCase\Api\SharingGroups;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use App\Test\Fixture\AuthKeysFixture;
|
||||
use App\Test\Fixture\SharingGroupsFixture;
|
||||
use App\Test\Helper\ApiTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class IndexSharingGroupsApiTest extends TestCase
|
||||
{
|
||||
|
@ -32,9 +32,14 @@ class IndexSharingGroupsApiTest extends TestCase
|
|||
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||
|
||||
$this->get(self::ENDPOINT);
|
||||
$sharingGroups = $this->getJsonResponseAsArray()['response'];
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains(sprintf('"uuid": "%s"', SharingGroupsFixture::SHARING_GROUP_A_UUID));
|
||||
$this->assertResponseContains(sprintf('"uuid": "%s"', SharingGroupsFixture::SHARING_GROUP_B_UUID));
|
||||
|
||||
$this->assertCount(2, $sharingGroups);
|
||||
$this->assertEquals('Sharing Group A', $sharingGroups[0]['name']);
|
||||
$this->assertEquals(SharingGroupsFixture::SHARING_GROUP_A_UUID, $sharingGroups[0]['uuid']);
|
||||
$this->assertEquals('Sharing Group B', $sharingGroups[1]['name']);
|
||||
$this->assertEquals(SharingGroupsFixture::SHARING_GROUP_B_UUID, $sharingGroups[1]['uuid']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\SharingGroups;
|
||||
|
||||
use App\Test\Fixture\AuthKeysFixture;
|
||||
use App\Test\Fixture\OrganisationsFixture;
|
||||
use App\Test\Fixture\SharingGroupsFixture;
|
||||
use App\Test\Helper\ApiTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class RemoveSharingGroupOrgApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
||||
protected const ENDPOINT = '/sharing-groups/remove-org';
|
||||
|
||||
protected $fixtures = [
|
||||
'app.Organisations',
|
||||
'app.Users',
|
||||
'app.AuthKeys',
|
||||
'app.Servers',
|
||||
'app.SharingGroups',
|
||||
'app.SharingGroupOrgs',
|
||||
'app.SharingGroupServers',
|
||||
];
|
||||
|
||||
public function testRemoveSharingGroupOrganisation(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||
|
||||
$this->assertDbRecordExists(
|
||||
'SharingGroupOrgs',
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'org_id' => OrganisationsFixture::ORGANISATION_B_ID
|
||||
]
|
||||
);
|
||||
|
||||
$this->post(
|
||||
sprintf("%s/%s/%s", self::ENDPOINT, SharingGroupsFixture::SHARING_GROUP_A_ID, OrganisationsFixture::ORGANISATION_B_ID)
|
||||
);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertDbRecordNotExists(
|
||||
'SharingGroupOrgs',
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'org_id' => OrganisationsFixture::ORGANISATION_B_ID
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\SharingGroups;
|
||||
|
||||
use App\Test\Fixture\AuthKeysFixture;
|
||||
use App\Test\Fixture\ServersFixture;
|
||||
use App\Test\Fixture\SharingGroupsFixture;
|
||||
use App\Test\Helper\ApiTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class RemoveSharingGroupServerApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
||||
protected const ENDPOINT = '/sharing-groups/remove-server';
|
||||
|
||||
protected $fixtures = [
|
||||
'app.Organisations',
|
||||
'app.Users',
|
||||
'app.AuthKeys',
|
||||
'app.Servers',
|
||||
'app.SharingGroups',
|
||||
'app.SharingGroupOrgs',
|
||||
'app.SharingGroupServers',
|
||||
];
|
||||
|
||||
public function testRemoveSharingGroupServer(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||
|
||||
$this->assertDbRecordExists(
|
||||
'SharingGroupServers',
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'server_id' => ServersFixture::SERVER_C_ID
|
||||
]
|
||||
);
|
||||
|
||||
$this->post(
|
||||
sprintf("%s/%s/%s", self::ENDPOINT, SharingGroupsFixture::SHARING_GROUP_A_ID, ServersFixture::SERVER_C_ID)
|
||||
);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertDbRecordNotExists(
|
||||
'SharingGroupServers',
|
||||
[
|
||||
'sharing_group_id' => SharingGroupsFixture::SHARING_GROUP_A_ID,
|
||||
'server_id' => ServersFixture::SERVER_C_ID
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -4,12 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Test\TestCase\Api\SharingGroups;
|
||||
|
||||
use Cake\TestSuite\TestCase;
|
||||
use App\Test\Fixture\AuthKeysFixture;
|
||||
use App\Test\Fixture\OrganisationsFixture;
|
||||
use App\Test\Fixture\ServersFixture;
|
||||
use App\Test\Fixture\SharingGroupsFixture;
|
||||
use App\Test\Helper\ApiTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
class ViewSharingGroupApiTest extends TestCase
|
||||
{
|
||||
|
@ -51,8 +51,10 @@ class ViewSharingGroupApiTest extends TestCase
|
|||
|
||||
// check that the sharing group contains the correct servers
|
||||
$this->assertArrayHasKey('SharingGroupServer', $sharingGroup);
|
||||
$this->assertCount(1, $sharingGroup['SharingGroupServer']);
|
||||
$this->assertCount(2, $sharingGroup['SharingGroupServer']);
|
||||
$this->assertEquals(ServersFixture::SERVER_A_ID, $sharingGroup['SharingGroupServer'][0]['Server']['id']);
|
||||
$this->assertEquals(ServersFixture::SERVER_A_NAME, $sharingGroup['SharingGroupServer'][0]['Server']['name']);
|
||||
$this->assertEquals(ServersFixture::SERVER_C_ID, $sharingGroup['SharingGroupServer'][1]['Server']['id']);
|
||||
$this->assertEquals(ServersFixture::SERVER_C_NAME, $sharingGroup['SharingGroupServer'][1]['Server']['name']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue