|
| 1 | +# SPDX-FileCopyrightText: 2025 Greenbone AG |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | +# |
| 5 | + |
| 6 | +from gvm.errors import RequiredArgument |
| 7 | + |
| 8 | + |
| 9 | +class GmpModifyCredentialStoreTestMixin: |
| 10 | + def test_modify_credential_store(self): |
| 11 | + self.gmp.modify_credential_store(credential_store_id="cs1") |
| 12 | + |
| 13 | + self.connection.send.has_been_called_with( |
| 14 | + b'<modify_credential_store credential_store_id="cs1">' |
| 15 | + b"<preferences/>" |
| 16 | + b"</modify_credential_store>" |
| 17 | + ) |
| 18 | + |
| 19 | + def test_modify_credential_store_without_id(self): |
| 20 | + with self.assertRaises(RequiredArgument): |
| 21 | + self.gmp.modify_credential_store(credential_store_id=None) |
| 22 | + |
| 23 | + with self.assertRaises(RequiredArgument): |
| 24 | + self.gmp.modify_credential_store(credential_store_id="") |
| 25 | + |
| 26 | + def test_modify_credential_store_with_active(self): |
| 27 | + self.gmp.modify_credential_store( |
| 28 | + credential_store_id="cs1", |
| 29 | + active=True, |
| 30 | + ) |
| 31 | + |
| 32 | + self.connection.send.has_been_called_with( |
| 33 | + b'<modify_credential_store credential_store_id="cs1">' |
| 34 | + b"<active>1</active>" |
| 35 | + b"<preferences/>" |
| 36 | + b"</modify_credential_store>" |
| 37 | + ) |
| 38 | + |
| 39 | + self.gmp.modify_credential_store( |
| 40 | + credential_store_id="cs1", |
| 41 | + active=False, |
| 42 | + ) |
| 43 | + |
| 44 | + self.connection.send.has_been_called_with( |
| 45 | + b'<modify_credential_store credential_store_id="cs1">' |
| 46 | + b"<active>0</active>" |
| 47 | + b"<preferences/>" |
| 48 | + b"</modify_credential_store>" |
| 49 | + ) |
| 50 | + |
| 51 | + def test_modify_credential_store_with_host(self): |
| 52 | + self.gmp.modify_credential_store( |
| 53 | + credential_store_id="cs1", |
| 54 | + host="foo", |
| 55 | + ) |
| 56 | + |
| 57 | + self.connection.send.has_been_called_with( |
| 58 | + b'<modify_credential_store credential_store_id="cs1">' |
| 59 | + b"<host>foo</host>" |
| 60 | + b"<preferences/>" |
| 61 | + b"</modify_credential_store>" |
| 62 | + ) |
| 63 | + |
| 64 | + def test_modify_credential_store_with_port(self): |
| 65 | + self.gmp.modify_credential_store( |
| 66 | + credential_store_id="cs1", |
| 67 | + port=1234, |
| 68 | + ) |
| 69 | + |
| 70 | + self.connection.send.has_been_called_with( |
| 71 | + b'<modify_credential_store credential_store_id="cs1">' |
| 72 | + b"<port>1234</port>" |
| 73 | + b"<preferences/>" |
| 74 | + b"</modify_credential_store>" |
| 75 | + ) |
| 76 | + |
| 77 | + def test_modify_credential_store_with_path(self): |
| 78 | + self.gmp.modify_credential_store( |
| 79 | + credential_store_id="cs1", |
| 80 | + path="/foo/bar", |
| 81 | + ) |
| 82 | + |
| 83 | + self.connection.send.has_been_called_with( |
| 84 | + b'<modify_credential_store credential_store_id="cs1">' |
| 85 | + b"<path>/foo/bar</path>" |
| 86 | + b"<preferences/>" |
| 87 | + b"</modify_credential_store>" |
| 88 | + ) |
| 89 | + |
| 90 | + def test_modify_credential_store_with_comment(self): |
| 91 | + self.gmp.modify_credential_store( |
| 92 | + credential_store_id="cs1", |
| 93 | + comment="ahoi", |
| 94 | + ) |
| 95 | + |
| 96 | + self.connection.send.has_been_called_with( |
| 97 | + b'<modify_credential_store credential_store_id="cs1">' |
| 98 | + b"<comment>ahoi</comment>" |
| 99 | + b"<preferences/>" |
| 100 | + b"</modify_credential_store>" |
| 101 | + ) |
| 102 | + |
| 103 | + def test_modify_credential_store_with_app_id(self): |
| 104 | + self.gmp.modify_credential_store( |
| 105 | + credential_store_id="cs1", |
| 106 | + app_id="foo", |
| 107 | + ) |
| 108 | + |
| 109 | + self.connection.send.has_been_called_with( |
| 110 | + b'<modify_credential_store credential_store_id="cs1">' |
| 111 | + b"<preferences>" |
| 112 | + b"<app_id>foo</app_id>" |
| 113 | + b"</preferences>" |
| 114 | + b"</modify_credential_store>" |
| 115 | + ) |
| 116 | + |
| 117 | + def test_modify_credential_store_with_client_cert(self): |
| 118 | + self.gmp.modify_credential_store( |
| 119 | + credential_store_id="cs1", |
| 120 | + client_cert="foo", |
| 121 | + ) |
| 122 | + |
| 123 | + self.connection.send.has_been_called_with( |
| 124 | + b'<modify_credential_store credential_store_id="cs1">' |
| 125 | + b"<preferences>" |
| 126 | + b"<client_cert>Zm9v</client_cert>" |
| 127 | + b"</preferences>" |
| 128 | + b"</modify_credential_store>" |
| 129 | + ) |
| 130 | + |
| 131 | + def test_modify_credential_store_with_client_key(self): |
| 132 | + self.gmp.modify_credential_store( |
| 133 | + credential_store_id="cs1", |
| 134 | + client_key="foo", |
| 135 | + ) |
| 136 | + |
| 137 | + self.connection.send.has_been_called_with( |
| 138 | + b'<modify_credential_store credential_store_id="cs1">' |
| 139 | + b"<preferences>" |
| 140 | + b"<client_key>Zm9v</client_key>" |
| 141 | + b"</preferences>" |
| 142 | + b"</modify_credential_store>" |
| 143 | + ) |
| 144 | + |
| 145 | + def test_modify_credential_store_with_client_pkcs12_file(self): |
| 146 | + self.gmp.modify_credential_store( |
| 147 | + credential_store_id="cs1", |
| 148 | + client_pkcs12_file="foo", |
| 149 | + ) |
| 150 | + |
| 151 | + self.connection.send.has_been_called_with( |
| 152 | + b'<modify_credential_store credential_store_id="cs1">' |
| 153 | + b"<preferences>" |
| 154 | + b"<client_pkcs12_file>Zm9v</client_pkcs12_file>" |
| 155 | + b"</preferences>" |
| 156 | + b"</modify_credential_store>" |
| 157 | + ) |
| 158 | + |
| 159 | + def test_modify_credential_store_with_passphrase(self): |
| 160 | + self.gmp.modify_credential_store( |
| 161 | + credential_store_id="cs1", |
| 162 | + passphrase="foo", |
| 163 | + ) |
| 164 | + |
| 165 | + self.connection.send.has_been_called_with( |
| 166 | + b'<modify_credential_store credential_store_id="cs1">' |
| 167 | + b"<preferences>" |
| 168 | + b"<passphrase>foo</passphrase>" |
| 169 | + b"</preferences>" |
| 170 | + b"</modify_credential_store>" |
| 171 | + ) |
| 172 | + |
| 173 | + def test_modify_credential_store_with_server_ca_cert(self): |
| 174 | + self.gmp.modify_credential_store( |
| 175 | + credential_store_id="cs1", |
| 176 | + server_ca_cert="foo", |
| 177 | + ) |
| 178 | + |
| 179 | + self.connection.send.has_been_called_with( |
| 180 | + b'<modify_credential_store credential_store_id="cs1">' |
| 181 | + b"<preferences>" |
| 182 | + b"<server_ca_cert>Zm9v</server_ca_cert>" |
| 183 | + b"</preferences>" |
| 184 | + b"</modify_credential_store>" |
| 185 | + ) |
| 186 | + |
| 187 | + def test_modify_credential_store_with_all(self): |
| 188 | + self.gmp.modify_credential_store( |
| 189 | + credential_store_id="cs1", |
| 190 | + active=False, |
| 191 | + host="localhost", |
| 192 | + port="80", |
| 193 | + path="/api", |
| 194 | + comment="why was 6 afraid of 7? because 7 8 9", |
| 195 | + app_id="appId", |
| 196 | + client_cert="clientCert", |
| 197 | + client_key="clientKey", |
| 198 | + client_pkcs12_file="clientPkcs12File", |
| 199 | + passphrase="secret", |
| 200 | + server_ca_cert="serverCaCert", |
| 201 | + ) |
| 202 | + |
| 203 | + self.connection.send.has_been_called_with( |
| 204 | + b'<modify_credential_store credential_store_id="cs1">' |
| 205 | + b"<active>0</active>" |
| 206 | + b"<host>localhost</host>" |
| 207 | + b"<port>80</port>" |
| 208 | + b"<path>/api</path>" |
| 209 | + b"<comment>why was 6 afraid of 7? because 7 8 9</comment>" |
| 210 | + b"<preferences>" |
| 211 | + b"<app_id>appId</app_id>" |
| 212 | + b"<client_cert>Y2xpZW50Q2VydA==</client_cert>" |
| 213 | + b"<client_key>Y2xpZW50S2V5</client_key>" |
| 214 | + b"<client_pkcs12_file>Y2xpZW50UGtjczEyRmlsZQ==</client_pkcs12_file>" |
| 215 | + b"<passphrase>secret</passphrase>" |
| 216 | + b"<server_ca_cert>c2VydmVyQ2FDZXJ0</server_ca_cert>" |
| 217 | + b"</preferences>" |
| 218 | + b"</modify_credential_store>" |
| 219 | + ) |
0 commit comments