File: test_cpes.py

package info (click to toggle)
python-gvm 26.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,132 kB
  • sloc: python: 44,662; makefile: 18
file content (65 lines) | stat: -rw-r--r-- 1,839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest

from gvm.errors import RequiredArgument
from gvm.protocols.gmp.requests.v224 import Cpes


class CpesTestCase(unittest.TestCase):
    def test_get_cpes(self):
        request = Cpes.get_cpes()
        self.assertEqual(
            bytes(request),
            b'<get_info type="CPE"/>',
        )

    def test_get_cpes_with_filter_string(self):
        request = Cpes.get_cpes(filter_string="filter_string")
        self.assertEqual(
            bytes(request),
            b'<get_info type="CPE" filter="filter_string"/>',
        )

    def test_get_cpes_with_filter_id(self):
        request = Cpes.get_cpes(filter_id="filter_id")
        self.assertEqual(
            bytes(request),
            b'<get_info type="CPE" filt_id="filter_id"/>',
        )

    def test_get_cpes_with_name(self):
        request = Cpes.get_cpes(name="name")
        self.assertEqual(
            bytes(request),
            b'<get_info type="CPE" name="name"/>',
        )

    def test_get_cpes_with_details(self):
        request = Cpes.get_cpes(details=True)
        self.assertEqual(
            bytes(request),
            b'<get_info type="CPE" details="1"/>',
        )

        request = Cpes.get_cpes(details=False)
        self.assertEqual(
            bytes(request),
            b'<get_info type="CPE" details="0"/>',
        )

    def test_get_cpe(self):
        request = Cpes.get_cpe("cpe_id")
        self.assertEqual(
            bytes(request),
            b'<get_info info_id="cpe_id" type="CPE" details="1"/>',
        )

    def test_get_cpe_missing_cpe_id(self):
        with self.assertRaises(RequiredArgument):
            Cpes.get_cpe(None)

        with self.assertRaises(RequiredArgument):
            Cpes.get_cpe("")