Files
coolify/tests/Unit/ConfigurationRepositoryMailConfigTest.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

79 lines
2.7 KiB
PHP

<?php
use App\Services\ConfigurationRepository;
use Illuminate\Config\Repository;
it('configures the laravel smtp scheme from encryption', function (string $mode, int $port, string $scheme, ?string $encryption, string $autoTls) {
$config = new Repository;
$repository = new ConfigurationRepository($config);
$repository->updateMailConfig((object) [
'resend_enabled' => false,
'smtp_enabled' => true,
'smtp_encryption' => $mode,
'smtp_host' => 'smtp.example.com',
'smtp_port' => $port,
'smtp_username' => 'user',
'smtp_password' => 'secret',
'smtp_timeout' => null,
'smtp_from_address' => 'from@example.com',
'smtp_from_name' => 'Coolify',
]);
expect($config->get('mail.mailers.smtp.scheme'))->toBe($scheme)
->and($config->get('mail.mailers.smtp.encryption'))->toBe($encryption)
->and($config->get('mail.mailers.smtp.auto_tls'))->toBe($autoTls);
})->with([
'none on port 465' => ['none', 465, 'smtp', null, '0'],
'tls on a non-465 port' => ['tls', 587, 'smtps', 'tls', ''],
]);
it('preserves the configured smtp ehlo domain', function () {
$config = new Repository([
'mail' => [
'mailers' => [
'smtp' => ['local_domain' => 'coolify.example.com'],
],
],
]);
$repository = new ConfigurationRepository($config);
$repository->updateMailConfig((object) [
'resend_enabled' => false,
'smtp_enabled' => true,
'smtp_encryption' => 'starttls',
'smtp_host' => 'smtp-relay.gmail.com',
'smtp_port' => 587,
'smtp_username' => null,
'smtp_password' => null,
'smtp_timeout' => null,
'smtp_from_address' => 'from@example.com',
'smtp_from_name' => 'Coolify',
]);
expect($config->get('mail.mailers.smtp.local_domain'))->toBe('coolify.example.com');
});
it('brackets an IPv6 smtp host in the laravel mail config', function (string $host, string $expected) {
$config = new Repository;
(new ConfigurationRepository($config))->updateMailConfig((object) [
'resend_enabled' => false,
'smtp_enabled' => true,
'smtp_encryption' => 'starttls',
'smtp_host' => $host,
'smtp_port' => 587,
'smtp_username' => null,
'smtp_password' => null,
'smtp_timeout' => null,
'smtp_from_address' => 'from@example.com',
'smtp_from_name' => 'Coolify',
]);
expect($config->get('mail.mailers.smtp.host'))->toBe($expected);
})->with([
'raw IPv6' => ['2001:db8::25', '[2001:db8::25]'],
'bracketed IPv6' => ['[2001:db8::25]', '[2001:db8::25]'],
'hostname' => ['smtp.example.com', 'smtp.example.com'],
]);