Files
coolify/tests/Unit/ValidServerIpTest.php
T
Andras Bacsai f39c884cc7 fix(servers): support IPv6 server addresses everywhere
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.
2026-10-09 13:50:28 +02:00

51 lines
1.3 KiB
PHP

<?php
use App\Rules\ValidServerIp;
use Tests\TestCase;
uses(TestCase::class);
it('accepts private and reserved IP addresses like the next branch', function (string $ip) {
$rule = new ValidServerIp;
$failCalled = false;
$rule->validate('ip', $ip, function () use (&$failCalled): void {
$failCalled = true;
});
expect($failCalled)->toBeFalse();
})->with([
'private IPv4' => '192.168.1.10',
'loopback IPv4' => '127.0.0.1',
'link-local IPv4' => '169.254.1.10',
'loopback IPv6' => '::1',
'unique local IPv6' => 'fd00::1',
]);
it('accepts an IPv6 address in brackets', function (string $ip) {
$failCalled = false;
(new ValidServerIp)->validate('ip', $ip, function () use (&$failCalled): void {
$failCalled = true;
});
expect($failCalled)->toBeFalse();
})->with([
'short form' => '[2a01:4f8::1]',
'long form' => '[2A01:04F8:0000:0000:0000:0000:0000:0001]',
]);
it('rejects brackets around anything other than an IPv6 address', function (string $ip) {
$failCalled = false;
(new ValidServerIp)->validate('ip', $ip, function () use (&$failCalled): void {
$failCalled = true;
});
expect($failCalled)->toBeTrue();
})->with([
'IPv4' => '[192.168.1.10]',
'hostname' => '[server.example.com]',
'missing closing bracket' => '[2a01:4f8::1',
]);