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