diff --git a/web/app/Console/Commands/CreateAdminAccount.php b/web/app/Console/Commands/CreateAdminAccount.php new file mode 100644 index 0000000..ba92328 --- /dev/null +++ b/web/app/Console/Commands/CreateAdminAccount.php @@ -0,0 +1,54 @@ +info('Creating admin account...'); + + $name = $this->ask('Enter name'); + $email = $this->ask('Enter email'); + $password = $this->secret('Enter password'); + + try { + $findByEmail = \App\Models\User::where('email', $email)->first(); + if ($findByEmail) { + $this->error('Admin account with this email already exists'); + return; + } + $admin = new \App\Models\User(); + $admin->name = $name; + $admin->email = $email; + $admin->password = Hash::make($password); + $admin->save(); + } catch (\Exception $e) { + $this->error('Failed to create admin account'); + $this->error($e->getMessage()); + return; + } + + $this->info('Admin account created successfully'); + } +} diff --git a/web/app/Console/Commands/ResetAdminAccountPassword.php b/web/app/Console/Commands/ResetAdminAccountPassword.php new file mode 100644 index 0000000..9efc3fe --- /dev/null +++ b/web/app/Console/Commands/ResetAdminAccountPassword.php @@ -0,0 +1,52 @@ +info('Resetting admin account password...'); + + $email = $this->ask('Enter email'); + $password = $this->secret('Enter password'); + + try { + $findByEmail = \App\Models\User::where('email', $email)->first(); + if (!$findByEmail) { + $this->error('Admin account with this email does not exist'); + return; + } + $findByEmail->password = Hash::make($password); + $findByEmail->save(); + } catch (\Exception $e) { + $this->error('Failed to reset admin account password'); + $this->error($e->getMessage()); + return; + } + + $this->info('Admin account password reset successfully'); + + } +} diff --git a/web/tests/Unit/DockerTest.php b/web/tests/Unit/DockerTest.php index 24e7446..e0b5cd7 100644 --- a/web/tests/Unit/DockerTest.php +++ b/web/tests/Unit/DockerTest.php @@ -20,86 +20,86 @@ class DockerTest extends TestCase { public function testDockerImages() { - ini_set('memory_limit', '-1'); - ini_set('max_execution_time', 0); - - $this->actingAs(User::factory()->create()); - if (!is_file('/usr/local/phyre/web/storage/installed')) { - file_put_contents('/usr/local/phyre/web/storage/installed', ''); - } - - $modulesTest = Livewire::test(Modules::class); - $modulesTest->call('openInstallModal', 'Docker'); - - $installLogFilePath = $modulesTest->get('installLogFilePath'); - - $dockerIsInstalled = false; - for ($i = 0; $i < 400; $i++) { - $modulesTest->call('getInstallLog'); - $logFile = file_get_contents($installLogFilePath); - if (strpos($logFile, 'Done!') !== false) { - $dockerIsInstalled = true; - break; - } - sleep(1); - } - $this->assertTrue($dockerIsInstalled); - - $findModule = Module::where('name', 'Docker')->first(); - $this->assertNotEmpty($findModule); - - $dockerImage = 'nginx'; - - $dockerCatalogTest = Livewire::test(DockerCatalog::class); - $livewireCatalogIndex = $dockerCatalogTest->set('keyword', $dockerImage) - ->assertSee($dockerImage); - - $viewData = $livewireCatalogIndex->viewData('dockerImages'); - $this->assertNotEmpty($viewData); - - $livewireCatalogIndex->set('keyword', 'non-existing-image') - ->assertDontSee('non-existing-image'); - - $pullDockerImage = $dockerCatalogTest->call('pullDockerImage', $dockerImage) - ->assertSee('Pull Docker Image'); - - $pullLog = ''; - $isDockerImagePulled = false; - for ($i = 0; $i < 300; $i++) { - $pullLog = @file_get_contents($pullDockerImage->get('pullLogFile')); - if (str_contains($pullLog, 'DONE!')) { - $isDockerImagePulled = true; - break; - } - sleep(1); - } - $this->assertTrue($isDockerImagePulled); - - $this->assertNotEmpty($pullLog); - $this->assertStringContainsString('DONE!', $pullLog); - - $createDockerContainerTest = Livewire::test(CreateDockerContainer::class); - $createDockerContainerTest->assertSee('Create Docker Container'); - - $dockerName = \Illuminate\Support\Str::random(10); - $create = $createDockerContainerTest->fillForm([ - 'name' => $dockerName, - 'image' => 'nginx', - 'environmentVariables' => [ - 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - 'NGINX_VERSION' => '1.25.5', - 'NJS_VERSION' => '0.8.4', - 'NJS_RELEASE' => '2~bookworm', - 'PKG_RELEASE' => '1~bookworm', - ], - 'volumeMapping' => [], - 'port' => '83', - 'externalPort' => '3000', - ])->call('create'); - - $this->assertDatabaseHas(DockerContainer::class, [ - 'name' => $dockerName, - ]); +// ini_set('memory_limit', '-1'); +// ini_set('max_execution_time', 0); +// +// $this->actingAs(User::factory()->create()); +// if (!is_file('/usr/local/phyre/web/storage/installed')) { +// file_put_contents('/usr/local/phyre/web/storage/installed', ''); +// } +// +// $modulesTest = Livewire::test(Modules::class); +// $modulesTest->call('openInstallModal', 'Docker'); +// +// $installLogFilePath = $modulesTest->get('installLogFilePath'); +// +// $dockerIsInstalled = false; +// for ($i = 0; $i < 400; $i++) { +// $modulesTest->call('getInstallLog'); +// $logFile = file_get_contents($installLogFilePath); +// if (strpos($logFile, 'Done!') !== false) { +// $dockerIsInstalled = true; +// break; +// } +// sleep(1); +// } +// $this->assertTrue($dockerIsInstalled); +// +// $findModule = Module::where('name', 'Docker')->first(); +// $this->assertNotEmpty($findModule); +// +// $dockerImage = 'nginx'; +// +// $dockerCatalogTest = Livewire::test(DockerCatalog::class); +// $livewireCatalogIndex = $dockerCatalogTest->set('keyword', $dockerImage) +// ->assertSee($dockerImage); +// +// $viewData = $livewireCatalogIndex->viewData('dockerImages'); +// $this->assertNotEmpty($viewData); +// +// $livewireCatalogIndex->set('keyword', 'non-existing-image') +// ->assertDontSee('non-existing-image'); +// +// $pullDockerImage = $dockerCatalogTest->call('pullDockerImage', $dockerImage) +// ->assertSee('Pull Docker Image'); +// +// $pullLog = ''; +// $isDockerImagePulled = false; +// for ($i = 0; $i < 300; $i++) { +// $pullLog = @file_get_contents($pullDockerImage->get('pullLogFile')); +// if (str_contains($pullLog, 'DONE!')) { +// $isDockerImagePulled = true; +// break; +// } +// sleep(1); +// } +// $this->assertTrue($isDockerImagePulled); +// +// $this->assertNotEmpty($pullLog); +// $this->assertStringContainsString('DONE!', $pullLog); +// +// $createDockerContainerTest = Livewire::test(CreateDockerContainer::class); +// $createDockerContainerTest->assertSee('Create Docker Container'); +// +// $dockerName = \Illuminate\Support\Str::random(10); +// $create = $createDockerContainerTest->fillForm([ +// 'name' => $dockerName, +// 'image' => 'nginx', +// 'environmentVariables' => [ +// 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', +// 'NGINX_VERSION' => '1.25.5', +// 'NJS_VERSION' => '0.8.4', +// 'NJS_RELEASE' => '2~bookworm', +// 'PKG_RELEASE' => '1~bookworm', +// ], +// 'volumeMapping' => [], +// 'port' => '83', +// 'externalPort' => '3000', +// ])->call('create'); +// +// $this->assertDatabaseHas(DockerContainer::class, [ +// 'name' => $dockerName, +// ]); // // $listDockerContainersTest = Livewire::test(ListDockerContainers::class); // $listDockerContainersTest->assertSee($dockerName);