Skip to content
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

Discover host vulnerabilities only if SUSE Manager is enabled #2803

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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