Skip to content
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
4 changes: 4 additions & 0 deletions gvm/protocols/gmp/_gmpnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ def get_agent_installer_instruction(
*,
scanner_id: EntityID,
language_type: AgentInstallerInstructionLanguageType,
origin_url: str,
) -> T:
"""Request an agent installer instruction.

Args:
scanner_id: UUID of the Agent controller to get the installer instruction for.
language_type: Language of the installer instruction.
origin_url: Origin URL used to generate the executable agent
installation command.
"""
return self._send_request_and_transform_response(
AgentInstallerInstructions.get_agent_installer_instruction(
scanner_id=scanner_id,
language_type=language_type,
origin_url=origin_url,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ def get_agent_installer_instruction(
cls,
scanner_id: EntityID,
language_type: AgentInstallerInstructionLanguageType,
origin_url: str,
) -> Request:
"""Request an agent installer instruction.

Args:
scanner_id: UUID of the Agent controller to get the installer instruction for.
language_type: Language of the installer instruction.
origin_url: Origin URL used to generate the executable agent
installation command.

Raises:
RequiredArgument: If scanner_id, language_type, or origin_url is
missing.
"""
if not scanner_id:
raise RequiredArgument(
Expand All @@ -36,8 +43,15 @@ def get_agent_installer_instruction(
argument="language_type",
)

if not origin_url:
raise RequiredArgument(
function=cls.get_agent_installer_instruction.__name__,
argument="origin_url",
)

cmd = XmlCommand("get_agent_installer_instruction")
cmd.set_attribute("scanner_id", str(scanner_id))
cmd.set_attribute("language", language_type.value)
cmd.set_attribute("origin_url", origin_url)

return cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,85 @@ def test_get_agent_installer_instruction(self):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type=AgentInstallerInstructionLanguageType.EN,
origin_url="https://example.com",
)

self.connection.send.has_been_called_with(
b'<get_agent_installer_instruction scanner_id="scanner1" language="en"/>'
b"<get_agent_installer_instruction"
b' scanner_id="scanner1"'
b' language="en"'
b' origin_url="https://example.com"/>'
)

def test_get_agent_installer_instruction_de(self):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type=AgentInstallerInstructionLanguageType.DE,
origin_url="https://example.com",
)

self.connection.send.has_been_called_with(
b'<get_agent_installer_instruction scanner_id="scanner1" language="de"/>'
b"<get_agent_installer_instruction"
b' scanner_id="scanner1"'
b' language="de"'
b' origin_url="https://example.com"/>'
)

def test_get_agent_installer_instruction_escapes_origin_url(self):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type=AgentInstallerInstructionLanguageType.EN,
origin_url="https://example.com/path?foo=bar&value=test",
)

self.connection.send.has_been_called_with(
b"<get_agent_installer_instruction"
b' scanner_id="scanner1"'
b' language="en"'
b' origin_url="https://example.com/path?foo=bar&amp;value=test"/>'
)

def test_get_agent_installer_instruction_without_scanner_id(self):
with self.assertRaises(RequiredArgument):
self.gmp.get_agent_installer_instruction(
scanner_id=None,
language_type=AgentInstallerInstructionLanguageType.EN,
origin_url="https://example.com",
)

with self.assertRaises(RequiredArgument):
self.gmp.get_agent_installer_instruction(
scanner_id="",
language_type=AgentInstallerInstructionLanguageType.EN,
origin_url="https://example.com",
)

def test_get_agent_installer_instruction_without_language_type(self):
with self.assertRaises(RequiredArgument):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type=None,
origin_url="https://example.com",
)

with self.assertRaises(RequiredArgument):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type="",
origin_url="https://example.com",
)

def test_get_agent_installer_instruction_without_origin_url(self):
with self.assertRaises(RequiredArgument):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type=AgentInstallerInstructionLanguageType.EN,
origin_url=None,
)

with self.assertRaises(RequiredArgument):
self.gmp.get_agent_installer_instruction(
scanner_id="scanner1",
language_type=AgentInstallerInstructionLanguageType.EN,
origin_url="",
)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading