mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
Store server IPs in one form (no brackets, short lower-case IPv6) and write each address in the form its context needs: - URLs and host:port (Sentinel, database URLs, SFTP backup download, DNS servers, SMTP, webhook base URLs, links, health checks) get brackets through formatHostForUrl(). - Traefik Host() rules use the address without brackets, so IPv6 domains no longer return 404; saved labels are fixed at deploy. Caddy keeps the brackets. - SSH keeps the plain address. - Hetzner gives an IPv6 /64 network; IPv6-only servers now get the server address (prefix::1) instead of the unusable prefix::64. - sslip labels, registry image names with an IPv6 host, the API domain list, allowlist matching and duplicate checks handle IPv6. A migration normalizes stored IPv6 server addresses, repairs Hetzner servers saved as ::64 that are not reachable, and adds brackets to saved Sentinel URLs.
144 lines
5.7 KiB
PHP
144 lines
5.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Application;
|
|
use App\Models\Environment;
|
|
use App\Models\InstanceSettings;
|
|
use App\Models\Project;
|
|
use App\Models\Server;
|
|
use App\Models\StandaloneDocker;
|
|
use App\Models\Team;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
InstanceSettings::forceCreate(['id' => 0, 'is_api_enabled' => true]);
|
|
|
|
$this->team = Team::factory()->create();
|
|
$this->user = User::factory()->create();
|
|
$this->team->members()->attach($this->user->id, ['role' => 'owner']);
|
|
|
|
session(['currentTeam' => $this->team]);
|
|
$this->token = $this->user->createToken('test-token', ['*']);
|
|
$this->bearerToken = $this->token->plainTextToken;
|
|
|
|
$this->server = Server::factory()->create(['team_id' => $this->team->id]);
|
|
$this->destination = StandaloneDocker::where('server_id', $this->server->id)->first();
|
|
$this->project = Project::factory()->create(['team_id' => $this->team->id]);
|
|
$this->environment = Environment::factory()->create(['project_id' => $this->project->id]);
|
|
});
|
|
|
|
function domainApiAuthHeaders(): array
|
|
{
|
|
return [
|
|
'Authorization' => 'Bearer '.test()->bearerToken,
|
|
];
|
|
}
|
|
|
|
test('returns domains for own team application via uuid query param', function () {
|
|
$application = Application::factory()->create([
|
|
'fqdn' => 'https://my-app.example.com',
|
|
'environment_id' => $this->environment->id,
|
|
'destination_id' => $this->destination->id,
|
|
'destination_type' => $this->destination->getMorphClass(),
|
|
]);
|
|
|
|
$response = $this->withHeaders(domainApiAuthHeaders())
|
|
->getJson("/api/v1/servers/{$this->server->uuid}/domains?uuid={$application->uuid}");
|
|
|
|
$response->assertOk();
|
|
$response->assertExactJson(['https://my-app.example.com']);
|
|
});
|
|
|
|
test('returns 404 when application uuid belongs to another team', function () {
|
|
$otherTeam = Team::factory()->create();
|
|
$otherUser = User::factory()->create();
|
|
$otherTeam->members()->attach($otherUser->id, ['role' => 'owner']);
|
|
|
|
$otherServer = Server::factory()->create(['team_id' => $otherTeam->id]);
|
|
$otherDestination = StandaloneDocker::where('server_id', $otherServer->id)->first();
|
|
$otherProject = Project::factory()->create(['team_id' => $otherTeam->id]);
|
|
$otherEnvironment = Environment::factory()->create(['project_id' => $otherProject->id]);
|
|
|
|
$otherApplication = Application::factory()->create([
|
|
'fqdn' => 'https://secret-app.internal.company.com',
|
|
'environment_id' => $otherEnvironment->id,
|
|
'destination_id' => $otherDestination->id,
|
|
'destination_type' => $otherDestination->getMorphClass(),
|
|
]);
|
|
|
|
$response = $this->withHeaders(domainApiAuthHeaders())
|
|
->getJson("/api/v1/servers/{$this->server->uuid}/domains?uuid={$otherApplication->uuid}");
|
|
|
|
$response->assertNotFound();
|
|
$response->assertJson(['message' => 'Application not found.']);
|
|
});
|
|
|
|
test('returns 404 for nonexistent application uuid', function () {
|
|
$response = $this->withHeaders(domainApiAuthHeaders())
|
|
->getJson("/api/v1/servers/{$this->server->uuid}/domains?uuid=nonexistent-uuid");
|
|
|
|
$response->assertNotFound();
|
|
$response->assertJson(['message' => 'Application not found.']);
|
|
});
|
|
|
|
test('returns 404 when server uuid belongs to another team', function () {
|
|
$otherTeam = Team::factory()->create();
|
|
$otherUser = User::factory()->create();
|
|
$otherTeam->members()->attach($otherUser->id, ['role' => 'owner']);
|
|
|
|
$otherServer = Server::factory()->create(['team_id' => $otherTeam->id]);
|
|
|
|
$response = $this->withHeaders(domainApiAuthHeaders())
|
|
->getJson("/api/v1/servers/{$otherServer->uuid}/domains");
|
|
|
|
$response->assertNotFound();
|
|
$response->assertJson(['message' => 'Server not found.']);
|
|
});
|
|
|
|
test('only returns domains for applications on the specified server', function () {
|
|
$application = Application::factory()->create([
|
|
'fqdn' => 'https://app-on-server.example.com',
|
|
'environment_id' => $this->environment->id,
|
|
'destination_id' => $this->destination->id,
|
|
'destination_type' => $this->destination->getMorphClass(),
|
|
]);
|
|
|
|
$otherServer = Server::factory()->create(['team_id' => $this->team->id]);
|
|
$otherDestination = StandaloneDocker::where('server_id', $otherServer->id)->first();
|
|
|
|
$applicationOnOtherServer = Application::factory()->create([
|
|
'fqdn' => 'https://app-on-other-server.example.com',
|
|
'environment_id' => $this->environment->id,
|
|
'destination_id' => $otherDestination->id,
|
|
'destination_type' => $otherDestination->getMorphClass(),
|
|
]);
|
|
|
|
$response = $this->withHeaders(domainApiAuthHeaders())
|
|
->getJson("/api/v1/servers/{$this->server->uuid}/domains");
|
|
|
|
$response->assertOk();
|
|
$responseContent = $response->json();
|
|
$allDomains = collect($responseContent)->pluck('domains')->flatten()->toArray();
|
|
expect($allDomains)->toContain('app-on-server.example.com');
|
|
expect($allDomains)->not->toContain('app-on-other-server.example.com');
|
|
});
|
|
|
|
test('returns IPv6 hosts with brackets and without the port', function () {
|
|
$application = Application::factory()->create([
|
|
'environment_id' => $this->environment->id,
|
|
'destination_id' => $this->destination->id,
|
|
'destination_type' => $this->destination->getMorphClass(),
|
|
]);
|
|
Application::query()->whereKey($application->id)->update([
|
|
'fqdn' => 'http://[2a01:4f8::1]:8080,https://app.example.com:8443/api,http://192.0.2.10:3000',
|
|
]);
|
|
|
|
$response = $this->withHeaders(domainApiAuthHeaders())
|
|
->getJson("/api/v1/servers/{$this->server->uuid}/domains");
|
|
|
|
$response->assertOk();
|
|
expect($response->json('0.domains'))->toBe(['[2a01:4f8::1]', 'app.example.com', '192.0.2.10']);
|
|
});
|