From a1b64dba0175f23e2b96592fcd1f6a920da89ea7 Mon Sep 17 00:00:00 2001 From: tswagger Date: Mon, 18 Sep 2023 09:07:05 -0500 Subject: [PATCH] Added config copy to Setup script Signed-off-by: tswagger --- src/Commands/Setup.php | 13 +++++++++++++ tests/Commands/SetupTest.php | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index c9ced3efd..ce052b714 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -83,6 +83,7 @@ private function publishConfig(): void { $this->publishConfigAuth(); $this->publishConfigAuthGroups(); + $this->publishConfigAuthToken(); $this->setupHelper(); $this->setupRoutes(); @@ -131,6 +132,18 @@ private function publishConfigAuthGroups(): void $this->copyAndReplace($file, $replaces); } + private function publishConfigAuthToken(): void + { + $file = 'Config/AuthToken.php'; + $replaces = [ + 'namespace CodeIgniter\Shield\Config' => 'namespace Config', + 'use CodeIgniter\\Config\\BaseConfig;' => 'use CodeIgniter\\Shield\\Config\\AuthToken as ShieldAuthToken;', + 'extends BaseConfig' => 'extends ShieldAuthToken', + ]; + + $this->copyAndReplace($file, $replaces); + } + /** * Write a file, catching any exceptions and showing a * nicely formatted error. diff --git a/tests/Commands/SetupTest.php b/tests/Commands/SetupTest.php index 43225adf9..9a4281715 100644 --- a/tests/Commands/SetupTest.php +++ b/tests/Commands/SetupTest.php @@ -68,6 +68,10 @@ public function testRun(): void $this->assertStringContainsString('namespace Config;', $auth); $this->assertStringContainsString('use CodeIgniter\Shield\Config\Auth as ShieldAuth;', $auth); + $authToken = file_get_contents($appFolder . 'Config/AuthToken.php'); + $this->assertStringContainsString('namespace Config;', $authToken); + $this->assertStringContainsString('use CodeIgniter\Shield\Config\AuthToken as ShieldAuthToken;', $authToken); + $routes = file_get_contents($appFolder . 'Config/Routes.php'); $this->assertStringContainsString('service(\'auth\')->routes($routes);', $routes); @@ -79,6 +83,7 @@ public function testRun(): void $this->assertStringContainsString( ' Created: vfs://root/Config/Auth.php Created: vfs://root/Config/AuthGroups.php + Created: vfs://root/Config/AuthToken.php Updated: vfs://root/Controllers/BaseController.php Updated: vfs://root/Config/Routes.php Updated: We have updated file \'vfs://root/Config/Security.php\' for security reasons.',