|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2018 Greenbone Networks GmbH |
|
3
|
|
|
# |
|
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
|
5
|
|
|
# |
|
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# This program is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
import unittest |
|
20
|
|
|
|
|
21
|
|
|
from gvm.errors import InvalidArgumentType, RequiredArgument |
|
22
|
|
|
|
|
23
|
|
|
from gvm.protocols.gmpv7 import CredentialFormat |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class GmpGetCredentialTestCase: |
|
27
|
|
|
def test_get_credential(self): |
|
28
|
|
|
self.gmp.get_credential('id') |
|
29
|
|
|
|
|
30
|
|
|
self.connection.send.has_been_called_with( |
|
31
|
|
|
'<get_credentials credential_id="id"/>' |
|
32
|
|
|
) |
|
33
|
|
|
|
|
34
|
|
|
def test_get_credential_missing_credential_id(self): |
|
35
|
|
|
with self.assertRaises(RequiredArgument): |
|
36
|
|
|
self.gmp.get_credential(None) |
|
37
|
|
|
|
|
38
|
|
|
def test_get_credential_invalid_credential_id(self): |
|
39
|
|
|
with self.assertRaises(RequiredArgument): |
|
40
|
|
|
self.gmp.get_credential(credential_id=None) |
|
41
|
|
|
|
|
42
|
|
|
with self.assertRaises(RequiredArgument): |
|
43
|
|
|
self.gmp.get_credential('') |
|
44
|
|
|
|
|
45
|
|
|
def test_get_credential_with_credential_format(self): |
|
46
|
|
|
self.gmp.get_credential('id', credential_format=CredentialFormat.KEY) |
|
47
|
|
|
|
|
48
|
|
|
self.connection.send.has_been_called_with( |
|
49
|
|
|
'<get_credentials credential_id="id" format="key"/>' |
|
50
|
|
|
) |
|
51
|
|
|
|
|
52
|
|
|
self.gmp.get_credential('id', credential_format=CredentialFormat.RPM) |
|
53
|
|
|
|
|
54
|
|
|
self.connection.send.has_been_called_with( |
|
55
|
|
|
'<get_credentials credential_id="id" format="rpm"/>' |
|
56
|
|
|
) |
|
57
|
|
|
|
|
58
|
|
|
self.gmp.get_credential('id', credential_format=CredentialFormat.DEB) |
|
59
|
|
|
|
|
60
|
|
|
self.connection.send.has_been_called_with( |
|
61
|
|
|
'<get_credentials credential_id="id" format="deb"/>' |
|
62
|
|
|
) |
|
63
|
|
|
|
|
64
|
|
|
self.gmp.get_credential('id', credential_format=CredentialFormat.EXE) |
|
65
|
|
|
|
|
66
|
|
|
self.connection.send.has_been_called_with( |
|
67
|
|
|
'<get_credentials credential_id="id" format="exe"/>' |
|
68
|
|
|
) |
|
69
|
|
|
|
|
70
|
|
|
self.gmp.get_credential('id', credential_format=CredentialFormat.PEM) |
|
71
|
|
|
|
|
72
|
|
|
self.connection.send.has_been_called_with( |
|
73
|
|
|
'<get_credentials credential_id="id" format="pem"/>' |
|
74
|
|
|
) |
|
75
|
|
|
|
|
76
|
|
|
def test_get_credential_with_invalid_credential_format(self): |
|
77
|
|
|
with self.assertRaises(InvalidArgumentType): |
|
78
|
|
|
self.gmp.get_credential('id', credential_format='foo') |
|
79
|
|
|
|
|
80
|
|
|
def test_get_credential_with_scanners(self): |
|
81
|
|
|
self.gmp.get_credential('id', scanners=True) |
|
82
|
|
|
|
|
83
|
|
|
self.connection.send.has_been_called_with( |
|
84
|
|
|
'<get_credentials credential_id="id" scanners="1"/>' |
|
85
|
|
|
) |
|
86
|
|
|
|
|
87
|
|
|
self.gmp.get_credential('id', scanners=False) |
|
88
|
|
|
|
|
89
|
|
|
self.connection.send.has_been_called_with( |
|
90
|
|
|
'<get_credentials credential_id="id" scanners="0"/>' |
|
91
|
|
|
) |
|
92
|
|
|
|
|
93
|
|
|
def test_get_credential_with_targets(self): |
|
94
|
|
|
self.gmp.get_credential('id', targets=True) |
|
95
|
|
|
|
|
96
|
|
|
self.connection.send.has_been_called_with( |
|
97
|
|
|
'<get_credentials credential_id="id" targets="1"/>' |
|
98
|
|
|
) |
|
99
|
|
|
|
|
100
|
|
|
self.gmp.get_credential('id', targets=False) |
|
101
|
|
|
|
|
102
|
|
|
self.connection.send.has_been_called_with( |
|
103
|
|
|
'<get_credentials credential_id="id" targets="0"/>' |
|
104
|
|
|
) |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
if __name__ == '__main__': |
|
108
|
|
|
unittest.main() |
|
109
|
|
|
|