|
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 gmp.xml import GmpCommandFactory |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class GMPCreateTaskCommandTestCase(unittest.TestCase): |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
TASK_NAME = "important task" |
|
27
|
|
|
CONFIG_ID = "cd0641e7-40b8-4e2c-811e-6b39d6d4b904" |
|
28
|
|
|
TARGET_ID = '267a3405-e84a-47da-97b2-5fa0d2e8995e' |
|
29
|
|
|
SCANNER_ID = 'b64c81b2-b9de-11e3-a2e9-406186ea4fc5' |
|
30
|
|
|
ALERT_ID = '3ab38c6a-30ac-407a-98db-ad6e74c98b9a' |
|
31
|
|
|
COMMENT = 'this task has been created for test purposes' |
|
32
|
|
|
|
|
33
|
|
|
def setUp(self): |
|
34
|
|
|
self.gmp = GmpCommandFactory() |
|
35
|
|
|
|
|
36
|
|
|
def test_without_alert_correct_cmd(self): |
|
|
|
|
|
|
37
|
|
|
cmd = self.gmp.create_task_command( |
|
38
|
|
|
self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID, |
|
39
|
|
|
comment=self.COMMENT) |
|
40
|
|
|
|
|
41
|
|
|
self.assertEqual( |
|
42
|
|
|
'<create_task>' |
|
43
|
|
|
'<name>{0}</name>' |
|
44
|
|
|
'<comment>{1}</comment>' |
|
45
|
|
|
'<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>' |
|
46
|
|
|
'</create_task>'.format(self.TASK_NAME, self.COMMENT, |
|
47
|
|
|
self.CONFIG_ID, self.TARGET_ID, |
|
48
|
|
|
self.SCANNER_ID), |
|
49
|
|
|
cmd) |
|
50
|
|
|
|
|
51
|
|
|
def test_single_alert_correct_cmd(self): |
|
|
|
|
|
|
52
|
|
|
cmd = self.gmp.create_task_command( |
|
53
|
|
|
self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID, |
|
54
|
|
|
self.ALERT_ID, self.COMMENT) |
|
55
|
|
|
|
|
56
|
|
|
self.assertEqual( |
|
57
|
|
|
'<create_task>' |
|
58
|
|
|
'<name>{0}</name>' |
|
59
|
|
|
'<comment>{1}</comment>' |
|
60
|
|
|
'<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>' |
|
61
|
|
|
'<alert id="{5}"/>' |
|
62
|
|
|
'</create_task>'.format(self.TASK_NAME, self.COMMENT, |
|
63
|
|
|
self.CONFIG_ID, self.TARGET_ID, |
|
64
|
|
|
self.SCANNER_ID, self.ALERT_ID), |
|
65
|
|
|
cmd) |
|
66
|
|
|
|
|
67
|
|
|
def test_multiple_alerts_correct_cmd(self): |
|
|
|
|
|
|
68
|
|
|
alert_id2 = 'fb3d6f82-d706-4f99-9e53-d7d85257e25f' |
|
69
|
|
|
alert_id3 = 'a33864a9-d3fd-44b3-8717-972bfb01dfcf' |
|
70
|
|
|
alert_ids = [self.ALERT_ID, alert_id2, alert_id3] |
|
71
|
|
|
|
|
72
|
|
|
cmd = self.gmp.create_task_command( |
|
73
|
|
|
self.TASK_NAME, self.CONFIG_ID, self.TARGET_ID, self.SCANNER_ID, |
|
74
|
|
|
alert_ids, self.COMMENT) |
|
75
|
|
|
|
|
76
|
|
|
self.assertEqual( |
|
77
|
|
|
'<create_task>' |
|
78
|
|
|
'<name>{0}</name>' |
|
79
|
|
|
'<comment>{1}</comment>' |
|
80
|
|
|
'<config id="{2}"/><target id="{3}"/><scanner id="{4}"/>' |
|
81
|
|
|
'<alert id="{5}"/><alert id="{6}"/><alert id="{7}"/>' |
|
82
|
|
|
'</create_task>'.format(self.TASK_NAME, self.COMMENT, |
|
83
|
|
|
self.CONFIG_ID, self.TARGET_ID, |
|
84
|
|
|
self.SCANNER_ID, self.ALERT_ID, |
|
85
|
|
|
alert_id2, alert_id3), |
|
86
|
|
|
cmd) |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
if __name__ == '__main__': |
|
90
|
|
|
unittest.main() |
|
91
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.