Skip to content

Commit e44c1ce

Browse files
ozgengreenbonebot
authored andcommitted
add: support origin URL for agent installer instructions
Add the required `origin_url` argument to the agent installer instruction request and public GMP method. Include the origin URL in the generated GMP command and update the related tests.
1 parent 94bfa11 commit e44c1ce

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,21 @@ def get_agent_installer_instruction(
6565
*,
6666
scanner_id: EntityID,
6767
language_type: AgentInstallerInstructionLanguageType,
68+
origin_url: str,
6869
) -> T:
6970
"""Request an agent installer instruction.
7071
7172
Args:
7273
scanner_id: UUID of the Agent controller to get the installer instruction for.
7374
language_type: Language of the installer instruction.
75+
origin_url: Origin URL used to generate the executable agent
76+
installation command.
7477
"""
7578
return self._send_request_and_transform_response(
7679
AgentInstallerInstructions.get_agent_installer_instruction(
7780
scanner_id=scanner_id,
7881
language_type=language_type,
82+
origin_url=origin_url,
7983
)
8084
)
8185

gvm/protocols/gmp/requests/next/_agent_installer_instructions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ def get_agent_installer_instruction(
1717
cls,
1818
scanner_id: EntityID,
1919
language_type: AgentInstallerInstructionLanguageType,
20+
origin_url: str,
2021
) -> Request:
2122
"""Request an agent installer instruction.
2223
2324
Args:
2425
scanner_id: UUID of the Agent controller to get the installer instruction for.
2526
language_type: Language of the installer instruction.
27+
origin_url: Origin URL used to generate the executable agent
28+
installation command.
29+
30+
Raises:
31+
RequiredArgument: If scanner_id, language_type, or origin_url is
32+
missing.
2633
"""
2734
if not scanner_id:
2835
raise RequiredArgument(
@@ -36,8 +43,15 @@ def get_agent_installer_instruction(
3643
argument="language_type",
3744
)
3845

46+
if not origin_url:
47+
raise RequiredArgument(
48+
function=cls.get_agent_installer_instruction.__name__,
49+
argument="origin_url",
50+
)
51+
3952
cmd = XmlCommand("get_agent_installer_instruction")
4053
cmd.set_attribute("scanner_id", str(scanner_id))
4154
cmd.set_attribute("language", language_type.value)
55+
cmd.set_attribute("origin_url", origin_url)
4256

4357
return cmd

tests/protocols/gmpnext/entities/agent_installer_instructions/test_get_aget_installer_instruction.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,85 @@ def test_get_agent_installer_instruction(self):
1414
self.gmp.get_agent_installer_instruction(
1515
scanner_id="scanner1",
1616
language_type=AgentInstallerInstructionLanguageType.EN,
17+
origin_url="https://example.com",
1718
)
1819

1920
self.connection.send.has_been_called_with(
20-
b'<get_agent_installer_instruction scanner_id="scanner1" language="en"/>'
21+
b"<get_agent_installer_instruction"
22+
b' scanner_id="scanner1"'
23+
b' language="en"'
24+
b' origin_url="https://example.com"/>'
2125
)
2226

2327
def test_get_agent_installer_instruction_de(self):
2428
self.gmp.get_agent_installer_instruction(
2529
scanner_id="scanner1",
2630
language_type=AgentInstallerInstructionLanguageType.DE,
31+
origin_url="https://example.com",
2732
)
2833

2934
self.connection.send.has_been_called_with(
30-
b'<get_agent_installer_instruction scanner_id="scanner1" language="de"/>'
35+
b"<get_agent_installer_instruction"
36+
b' scanner_id="scanner1"'
37+
b' language="de"'
38+
b' origin_url="https://example.com"/>'
39+
)
40+
41+
def test_get_agent_installer_instruction_escapes_origin_url(self):
42+
self.gmp.get_agent_installer_instruction(
43+
scanner_id="scanner1",
44+
language_type=AgentInstallerInstructionLanguageType.EN,
45+
origin_url="https://example.com/path?foo=bar&value=test",
46+
)
47+
48+
self.connection.send.has_been_called_with(
49+
b"<get_agent_installer_instruction"
50+
b' scanner_id="scanner1"'
51+
b' language="en"'
52+
b' origin_url="https://example.com/path?foo=bar&amp;value=test"/>'
3153
)
3254

3355
def test_get_agent_installer_instruction_without_scanner_id(self):
3456
with self.assertRaises(RequiredArgument):
3557
self.gmp.get_agent_installer_instruction(
3658
scanner_id=None,
3759
language_type=AgentInstallerInstructionLanguageType.EN,
60+
origin_url="https://example.com",
3861
)
3962

4063
with self.assertRaises(RequiredArgument):
4164
self.gmp.get_agent_installer_instruction(
4265
scanner_id="",
4366
language_type=AgentInstallerInstructionLanguageType.EN,
67+
origin_url="https://example.com",
4468
)
4569

4670
def test_get_agent_installer_instruction_without_language_type(self):
4771
with self.assertRaises(RequiredArgument):
4872
self.gmp.get_agent_installer_instruction(
4973
scanner_id="scanner1",
5074
language_type=None,
75+
origin_url="https://example.com",
5176
)
5277

5378
with self.assertRaises(RequiredArgument):
5479
self.gmp.get_agent_installer_instruction(
5580
scanner_id="scanner1",
5681
language_type="",
82+
origin_url="https://example.com",
83+
)
84+
85+
def test_get_agent_installer_instruction_without_origin_url(self):
86+
with self.assertRaises(RequiredArgument):
87+
self.gmp.get_agent_installer_instruction(
88+
scanner_id="scanner1",
89+
language_type=AgentInstallerInstructionLanguageType.EN,
90+
origin_url=None,
91+
)
92+
93+
with self.assertRaises(RequiredArgument):
94+
self.gmp.get_agent_installer_instruction(
95+
scanner_id="scanner1",
96+
language_type=AgentInstallerInstructionLanguageType.EN,
97+
origin_url="",
5798
)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)