-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97f4b9f
commit b438786
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from typing import Union | ||
|
||
from gvm._enum import Enum | ||
from gvm.errors import RequiredArgument | ||
from gvm.protocols.core import Request | ||
from gvm.xml import XmlCommand | ||
|
||
|
||
class FeedType(Enum): | ||
"""Enum for feed types""" | ||
|
||
NVT = "NVT" | ||
CERT = "CERT" | ||
SCAP = "SCAP" | ||
GVMD_DATA = "GVMD_DATA" | ||
|
||
|
||
class Feed: | ||
@staticmethod | ||
def get_feeds() -> Request: | ||
"""Request the list of feeds""" | ||
return XmlCommand("get_feeds") | ||
|
||
@classmethod | ||
def get_feed(cls, feed_type: Union[FeedType, str]) -> Request: | ||
"""Request a single feed | ||
Arguments: | ||
feed_type: Type of single feed to get: NVT, CERT or SCAP | ||
""" | ||
if not feed_type: | ||
raise RequiredArgument( | ||
function=cls.get_feed.__name__, argument="feed_type" | ||
) | ||
|
||
if not isinstance(feed_type, FeedType): | ||
feed_type = FeedType(feed_type) | ||
|
||
cmd = XmlCommand("get_feeds") | ||
cmd.set_attribute("type", feed_type.value) | ||
|
||
return cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import unittest | ||
|
||
from gvm.errors import InvalidArgument, RequiredArgument | ||
from gvm.protocols.gmp.requests import Feed, FeedType | ||
|
||
|
||
class FeedTestCase(unittest.TestCase): | ||
def test_get_feed(self) -> None: | ||
""" | ||
Test basic get_feed calls with only resource_type except special | ||
cases for audit, policy, scan_config and task. | ||
""" | ||
request = Feed.get_feed(FeedType.NVT) | ||
|
||
self.assertEqual(bytes(request), b'<get_feeds type="NVT"/>') | ||
|
||
request = Feed.get_feed(FeedType.CERT) | ||
|
||
self.assertEqual(bytes(request), b'<get_feeds type="CERT"/>') | ||
|
||
request = Feed.get_feed(FeedType.SCAP) | ||
|
||
self.assertEqual(bytes(request), b'<get_feeds type="SCAP"/>') | ||
|
||
request = Feed.get_feed(FeedType.GVMD_DATA) | ||
|
||
self.assertEqual(bytes(request), b'<get_feeds type="GVMD_DATA"/>') | ||
|
||
def test_get_feed_missing_type(self): | ||
""" | ||
Test get_feed calls with missing resource_type | ||
""" | ||
with self.assertRaises(RequiredArgument): | ||
Feed.get_feed(feed_type=None) | ||
|
||
with self.assertRaises(RequiredArgument): | ||
Feed.get_feed(feed_type="") | ||
|
||
with self.assertRaises(RequiredArgument): | ||
Feed.get_feed("") | ||
|
||
def test_get_feed_invalid_type(self): | ||
""" | ||
Test get_feed calls with invalid resource_type | ||
""" | ||
with self.assertRaises(InvalidArgument): | ||
Feed.get_feed("foo") |