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

Redact sensitive data in SUMA GenServer state #2381

Merged
merged 1 commit into from
Mar 4, 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
16 changes: 16 additions & 0 deletions lib/trento/infrastructure/software_updates/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma.State do
@moduledoc """
State for the SUMA Software Updates discovery adapter
"""
alias __MODULE__

defstruct [
:url,
Expand All @@ -18,4 +19,19 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma.State do
ca_cert: String.t() | nil,
auth: String.t() | nil
}

defimpl Inspect, for: State do
def inspect(%State{url: url, username: username}, opts) do
Inspect.Map.inspect(
%{
url: url,
username: username,
password: "<REDACTED>",
auth: "<REDACTED>",
ca_cert: "<REDACTED>"
},
opts
)
end
end
end
44 changes: 44 additions & 0 deletions test/trento/infrastructure/software_updates/suma_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,50 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
assert :sys.get_state(Suma.identify()) == expected_state
assert :sys.get_state(Suma.identify(@test_integration_name)) == expected_state
end

test "should redact sensitive data in SUMA state", %{
settings: %Settings{url: url, username: username, password: password}
} do
{:ok, _} = start_supervised({Suma, @test_integration_name})

base_api_url = "#{url}/rhn/manager/api"
ignored_cookie = "pxt-session-cookie=1234"
auth_cookie = "pxt-session-cookie=4321"

expect(SumaApiMock, :login, fn ^base_api_url, ^username, ^password ->
{:ok,
%HTTPoison.Response{
status_code: 200,
headers: [
{"Set-Cookie",
"JSESSIONID=FOOBAR; Path=/; Secure; HttpOnly; HttpOnly;HttpOnly;Secure"},
{"Set-Cookie",
"#{ignored_cookie}; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/; Secure; HttpOnly;HttpOnly;Secure"},
{"Set-Cookie",
"#{auth_cookie}; Max-Age=3600; Expires=Mon, 4 Mar 2024 10:53:57 GMT; Path=/; Secure; HttpOnly;HttpOnly;Secure"}
]
}}
end)

assert :ok = Suma.setup(@test_integration_name)

expected = %{
url: url,
username: username,
password: "<REDACTED>",
ca_cert: "<REDACTED>",
auth: "<REDACTED>"
}

{output, _} =
@test_integration_name
|> Suma.identify()
|> :sys.get_state()
|> inspect
|> Code.eval_string()

assert expected == output
end
end

describe "Setting up SUMA integration service" do
Expand Down
Loading