1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
# SPDX-FileCopyrightText: 2021-2025 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmp.requests.v227 import ScannerType
class GmpModifyScannerTestMixin:
def test_modify_scanner(self):
self.gmp.modify_scanner(scanner_id="s1")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1"/>'
)
def test_modify_scanner_missing_scanner_id(self):
with self.assertRaises(RequiredArgument):
self.gmp.modify_scanner(scanner_id=None)
with self.assertRaises(RequiredArgument):
self.gmp.modify_scanner(scanner_id="")
def test_modify_scanner_with_comment(self):
self.gmp.modify_scanner(scanner_id="s1", comment="foo")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<comment>foo</comment>"
b"</modify_scanner>"
)
def test_modify_scanner_with_host(self):
self.gmp.modify_scanner(scanner_id="s1", host="foo")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<host>foo</host>"
b"</modify_scanner>"
)
def test_modify_scanner_with_port(self):
self.gmp.modify_scanner(scanner_id="s1", port=1234)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<port>1234</port>"
b"</modify_scanner>"
)
self.gmp.modify_scanner(scanner_id="s1", port="1234")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<port>1234</port>"
b"</modify_scanner>"
)
def test_modify_scanner_with_name(self):
self.gmp.modify_scanner(scanner_id="s1", name="foo")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<name>foo</name>"
b"</modify_scanner>"
)
def test_modify_scanner_with_ca_pub(self):
self.gmp.modify_scanner(scanner_id="s1", ca_pub="foo")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<ca_pub>foo</ca_pub>"
b"</modify_scanner>"
)
def test_modify_scanner_with_credential_id(self):
self.gmp.modify_scanner(scanner_id="s1", credential_id="c1")
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b'<credential id="c1"/>'
b"</modify_scanner>"
)
def test_modify_scanner_with_scanner_type(self):
self.gmp.modify_scanner(
scanner_id="s1", scanner_type=ScannerType.OPENVAS_SCANNER_TYPE
)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<type>2</type>"
b"</modify_scanner>"
)
self.gmp.modify_scanner(
scanner_id="s1", scanner_type=ScannerType.CVE_SCANNER_TYPE
)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<type>3</type>"
b"</modify_scanner>"
)
self.gmp.modify_scanner(
scanner_id="s1",
scanner_type=ScannerType.GREENBONE_SENSOR_SCANNER_TYPE,
)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<type>5</type>"
b"</modify_scanner>"
)
def test_modify_scanner_invalid_scanner_type(self):
with self.assertRaises(ValueError):
self.gmp.modify_scanner(scanner_id="s1", scanner_type="")
with self.assertRaises(InvalidArgument):
self.gmp.modify_scanner(scanner_id="s1", scanner_type="-1")
with self.assertRaises(InvalidArgument):
self.gmp.modify_scanner(scanner_id="s1", scanner_type=1)
def test_modify_scanner_with_openvasd_type(self):
self.gmp.modify_scanner(
scanner_id="s1",
scanner_type=ScannerType.OPENVASD_SCANNER_TYPE,
)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<type>6</type>"
b"</modify_scanner>"
)
def test_modify_scanner_with_relay_host(self):
self.gmp.modify_scanner(
scanner_id="s1",
relay_host="localhost",
)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<relay_host>localhost</relay_host>"
b"</modify_scanner>"
)
def test_modify_scanner_with_relay_port(self):
self.gmp.modify_scanner(
scanner_id="s1",
relay_port=2345,
)
self.connection.send.has_been_called_with(
b'<modify_scanner scanner_id="s1">'
b"<relay_port>2345</relay_port>"
b"</modify_scanner>"
)
|