From 4ebdbf8ba3f20094f90fe11bcd58b0d913c96e45 Mon Sep 17 00:00:00 2001 From: Luciano Righetti Date: Thu, 6 Apr 2023 18:00:46 +0200 Subject: [PATCH] fix: fix most of the tests --- tests/Fixture/BroodsFixture.php | 2 +- .../Fixture/MetaTemplateDirectoryFixture.php | 30 +++++++++++++++++++ tests/Fixture/MetaTemplateFieldsFixture.php | 1 + tests/Fixture/MetaTemplatesFixture.php | 2 ++ tests/Helper/WireMockTestTrait.php | 14 +++++---- .../LocalTools/MispInterConnectionTest.php | 18 +++++------ .../TestCase/Api/Users/DeleteUserApiTest.php | 2 ++ tests/TestCase/ApplicationTest.php | 3 +- 8 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 tests/Fixture/MetaTemplateDirectoryFixture.php diff --git a/tests/Fixture/BroodsFixture.php b/tests/Fixture/BroodsFixture.php index c329e6a..7cc26a1 100644 --- a/tests/Fixture/BroodsFixture.php +++ b/tests/Fixture/BroodsFixture.php @@ -56,7 +56,7 @@ class BroodsFixture extends TestFixture 'id' => self::BROOD_WIREMOCK_ID, 'uuid' => $faker->uuid(), 'name' => 'wiremock', - 'url' => 'http://localhost:8080', + 'url' => sprintf('http://%s:%s', $_ENV['WIREMOCK_HOST'] ?? 'localhost', $_ENV['WIREMOCK_PORT'] ?? '8080'), 'description' => $faker->text, 'organisation_id' => OrganisationsFixture::ORGANISATION_B_ID, 'trusted' => true, diff --git a/tests/Fixture/MetaTemplateDirectoryFixture.php b/tests/Fixture/MetaTemplateDirectoryFixture.php new file mode 100644 index 0000000..04c6242 --- /dev/null +++ b/tests/Fixture/MetaTemplateDirectoryFixture.php @@ -0,0 +1,30 @@ +records = [ + [ + 'id' => self::META_TEMPLATE_DIRECTORY_ID, + 'uuid' => self::META_TEMPLATE_DIRECTORY_UUID, + 'name' => 'Test Meta Template Directory', + 'namespace' => 'cerebrate', + 'version' => '1' + ] + ]; + + parent::init(); + } +} diff --git a/tests/Fixture/MetaTemplateFieldsFixture.php b/tests/Fixture/MetaTemplateFieldsFixture.php index 141a7aa..ff38317 100644 --- a/tests/Fixture/MetaTemplateFieldsFixture.php +++ b/tests/Fixture/MetaTemplateFieldsFixture.php @@ -17,6 +17,7 @@ class MetaTemplateFieldsFixture extends TestFixture 'field' => 'test_field_1', 'type' => 'text', 'meta_template_id' => MetaTemplatesFixture::ENABLED_TEST_ORG_META_TEMPLATE_ID, + 'meta_template_directory_id' => MetaTemplateDirectoryFixture::META_TEMPLATE_DIRECTORY_ID, 'regex' => null, 'multiple' => 1, 'enabled' => 1, diff --git a/tests/Fixture/MetaTemplatesFixture.php b/tests/Fixture/MetaTemplatesFixture.php index cbe96a2..6eed2bb 100644 --- a/tests/Fixture/MetaTemplatesFixture.php +++ b/tests/Fixture/MetaTemplatesFixture.php @@ -44,6 +44,7 @@ class MetaTemplatesFixture extends TestFixture $this->records = [ [ 'id' => self::ENABLED_TEST_ORG_META_TEMPLATE_ID, + 'meta_template_directory_id' => MetaTemplateDirectoryFixture::META_TEMPLATE_DIRECTORY_ID, 'scope' => 'organisation', 'name' => 'Test Meta Template (enabled)', 'namespace' => 'cerebrate', @@ -58,6 +59,7 @@ class MetaTemplatesFixture extends TestFixture ], [ 'id' => self::DISABLED_TEST_ORG_META_TEMPLATE_ID, + 'meta_template_directory_id' => MetaTemplateDirectoryFixture::META_TEMPLATE_DIRECTORY_ID, 'scope' => 'organisation', 'name' => 'Test Meta Template (disabled)', 'namespace' => 'cerebrate', diff --git a/tests/Helper/WireMockTestTrait.php b/tests/Helper/WireMockTestTrait.php index 41aea61..69d33c5 100644 --- a/tests/Helper/WireMockTestTrait.php +++ b/tests/Helper/WireMockTestTrait.php @@ -15,16 +15,18 @@ trait WireMockTestTrait private $wiremock; /** @var array */ - private $config = [ - 'hostname' => 'localhost', - 'port' => 8080 - ]; + private $config; public function initializeWireMock(): void { + $this->config = [ + 'hostname' => $_ENV['WIREMOCK_HOST'] ?? 'localhost', + 'port' => $_ENV['WIREMOCK_PORT'] ?? 8080 + ]; + $this->wiremock = WireMock::create( - $_ENV['WIREMOCK_HOST'] ?? $this->config['hostname'], - $_ENV['WIREMOCK_PORT'] ?? $this->config['port'] + $this->config['hostname'], + $this->config['port'] ); if (!$this->wiremock->isAlive()) { diff --git a/tests/TestCase/Api/LocalTools/MispInterConnectionTest.php b/tests/TestCase/Api/LocalTools/MispInterConnectionTest.php index 7f643d3..e81c4ec 100644 --- a/tests/TestCase/Api/LocalTools/MispInterConnectionTest.php +++ b/tests/TestCase/Api/LocalTools/MispInterConnectionTest.php @@ -31,20 +31,20 @@ class MispInterConnectionTest extends TestCase ]; /** constants related to the local Cerebrate instance */ - private const LOCAL_CEREBRATE_URL = 'http://127.0.0.1'; + private const LOCAL_CEREBRATE_URL = 'http://localhost'; /** constants related to the local MISP instance */ - private const LOCAL_MISP_INSTANCE_URL = 'http://localhost:8080/MISP_LOCAL'; + private const LOCAL_MISP_INSTANCE_URL = '/MISP_LOCAL'; private const LOCAL_MISP_ADMIN_USER_AUTHKEY = 'b17ce79ac0f05916f382ab06ea4790665dbc174c'; /** constants related to the remote Cerebrate instance */ - private const REMOTE_CEREBRATE_URL = 'http://127.0.0.1:8080/CEREBRATE_REMOTE'; + private const REMOTE_CEREBRATE_URL = '/CEREBRATE_REMOTE'; private const REMOTE_CEREBRATE_AUTHKEY = 'a192ba3c749b545f9cec6b6bba0643736f6c3022'; /** constants related to the remote MISP instance */ private const REMOTE_MISP_SYNC_USER_ID = 333; private const REMOTE_MISP_SYNC_USER_EMAIL = 'sync@misp.remote'; - private const REMOTE_MISP_INSTANCE_URL = 'http://localhost:8080/MISP_REMOTE'; + private const REMOTE_MISP_INSTANCE_URL = '/MISP_REMOTE'; private const REMOTE_MISP_AUTHKEY = '19ca57ecebd2fe34c1c17d729980678eb648d541'; @@ -64,7 +64,7 @@ class MispInterConnectionTest extends TestCase 'name' => 'MISP_LOCAL', 'connector' => 'MispConnector', 'settings' => json_encode([ - 'url' => self::LOCAL_MISP_INSTANCE_URL, + 'url' => $this->getWireMockBaseUrl() . self::LOCAL_MISP_INSTANCE_URL, 'authkey' => self::LOCAL_MISP_ADMIN_USER_AUTHKEY, 'skip_ssl' => true, ]), @@ -90,7 +90,7 @@ class MispInterConnectionTest extends TestCase [ 'uuid' => $LOCAL_BROOD_UUID, 'name' => 'Local Brood', - 'url' => self::REMOTE_CEREBRATE_URL, + 'url' => $this->getWireMockBaseUrl() . self::REMOTE_CEREBRATE_URL, 'description' => $faker->text, 'organisation_id' => OrganisationsFixture::ORGANISATION_A_ID, 'trusted' => true, @@ -228,10 +228,10 @@ class MispInterConnectionTest extends TestCase [ 'email' => self::REMOTE_MISP_SYNC_USER_EMAIL, 'authkey' => self::REMOTE_MISP_AUTHKEY, - 'url' => self::REMOTE_MISP_INSTANCE_URL, + 'url' => $this->getWireMockBaseUrl() . self::REMOTE_MISP_INSTANCE_URL, 'reflected_user_id' => self::REMOTE_MISP_SYNC_USER_ID, 'connectorName' => 'MispConnector', - 'cerebrateURL' => self::REMOTE_CEREBRATE_URL, + 'cerebrateURL' => $this->getWireMockBaseUrl() . self::REMOTE_CEREBRATE_URL, 'local_tool_id' => 1, 'remote_tool_id' => 1, 'tool_name' => 'MISP_REMOTE' @@ -250,7 +250,7 @@ class MispInterConnectionTest extends TestCase self::LOCAL_MISP_ADMIN_USER_AUTHKEY, [ 'authkey' => self::REMOTE_MISP_AUTHKEY, - 'url' => self::REMOTE_MISP_INSTANCE_URL, + 'url' => $this->getWireMockBaseUrl() . self::REMOTE_MISP_INSTANCE_URL, 'name' => 'MISP_REMOTE', 'remote_org_id' => OrganisationsFixture::ORGANISATION_A_ID ] diff --git a/tests/TestCase/Api/Users/DeleteUserApiTest.php b/tests/TestCase/Api/Users/DeleteUserApiTest.php index 9288b9a..2ffe0be 100644 --- a/tests/TestCase/Api/Users/DeleteUserApiTest.php +++ b/tests/TestCase/Api/Users/DeleteUserApiTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Test\TestCase\Api\Users; +use Cake\Core\Configure; use Cake\TestSuite\TestCase; use App\Test\Fixture\AuthKeysFixture; use App\Test\Fixture\UsersFixture; @@ -25,6 +26,7 @@ class DeleteUserApiTest extends TestCase public function testDeleteUser(): void { + Configure::write('user.allow-user-deletion', true); $this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY); $url = sprintf('%s/%d', self::ENDPOINT, UsersFixture::USER_REGULAR_USER_ID); $this->delete($url); diff --git a/tests/TestCase/ApplicationTest.php b/tests/TestCase/ApplicationTest.php index e2d3183..01afe27 100644 --- a/tests/TestCase/ApplicationTest.php +++ b/tests/TestCase/ApplicationTest.php @@ -40,14 +40,13 @@ class ApplicationTest extends IntegrationTestCase $app->bootstrap(); $plugins = $app->getPlugins(); - $this->assertCount(7, $plugins); + $this->assertCount(6, $plugins); $this->assertSame('Bake', $plugins->get('Bake')->getName()); $this->assertSame('DebugKit', $plugins->get('DebugKit')->getName()); $this->assertSame('Migrations', $plugins->get('Migrations')->getName()); $this->assertSame('Authentication', $plugins->get('Authentication')->getName()); $this->assertSame('ADmad/SocialAuth', $plugins->get('ADmad/SocialAuth')->getName()); $this->assertSame('Tags', $plugins->get('Tags')->getName()); - $this->assertSame('Cake/TwigView', $plugins->get('Cake/TwigView')->getName()); } /**