Skip to content

Commit d895a0a

Browse files
committed
revert changes on elixir suma mock and refresh api key in after hook in settings tests
1 parent f5dc72d commit d895a0a

5 files changed

Lines changed: 238 additions & 160 deletions

File tree

lib/trento/infrastructure/software_updates/adapter/mock_suma.ex

Lines changed: 115 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ defmodule Trento.Infrastructure.SoftwareUpdates.MockSuma do
55

66
@behaviour Trento.SoftwareUpdates.Discovery.Gen
77

8-
alias Trento.Support.StructHelper
9-
108
@impl true
119
def setup, do: :ok
1210

@@ -22,94 +20,161 @@ defmodule Trento.Infrastructure.SoftwareUpdates.MockSuma do
2220
def get_relevant_patches(system_id) do
2321
if system_id in mocked_relevant_patches_system_ids() do
2422
{:ok,
25-
get_mock_data()
26-
|> Map.get("relevant_patches")
27-
|> Enum.map(fn patch ->
28-
patch
29-
|> StructHelper.to_atomized_map()
30-
|> Map.update!(:advisory_type, &String.to_existing_atom/1)
31-
end)}
23+
[
24+
%{
25+
date: "2024-02-27",
26+
advisory_name: "SUSE-15-SP4-2024-630",
27+
advisory_type: :bugfix,
28+
advisory_status: "stable",
29+
id: 4182,
30+
advisory_synopsis: "Recommended update for cloud-netconfig",
31+
update_date: "2024-02-27"
32+
},
33+
%{
34+
date: "2024-02-26",
35+
advisory_name: "SUSE-15-SP4-2024-619",
36+
advisory_type: :security_advisory,
37+
advisory_status: "stable",
38+
id: 4174,
39+
advisory_synopsis: "important: Security update for java-1_8_0-ibm",
40+
update_date: "2024-02-26"
41+
}
42+
]}
3243
else
33-
{:error, :system_id_not_found}
44+
{:ok, []}
3445
end
3546
end
3647

3748
@impl true
38-
def get_upgradable_packages(system_id),
49+
def get_upgradable_packages(_system_id),
3950
do:
40-
(if system_id in mocked_relevant_patches_system_ids() do
41-
{:ok,
42-
get_mock_data()
43-
|> Map.get("upgradable_packages")
44-
|> Enum.map(&StructHelper.to_atomized_map/1)}
45-
else
46-
{:error, :system_id_not_found}
47-
end)
51+
{:ok,
52+
[
53+
%{
54+
name: "elixir",
55+
arch: "x86_64",
56+
from_version: "1.15.7",
57+
from_release: "3",
58+
from_epoch: "0",
59+
to_version: "1.16.2",
60+
to_release: "1",
61+
to_epoch: "0",
62+
to_package_id: 92_348_112_636
63+
},
64+
%{
65+
name: "systemd",
66+
arch: "x86_64",
67+
from_version: "254",
68+
from_release: "1",
69+
from_epoch: "",
70+
to_version: "255",
71+
to_release: "1",
72+
to_epoch: "0",
73+
to_package_id: 8_912_349_843
74+
}
75+
]}
4876

4977
@impl true
5078
def get_patches_for_package(_package_id),
5179
do:
5280
{:ok,
53-
get_mock_data()
54-
|> Map.get("relevant_patches")
55-
|> Enum.map(fn patch ->
81+
[
82+
%{
83+
advisory: "SUSE-15-SP4-2024-630",
84+
type: "bugfix",
85+
synopsis: "Recommended update for cloud-netconfig",
86+
issue_date: "2024-02-27",
87+
update_date: "2024-02-27",
88+
last_modified_date: "2024-02-27"
89+
},
5690
%{
57-
advisory: patch["advisory_name"],
58-
type: patch["advisory_type"],
59-
synopsis: patch["advisory_synopsis"],
60-
issue_date: patch["date"],
61-
update_date: patch["update_date"],
62-
last_modified_date: patch["update_date"]
91+
advisory: "SUSE-15-SP4-2024-619",
92+
type: "security_advisory",
93+
synopsis: "important: Security update for java-1_8_0-ibm",
94+
issue_date: "2024-02-27",
95+
update_date: "2024-02-27",
96+
last_modified_date: "2024-02-27"
6397
}
64-
end)}
98+
]}
6599

66100
@impl true
67101
def get_errata_details(_advisory_name),
68102
do:
69103
{:ok,
70-
get_mock_data()
71-
|> Map.get("errata_details")
72-
|> StructHelper.to_atomized_map()}
104+
%{
105+
type: "security_advisory",
106+
synopsis: "important: Security update for java-1_8_0-ibm",
107+
issue_date: "2024-02-27",
108+
update_date: "2024-02-27",
109+
last_modified_date: "2024-02-27",
110+
advisory_status: "stable",
111+
reboot_suggested: true,
112+
restart_suggested: true,
113+
id: 2,
114+
release: 3,
115+
vendor_advisory: "IBM",
116+
product: "IBM® Semeru Runtime™ Certified Edition",
117+
errataFrom: "SUSE",
118+
topic: "Java",
119+
description: "Minor security bug fixes",
120+
references: "N.A.",
121+
notes: "N.A.",
122+
solution: "N.A."
123+
}}
73124

74125
@impl true
75126
def get_affected_systems(_advisory_name),
76127
do:
77128
{:ok,
78-
get_mock_data()
79-
|> Map.get("affected_systems")
80-
|> Enum.map(&StructHelper.to_atomized_map/1)}
129+
[
130+
%{
131+
name: "vmdrbddev01"
132+
},
133+
%{name: "vmdrbddev02"}
134+
]}
81135

82136
@impl true
83137
def get_cves(_advisory_name),
84-
do: {:ok, Map.get(get_mock_data(), "cves")}
138+
do:
139+
{:ok,
140+
[
141+
"SUSE-15-SP4-2024-630",
142+
"SUSE-15-SP4-2024-234",
143+
"SUSE-15-SP4-2024-990"
144+
]}
85145

86146
@impl true
87147
def get_affected_packages(_advisory_name),
88148
do:
89149
{:ok,
90-
get_mock_data()
91-
|> Map.get("affected_packages")
92-
|> Enum.map(&StructHelper.to_atomized_map/1)}
150+
[
151+
%{
152+
name: "elixir",
153+
version: "6.9.7",
154+
release: "2",
155+
arch_label: "x86_64",
156+
epoch: "0"
157+
},
158+
%{
159+
name: "systemd",
160+
version: "6.9.7",
161+
release: "2",
162+
arch_label: "x86_64",
163+
epoch: "0"
164+
}
165+
]}
93166

94167
@impl true
95168
def get_bugzilla_fixes(_advisory_name),
96169
do:
97170
{:ok,
98-
get_mock_data()
99-
|> Map.get("bugzilla_fixes")
100-
|> StructHelper.to_atomized_map()}
171+
%{
172+
"1210660": "VUL-0: CVE-2023-2137: sqlite2,sqlite3: Heap buffer overflow in sqlite"
173+
}}
101174

102175
@impl true
103176
def clear, do: :ok
104177

105178
defp mocked_relevant_patches_system_ids,
106179
do: Application.fetch_env!(:trento, __MODULE__)[:relevant_patches_system_ids]
107-
108-
defp get_mock_data do
109-
:trento
110-
|> :code.priv_dir()
111-
|> Path.join("fixtures/software_updates.json")
112-
|> File.read!()
113-
|> Jason.decode!()
114-
end
115180
end

priv/fixtures/software_updates.json

Lines changed: 0 additions & 108 deletions
This file was deleted.

test/e2e/cypress.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ module.exports = defineConfig({
6161
async setupNodeEvents(on, config) {
6262
config.env.wandaUrl = calculateWandaUrl(config);
6363

64+
on('task', {
65+
async refreshApiKey() {
66+
return await discoverApiKey(config);
67+
},
68+
});
69+
6470
if (
6571
config.env.auto_discover_api_key === true ||
6672
config.env.auto_discover_api_key === 'true'

test/e2e/cypress/e2e/settings.cy.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ context('Settings page', () => {
66
settingsPage.waitForRequest('settingsEndpoint');
77
});
88

9-
after(() => settingsPage.updateApiKeyExpiration(null));
9+
after(() => {
10+
settingsPage.updateApiKeyExpiration(null);
11+
12+
const isRealInstance = !Cypress.config().baseUrl.includes('localhost');
13+
14+
if (isRealInstance) {
15+
cy.task('refreshApiKey').then((newKey) => Cypress.env('api_key', newKey));
16+
}
17+
});
1018

1119
describe('Api key display', () => {
1220
it('should display the api key with the copy button', () => {

0 commit comments

Comments
 (0)