Skip to content

Commit 5da33c2

Browse files
committed
PB-29148 Remove config endpoints from selenium api plugin
1 parent e44acb0 commit 5da33c2

File tree

6 files changed

+55
-199
lines changed

6 files changed

+55
-199
lines changed

config/bootstrap.php

-9
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@
1313
* @since 2.0.0
1414
*/
1515
use Cake\Core\Configure;
16-
use Cake\Core\Configure\Engine\PhpConfig;
1716

18-
/*
19-
* Load Selenium testing extra config if any
20-
* This allow redefining server config on the fly when running integration tests
21-
*/
2217
if (Configure::read('debug') && Configure::read('passbolt.selenium.active')) {
2318
Configure::load('PassboltSeleniumApi.config', 'default', true);
24-
if (file_exists(TMP . 'selenium' . DS . 'core_extra_config.php')) {
25-
Configure::config('extra_config', new PhpConfig(TMP . 'selenium' . DS));
26-
Configure::load('core_extra_config', 'extra_config', true);
27-
}
2819
}

config/config.php

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
'unlockedActions' => [
1010
'Config' => ['setExtraConfig']
1111
]
12+
],
13+
'endpoints' => [
14+
'reset' => filter_var(env('PASSBOLT_PLUGIN_SELENIUM_API_SECURITY_ENDPOINTS_RESET', false), FILTER_VALIDATE_BOOLEAN),
15+
'error' => filter_var(env('PASSBOLT_PLUGIN_SELENIUM_API_SECURITY_ENDPOINTS_ERROR', true), FILTER_VALIDATE_BOOLEAN),
16+
'email' => filter_var(env('PASSBOLT_PLUGIN_SELENIUM_API_SECURITY_ENDPOINTS_EMAIL', true), FILTER_VALIDATE_BOOLEAN),
1217
]
1318
],
1419
]

config/routes.php

+25-26
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,43 @@
1414
*/
1515

1616
/** @var \Cake\Routing\RouteBuilder $routes */
17+
use Cake\Core\Configure;
1718

1819
/**
1920
* Selenium tests routes
2021
*/
2122
$routes->plugin('PassboltSeleniumApi', ['path' => '/seleniumtests'], function ($routes) {
2223
$routes->setExtensions(['json']);
2324

24-
$routes->connect('/resetInstance/{dataset}', ['controller' => 'ResetInstance', 'action' => 'resetInstance'])
25-
->setPass(['dataset'])
26-
->setMethods(['GET']);
25+
if (Configure::read('passbolt.plugins.selenium_api.security.endpoints.reset')) {
26+
$routes->connect('/resetInstance/{dataset}', ['controller' => 'ResetInstance', 'action' => 'resetInstance'])
27+
->setPass(['dataset'])
28+
->setMethods(['GET']);
29+
}
2730

28-
$routes->connect('/config', ['controller' => 'Config', 'action' => 'index'])
29-
->setMethods(['GET']);
31+
if (Configure::read('passbolt.plugins.selenium_api.security.endpoints.error')) {
32+
$routes->connect('/error400', ['controller' => 'SimulateError', 'action' => 'error400'])
33+
->setMethods(['GET']);
3034

31-
$routes->connect('/setExtraConfig', ['controller' => 'Config', 'action' => 'setExtraConfig'])
32-
->setMethods(['POST']);
35+
$routes->connect('/error404', ['controller' => 'SimulateError', 'action' => 'error404'])
36+
->setMethods(['GET']);
3337

34-
$routes->connect('/resetExtraConfig', ['controller' => 'Config', 'action' => 'resetExtraConfig'])
35-
->setMethods(['GET']);
38+
$routes->connect('/error403', ['controller' => 'SimulateError', 'action' => 'error403'])
39+
->setMethods(['GET']);
3640

37-
$routes->connect('/error400', ['controller' => 'SimulateError', 'action' => 'error400'])
38-
->setMethods(['GET']);
41+
$routes->connect('/error500', ['controller' => 'SimulateError', 'action' => 'error500'])
42+
->setMethods(['GET']);
43+
}
3944

40-
$routes->connect('/error404', ['controller' => 'SimulateError', 'action' => 'error404'])
41-
->setMethods(['GET']);
45+
if (Configure::read('passbolt.plugins.selenium_api.security.endpoints.email')) {
46+
$routes->connect('/showlastemail/{username}', ['controller' => 'Email', 'action' => 'showLastEmail'])
47+
->setPass(['username'])
48+
->setMethods(['GET']);
4249

43-
$routes->connect('/error403', ['controller' => 'SimulateError', 'action' => 'error403'])
44-
->setMethods(['GET']);
50+
// Legacy v1 backward compatibility routes
51+
$routes->connect('/showLastEmail/{username}', ['controller' => 'Email', 'action' => 'showLastEmail'])
52+
->setPass(['username'])
53+
->setMethods(['GET']);
54+
}
4555

46-
$routes->connect('/error500', ['controller' => 'SimulateError', 'action' => 'error500'])
47-
->setMethods(['GET']);
48-
49-
$routes->connect('/showlastemail/{username}', ['controller' => 'Email', 'action' => 'showLastEmail'])
50-
->setPass(['username'])
51-
->setMethods(['GET']);
52-
53-
// Legacy v1 backward compatibility routes
54-
$routes->connect('/showLastEmail/{username}', ['controller' => 'Email', 'action' => 'showLastEmail'])
55-
->setPass(['username'])
56-
->setMethods(['GET']);
5756
});

src/Controller/ConfigController.php

-90
This file was deleted.

tests/TestCase/Controller/ConfigControllerTest.php

-74
This file was deleted.

tests/TestCase/Controller/SimulateErrorsControllerTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,34 @@
1616

1717
use App\Test\Lib\AppIntegrationTestCase;
1818
use Cake\Core\Configure;
19+
use PassboltSeleniumApi\Controller\ConfigController;
1920

2021
class SimulateErrorsControllerTest extends AppIntegrationTestCase
2122
{
23+
/** @var bool error endpoint flag */
24+
private $default;
25+
26+
/**
27+
* @return void
28+
*/
29+
public function setUp(): void
30+
{
31+
parent::setUp();
32+
$this->default = Configure::read('passbolt.plugins.selenium_api.security.endpoints.error');
33+
Configure::write('passbolt.plugins.selenium_api.security.endpoints.error', true);
34+
}
35+
36+
/**
37+
* Clears the state used for tests.
38+
*
39+
* @return void
40+
*/
41+
public function tearDown(): void
42+
{
43+
Configure::write('passbolt.plugins.selenium_api.security.endpoints.error', $this->default);
44+
parent::tearDown();
45+
}
46+
2247
public function testSimulateError404()
2348
{
2449
$this->getJson('/seleniumtests/error404.json');

0 commit comments

Comments
 (0)