-
Notifications
You must be signed in to change notification settings - Fork 8
Fixes #38862 - Handle nil host UUIDs properly #60
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
+121
−1
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -427,4 +427,71 @@ def test_flatpak_static_index_server_error | |
| assert_equal 500, last_response.status | ||
| assert_equal '{"error": "internal server error"}', last_response.body | ||
| end | ||
|
|
||
| def test_update_hosts_filters_nil_uuids | ||
| hosts = [ | ||
| { 'uuid' => 'host-uuid-1' }, | ||
| { 'uuid' => nil }, | ||
| { 'uuid' => 'host-uuid-2' } | ||
| ] | ||
|
|
||
| put '/update_hosts', { 'hosts' => hosts } | ||
| assert last_response.ok? | ||
|
|
||
| # Verify only valid hosts were inserted (old behavior would have failed or inserted nil) | ||
| assert @database.connection[:hosts].count >= 2 | ||
| assert_not_nil @database.connection[:hosts].first(uuid: 'host-uuid-1') | ||
| assert_not_nil @database.connection[:hosts].first(uuid: 'host-uuid-2') | ||
| end | ||
|
|
||
| def test_update_hosts_filters_empty_string_uuids | ||
| hosts = [ | ||
| { 'uuid' => 'host-uuid-1' }, | ||
| { 'uuid' => '' }, | ||
| { 'uuid' => 'host-uuid-2' } | ||
| ] | ||
|
|
||
| put '/update_hosts', { 'hosts' => hosts } | ||
| assert last_response.ok? | ||
|
|
||
| # Verify only valid hosts were inserted | ||
| assert @database.connection[:hosts].count >= 2 | ||
| assert_not_nil @database.connection[:hosts].first(uuid: 'host-uuid-1') | ||
| assert_not_nil @database.connection[:hosts].first(uuid: 'host-uuid-2') | ||
| end | ||
|
|
||
| def test_update_hosts_handles_missing_uuid_key | ||
| hosts = [ | ||
| { 'uuid' => 'host-uuid-1' }, | ||
| { 'name' => 'host-without-uuid' }, | ||
| { 'uuid' => 'host-uuid-2' } | ||
| ] | ||
|
|
||
| put '/update_hosts', { 'hosts' => hosts } | ||
| assert last_response.ok? | ||
|
|
||
| # Verify only valid hosts were inserted | ||
| assert @database.connection[:hosts].count >= 2 | ||
| assert_not_nil @database.connection[:hosts].first(uuid: 'host-uuid-1') | ||
| assert_not_nil @database.connection[:hosts].first(uuid: 'host-uuid-2') | ||
| end | ||
|
|
||
| def test_update_hosts_with_empty_array | ||
| put '/update_hosts', { 'hosts' => [] } | ||
| assert last_response.ok? | ||
| end | ||
|
|
||
| def test_update_hosts_with_all_invalid_uuids | ||
| hosts = [ | ||
| { 'uuid' => nil }, | ||
| { 'uuid' => '' }, | ||
| { 'name' => 'no-uuid' } | ||
| ] | ||
|
|
||
| put '/update_hosts', { 'hosts' => hosts } | ||
| assert last_response.ok? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't verify that no hosts were added to the DB. |
||
|
|
||
| # Verify that no hosts were added to the DB | ||
| assert_equal 0, @database.connection[:hosts].count | ||
| end | ||
| end | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a test with nil UUIDs in
test/container_gateway_backend_test.rb?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used claude and it added some tests that cover some blank uuid cases.. 🤖