|
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.protocols.gmpv7 import Gmp |
|
22
|
|
|
|
|
23
|
|
|
from .. import MockConnection |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class GMPCreateTaskCommandTestCase(unittest.TestCase): |
|
27
|
|
|
|
|
28
|
|
|
TASK_NAME = "important task" |
|
29
|
|
|
CONFIG_ID = "cd0641e7-40b8-4e2c-811e-6b39d6d4b904" |
|
30
|
|
|
TARGET_ID = '267a3405-e84a-47da-97b2-5fa0d2e8995e' |
|
31
|
|
|
SCANNER_ID = 'b64c81b2-b9de-11e3-a2e9-406186ea4fc5' |
|
32
|
|
|
ALERT_IDS = ['3ab38c6a-30ac-407a-98db-ad6e74c98b9a',] |
|
33
|
|
|
COMMENT = 'this task has been created for test purposes' |
|
34
|
|
|
|
|
35
|
|
|
def setUp(self): |
|
36
|
|
|
self.connection = MockConnection() |
|
37
|
|
|
self.gmp = Gmp(self.connection) |
|
38
|
|
|
|
|
39
|
|
|
def test_without_alert_correct_cmd(self): |
|
40
|
|
|
self.gmp.create_task( |
|
41
|
|
|
self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID, |
|
42
|
|
|
comment=self.COMMENT) |
|
43
|
|
|
|
|
44
|
|
|
self.connection.send.has_been_called_with( |
|
45
|
|
|
'<create_task>' |
|
46
|
|
|
'<name>{0}</name>' |
|
47
|
|
|
'<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>' |
|
48
|
|
|
'<comment>{1}</comment>' |
|
49
|
|
|
'</create_task>'.format(self.TASK_NAME, self.COMMENT, |
|
50
|
|
|
self.CONFIG_ID, self.TARGET_ID, |
|
51
|
|
|
self.SCANNER_ID) |
|
52
|
|
|
) |
|
53
|
|
|
|
|
54
|
|
|
def test_single_alert(self): |
|
55
|
|
|
self.gmp.create_task( |
|
56
|
|
|
self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID, |
|
57
|
|
|
alert_ids=self.ALERT_IDS) |
|
58
|
|
|
|
|
59
|
|
|
self.connection.send.has_been_called_with( |
|
60
|
|
|
'<create_task>' |
|
61
|
|
|
'<name>{task}</name>' |
|
62
|
|
|
'<config id="{config}"/>' |
|
63
|
|
|
'<target id="{target}"/>' |
|
64
|
|
|
'<scanner id="{scanner}"/>' |
|
65
|
|
|
'<alert id="{alert}"/>' |
|
66
|
|
|
'</create_task>'.format( |
|
67
|
|
|
task=self.TASK_NAME, config=self.CONFIG_ID, |
|
68
|
|
|
target=self.TARGET_ID, scanner=self.SCANNER_ID, |
|
69
|
|
|
alert=self.ALERT_IDS[0]) |
|
70
|
|
|
) |
|
71
|
|
|
|
|
72
|
|
|
def test_multiple_alerts(self): |
|
73
|
|
|
alert_id2 = 'fb3d6f82-d706-4f99-9e53-d7d85257e25f' |
|
74
|
|
|
alert_id3 = 'a33864a9-d3fd-44b3-8717-972bfb01dfcf' |
|
75
|
|
|
alert_ids = self.ALERT_IDS[:] |
|
76
|
|
|
alert_ids.extend([alert_id2, alert_id3]) |
|
77
|
|
|
|
|
78
|
|
|
self.gmp.create_task( |
|
79
|
|
|
self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID, |
|
80
|
|
|
alert_ids=alert_ids) |
|
81
|
|
|
|
|
82
|
|
|
self.connection.send.has_been_called_with( |
|
83
|
|
|
'<create_task>' |
|
84
|
|
|
'<name>{task}</name>' |
|
85
|
|
|
'<config id="{config}"/>' |
|
86
|
|
|
'<target id="{target}"/>' |
|
87
|
|
|
'<scanner id="{scanner}"/>' |
|
88
|
|
|
'<alert id="{alert1}"/>' |
|
89
|
|
|
'<alert id="{alert2}"/>' |
|
90
|
|
|
'<alert id="{alert3}"/>' |
|
91
|
|
|
'</create_task>'.format( |
|
92
|
|
|
task=self.TASK_NAME, config=self.CONFIG_ID, |
|
93
|
|
|
target=self.TARGET_ID, scanner=self.SCANNER_ID, |
|
94
|
|
|
alert1=alert_ids[0], |
|
95
|
|
|
alert2=alert_ids[1], |
|
96
|
|
|
alert3=alert_ids[2]) |
|
97
|
|
|
) |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
if __name__ == '__main__': |
|
101
|
|
|
unittest.main() |
|
102
|
|
|
|