-
-
Couldn't load subscription status.
- Fork 3.1k
fix: server URL generation in ServerPatchCheck notification #7018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrasbacsai
merged 5 commits into
coollabsio:next
from
Cinzya:hotfix/serverpatch-notification-url
Oct 27, 2025
+147
−4
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e29b517
fix: server URL generation in ServerPatchCheck notification
Cinzya c16844d
test: add unit tests for ServerPatchCheck notification URL generation
Cinzya c4bfbad
Merge branch 'next' into hotfix/serverpatch-notification-url
Cinzya bceef41
refactor: remove staging URL logic from ServerPatchCheck constructor
Cinzya 35b1044
test: fix ServerPatchCheckNotification tests to avoid global state po…
Cinzya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| <?php | ||
|
|
||
| use App\Models\InstanceSettings; | ||
| use App\Models\Server; | ||
| use App\Notifications\Server\ServerPatchCheck; | ||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
|
||
| uses(RefreshDatabase::class); | ||
|
|
||
| beforeEach(function () { | ||
| // Create a real InstanceSettings record in the test database | ||
| // This avoids Mockery alias/overload issues that pollute global state | ||
| $this->setInstanceSettings = function ($fqdn = null, $publicIpv4 = null, $publicIpv6 = null) { | ||
| InstanceSettings::query()->delete(); | ||
| InstanceSettings::create([ | ||
| 'id' => 0, | ||
| 'fqdn' => $fqdn, | ||
| 'public_ipv4' => $publicIpv4, | ||
| 'public_ipv6' => $publicIpv6, | ||
| ]); | ||
| }; | ||
|
|
||
| $this->createMockServer = function ($uuid, $name = 'Test Server') { | ||
| $mockServer = Mockery::mock(Server::class); | ||
| $mockServer->shouldReceive('getAttribute') | ||
| ->with('uuid') | ||
| ->andReturn($uuid); | ||
| $mockServer->shouldReceive('getAttribute') | ||
| ->with('name') | ||
| ->andReturn($name); | ||
| $mockServer->shouldReceive('setAttribute')->andReturnSelf(); | ||
| $mockServer->shouldReceive('getSchemalessAttributes')->andReturn([]); | ||
| $mockServer->uuid = $uuid; | ||
| $mockServer->name = $name; | ||
|
|
||
| return $mockServer; | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| Mockery::close(); | ||
| }); | ||
|
|
||
| it('generates url using base_url instead of APP_URL', function () { | ||
| // Set InstanceSettings to return a specific FQDN | ||
| ($this->setInstanceSettings)('https://coolify.example.com'); | ||
|
|
||
| $mockServer = ($this->createMockServer)('test-server-uuid'); | ||
|
|
||
| $patchData = [ | ||
| 'total_updates' => 5, | ||
| 'updates' => [], | ||
| 'osId' => 'ubuntu', | ||
| 'package_manager' => 'apt', | ||
| ]; | ||
|
|
||
| $notification = new ServerPatchCheck($mockServer, $patchData); | ||
|
|
||
| // The URL should use the FQDN from InstanceSettings, not APP_URL | ||
| expect($notification->serverUrl)->toBe('https://coolify.example.com/server/test-server-uuid/security/patches'); | ||
| }); | ||
|
|
||
| it('falls back to public_ipv4 with port when fqdn is not set', function () { | ||
| // Set InstanceSettings to return public IPv4 | ||
| ($this->setInstanceSettings)(null, '192.168.1.100'); | ||
|
|
||
| $mockServer = ($this->createMockServer)('test-server-uuid'); | ||
|
|
||
| $patchData = [ | ||
| 'total_updates' => 3, | ||
| 'updates' => [], | ||
| 'osId' => 'debian', | ||
| 'package_manager' => 'apt', | ||
| ]; | ||
|
|
||
| $notification = new ServerPatchCheck($mockServer, $patchData); | ||
|
|
||
| // The URL should use public IPv4 with default port 8000 | ||
| expect($notification->serverUrl)->toBe('http://192.168.1.100:8000/server/test-server-uuid/security/patches'); | ||
| }); | ||
andrasbacsai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it('includes server url in all notification channels', function () { | ||
| ($this->setInstanceSettings)('https://coolify.test'); | ||
|
|
||
| $mockServer = ($this->createMockServer)('abc-123', 'Test Server'); | ||
|
|
||
| $patchData = [ | ||
| 'total_updates' => 10, | ||
| 'updates' => [ | ||
| [ | ||
| 'package' => 'nginx', | ||
| 'current_version' => '1.18', | ||
| 'new_version' => '1.20', | ||
| 'architecture' => 'amd64', | ||
| 'repository' => 'main', | ||
| ], | ||
| ], | ||
| 'osId' => 'ubuntu', | ||
| 'package_manager' => 'apt', | ||
| ]; | ||
|
|
||
| $notification = new ServerPatchCheck($mockServer, $patchData); | ||
|
|
||
| // Check Discord | ||
| $discord = $notification->toDiscord(); | ||
| expect($discord->description)->toContain('https://coolify.test/server/abc-123/security/patches'); | ||
|
|
||
| // Check Telegram | ||
| $telegram = $notification->toTelegram(); | ||
| expect($telegram['buttons'][0]['url'])->toBe('https://coolify.test/server/abc-123/security/patches'); | ||
|
|
||
| // Check Pushover | ||
| $pushover = $notification->toPushover(); | ||
| expect($pushover->buttons[0]['url'])->toBe('https://coolify.test/server/abc-123/security/patches'); | ||
|
|
||
| // Check Slack | ||
| $slack = $notification->toSlack(); | ||
| expect($slack->description)->toContain('https://coolify.test/server/abc-123/security/patches'); | ||
|
|
||
| // Check Webhook | ||
| $webhook = $notification->toWebhook(); | ||
| expect($webhook['url'])->toBe('https://coolify.test/server/abc-123/security/patches'); | ||
| }); | ||
|
|
||
| it('uses correct url in error notifications', function () { | ||
| ($this->setInstanceSettings)('https://coolify.production.com'); | ||
|
|
||
| $mockServer = ($this->createMockServer)('error-server-uuid', 'Error Server'); | ||
|
|
||
| $patchData = [ | ||
| 'error' => 'Failed to connect to package manager', | ||
| 'osId' => 'ubuntu', | ||
| 'package_manager' => 'apt', | ||
| ]; | ||
|
|
||
| $notification = new ServerPatchCheck($mockServer, $patchData); | ||
|
|
||
| // Check error Discord notification | ||
| $discord = $notification->toDiscord(); | ||
| expect($discord->description)->toContain('https://coolify.production.com/server/error-server-uuid/security/patches'); | ||
|
|
||
| // Check error webhook | ||
| $webhook = $notification->toWebhook(); | ||
| expect($webhook['url'])->toBe('https://coolify.production.com/server/error-server-uuid/security/patches') | ||
| ->and($webhook['event'])->toBe('server_patch_check_error'); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.