|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (C) 2022 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.utils import check_port |
| 22 | + |
| 23 | + |
| 24 | +class TestCheckPort(unittest.TestCase): |
| 25 | + def test_port_cpe(self): |
| 26 | + self.assertTrue(check_port("cpe:meh:moo*")) |
| 27 | + |
| 28 | + def test_port_cpe_fail(self): |
| 29 | + self.assertFalse(check_port("cpe:meh haha")) |
| 30 | + |
| 31 | + def test_port_general(self): |
| 32 | + self.assertTrue(check_port("general/tcp")) |
| 33 | + |
| 34 | + def test_ports(self): |
| 35 | + self.assertTrue(check_port("1/tcp")) |
| 36 | + self.assertTrue(check_port("12/tcp")) |
| 37 | + self.assertTrue(check_port("123/tcp")) |
| 38 | + self.assertTrue(check_port("1234/tcp")) |
| 39 | + self.assertTrue(check_port("12345/tcp")) |
| 40 | + self.assertTrue(check_port("1/udp")) |
| 41 | + self.assertTrue(check_port("12/udp")) |
| 42 | + |
| 43 | + def test_ports_fail(self): |
| 44 | + self.assertFalse(check_port("1")) |
| 45 | + self.assertFalse(check_port("1//udp")) |
| 46 | + self.assertFalse(check_port("1/12/tcp")) |
| 47 | + self.assertFalse(check_port("tcp")) |
| 48 | + self.assertFalse(check_port("general")) |
| 49 | + self.assertFalse(check_port("lol")) |
0 commit comments