mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04: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>
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Models\InstanceSettings;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Process;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Process::fake([
|
|
'curl -4s https://ifconfig.io' => "203.0.113.1\n",
|
|
'curl -6s https://ifconfig.io' => "2001:db8::1\n",
|
|
]);
|
|
});
|
|
|
|
it('detects the public IPs when the settings are empty', function () {
|
|
InstanceSettings::forceCreate(['id' => 0]);
|
|
|
|
get_public_ips();
|
|
|
|
$settings = InstanceSettings::find(0);
|
|
expect($settings->public_ipv4)->toBe('203.0.113.1')
|
|
->and($settings->public_ipv6)->toBe('2001:db8::1');
|
|
});
|
|
|
|
it('keeps public IPs that are already set', function () {
|
|
InstanceSettings::forceCreate(['id' => 0, 'public_ipv4' => '203.0.113.21', 'public_ipv6' => '2001:db8::21']);
|
|
|
|
get_public_ips();
|
|
|
|
$settings = InstanceSettings::find(0);
|
|
expect($settings->public_ipv4)->toBe('203.0.113.21')
|
|
->and($settings->public_ipv6)->toBe('2001:db8::21');
|
|
Process::assertNothingRan();
|
|
});
|
|
|
|
it('detects only the address family that is empty', function () {
|
|
InstanceSettings::forceCreate(['id' => 0, 'public_ipv4' => '203.0.113.21']);
|
|
|
|
get_public_ips();
|
|
|
|
$settings = InstanceSettings::find(0);
|
|
expect($settings->public_ipv4)->toBe('203.0.113.21')
|
|
->and($settings->public_ipv6)->toBe('2001:db8::1');
|
|
Process::assertNotRan('curl -4s https://ifconfig.io');
|
|
});
|
|
|
|
it('still detects IPv6 when the IPv4 lookup returns an invalid address', function () {
|
|
Process::fake([
|
|
'curl -4s https://ifconfig.io' => 'not-an-ip',
|
|
'curl -6s https://ifconfig.io' => "2001:db8::1\n",
|
|
]);
|
|
InstanceSettings::forceCreate(['id' => 0]);
|
|
|
|
get_public_ips();
|
|
|
|
$settings = InstanceSettings::find(0);
|
|
expect($settings->public_ipv4)->toBeNull()
|
|
->and($settings->public_ipv6)->toBe('2001:db8::1');
|
|
});
|