| @@ 23-150 (lines=128) @@ | ||
| 20 | from gvm.protocols.gmpv214 import ScannerType |
|
| 21 | ||
| 22 | ||
| 23 | class GmpModifyScannerTestMixin: |
|
| 24 | def test_modify_scanner(self): |
|
| 25 | self.gmp.modify_scanner(scanner_id='s1') |
|
| 26 | ||
| 27 | self.connection.send.has_been_called_with( |
|
| 28 | '<modify_scanner scanner_id="s1"/>' |
|
| 29 | ) |
|
| 30 | ||
| 31 | def test_modify_scanner_missing_scanner_id(self): |
|
| 32 | with self.assertRaises(RequiredArgument): |
|
| 33 | self.gmp.modify_scanner(scanner_id=None) |
|
| 34 | ||
| 35 | with self.assertRaises(RequiredArgument): |
|
| 36 | self.gmp.modify_scanner(scanner_id='') |
|
| 37 | ||
| 38 | def test_modify_scanner_with_comment(self): |
|
| 39 | self.gmp.modify_scanner(scanner_id='s1', comment='foo') |
|
| 40 | ||
| 41 | self.connection.send.has_been_called_with( |
|
| 42 | '<modify_scanner scanner_id="s1">' |
|
| 43 | '<comment>foo</comment>' |
|
| 44 | '</modify_scanner>' |
|
| 45 | ) |
|
| 46 | ||
| 47 | def test_modify_scanner_with_host(self): |
|
| 48 | self.gmp.modify_scanner(scanner_id='s1', host='foo') |
|
| 49 | ||
| 50 | self.connection.send.has_been_called_with( |
|
| 51 | '<modify_scanner scanner_id="s1">' |
|
| 52 | '<host>foo</host>' |
|
| 53 | '</modify_scanner>' |
|
| 54 | ) |
|
| 55 | ||
| 56 | def test_modify_scanner_with_port(self): |
|
| 57 | self.gmp.modify_scanner(scanner_id='s1', port=1234) |
|
| 58 | ||
| 59 | self.connection.send.has_been_called_with( |
|
| 60 | '<modify_scanner scanner_id="s1">' |
|
| 61 | '<port>1234</port>' |
|
| 62 | '</modify_scanner>' |
|
| 63 | ) |
|
| 64 | ||
| 65 | self.gmp.modify_scanner(scanner_id='s1', port='1234') |
|
| 66 | ||
| 67 | self.connection.send.has_been_called_with( |
|
| 68 | '<modify_scanner scanner_id="s1">' |
|
| 69 | '<port>1234</port>' |
|
| 70 | '</modify_scanner>' |
|
| 71 | ) |
|
| 72 | ||
| 73 | def test_modify_scanner_with_name(self): |
|
| 74 | self.gmp.modify_scanner(scanner_id='s1', name='foo') |
|
| 75 | ||
| 76 | self.connection.send.has_been_called_with( |
|
| 77 | '<modify_scanner scanner_id="s1">' |
|
| 78 | '<name>foo</name>' |
|
| 79 | '</modify_scanner>' |
|
| 80 | ) |
|
| 81 | ||
| 82 | def test_modify_scanner_with_ca_pub(self): |
|
| 83 | self.gmp.modify_scanner(scanner_id='s1', ca_pub='foo') |
|
| 84 | ||
| 85 | self.connection.send.has_been_called_with( |
|
| 86 | '<modify_scanner scanner_id="s1">' |
|
| 87 | '<ca_pub>foo</ca_pub>' |
|
| 88 | '</modify_scanner>' |
|
| 89 | ) |
|
| 90 | ||
| 91 | def test_modify_scanner_with_credential_id(self): |
|
| 92 | self.gmp.modify_scanner(scanner_id='s1', credential_id='c1') |
|
| 93 | ||
| 94 | self.connection.send.has_been_called_with( |
|
| 95 | '<modify_scanner scanner_id="s1">' |
|
| 96 | '<credential id="c1"/>' |
|
| 97 | '</modify_scanner>' |
|
| 98 | ) |
|
| 99 | ||
| 100 | def test_modify_scanner_with_scanner_type(self): |
|
| 101 | self.gmp.modify_scanner( |
|
| 102 | scanner_id='s1', scanner_type=ScannerType.OSP_SCANNER_TYPE |
|
| 103 | ) |
|
| 104 | ||
| 105 | self.connection.send.has_been_called_with( |
|
| 106 | '<modify_scanner scanner_id="s1">' |
|
| 107 | '<type>1</type>' |
|
| 108 | '</modify_scanner>' |
|
| 109 | ) |
|
| 110 | ||
| 111 | self.gmp.modify_scanner( |
|
| 112 | scanner_id='s1', scanner_type=ScannerType.OPENVAS_SCANNER_TYPE |
|
| 113 | ) |
|
| 114 | ||
| 115 | self.connection.send.has_been_called_with( |
|
| 116 | '<modify_scanner scanner_id="s1">' |
|
| 117 | '<type>2</type>' |
|
| 118 | '</modify_scanner>' |
|
| 119 | ) |
|
| 120 | ||
| 121 | self.gmp.modify_scanner( |
|
| 122 | scanner_id='s1', scanner_type=ScannerType.CVE_SCANNER_TYPE |
|
| 123 | ) |
|
| 124 | ||
| 125 | self.connection.send.has_been_called_with( |
|
| 126 | '<modify_scanner scanner_id="s1">' |
|
| 127 | '<type>3</type>' |
|
| 128 | '</modify_scanner>' |
|
| 129 | ) |
|
| 130 | ||
| 131 | self.gmp.modify_scanner( |
|
| 132 | scanner_id='s1', |
|
| 133 | scanner_type=ScannerType.GREENBONE_SENSOR_SCANNER_TYPE, |
|
| 134 | ) |
|
| 135 | ||
| 136 | self.connection.send.has_been_called_with( |
|
| 137 | '<modify_scanner scanner_id="s1">' |
|
| 138 | '<type>5</type>' |
|
| 139 | '</modify_scanner>' |
|
| 140 | ) |
|
| 141 | ||
| 142 | def test_modify_scanner_invalid_scanner_type(self): |
|
| 143 | with self.assertRaises(InvalidArgumentType): |
|
| 144 | self.gmp.modify_scanner(scanner_id='s1', scanner_type='') |
|
| 145 | ||
| 146 | with self.assertRaises(InvalidArgumentType): |
|
| 147 | self.gmp.modify_scanner(scanner_id='s1', scanner_type='-1') |
|
| 148 | ||
| 149 | with self.assertRaises(InvalidArgumentType): |
|
| 150 | self.gmp.modify_scanner(scanner_id='s1', scanner_type=1) |
|
| 151 | ||
| @@ 23-149 (lines=127) @@ | ||
| 20 | from gvm.protocols.gmpv208 import ScannerType |
|
| 21 | ||
| 22 | ||
| 23 | class GmpModifyScannerTestMixin: |
|
| 24 | def test_modify_scanner(self): |
|
| 25 | self.gmp.modify_scanner(scanner_id='s1') |
|
| 26 | ||
| 27 | self.connection.send.has_been_called_with( |
|
| 28 | '<modify_scanner scanner_id="s1"/>' |
|
| 29 | ) |
|
| 30 | ||
| 31 | def test_modify_scanner_missing_scanner_id(self): |
|
| 32 | with self.assertRaises(RequiredArgument): |
|
| 33 | self.gmp.modify_scanner(scanner_id=None) |
|
| 34 | ||
| 35 | with self.assertRaises(RequiredArgument): |
|
| 36 | self.gmp.modify_scanner(scanner_id='') |
|
| 37 | ||
| 38 | def test_modify_scanner_with_comment(self): |
|
| 39 | self.gmp.modify_scanner(scanner_id='s1', comment='foo') |
|
| 40 | ||
| 41 | self.connection.send.has_been_called_with( |
|
| 42 | '<modify_scanner scanner_id="s1">' |
|
| 43 | '<comment>foo</comment>' |
|
| 44 | '</modify_scanner>' |
|
| 45 | ) |
|
| 46 | ||
| 47 | def test_modify_scanner_with_host(self): |
|
| 48 | self.gmp.modify_scanner(scanner_id='s1', host='foo') |
|
| 49 | ||
| 50 | self.connection.send.has_been_called_with( |
|
| 51 | '<modify_scanner scanner_id="s1">' |
|
| 52 | '<host>foo</host>' |
|
| 53 | '</modify_scanner>' |
|
| 54 | ) |
|
| 55 | ||
| 56 | def test_modify_scanner_with_port(self): |
|
| 57 | self.gmp.modify_scanner(scanner_id='s1', port=1234) |
|
| 58 | ||
| 59 | self.connection.send.has_been_called_with( |
|
| 60 | '<modify_scanner scanner_id="s1">' |
|
| 61 | '<port>1234</port>' |
|
| 62 | '</modify_scanner>' |
|
| 63 | ) |
|
| 64 | ||
| 65 | self.gmp.modify_scanner(scanner_id='s1', port='1234') |
|
| 66 | ||
| 67 | self.connection.send.has_been_called_with( |
|
| 68 | '<modify_scanner scanner_id="s1">' |
|
| 69 | '<port>1234</port>' |
|
| 70 | '</modify_scanner>' |
|
| 71 | ) |
|
| 72 | ||
| 73 | def test_modify_scanner_with_name(self): |
|
| 74 | self.gmp.modify_scanner(scanner_id='s1', name='foo') |
|
| 75 | ||
| 76 | self.connection.send.has_been_called_with( |
|
| 77 | '<modify_scanner scanner_id="s1">' |
|
| 78 | '<name>foo</name>' |
|
| 79 | '</modify_scanner>' |
|
| 80 | ) |
|
| 81 | ||
| 82 | def test_modify_scanner_with_ca_pub(self): |
|
| 83 | self.gmp.modify_scanner(scanner_id='s1', ca_pub='foo') |
|
| 84 | ||
| 85 | self.connection.send.has_been_called_with( |
|
| 86 | '<modify_scanner scanner_id="s1">' |
|
| 87 | '<ca_pub>foo</ca_pub>' |
|
| 88 | '</modify_scanner>' |
|
| 89 | ) |
|
| 90 | ||
| 91 | def test_modify_scanner_with_credential_id(self): |
|
| 92 | self.gmp.modify_scanner(scanner_id='s1', credential_id='c1') |
|
| 93 | ||
| 94 | self.connection.send.has_been_called_with( |
|
| 95 | '<modify_scanner scanner_id="s1">' |
|
| 96 | '<credential id="c1"/>' |
|
| 97 | '</modify_scanner>' |
|
| 98 | ) |
|
| 99 | ||
| 100 | def test_modify_scanner_with_scanner_type(self): |
|
| 101 | self.gmp.modify_scanner( |
|
| 102 | scanner_id='s1', scanner_type=ScannerType.OSP_SCANNER_TYPE |
|
| 103 | ) |
|
| 104 | ||
| 105 | self.connection.send.has_been_called_with( |
|
| 106 | '<modify_scanner scanner_id="s1">' |
|
| 107 | '<type>1</type>' |
|
| 108 | '</modify_scanner>' |
|
| 109 | ) |
|
| 110 | ||
| 111 | self.gmp.modify_scanner( |
|
| 112 | scanner_id='s1', scanner_type=ScannerType.OPENVAS_SCANNER_TYPE |
|
| 113 | ) |
|
| 114 | ||
| 115 | self.connection.send.has_been_called_with( |
|
| 116 | '<modify_scanner scanner_id="s1">' |
|
| 117 | '<type>2</type>' |
|
| 118 | '</modify_scanner>' |
|
| 119 | ) |
|
| 120 | ||
| 121 | self.gmp.modify_scanner( |
|
| 122 | scanner_id='s1', scanner_type=ScannerType.CVE_SCANNER_TYPE |
|
| 123 | ) |
|
| 124 | ||
| 125 | self.connection.send.has_been_called_with( |
|
| 126 | '<modify_scanner scanner_id="s1">' |
|
| 127 | '<type>3</type>' |
|
| 128 | '</modify_scanner>' |
|
| 129 | ) |
|
| 130 | ||
| 131 | self.gmp.modify_scanner( |
|
| 132 | scanner_id='s1', scanner_type=ScannerType.GMP_SCANNER_TYPE |
|
| 133 | ) |
|
| 134 | ||
| 135 | self.connection.send.has_been_called_with( |
|
| 136 | '<modify_scanner scanner_id="s1">' |
|
| 137 | '<type>4</type>' |
|
| 138 | '</modify_scanner>' |
|
| 139 | ) |
|
| 140 | ||
| 141 | def test_modify_scanner_invalid_scanner_type(self): |
|
| 142 | with self.assertRaises(InvalidArgumentType): |
|
| 143 | self.gmp.modify_scanner(scanner_id='s1', scanner_type='') |
|
| 144 | ||
| 145 | with self.assertRaises(InvalidArgumentType): |
|
| 146 | self.gmp.modify_scanner(scanner_id='s1', scanner_type='-1') |
|
| 147 | ||
| 148 | with self.assertRaises(InvalidArgumentType): |
|
| 149 | self.gmp.modify_scanner(scanner_id='s1', scanner_type=1) |
|
| 150 | ||