| @@ 26-195 (lines=170) @@ | ||
| 23 | from gvm.protocols.gmpv208 import AliveTest |
|
| 24 | ||
| 25 | ||
| 26 | class GmpModifyTargetTestCase: |
|
| 27 | def test_modify_target(self): |
|
| 28 | self.gmp.modify_target(target_id='t1') |
|
| 29 | ||
| 30 | self.connection.send.has_been_called_with( |
|
| 31 | '<modify_target target_id="t1"/>' |
|
| 32 | ) |
|
| 33 | ||
| 34 | def test_modify_target_missing_target_id(self): |
|
| 35 | with self.assertRaises(RequiredArgument): |
|
| 36 | self.gmp.modify_target(target_id=None) |
|
| 37 | ||
| 38 | with self.assertRaises(RequiredArgument): |
|
| 39 | self.gmp.modify_target(target_id='') |
|
| 40 | ||
| 41 | def test_modify_target_with_comment(self): |
|
| 42 | self.gmp.modify_target(target_id='t1', comment='foo') |
|
| 43 | ||
| 44 | self.connection.send.has_been_called_with( |
|
| 45 | '<modify_target target_id="t1">' |
|
| 46 | '<comment>foo</comment>' |
|
| 47 | '</modify_target>' |
|
| 48 | ) |
|
| 49 | ||
| 50 | def test_modify_target_with_hosts(self): |
|
| 51 | self.gmp.modify_target(target_id='t1', hosts=['foo']) |
|
| 52 | ||
| 53 | self.connection.send.has_been_called_with( |
|
| 54 | '<modify_target target_id="t1">' |
|
| 55 | '<hosts>foo</hosts>' |
|
| 56 | '<exclude_hosts></exclude_hosts>' |
|
| 57 | '</modify_target>' |
|
| 58 | ) |
|
| 59 | ||
| 60 | self.gmp.modify_target(target_id='t1', hosts=['foo', 'bar']) |
|
| 61 | ||
| 62 | self.connection.send.has_been_called_with( |
|
| 63 | '<modify_target target_id="t1">' |
|
| 64 | '<hosts>foo,bar</hosts>' |
|
| 65 | '<exclude_hosts></exclude_hosts>' |
|
| 66 | '</modify_target>' |
|
| 67 | ) |
|
| 68 | ||
| 69 | def test_modify_target_with_name(self): |
|
| 70 | self.gmp.modify_target(target_id='t1', name='foo') |
|
| 71 | ||
| 72 | self.connection.send.has_been_called_with( |
|
| 73 | '<modify_target target_id="t1">' |
|
| 74 | '<name>foo</name>' |
|
| 75 | '</modify_target>' |
|
| 76 | ) |
|
| 77 | ||
| 78 | def test_modify_target_with_exclude_hosts(self): |
|
| 79 | self.gmp.modify_target(target_id='t1', exclude_hosts=['foo']) |
|
| 80 | ||
| 81 | self.connection.send.has_been_called_with( |
|
| 82 | '<modify_target target_id="t1">' |
|
| 83 | '<exclude_hosts>foo</exclude_hosts>' |
|
| 84 | '</modify_target>' |
|
| 85 | ) |
|
| 86 | ||
| 87 | self.gmp.modify_target(target_id='t1', exclude_hosts=['foo', 'bar']) |
|
| 88 | ||
| 89 | self.connection.send.has_been_called_with( |
|
| 90 | '<modify_target target_id="t1">' |
|
| 91 | '<exclude_hosts>foo,bar</exclude_hosts>' |
|
| 92 | '</modify_target>' |
|
| 93 | ) |
|
| 94 | ||
| 95 | def test_modify_target_with_ssh_credential(self): |
|
| 96 | self.gmp.modify_target(target_id='t1', ssh_credential_id='c1') |
|
| 97 | ||
| 98 | self.connection.send.has_been_called_with( |
|
| 99 | '<modify_target target_id="t1">' |
|
| 100 | '<ssh_credential id="c1"/>' |
|
| 101 | '</modify_target>' |
|
| 102 | ) |
|
| 103 | ||
| 104 | def test_modify_target_with_ssh_credential_port(self): |
|
| 105 | self.gmp.modify_target( |
|
| 106 | target_id='t1', ssh_credential_id='c1', ssh_credential_port=123 |
|
| 107 | ) |
|
| 108 | ||
| 109 | self.connection.send.has_been_called_with( |
|
| 110 | '<modify_target target_id="t1">' |
|
| 111 | '<ssh_credential id="c1">' |
|
| 112 | '<port>123</port>' |
|
| 113 | '</ssh_credential>' |
|
| 114 | '</modify_target>' |
|
| 115 | ) |
|
| 116 | ||
| 117 | def test_modify_target_with_smb_credential_id(self): |
|
| 118 | self.gmp.modify_target(target_id='t1', smb_credential_id='c1') |
|
| 119 | ||
| 120 | self.connection.send.has_been_called_with( |
|
| 121 | '<modify_target target_id="t1">' |
|
| 122 | '<smb_credential id="c1"/>' |
|
| 123 | '</modify_target>' |
|
| 124 | ) |
|
| 125 | ||
| 126 | def test_modify_target_with_esxi_credential_id(self): |
|
| 127 | self.gmp.modify_target(target_id='t1', esxi_credential_id='c1') |
|
| 128 | ||
| 129 | self.connection.send.has_been_called_with( |
|
| 130 | '<modify_target target_id="t1">' |
|
| 131 | '<esxi_credential id="c1"/>' |
|
| 132 | '</modify_target>' |
|
| 133 | ) |
|
| 134 | ||
| 135 | def test_modify_target_with_snmp_credential_id(self): |
|
| 136 | self.gmp.modify_target(target_id='t1', snmp_credential_id='c1') |
|
| 137 | ||
| 138 | self.connection.send.has_been_called_with( |
|
| 139 | '<modify_target target_id="t1">' |
|
| 140 | '<snmp_credential id="c1"/>' |
|
| 141 | '</modify_target>' |
|
| 142 | ) |
|
| 143 | ||
| 144 | def test_modify_target_with_alive_tests(self): |
|
| 145 | self.gmp.modify_target(target_id='t1', alive_test=AliveTest.ICMP_PING) |
|
| 146 | ||
| 147 | self.connection.send.has_been_called_with( |
|
| 148 | '<modify_target target_id="t1">' |
|
| 149 | '<alive_tests>ICMP Ping</alive_tests>' |
|
| 150 | '</modify_target>' |
|
| 151 | ) |
|
| 152 | ||
| 153 | def test_modify_target_invalid_alive_tests(self): |
|
| 154 | with self.assertRaises(InvalidArgumentType): |
|
| 155 | self.gmp.modify_target(target_id='t1', alive_test='foo') |
|
| 156 | ||
| 157 | def test_modify_target_with_reverse_lookup_only(self): |
|
| 158 | self.gmp.modify_target(target_id='t1', reverse_lookup_only=True) |
|
| 159 | ||
| 160 | self.connection.send.has_been_called_with( |
|
| 161 | '<modify_target target_id="t1">' |
|
| 162 | '<reverse_lookup_only>1</reverse_lookup_only>' |
|
| 163 | '</modify_target>' |
|
| 164 | ) |
|
| 165 | ||
| 166 | self.gmp.modify_target(target_id='t1', reverse_lookup_only=False) |
|
| 167 | ||
| 168 | self.connection.send.has_been_called_with( |
|
| 169 | '<modify_target target_id="t1">' |
|
| 170 | '<reverse_lookup_only>0</reverse_lookup_only>' |
|
| 171 | '</modify_target>' |
|
| 172 | ) |
|
| 173 | ||
| 174 | def test_modify_target_with_reverse_lookup_unify(self): |
|
| 175 | self.gmp.modify_target(target_id='t1', reverse_lookup_unify=True) |
|
| 176 | ||
| 177 | self.connection.send.has_been_called_with( |
|
| 178 | '<modify_target target_id="t1">' |
|
| 179 | '<reverse_lookup_unify>1</reverse_lookup_unify>' |
|
| 180 | '</modify_target>' |
|
| 181 | ) |
|
| 182 | ||
| 183 | self.gmp.modify_target(target_id='t1', reverse_lookup_unify=False) |
|
| 184 | ||
| 185 | self.connection.send.has_been_called_with( |
|
| 186 | '<modify_target target_id="t1">' |
|
| 187 | '<reverse_lookup_unify>0</reverse_lookup_unify>' |
|
| 188 | '</modify_target>' |
|
| 189 | ) |
|
| 190 | ||
| 191 | def test_modify_target_with_port_list_id(self): |
|
| 192 | self.gmp.modify_target(target_id='t1', port_list_id='pl1') |
|
| 193 | ||
| 194 | self.connection.send.has_been_called_with( |
|
| 195 | '<modify_target target_id="t1">' |
|
| 196 | '<port_list id="pl1"/>' |
|
| 197 | '</modify_target>' |
|
| 198 | ) |
|
| @@ 26-195 (lines=170) @@ | ||
| 23 | from gvm.protocols.gmpv7 import AliveTest |
|
| 24 | ||
| 25 | ||
| 26 | class GmpModifyTargetTestCase: |
|
| 27 | def test_modify_target(self): |
|
| 28 | self.gmp.modify_target(target_id='t1') |
|
| 29 | ||
| 30 | self.connection.send.has_been_called_with( |
|
| 31 | '<modify_target target_id="t1"/>' |
|
| 32 | ) |
|
| 33 | ||
| 34 | def test_modify_target_missing_target_id(self): |
|
| 35 | with self.assertRaises(RequiredArgument): |
|
| 36 | self.gmp.modify_target(target_id=None) |
|
| 37 | ||
| 38 | with self.assertRaises(RequiredArgument): |
|
| 39 | self.gmp.modify_target(target_id='') |
|
| 40 | ||
| 41 | def test_modify_target_with_comment(self): |
|
| 42 | self.gmp.modify_target(target_id='t1', comment='foo') |
|
| 43 | ||
| 44 | self.connection.send.has_been_called_with( |
|
| 45 | '<modify_target target_id="t1">' |
|
| 46 | '<comment>foo</comment>' |
|
| 47 | '</modify_target>' |
|
| 48 | ) |
|
| 49 | ||
| 50 | def test_modify_target_with_hosts(self): |
|
| 51 | self.gmp.modify_target(target_id='t1', hosts=['foo']) |
|
| 52 | ||
| 53 | self.connection.send.has_been_called_with( |
|
| 54 | '<modify_target target_id="t1">' |
|
| 55 | '<hosts>foo</hosts>' |
|
| 56 | '<exclude_hosts></exclude_hosts>' |
|
| 57 | '</modify_target>' |
|
| 58 | ) |
|
| 59 | ||
| 60 | self.gmp.modify_target(target_id='t1', hosts=['foo', 'bar']) |
|
| 61 | ||
| 62 | self.connection.send.has_been_called_with( |
|
| 63 | '<modify_target target_id="t1">' |
|
| 64 | '<hosts>foo,bar</hosts>' |
|
| 65 | '<exclude_hosts></exclude_hosts>' |
|
| 66 | '</modify_target>' |
|
| 67 | ) |
|
| 68 | ||
| 69 | def test_modify_target_with_name(self): |
|
| 70 | self.gmp.modify_target(target_id='t1', name='foo') |
|
| 71 | ||
| 72 | self.connection.send.has_been_called_with( |
|
| 73 | '<modify_target target_id="t1">' |
|
| 74 | '<name>foo</name>' |
|
| 75 | '</modify_target>' |
|
| 76 | ) |
|
| 77 | ||
| 78 | def test_modify_target_with_exclude_hosts(self): |
|
| 79 | self.gmp.modify_target(target_id='t1', exclude_hosts=['foo']) |
|
| 80 | ||
| 81 | self.connection.send.has_been_called_with( |
|
| 82 | '<modify_target target_id="t1">' |
|
| 83 | '<exclude_hosts>foo</exclude_hosts>' |
|
| 84 | '</modify_target>' |
|
| 85 | ) |
|
| 86 | ||
| 87 | self.gmp.modify_target(target_id='t1', exclude_hosts=['foo', 'bar']) |
|
| 88 | ||
| 89 | self.connection.send.has_been_called_with( |
|
| 90 | '<modify_target target_id="t1">' |
|
| 91 | '<exclude_hosts>foo,bar</exclude_hosts>' |
|
| 92 | '</modify_target>' |
|
| 93 | ) |
|
| 94 | ||
| 95 | def test_modify_target_with_ssh_credential(self): |
|
| 96 | self.gmp.modify_target(target_id='t1', ssh_credential_id='c1') |
|
| 97 | ||
| 98 | self.connection.send.has_been_called_with( |
|
| 99 | '<modify_target target_id="t1">' |
|
| 100 | '<ssh_credential id="c1"/>' |
|
| 101 | '</modify_target>' |
|
| 102 | ) |
|
| 103 | ||
| 104 | def test_modify_target_with_ssh_credential_port(self): |
|
| 105 | self.gmp.modify_target( |
|
| 106 | target_id='t1', ssh_credential_id='c1', ssh_credential_port=123 |
|
| 107 | ) |
|
| 108 | ||
| 109 | self.connection.send.has_been_called_with( |
|
| 110 | '<modify_target target_id="t1">' |
|
| 111 | '<ssh_credential id="c1">' |
|
| 112 | '<port>123</port>' |
|
| 113 | '</ssh_credential>' |
|
| 114 | '</modify_target>' |
|
| 115 | ) |
|
| 116 | ||
| 117 | def test_modify_target_with_smb_credential_id(self): |
|
| 118 | self.gmp.modify_target(target_id='t1', smb_credential_id='c1') |
|
| 119 | ||
| 120 | self.connection.send.has_been_called_with( |
|
| 121 | '<modify_target target_id="t1">' |
|
| 122 | '<smb_credential id="c1"/>' |
|
| 123 | '</modify_target>' |
|
| 124 | ) |
|
| 125 | ||
| 126 | def test_modify_target_with_esxi_credential_id(self): |
|
| 127 | self.gmp.modify_target(target_id='t1', esxi_credential_id='c1') |
|
| 128 | ||
| 129 | self.connection.send.has_been_called_with( |
|
| 130 | '<modify_target target_id="t1">' |
|
| 131 | '<esxi_credential id="c1"/>' |
|
| 132 | '</modify_target>' |
|
| 133 | ) |
|
| 134 | ||
| 135 | def test_modify_target_with_snmp_credential_id(self): |
|
| 136 | self.gmp.modify_target(target_id='t1', snmp_credential_id='c1') |
|
| 137 | ||
| 138 | self.connection.send.has_been_called_with( |
|
| 139 | '<modify_target target_id="t1">' |
|
| 140 | '<snmp_credential id="c1"/>' |
|
| 141 | '</modify_target>' |
|
| 142 | ) |
|
| 143 | ||
| 144 | def test_modify_target_with_alive_tests(self): |
|
| 145 | self.gmp.modify_target(target_id='t1', alive_test=AliveTest.ICMP_PING) |
|
| 146 | ||
| 147 | self.connection.send.has_been_called_with( |
|
| 148 | '<modify_target target_id="t1">' |
|
| 149 | '<alive_tests>ICMP Ping</alive_tests>' |
|
| 150 | '</modify_target>' |
|
| 151 | ) |
|
| 152 | ||
| 153 | def test_modify_target_invalid_alive_tests(self): |
|
| 154 | with self.assertRaises(InvalidArgumentType): |
|
| 155 | self.gmp.modify_target(target_id='t1', alive_test='foo') |
|
| 156 | ||
| 157 | def test_modify_target_with_reverse_lookup_only(self): |
|
| 158 | self.gmp.modify_target(target_id='t1', reverse_lookup_only=True) |
|
| 159 | ||
| 160 | self.connection.send.has_been_called_with( |
|
| 161 | '<modify_target target_id="t1">' |
|
| 162 | '<reverse_lookup_only>1</reverse_lookup_only>' |
|
| 163 | '</modify_target>' |
|
| 164 | ) |
|
| 165 | ||
| 166 | self.gmp.modify_target(target_id='t1', reverse_lookup_only=False) |
|
| 167 | ||
| 168 | self.connection.send.has_been_called_with( |
|
| 169 | '<modify_target target_id="t1">' |
|
| 170 | '<reverse_lookup_only>0</reverse_lookup_only>' |
|
| 171 | '</modify_target>' |
|
| 172 | ) |
|
| 173 | ||
| 174 | def test_modify_target_with_reverse_lookup_unify(self): |
|
| 175 | self.gmp.modify_target(target_id='t1', reverse_lookup_unify=True) |
|
| 176 | ||
| 177 | self.connection.send.has_been_called_with( |
|
| 178 | '<modify_target target_id="t1">' |
|
| 179 | '<reverse_lookup_unify>1</reverse_lookup_unify>' |
|
| 180 | '</modify_target>' |
|
| 181 | ) |
|
| 182 | ||
| 183 | self.gmp.modify_target(target_id='t1', reverse_lookup_unify=False) |
|
| 184 | ||
| 185 | self.connection.send.has_been_called_with( |
|
| 186 | '<modify_target target_id="t1">' |
|
| 187 | '<reverse_lookup_unify>0</reverse_lookup_unify>' |
|
| 188 | '</modify_target>' |
|
| 189 | ) |
|
| 190 | ||
| 191 | def test_modify_target_with_port_list_id(self): |
|
| 192 | self.gmp.modify_target(target_id='t1', port_list_id='pl1') |
|
| 193 | ||
| 194 | self.connection.send.has_been_called_with( |
|
| 195 | '<modify_target target_id="t1">' |
|
| 196 | '<port_list id="pl1"/>' |
|
| 197 | '</modify_target>' |
|
| 198 | ) |
|