From fcc8ecd4139a6037f6878008d2564d2b8aa99fef Mon Sep 17 00:00:00 2001 From: Michael Wiegand Date: Thu, 8 Oct 2026 14:52:16 +0200 Subject: [PATCH 1/2] Fix: Include slave_id when moving tasks Send an empty slave_id for the master by default and reject explicit None instead of omitting the required attribute. Cover default, master, slave, and invalid values in request and client tests. Commit generated using the `pi` coding agent harness (model: openai-codex/gpt-6-sol). --- gvm/protocols/gmp/_gmp224.py | 5 +++-- gvm/protocols/gmp/_gmpnext.py | 5 +++-- gvm/protocols/gmp/requests/next/_tasks.py | 13 ++++++++----- gvm/protocols/gmp/requests/v224/_tasks.py | 13 ++++++++----- tests/protocols/gmp/requests/v224/test_tasks.py | 13 ++++++++++++- .../gmpnext/entities/tasks/test_move_task.py | 15 ++++++++++++++- .../gmpv224/entities/tasks/test_move_task.py | 15 ++++++++++++++- 7 files changed, 62 insertions(+), 17 deletions(-) diff --git a/gvm/protocols/gmp/_gmp224.py b/gvm/protocols/gmp/_gmp224.py index bc263e863..98a37b7e3 100644 --- a/gvm/protocols/gmp/_gmp224.py +++ b/gvm/protocols/gmp/_gmp224.py @@ -3926,13 +3926,14 @@ def modify_task( ) def move_task( - self, task_id: EntityID, *, slave_id: EntityID | None = None + self, task_id: EntityID, *, slave_id: EntityID = "" ) -> T: """Move an existing task to another GMP slave scanner or the master Args: task_id: UUID of the task to be moved - slave_id: UUID of the sensor to reassign the task to, empty for master. + slave_id: UUID of the sensor to reassign the task to. Defaults to + an empty string, which selects the master. """ return self._send_request_and_transform_response( Tasks.move_task(task_id, slave_id=slave_id) diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index e5316957c..61a016c80 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -958,13 +958,14 @@ def modify_task( ) def move_task( - self, task_id: EntityID, *, slave_id: EntityID | None = None + self, task_id: EntityID, *, slave_id: EntityID = "" ) -> T: """Move an existing task to another GMP slave scanner or the master Args: task_id: UUID of the task to be moved - slave_id: UUID of the sensor to reassign the task to, empty for master. + slave_id: UUID of the sensor to reassign the task to. Defaults to + an empty string, which selects the master. """ return self._send_request_and_transform_response( Tasks.move_task( diff --git a/gvm/protocols/gmp/requests/next/_tasks.py b/gvm/protocols/gmp/requests/next/_tasks.py index 7b1158e38..23ca32b40 100644 --- a/gvm/protocols/gmp/requests/next/_tasks.py +++ b/gvm/protocols/gmp/requests/next/_tasks.py @@ -695,24 +695,27 @@ def modify_task( @classmethod def move_task( - cls, task_id: EntityID, *, slave_id: EntityID | None = None + cls, task_id: EntityID, *, slave_id: EntityID = "" ) -> Request: """Move an existing task to another GMP slave scanner or the master Args: task_id: UUID of the task to be moved - slave_id: UUID of the sensor to reassign the task to, empty for master. + slave_id: UUID of the sensor to reassign the task to. Defaults to + an empty string, which selects the master. """ if not task_id: raise RequiredArgument( function=cls.move_task.__name__, argument="task_id" ) + if slave_id is None: + raise RequiredArgument( + function=cls.move_task.__name__, argument="slave_id" + ) cmd = XmlCommand("move_task") cmd.set_attribute("task_id", str(task_id)) - - if slave_id is not None: - cmd.set_attribute("slave_id", str(slave_id)) + cmd.set_attribute("slave_id", str(slave_id)) return cmd diff --git a/gvm/protocols/gmp/requests/v224/_tasks.py b/gvm/protocols/gmp/requests/v224/_tasks.py index f6056cc90..8323db713 100644 --- a/gvm/protocols/gmp/requests/v224/_tasks.py +++ b/gvm/protocols/gmp/requests/v224/_tasks.py @@ -354,24 +354,27 @@ def modify_task( @classmethod def move_task( - cls, task_id: EntityID, *, slave_id: EntityID | None = None + cls, task_id: EntityID, *, slave_id: EntityID = "" ) -> Request: """Move an existing task to another GMP slave scanner or the master Args: task_id: UUID of the task to be moved - slave_id: UUID of the sensor to reassign the task to, empty for master. + slave_id: UUID of the sensor to reassign the task to. Defaults to + an empty string, which selects the master. """ if not task_id: raise RequiredArgument( function=cls.move_task.__name__, argument="task_id" ) + if slave_id is None: + raise RequiredArgument( + function=cls.move_task.__name__, argument="slave_id" + ) cmd = XmlCommand("move_task") cmd.set_attribute("task_id", str(task_id)) - - if slave_id is not None: - cmd.set_attribute("slave_id", str(slave_id)) + cmd.set_attribute("slave_id", str(slave_id)) return cmd diff --git a/tests/protocols/gmp/requests/v224/test_tasks.py b/tests/protocols/gmp/requests/v224/test_tasks.py index afe519964..2f785a9d0 100644 --- a/tests/protocols/gmp/requests/v224/test_tasks.py +++ b/tests/protocols/gmp/requests/v224/test_tasks.py @@ -664,7 +664,14 @@ def test_move_task(self): request = Tasks().move_task("task_id") self.assertEqual( bytes(request), - b'', + b'', + ) + + def test_move_task_to_master(self): + request = Tasks().move_task("task_id", slave_id="") + self.assertEqual( + bytes(request), + b'', ) def test_move_task_with_slave_id(self): @@ -681,6 +688,10 @@ def test_move_task_missing_task_id(self): with self.assertRaises(RequiredArgument): Tasks().move_task(None) + def test_move_task_none_slave_id(self): + with self.assertRaises(RequiredArgument): + Tasks().move_task("task_id", slave_id=None) + def test_start_task(self): request = Tasks().start_task("task_id") self.assertEqual( diff --git a/tests/protocols/gmpnext/entities/tasks/test_move_task.py b/tests/protocols/gmpnext/entities/tasks/test_move_task.py index efc58af50..e690b7ecb 100644 --- a/tests/protocols/gmpnext/entities/tasks/test_move_task.py +++ b/tests/protocols/gmpnext/entities/tasks/test_move_task.py @@ -10,7 +10,16 @@ class GmpMoveTaskTestMixin: def test_move_task(self): self.gmp.move_task("a1") - self.connection.send.has_been_called_with(b'') + self.connection.send.has_been_called_with( + b'' + ) + + def test_move_task_to_master(self): + self.gmp.move_task("a1", slave_id="") + + self.connection.send.has_been_called_with( + b'' + ) def test_move_task_to_slave(self): self.gmp.move_task("a1", slave_id="s1") @@ -25,3 +34,7 @@ def test_missing_id(self): with self.assertRaises(GvmError): self.gmp.move_task("") + + def test_none_slave_id(self): + with self.assertRaises(GvmError): + self.gmp.move_task("a1", slave_id=None) diff --git a/tests/protocols/gmpv224/entities/tasks/test_move_task.py b/tests/protocols/gmpv224/entities/tasks/test_move_task.py index 6898abbc6..3c0095f64 100644 --- a/tests/protocols/gmpv224/entities/tasks/test_move_task.py +++ b/tests/protocols/gmpv224/entities/tasks/test_move_task.py @@ -10,7 +10,16 @@ class GmpMoveTaskTestMixin: def test_move_task(self): self.gmp.move_task("a1") - self.connection.send.has_been_called_with(b'') + self.connection.send.has_been_called_with( + b'' + ) + + def test_move_task_to_master(self): + self.gmp.move_task("a1", slave_id="") + + self.connection.send.has_been_called_with( + b'' + ) def test_move_task_to_slave(self): self.gmp.move_task("a1", slave_id="s1") @@ -25,3 +34,7 @@ def test_missing_id(self): with self.assertRaises(GvmError): self.gmp.move_task("") + + def test_none_slave_id(self): + with self.assertRaises(GvmError): + self.gmp.move_task("a1", slave_id=None) From be71c3c26e4d1c117a07f8c2bfc7275e51483050 Mon Sep 17 00:00:00 2001 From: Michael Wiegand Date: Thu, 8 Oct 2026 15:01:21 +0200 Subject: [PATCH 2/2] Fix: Format move_task signatures Match Ruff formatting for the GMPv224 and GMPNext move_task methods. Commit generated using the `pi` coding agent harness (model: openai-codex/gpt-6-sol). --- gvm/protocols/gmp/_gmp224.py | 4 +--- gvm/protocols/gmp/_gmpnext.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/gvm/protocols/gmp/_gmp224.py b/gvm/protocols/gmp/_gmp224.py index 98a37b7e3..b3e21cd8c 100644 --- a/gvm/protocols/gmp/_gmp224.py +++ b/gvm/protocols/gmp/_gmp224.py @@ -3925,9 +3925,7 @@ def modify_task( ) ) - def move_task( - self, task_id: EntityID, *, slave_id: EntityID = "" - ) -> T: + def move_task(self, task_id: EntityID, *, slave_id: EntityID = "") -> T: """Move an existing task to another GMP slave scanner or the master Args: diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index 61a016c80..cd92aaeef 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -957,9 +957,7 @@ def modify_task( ) ) - def move_task( - self, task_id: EntityID, *, slave_id: EntityID = "" - ) -> T: + def move_task(self, task_id: EntityID, *, slave_id: EntityID = "") -> T: """Move an existing task to another GMP slave scanner or the master Args: