Skip to content

Commit

Permalink
Discover host vulnerabilities only if SUSE Manager is enabled (#2803)
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster authored Jul 23, 2024
1 parent 69d453b commit 1fd3f91
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ defmodule Trento.Infrastructure.Commanded.EventHandlers.SoftwareUpdatesDiscovery
SoftwareUpdatesHealthChanged
}

alias Trento.Settings

alias Trento.SoftwareUpdates.Discovery

def handle(
Expand All @@ -23,9 +25,14 @@ defmodule Trento.Infrastructure.Commanded.EventHandlers.SoftwareUpdatesDiscovery
},
_
) do
Discovery.discover_host_software_updates(host_id, fully_qualified_domain_name)

:ok
case Settings.get_suse_manager_settings() do
{:ok, _} ->
Discovery.discover_host_software_updates(host_id, fully_qualified_domain_name)
:ok

_ ->
:ok
end
end

def handle(%SoftwareUpdatesHealthChanged{host_id: host_id}, _) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ defmodule Trento.Infrastructure.Commanded.EventHandlers.SoftwareUpdatesDiscovery

describe "Discovering software updates" do
test "should discover software updates when a SoftwareUpdatesDiscoveryRequested is emitted" do
insert_software_updates_settings()

%SoftwareUpdatesDiscoveryRequested{
host_id: host_id,
fully_qualified_domain_name: fully_qualified_domain_name
Expand Down Expand Up @@ -66,7 +68,43 @@ defmodule Trento.Infrastructure.Commanded.EventHandlers.SoftwareUpdatesDiscovery
assert :ok = SoftwareUpdatesDiscoveryEventHandler.handle(event, %{})
end

test "should discover data about hosts just when SUSE Manager's settings are set" do
event = build(:software_updates_discovery_requested_event)

expect(
SoftwareUpdatesDiscoveryMock,
:get_system_id,
0,
fn _ -> :ok end
)

expect(
SoftwareUpdatesDiscoveryMock,
:get_relevant_patches,
0,
fn _ -> :ok end
)

expect(
SoftwareUpdatesDiscoveryMock,
:get_upgradable_packages,
0,
fn _ -> :ok end
)

expect(
Trento.Commanded.Mock,
:dispatch,
0,
fn _ -> :ok end
)

assert :ok = SoftwareUpdatesDiscoveryEventHandler.handle(event, %{})
end

test "should pass through failures" do
insert_software_updates_settings()

%SoftwareUpdatesDiscoveryRequested{
fully_qualified_domain_name: fully_qualified_domain_name
} = event = build(:software_updates_discovery_requested_event)
Expand Down

0 comments on commit 1fd3f91

Please sign in to comment.