Files
coolify/tests/Feature/RootUserSeederTest.php
Andras Bacsai 5d66fb719e fix(registration): time-limit first root account creation
Open root registration for ten minutes after startup, then require a Coolify restart to reopen it. Update installer credential handling and explain the setup window in the registration UI.
2026-10-26 10:49:19 +01:00

40 lines
1.1 KiB
PHP

<?php
use App\Models\InstanceSettings;
use App\Models\Team;
use App\Models\User;
use Database\Seeders\RootUserSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
uses(RefreshDatabase::class);
beforeEach(function () {
InstanceSettings::query()->forceCreate(['id' => 0, 'is_registration_enabled' => true]);
Team::factory()->create(['id' => 0, 'personal_team' => true]);
Http::fake(['api.pwnedpasswords.com/*' => Http::response('')]);
// The .env template of the installer has an empty ROOT_USERNAME line.
putenv('ROOT_USERNAME=');
putenv('ROOT_USER_EMAIL=root@coollabs.io');
putenv('ROOT_USER_PASSWORD=Rw-Seeder-Test-Aa1!');
});
afterEach(function () {
putenv('ROOT_USERNAME');
putenv('ROOT_USER_EMAIL');
putenv('ROOT_USER_PASSWORD');
});
it('creates the root user when ROOT_USERNAME is empty', function () {
ob_start();
(new RootUserSeeder)->run();
ob_end_clean();
expect(User::find(0))
->not->toBeNull()
->name->toBe('Root User')
->email->toBe('root@coollabs.io');
expect(InstanceSettings::find(0)->is_registration_enabled)->toBeFalse();
});