File: test_openvasd1.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 (38 lines) | stat: -rw-r--r-- 1,433 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
# SPDX-FileCopyrightText: 2025 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest
from unittest.mock import MagicMock, patch

from gvm.protocols.http.openvasd import OpenvasdHttpAPIv1


class TestOpenvasdHttpApiV1(unittest.TestCase):
    @patch("gvm.protocols.http.openvasd._openvasd1.create_openvasd_http_client")
    def test_initializes_all_sub_apis(self, mock_crate_openvasd_client):
        mock_httpx_client = MagicMock()
        mock_crate_openvasd_client.return_value = mock_httpx_client

        api = OpenvasdHttpAPIv1(
            host_name="localhost",
            port=3000,
            api_key="test-key",
            server_ca_path="/path/to/ca.pem",
            client_cert_paths=("/path/to/client.pem", "/path/to/key.pem"),
        )

        mock_crate_openvasd_client.assert_called_once_with(
            host_name="localhost",
            port=3000,
            api_key="test-key",
            server_ca_path="/path/to/ca.pem",
            client_cert_paths=("/path/to/client.pem", "/path/to/key.pem"),
        )

        self.assertEqual(api._client, mock_httpx_client)
        self.assertEqual(api.health._client, mock_httpx_client)
        self.assertEqual(api.metadata._client, mock_httpx_client)
        self.assertEqual(api.notus._client, mock_httpx_client)
        self.assertEqual(api.scans._client, mock_httpx_client)
        self.assertEqual(api.vts._client, mock_httpx_client)