Skip to content

Commit 5398f6c

Browse files
authored
Merge pull request #300 from jjnicola/identity
Fix ScannerType check for newer protocols
2 parents 4be2dca + 63bc641 commit 5398f6c

File tree

9 files changed

+389
-20
lines changed

9 files changed

+389
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Deprecated
1717
### Removed
1818
### Fixed
19+
* Fix ScannerType check for newer protocols. [#300](https://github.com/greenbone/python-gvm/pull/300)
1920

2021
[Unreleased]: https://github.com/greenbone/python-gvm/compare/v20.9.0...HEAD
2122

gvm/protocols/gmpv7/gmpv7.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,11 +1458,11 @@ def create_scanner(
14581458
function=self.create_scanner.__name__, argument='credential_id'
14591459
)
14601460

1461-
if not isinstance(scanner_type, ScannerType):
1461+
if not isinstance(scanner_type, self.types.ScannerType):
14621462
raise InvalidArgumentType(
14631463
function=self.create_scanner.__name__,
14641464
argument='scanner_type',
1465-
arg_type=ScannerType.__name__,
1465+
arg_type=self.types.ScannerType.__name__,
14661466
)
14671467

14681468
cmd = XmlCommand("create_scanner")
@@ -5417,11 +5417,11 @@ def modify_scanner(
54175417
cmd.set_attribute("scanner_id", scanner_id)
54185418

54195419
if scanner_type is not None:
5420-
if not isinstance(scanner_type, ScannerType):
5420+
if not isinstance(scanner_type, self.types.ScannerType):
54215421
raise InvalidArgumentType(
54225422
function=self.modify_scanner.__name__,
54235423
argument='scanner_type',
5424-
arg_type=ScannerType.__name__,
5424+
arg_type=self.types.ScannerType.__name__,
54255425
)
54265426

54275427
cmd.add_element("type", scanner_type.value)

tests/protocols/gmpv208/test_v7_from_gmpv208.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ class Gmpv208CreateRoleTestCase(GmpCreateRoleTestCase, Gmpv208TestCase):
136136
pass
137137

138138

139-
class Gmpv208CreateScannerTestCase(GmpCreateScannerTestCase, Gmpv208TestCase):
140-
pass
141-
142-
143139
class Gmpv208CreateUserTestCase(GmpCreateUserTestCase, Gmpv208TestCase):
144140
pass
145141

@@ -516,10 +512,6 @@ class Gmpv208ModifyRoleTestCase(GmpModifyRoleTestCase, Gmpv208TestCase):
516512
pass
517513

518514

519-
class Gmpv208ModifyScannerTestCase(GmpModifyScannerTestCase, Gmpv208TestCase):
520-
pass
521-
522-
523515
class Gmpv208ModifySettingTestCase(GmpModifySettingTestCase, Gmpv208TestCase):
524516
pass
525517

tests/protocols/gmpv208/test_v9_from_gmpv208.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,14 @@ class Gmpv208ModifyTLSCertificateTestCase(
166166
GmpModifyTLSCertificateTestCase, Gmpv208TestCase
167167
):
168168
pass
169+
170+
171+
class Gmpv208CreateScannerTestCase(
172+
GmpCreateScannerTestCase, Gmpv208TestCase
173+
):
174+
pass
175+
176+
class Gmpv208ModifyScannerTestCase(
177+
GmpModifyScannerTestCase, Gmpv208TestCase
178+
):
179+
pass

tests/protocols/gmpv9/test_new_gmpv9.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,15 @@ class Gmpv9ModifyTLSCertificateTestCase(
190190
GmpModifyTLSCertificateTestCase, Gmpv9TestCase
191191
):
192192
pass
193+
194+
195+
class Gmpv9CreateScannerTestCase(
196+
GmpCreateScannerTestCase, Gmpv9TestCase
197+
):
198+
pass
199+
200+
201+
class Gmpv9ModifyScannerTestCase(
202+
GmpModifyScannerTestCase, Gmpv9TestCase
203+
):
204+
pass

tests/protocols/gmpv9/test_v7_from_gmpv9.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ class Gmpv9CreateRoleTestCase(GmpCreateRoleTestCase, Gmpv9TestCase):
138138
pass
139139

140140

141-
class Gmpv9CreateScannerTestCase(GmpCreateScannerTestCase, Gmpv9TestCase):
142-
pass
143-
144-
145141
class Gmpv9CreateUserTestCase(GmpCreateUserTestCase, Gmpv9TestCase):
146142
pass
147143

@@ -532,10 +528,6 @@ class Gmpv9ModifyRoleTestCase(GmpModifyRoleTestCase, Gmpv9TestCase):
532528
pass
533529

534530

535-
class Gmpv9ModifyScannerTestCase(GmpModifyScannerTestCase, Gmpv9TestCase):
536-
pass
537-
538-
539531
class Gmpv9ModifySettingTestCase(GmpModifySettingTestCase, Gmpv9TestCase):
540532
pass
541533

tests/protocols/gmpv9/testcmds/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@
5858
from .test_modify_tag import GmpModifyTagTestCase
5959
from .test_modify_ticket import GmpModifyTicketTestCase
6060
from .test_modify_tls_certificate import GmpModifyTLSCertificateTestCase
61+
from .test_create_scanner import GmpCreateScannerTestCase
62+
from .test_modify_scanner import GmpModifyScannerTestCase
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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 RequiredArgument, InvalidArgumentType
22+
23+
from gvm.protocols.gmpv9 import ScannerType
24+
25+
26+
class GmpCreateScannerTestCase:
27+
def test_create_scanner(self):
28+
self.gmp.create_scanner(
29+
name='foo',
30+
host='localhost',
31+
port=1234,
32+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
33+
credential_id='c1',
34+
)
35+
36+
self.connection.send.has_been_called_with(
37+
'<create_scanner>'
38+
'<name>foo</name>'
39+
'<host>localhost</host>'
40+
'<port>1234</port>'
41+
'<type>1</type>'
42+
'<credential id="c1"/>'
43+
'</create_scanner>'
44+
)
45+
46+
def test_create_scanner_missing_name(self):
47+
with self.assertRaises(RequiredArgument):
48+
self.gmp.create_scanner(
49+
name=None,
50+
host='localhost',
51+
port=1234,
52+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
53+
credential_id='c1',
54+
)
55+
56+
with self.assertRaises(RequiredArgument):
57+
self.gmp.create_scanner(
58+
name='',
59+
host='localhost',
60+
port=1234,
61+
scanner_type='1',
62+
credential_id='c1',
63+
)
64+
65+
def test_create_scanner_missing_host(self):
66+
with self.assertRaises(RequiredArgument):
67+
self.gmp.create_scanner(
68+
name='foo',
69+
host=None,
70+
port=1234,
71+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
72+
credential_id='c1',
73+
)
74+
75+
with self.assertRaises(RequiredArgument):
76+
self.gmp.create_scanner(
77+
name='foo',
78+
host='',
79+
port=1234,
80+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
81+
credential_id='c1',
82+
)
83+
84+
def test_create_scanner_missing_port(self):
85+
with self.assertRaises(RequiredArgument):
86+
self.gmp.create_scanner(
87+
name='foo',
88+
host='localhost',
89+
port=None,
90+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
91+
credential_id='c1',
92+
)
93+
94+
with self.assertRaises(RequiredArgument):
95+
self.gmp.create_scanner(
96+
name='foo',
97+
host='localhost',
98+
port='',
99+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
100+
credential_id='c1',
101+
)
102+
103+
def test_create_scanner_missing_scanner_type(self):
104+
with self.assertRaises(RequiredArgument):
105+
self.gmp.create_scanner(
106+
name='foo',
107+
host='localhost',
108+
port=1234,
109+
scanner_type=None,
110+
credential_id='c1',
111+
)
112+
113+
with self.assertRaises(RequiredArgument):
114+
self.gmp.create_scanner(
115+
name='foo',
116+
host='localhost',
117+
port=1234,
118+
scanner_type='',
119+
credential_id='c1',
120+
)
121+
122+
def test_create_scanner_missing_credential_id(self):
123+
with self.assertRaises(RequiredArgument):
124+
self.gmp.create_scanner(
125+
name='foo',
126+
host='localhost',
127+
port=1234,
128+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
129+
credential_id=None,
130+
)
131+
132+
with self.assertRaises(RequiredArgument):
133+
self.gmp.create_scanner(
134+
name='foo',
135+
host='localhost',
136+
port=1234,
137+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
138+
credential_id='',
139+
)
140+
141+
def test_create_scanner_invalid_scanner_type(self):
142+
with self.assertRaises(InvalidArgumentType):
143+
self.gmp.create_scanner(
144+
name='foo',
145+
host='localhost',
146+
port=1234,
147+
scanner_type='bar',
148+
credential_id='c1',
149+
)
150+
151+
with self.assertRaises(InvalidArgumentType):
152+
self.gmp.create_scanner(
153+
name='foo',
154+
host='localhost',
155+
port=1234,
156+
scanner_type='55',
157+
credential_id='c1',
158+
)
159+
160+
def test_create_scanner_with_ca_pub(self):
161+
self.gmp.create_scanner(
162+
name='foo',
163+
host='localhost',
164+
port=1234,
165+
ca_pub='foo',
166+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
167+
credential_id='c1',
168+
)
169+
170+
self.connection.send.has_been_called_with(
171+
'<create_scanner>'
172+
'<name>foo</name>'
173+
'<host>localhost</host>'
174+
'<port>1234</port>'
175+
'<type>1</type>'
176+
'<ca_pub>foo</ca_pub>'
177+
'<credential id="c1"/>'
178+
'</create_scanner>'
179+
)
180+
181+
def test_create_scanner_with_comment(self):
182+
self.gmp.create_scanner(
183+
name='foo',
184+
host='localhost',
185+
port=1234,
186+
scanner_type=ScannerType.OSP_SCANNER_TYPE,
187+
credential_id='c1',
188+
comment='bar',
189+
)
190+
191+
self.connection.send.has_been_called_with(
192+
'<create_scanner>'
193+
'<name>foo</name>'
194+
'<host>localhost</host>'
195+
'<port>1234</port>'
196+
'<type>1</type>'
197+
'<credential id="c1"/>'
198+
'<comment>bar</comment>'
199+
'</create_scanner>'
200+
)
201+
202+
203+
if __name__ == '__main__':
204+
unittest.main()

0 commit comments

Comments
 (0)