Skip to content

Commit 4b76dda

Browse files
robindittmargreenbonebot
authored andcommitted
added tests
1 parent c82572d commit 4b76dda

File tree

10 files changed

+695
-5
lines changed

10 files changed

+695
-5
lines changed

gvm/protocols/gmp/requests/next/_credential_stores.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ def modify_credential_store(
7878
comment: An optional comment to store alongside the credential store
7979
"""
8080

81+
if not credential_store_id:
82+
raise RequiredArgument(
83+
function=cls.verify_credential_store.__name__,
84+
argument="credential_store_id",
85+
)
86+
8187
cmd = XmlCommand("modify_credential_store")
8288
cmd.set_attribute("credential_store_id", str(credential_store_id))
8389

84-
if active:
90+
if active is not None:
8591
cmd.add_element("active", to_bool(active))
8692
if host:
8793
cmd.add_element("host", host)
@@ -138,5 +144,5 @@ def verify_credential_store(
138144
)
139145

140146
cmd = XmlCommand("verify_credential_store")
141-
cmd.add_element("credential_store_id", str(credential_store_id))
147+
cmd.set_attribute("credential_store_id", str(credential_store_id))
142148
return cmd
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2025 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
from .test_get_credential_stores import GmpGetCredentialStoresTestMixin
6+
from .test_modify_credential_stores import GmpModifyCredentialStoreTestMixin
7+
from .test_verify_credential_stores import GmpVerifyCredentialStoreTestMixin
8+
9+
__all__ = (
10+
"GmpGetCredentialStoresTestMixin",
11+
"GmpModifyCredentialStoreTestMixin",
12+
"GmpVerifyCredentialStoreTestMixin",
13+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2025 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
7+
class GmpGetCredentialStoresTestMixin:
8+
def test_get_credential_stores(self):
9+
self.gmp.get_credential_stores()
10+
11+
self.connection.send.has_been_called_with(b"<get_credential_stores/>")
12+
13+
def test_get_credential_stores_with_filter_string(self):
14+
self.gmp.get_credential_stores(filter_string="foo=bar")
15+
16+
self.connection.send.has_been_called_with(
17+
b'<get_credential_stores filter="foo=bar"/>'
18+
)
19+
20+
def test_get_credential_stores_with_filter_id(self):
21+
self.gmp.get_credential_stores(filter_id="f1")
22+
23+
self.connection.send.has_been_called_with(
24+
b'<get_credential_stores filt_id="f1"/>'
25+
)
26+
27+
def test_get_credential_stores_with_id(self):
28+
self.gmp.get_credential_stores(credential_store_id="cs1")
29+
30+
self.connection.send.has_been_called_with(
31+
b"<get_credential_stores>"
32+
b"<credential_store_id>cs1</credential_store_id>"
33+
b"</get_credential_stores>"
34+
)
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
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+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 GmpVerifyCredentialStoreTestMixin:
10+
def test_verify_credential_store(self):
11+
self.gmp.verify_credential_store(credential_store_id="cs1")
12+
13+
self.connection.send.has_been_called_with(
14+
b'<verify_credential_store credential_store_id="cs1"/>'
15+
)
16+
17+
def test_verify_credential_store_without_id(self):
18+
with self.assertRaises(RequiredArgument):
19+
self.gmp.verify_credential_store(credential_store_id=None)
20+
21+
with self.assertRaises(RequiredArgument):
22+
self.gmp.verify_credential_store(credential_store_id="")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2025 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
from .test_create_credential_store_credential import (
6+
GmpCreateCredentialStoreCredentialTestMixin,
7+
)
8+
from .test_modify_credential_store_credential import (
9+
GmpModifyCredentialStoreCredentialTestMixin,
10+
)
11+
12+
__all__ = (
13+
"GmpCreateCredentialStoreCredentialTestMixin",
14+
"GmpModifyCredentialStoreCredentialTestMixin",
15+
)

0 commit comments

Comments
 (0)