From a473a9d3fb2e6a8ed7ffbdb7f37ab5c91b0d3188 Mon Sep 17 00:00:00 2001 From: Luciano Righetti Date: Wed, 5 Jan 2022 17:44:02 +0100 Subject: [PATCH] new: initial api and integration tests. --- .gitignore | 2 + config/Migrations/schema-dump-default.lock | Bin 42139 -> 56757 bytes phpunit.xml.dist | 18 +-- src/Model/Table/AuditLogsTable.php | 4 +- tests/Fixture/AuthKeysFixture.php | 36 +++++ tests/Fixture/IndividualsFixture.php | 25 ++++ tests/Fixture/RolesFixture.php | 24 ++++ tests/Fixture/UsersFixture.php | 38 ++++++ tests/README.md | 48 +++++++ tests/TestCase/Api/UsersApiTest.php | 40 ++++++ tests/TestCase/ApplicationTest.php | 6 +- .../Controller/PagesControllerTest.php | 126 ------------------ .../Controller/UsersControllerTest.php | 32 +++++ tests/bootstrap.php | 17 +++ 14 files changed, 278 insertions(+), 138 deletions(-) create mode 100644 tests/Fixture/AuthKeysFixture.php create mode 100644 tests/Fixture/IndividualsFixture.php create mode 100644 tests/Fixture/RolesFixture.php create mode 100644 tests/Fixture/UsersFixture.php create mode 100644 tests/README.md create mode 100644 tests/TestCase/Api/UsersApiTest.php delete mode 100644 tests/TestCase/Controller/PagesControllerTest.php create mode 100644 tests/TestCase/Controller/UsersControllerTest.php diff --git a/.gitignore b/.gitignore index f84928d..869728c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ vendor webroot/theme/node_modules .vscode docker/run/ +.phpunit.result.cache +config.json \ No newline at end of file diff --git a/config/Migrations/schema-dump-default.lock b/config/Migrations/schema-dump-default.lock index 291060ccbeef6d3415e60d985954fd26141e1c02..8c9385cea7539531476901ab307ae28e67e054d4 100644 GIT binary patch literal 56757 zcmeHQOLOBm4&I-V%5hKK>GaEe+S$3xVRsKZ$Ek8DwvwpYmb{YOkLsHLz8@%w0zuFZ z%8sQT-x5Or(%VmdXZYoH^T?uDZPz*aPiF7v zO^lH(>A#Qk-~H^i{=P9?yhlS`r%!1~9lo30uG0L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0R+#v%wZ9xS5 z__ft2=3>y$JzIm#wAE0jhecG`GG0jYgv)08W_P30YjfE3wdTgjI6qMcNXkHou?YeD8}M zdfL4cx=s|47J-4{&St@H11Y33%Wfv?&69uBZ`B@O)u{Gp*~33I7C{T^du zMinu7Y(qcHKI{i)bT)H+(~1y|fUvXvGQ4K&C%p-7OWl|Wzi#%jgxlxLh4)RWI58C{ zgoj5>pnoNa(*dT+oE5B2Z8cSRWpu3y#jCXTPoiwITQi~B`2|iyy4G@Nv>7Yh_I2=yIdvG*lLzzN@a7-0o_ z)Z~KY2c^uZ?RzBw@j8DfO{yi*EC^eTBB}`0$Za*)Z5{(lbRr35d`Sr2Af(Q8qA+sy zl33PE-5Zh`Bc=$VX@QL(7;@ra`S*GS_K89rA=x>tPGF$1a;0f7CIa_`-T@JY!E*_a zrrwv1Bzem2|4kDG9NM)4p$zTHz%jU5R5V+qVwHg_SxHd2-y#~D0wHBc*@BZxDw!Jx zG{Mwii}a^-7VpW?OShwrwA)<&&1?L%*!cGa_=E`x%hyREs%aIBM6ZF;bzz|S+>fY* zt-ltAy0L;{mFFsMb!#cfSKP)cw|QW=W(*KbG-nCkQ(qR%=ix%!8WtSA#7^pH7C+_S?8gKn<+s`JJ)wM+d3qS)GKLT>paI1z{%J zCvEvEbK;G-HimO>eos4bFiPNHke0!t1x6@m8jz+kczmup2n6wUS8p-S_VgyAiVXKk zLh;Ali#{ByE_p?^UmB#7d7;6l-0CsAC!Z2ZYx|+%vpL)gGL1Lh3ms3g*{y6JCiA*& zb}OvBb@WO2LA^#8k`6Nk)Gi&Ix)TXMSrqW~u#^1DLTIEj+Ws8n=kxssYtD)Z diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7107122..7be6529 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,17 +15,17 @@ tests/TestCase/ - + + ./tests/TestCase/Controller + + + ./tests/TestCase/Api + - - - - - - - - + + + diff --git a/src/Model/Table/AuditLogsTable.php b/src/Model/Table/AuditLogsTable.php index efd6339..7987af6 100644 --- a/src/Model/Table/AuditLogsTable.php +++ b/src/Model/Table/AuditLogsTable.php @@ -163,8 +163,8 @@ class AuditLogsTable extends AppTable if ($this->user !== null) { return $this->user; } - - $this->user = ['id' => 0, /*'org_id' => 0, */'authkey_id' => 0, 'request_type' => self::REQUEST_TYPE_DEFAULT]; + + $this->user = ['id' => 0, /*'org_id' => 0, */'authkey_id' => 0, 'request_type' => self::REQUEST_TYPE_DEFAULT, 'name' => '']; $isShell = (php_sapi_name() === 'cli'); if ($isShell) { diff --git a/tests/Fixture/AuthKeysFixture.php b/tests/Fixture/AuthKeysFixture.php new file mode 100644 index 0000000..5924c5b --- /dev/null +++ b/tests/Fixture/AuthKeysFixture.php @@ -0,0 +1,36 @@ +records = [ + [ + 'id' => 1, + 'uuid' => '3ebfbe50-e7d2-406e-a092-f031e604b6e5', + 'authkey' => $hasher->hash(self::ADMIN_API_KEY), + 'authkey_start' => '4cd6', + 'authkey_end' => '4c2f', + 'expiration' => 0, + 'user_id' => 1, + 'comment' => '', + 'created' => time(), + 'modified' => time() + ] + ]; + parent::init(); + } +} diff --git a/tests/Fixture/IndividualsFixture.php b/tests/Fixture/IndividualsFixture.php new file mode 100644 index 0000000..31261f2 --- /dev/null +++ b/tests/Fixture/IndividualsFixture.php @@ -0,0 +1,25 @@ + 1, + 'uuid' => '3ebfbe50-e7d2-406e-a092-f031e604b6e1', + 'email' => 'admin@admin.test', + 'first_name' => 'admin', + 'last_name' => 'admin', + 'position' => 'admin', + 'created' => '2022-01-04 10:00:00', + 'modified' => '2022-01-04 10:00:00' + ] + ]; +} diff --git a/tests/Fixture/RolesFixture.php b/tests/Fixture/RolesFixture.php new file mode 100644 index 0000000..ced82a1 --- /dev/null +++ b/tests/Fixture/RolesFixture.php @@ -0,0 +1,24 @@ + 1, + 'uuid' => '3ebfbe50-e7d2-406e-a092-f031e604b6e4', + 'name' => 'admin', + 'is_default' => true, + 'perm_admin' => true, + 'perm_sync' => true, + 'perm_org_admin' => true + ] + ]; +} diff --git a/tests/Fixture/UsersFixture.php b/tests/Fixture/UsersFixture.php new file mode 100644 index 0000000..df6b8bd --- /dev/null +++ b/tests/Fixture/UsersFixture.php @@ -0,0 +1,38 @@ +records = [ + [ + 'id' => 1, + 'uuid' => '3ebfbe50-e7d2-406e-a092-f031e604b6e5', + 'username' => self::ADMIN_USER, + 'password' => $hasher->hash(self::ADMIN_PASSWORD), + 'role_id' => 1, + 'individual_id' => 1, + 'disabled' => 0, + 'organisation_id' => 1, + 'created' => '2022-01-04 10:00:00', + 'modified' => '2022-01-04 10:00:00' + ] + ]; + parent::init(); + } +} diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..898e249 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,48 @@ +# Testing +Add a test database to your `config/app_local.php` config file and set `debug` mode to `true`. +```php +'debug' => true, +'Datasources' => [ + 'default' => [ + ... + ], + /* + * The test connection is used during the test suite. + */ + 'test' => [ + 'host' => 'localhost', + 'username' => 'cerebrate', + 'password' => 'cerebrate', + 'database' => 'cerebrate_test', + ], +], +``` + +## Runing the tests + +``` +$ composer install +$ vendor/bin/phpunit +PHPUnit 8.5.22 by Sebastian Bergmann and contributors. + +..... 5 / 5 (100%) + +Time: 11.61 seconds, Memory: 26.00 MB + +OK (5 tests, 15 assertions) +``` + +Running a specific suite: +``` +$ vendor/bin/phpunit --testsuite=api +``` +Available suites: +* `app`: runs all test suites +* `api`: runs only api tests +* `controller`: runs only controller tests +* _to be continued ..._ + +By default the database is re-generated before running the test suite, to skip this step and speed up the test run use the `-d skip-migrations` option: +``` +$ vendor/bin/phpunit -d skip-migrations +``` diff --git a/tests/TestCase/Api/UsersApiTest.php b/tests/TestCase/Api/UsersApiTest.php new file mode 100644 index 0000000..5353305 --- /dev/null +++ b/tests/TestCase/Api/UsersApiTest.php @@ -0,0 +1,40 @@ +configRequest([ + 'headers' => [ + // this does not work: https://book.cakephp.org/4/en/development/testing.html#testing-stateless-authentication-and-apis + // 'Authorization' => AuthKeysFixture::ADMIN_API_KEY, + 'Accept' => 'application/json' + ] + ]); + + $this->get('/users/view'); + + $this->assertResponseOk(); + $this->assertResponseContains(sprintf('"username": "%s"', UsersFixture::ADMIN_USER)); + } +} diff --git a/tests/TestCase/ApplicationTest.php b/tests/TestCase/ApplicationTest.php index cd09f1e..e2d3183 100644 --- a/tests/TestCase/ApplicationTest.php +++ b/tests/TestCase/ApplicationTest.php @@ -40,10 +40,14 @@ class ApplicationTest extends IntegrationTestCase $app->bootstrap(); $plugins = $app->getPlugins(); - $this->assertCount(3, $plugins); + $this->assertCount(7, $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()); } /** diff --git a/tests/TestCase/Controller/PagesControllerTest.php b/tests/TestCase/Controller/PagesControllerTest.php deleted file mode 100644 index f2958f9..0000000 --- a/tests/TestCase/Controller/PagesControllerTest.php +++ /dev/null @@ -1,126 +0,0 @@ -get('/'); - $this->assertResponseOk(); - $this->get('/'); - $this->assertResponseOk(); - } - - /** - * testDisplay method - * - * @return void - */ - public function testDisplay() - { - $this->get('/pages/home'); - $this->assertResponseOk(); - $this->assertResponseContains('CakePHP'); - $this->assertResponseContains(''); - } - - /** - * Test that missing template renders 404 page in production - * - * @return void - */ - public function testMissingTemplate() - { - Configure::write('debug', false); - $this->get('/pages/not_existing'); - - $this->assertResponseError(); - $this->assertResponseContains('Error'); - } - - /** - * Test that missing template in debug mode renders missing_template error page - * - * @return void - */ - public function testMissingTemplateInDebug() - { - Configure::write('debug', true); - $this->get('/pages/not_existing'); - - $this->assertResponseFailure(); - $this->assertResponseContains('Missing Template'); - $this->assertResponseContains('Stacktrace'); - $this->assertResponseContains('not_existing.php'); - } - - /** - * Test directory traversal protection - * - * @return void - */ - public function testDirectoryTraversalProtection() - { - $this->get('/pages/../Layout/ajax'); - $this->assertResponseCode(403); - $this->assertResponseContains('Forbidden'); - } - - /** - * Test that CSRF protection is applied to page rendering. - * - * @reutrn void - */ - public function testCsrfAppliedError() - { - $this->post('/pages/home', ['hello' => 'world']); - - $this->assertResponseCode(403); - $this->assertResponseContains('CSRF'); - } - - /** - * Test that CSRF protection is applied to page rendering. - * - * @reutrn void - */ - public function testCsrfAppliedOk() - { - $this->enableCsrfToken(); - $this->post('/pages/home', ['hello' => 'world']); - - $this->assertResponseCode(200); - $this->assertResponseContains('CakePHP'); - } -} diff --git a/tests/TestCase/Controller/UsersControllerTest.php b/tests/TestCase/Controller/UsersControllerTest.php new file mode 100644 index 0000000..0c856e8 --- /dev/null +++ b/tests/TestCase/Controller/UsersControllerTest.php @@ -0,0 +1,32 @@ +enableCsrfToken(); + $this->enableSecurityToken(); + + $this->post('/users/login', [ + 'username' => UsersFixture::ADMIN_USER, + 'password' => UsersFixture::ADMIN_PASSWORD, + ]); + + $this->assertSessionHasKey('authUser.uuid'); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 962815c..f8088be 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,5 @@ ['*']`, prevents migrations from droping already created tables + (new SchemaLoader())->loadSqlFiles('./INSTALL/mysql.sql', 'test'); + $migrator = new Migrator(); + $migrator->runMany([ + ['connection' => 'test', 'skip' => ['*']], + ['plugin' => 'Tags', 'connection' => 'test', 'skip' => ['*']], + ['plugin' => 'ADmad/SocialAuth', 'connection' => 'test', 'skip' => ['*']] + ]); +}