1
|
|
|
# Copyright (C) 2014-2018 Greenbone Networks GmbH |
2
|
|
|
# |
3
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later |
4
|
|
|
# |
5
|
|
|
# This program is free software; you can redistribute it and/or |
6
|
|
|
# modify it under the terms of the GNU General Public License |
7
|
|
|
# as published by the Free Software Foundation; either version 2 |
8
|
|
|
# of the License, or (at your option) any later version. |
9
|
|
|
# |
10
|
|
|
# This program is distributed in the hope that it will be useful, |
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
# GNU General Public License for more details. |
14
|
|
|
# |
15
|
|
|
# You should have received a copy of the GNU General Public License |
16
|
|
|
# along with this program; if not, write to the Free Software |
17
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18
|
|
|
|
19
|
|
|
""" Test suites for Target manipulations. |
20
|
|
|
""" |
21
|
|
|
|
22
|
|
|
import unittest |
23
|
|
|
|
24
|
|
|
from ospd.misc import target_str_to_list |
25
|
|
|
from ospd.misc import get_hostname_by_address |
26
|
|
|
|
27
|
|
|
class testTargetLists(unittest.TestCase): |
28
|
|
|
|
29
|
|
|
def test24Net(self): |
30
|
|
|
addresses = target_str_to_list('195.70.81.0/24') |
31
|
|
|
self.assertFalse(addresses is None) |
32
|
|
|
self.assertEqual(len(addresses), 254) |
33
|
|
|
for i in range(1, 255): |
34
|
|
|
self.assertTrue('195.70.81.%d' % i in addresses) |
35
|
|
|
|
36
|
|
|
def testRange(self): |
37
|
|
|
addresses = target_str_to_list('195.70.81.1-10') |
38
|
|
|
self.assertFalse(addresses is None) |
39
|
|
|
self.assertEqual(len(addresses), 10) |
40
|
|
|
for i in range(1, 10): |
41
|
|
|
self.assertTrue('195.70.81.%d' % i in addresses) |
42
|
|
|
|
43
|
|
|
def testGetHostnameByAddress(self): |
44
|
|
|
hostname = get_hostname_by_address('127.0.0.1') |
45
|
|
|
self.assertEqual(hostname, 'localhost') |
46
|
|
|
hostname = get_hostname_by_address('') |
47
|
|
|
self.assertTrue(hostname is '') |
48
|
|
|
hostname = get_hostname_by_address('127.0.0.1111') |
49
|
|
|
self.assertTrue(hostname is '') |
50
|
|
|
|