@@ -427,4 +427,68 @@ def test_flatpak_static_index_server_error
427427 assert_equal 500 , last_response . status
428428 assert_equal '{"error": "internal server error"}' , last_response . body
429429 end
430+
431+ def test_update_hosts_filters_nil_uuids
432+ hosts = [
433+ { 'uuid' => 'host-uuid-1' } ,
434+ { 'uuid' => nil } ,
435+ { 'uuid' => 'host-uuid-2' }
436+ ]
437+
438+ put '/update_hosts' , { 'hosts' => hosts }
439+ assert last_response . ok?
440+
441+ # Verify only valid hosts were inserted (old behavior would have failed or inserted nil)
442+ assert @database . connection [ :hosts ] . count >= 2
443+ assert_not_nil @database . connection [ :hosts ] . first ( uuid : 'host-uuid-1' )
444+ assert_not_nil @database . connection [ :hosts ] . first ( uuid : 'host-uuid-2' )
445+ end
446+
447+ def test_update_hosts_filters_empty_string_uuids
448+ hosts = [
449+ { 'uuid' => 'host-uuid-1' } ,
450+ { 'uuid' => '' } ,
451+ { 'uuid' => 'host-uuid-2' }
452+ ]
453+
454+ put '/update_hosts' , { 'hosts' => hosts }
455+ assert last_response . ok?
456+
457+ # Verify only valid hosts were inserted
458+ assert @database . connection [ :hosts ] . count >= 2
459+ assert_not_nil @database . connection [ :hosts ] . first ( uuid : 'host-uuid-1' )
460+ assert_not_nil @database . connection [ :hosts ] . first ( uuid : 'host-uuid-2' )
461+ end
462+
463+ def test_update_hosts_handles_missing_uuid_key
464+ hosts = [
465+ { 'uuid' => 'host-uuid-1' } ,
466+ { 'name' => 'host-without-uuid' } ,
467+ { 'uuid' => 'host-uuid-2' }
468+ ]
469+
470+ put '/update_hosts' , { 'hosts' => hosts }
471+ assert last_response . ok?
472+
473+ # Verify only valid hosts were inserted
474+ assert @database . connection [ :hosts ] . count >= 2
475+ assert_not_nil @database . connection [ :hosts ] . first ( uuid : 'host-uuid-1' )
476+ assert_not_nil @database . connection [ :hosts ] . first ( uuid : 'host-uuid-2' )
477+ end
478+
479+ def test_update_hosts_with_empty_array
480+ put '/update_hosts' , { 'hosts' => [ ] }
481+ assert last_response . ok?
482+ end
483+
484+ def test_update_hosts_with_all_invalid_uuids
485+ hosts = [
486+ { 'uuid' => nil } ,
487+ { 'uuid' => '' } ,
488+ { 'name' => 'no-uuid' }
489+ ]
490+
491+ put '/update_hosts' , { 'hosts' => hosts }
492+ assert last_response . ok?
493+ end
430494end
0 commit comments