@@ 26-192 (lines=167) @@ | ||
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>' |
@@ 26-192 (lines=167) @@ | ||
23 | from gvm.protocols.gmpv7 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>' |