mirror of
https://github.com/coollabsio/coolify.git
synced 2026-10-29 01:54:37 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Furox <177975472+Furox-Art@users.noreply.github.com> Co-authored-by: johandenhollander <johan.den.hollander@finalist.nl> Co-authored-by: João Cruz <161638790+SrJooJ@users.noreply.github.com> Co-authored-by: Saim Hashmi <hashmisaim037@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
151 lines
5.1 KiB
PHP
151 lines
5.1 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Settings\Advanced;
|
|
use App\Models\InstanceSettings;
|
|
use App\Models\Server;
|
|
use App\Models\Team;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Once;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('instance admin can toggle registration via listbox instantSave', function () {
|
|
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
|
|
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
|
|
$settings = InstanceSettings::forceCreate([
|
|
'id' => 0,
|
|
'is_registration_enabled' => false,
|
|
'disable_two_step_confirmation' => false,
|
|
]);
|
|
Once::flush();
|
|
|
|
$user = User::factory()->create();
|
|
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
|
|
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => ['id' => $rootTeam->id]]);
|
|
|
|
Livewire::test(Advanced::class)
|
|
->assertSet('is_registration_enabled', false)
|
|
->assertSee('Registration')
|
|
->assertSee('Destructive action confirmation')
|
|
->assertDontSee('Only administrators can create accounts.')
|
|
->set('is_registration_enabled', true)
|
|
->call('instantSave')
|
|
->assertDispatched('success');
|
|
|
|
expect((bool) $settings->fresh()->is_registration_enabled)->toBeTrue();
|
|
});
|
|
|
|
test('instance admin can toggle two-step confirmation via listbox instantSave', function () {
|
|
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
|
|
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
|
|
$settings = InstanceSettings::forceCreate([
|
|
'id' => 0,
|
|
'is_registration_enabled' => true,
|
|
'disable_two_step_confirmation' => false,
|
|
]);
|
|
Once::flush();
|
|
|
|
$user = User::factory()->create();
|
|
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
|
|
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => ['id' => $rootTeam->id]]);
|
|
|
|
Livewire::test(Advanced::class)
|
|
->assertSet('disable_two_step_confirmation', false)
|
|
->set('disable_two_step_confirmation', true)
|
|
->call('instantSave')
|
|
->assertDispatched('success');
|
|
|
|
expect((bool) $settings->fresh()->disable_two_step_confirmation)->toBeTrue();
|
|
});
|
|
|
|
test('instance admin can configure the image CDN URL at runtime', function () {
|
|
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
|
|
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
|
|
$settings = InstanceSettings::forceCreate(['id' => 0]);
|
|
Once::flush();
|
|
|
|
$user = User::factory()->create();
|
|
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
|
|
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => ['id' => $rootTeam->id]]);
|
|
|
|
Livewire::test(Advanced::class)
|
|
->assertSee('Image CDN URL')
|
|
->set('image_cdn_url', 'https://images.example.com/media/')
|
|
->call('submit')
|
|
->assertHasNoErrors()
|
|
->assertDispatched('success');
|
|
|
|
expect($settings->fresh()->image_cdn_url)->toBe('https://images.example.com/media');
|
|
});
|
|
|
|
test('open API allowlist warning is hidden when API access is disabled', function () {
|
|
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
|
|
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
|
|
InstanceSettings::forceCreate([
|
|
'id' => 0,
|
|
'is_api_enabled' => false,
|
|
'allowed_ips' => null,
|
|
]);
|
|
Once::flush();
|
|
|
|
$user = User::factory()->create();
|
|
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
|
|
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => ['id' => $rootTeam->id]]);
|
|
|
|
Livewire::test(Advanced::class)
|
|
->assertSet('is_api_enabled', false)
|
|
->assertDontSee('API access is open to every source');
|
|
});
|
|
|
|
test('open API allowlist warning is shown when API access is enabled without allowlist', function () {
|
|
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
|
|
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
|
|
InstanceSettings::forceCreate([
|
|
'id' => 0,
|
|
'is_api_enabled' => true,
|
|
'allowed_ips' => null,
|
|
]);
|
|
Once::flush();
|
|
|
|
$user = User::factory()->create();
|
|
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
|
|
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => ['id' => $rootTeam->id]]);
|
|
|
|
Livewire::test(Advanced::class)
|
|
->assertSet('is_api_enabled', true)
|
|
->assertSee('API access is open to every source');
|
|
});
|
|
|
|
test('MCP endpoint callout links to API token management', function () {
|
|
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
|
|
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
|
|
InstanceSettings::forceCreate([
|
|
'id' => 0,
|
|
'is_api_enabled' => false,
|
|
'is_mcp_server_enabled' => true,
|
|
]);
|
|
Once::flush();
|
|
|
|
$user = User::factory()->create();
|
|
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
|
|
|
|
$this->actingAs($user);
|
|
session(['currentTeam' => ['id' => $rootTeam->id]]);
|
|
|
|
Livewire::test(Advanced::class)
|
|
->assertSee(url('/mcp'))
|
|
->assertSee('href="'.route('security.api-tokens').'"', false);
|
|
});
|