Skip to content

Commit d46a3ca

Browse files
ozgengreenbonebot
authored andcommitted
test: add missing unit test to increase coverage
1 parent 9d8e1b1 commit d46a3ca

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

tests/protocols/gmpnext/entities/agents/test_modify_agent_controller_scan_config.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

5-
from gvm.errors import RequiredArgument
5+
from gvm.errors import InvalidArgumentType, RequiredArgument
66

77

88
class GmpModifyAgentControllerScanConfigTestMixin:
@@ -694,3 +694,38 @@ def test_modify_agent_control_scan_config_missing_update_to_latest_raises(
694694
self.gmp.modify_agent_control_scan_config(
695695
"fb6451bf-ec5a-45a8-8bab-5cf4b862e51b", config=cfg
696696
)
697+
698+
def test_modify_agent_control_scan_config_wrong_update_to_latest_raises(
699+
self,
700+
):
701+
cfg = {
702+
"agent_defaults": {
703+
"agent_control": {
704+
"retry": {
705+
"attempts": 6,
706+
"delay_in_seconds": 60,
707+
"max_jitter_in_seconds": 10,
708+
}
709+
},
710+
"agent_script_executor": {
711+
"bulk_size": 1,
712+
"bulk_throttle_time_in_ms": 100,
713+
"indexer_dir_depth": 10,
714+
"scheduler_cron_time": [
715+
"0 23 * * *",
716+
"0 22 * * *",
717+
],
718+
},
719+
"heartbeat": {
720+
"interval_in_seconds": 600,
721+
"miss_until_inactive": 1,
722+
},
723+
},
724+
"agent_control_defaults": {
725+
"update_to_latest": "test",
726+
},
727+
}
728+
with self.assertRaises(InvalidArgumentType):
729+
self.gmp.modify_agent_control_scan_config(
730+
"fb6451bf-ec5a-45a8-8bab-5cf4b862e51b", config=cfg
731+
)

tests/protocols/gmpnext/entities/agents/test_modify_agents.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,62 @@ def test_modify_agents_with_full_config_and_comment(self):
9595
b"</modify_agent>"
9696
)
9797

98+
def test_modify_agents_omits_optional_elements_when_none(self):
99+
cfg = {
100+
"agent_control": {
101+
"retry": {
102+
"attempts": 6,
103+
"delay_in_seconds": 60,
104+
"max_jitter_in_seconds": 10,
105+
}
106+
},
107+
"agent_script_executor": {
108+
"bulk_size": 2,
109+
"bulk_throttle_time_in_ms": 300,
110+
"indexer_dir_depth": 100,
111+
"scheduler_cron_time": ["0 */12 * * *"],
112+
},
113+
"heartbeat": {
114+
"interval_in_seconds": 300,
115+
"miss_until_inactive": 1,
116+
},
117+
}
118+
119+
self.gmp.modify_agents(
120+
agent_ids=["agent-123"],
121+
authorized=None,
122+
update_to_latest=None,
123+
config=cfg,
124+
comment=None,
125+
)
126+
127+
self.connection.send.has_been_called_with(
128+
b"<modify_agent>"
129+
b'<agents><agent id="agent-123"/></agents>'
130+
b"<config>"
131+
b"<agent_control>"
132+
b"<retry>"
133+
b"<attempts>6</attempts>"
134+
b"<delay_in_seconds>60</delay_in_seconds>"
135+
b"<max_jitter_in_seconds>10</max_jitter_in_seconds>"
136+
b"</retry>"
137+
b"</agent_control>"
138+
b"<agent_script_executor>"
139+
b"<bulk_size>2</bulk_size>"
140+
b"<bulk_throttle_time_in_ms>300</bulk_throttle_time_in_ms>"
141+
b"<indexer_dir_depth>100</indexer_dir_depth>"
142+
b'<scheduler_cron_time is_list="1">'
143+
b"<item>0 */12 * * *</item>"
144+
b"</scheduler_cron_time>"
145+
b"</agent_script_executor>"
146+
b"<heartbeat>"
147+
b"<interval_in_seconds>300</interval_in_seconds>"
148+
b"<miss_until_inactive>1</miss_until_inactive>"
149+
b"</heartbeat>"
150+
b"</config>"
151+
b"</modify_agent>"
152+
)
153+
98154
def test_modify_agents_with_full_config_with_missing_element(self):
99155
cfg = {
100156
"agent_control": {

0 commit comments

Comments
 (0)