From 603e685427e5c0a8119a20d9f7bd9eb8e3219ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 27 Jan 2025 12:55:53 +0100 Subject: [PATCH 1/6] Add: Support GMP version 22.6 Implement support for GMP version 22.6 which adds audit reports, report configs and changes get feeds. --- gvm/protocols/gmp/__init__.py | 2 + gvm/protocols/gmp/_gmp.py | 13 +- gvm/protocols/gmp/_gmp226.py | 278 +++++++++++ gvm/protocols/gmp/requests/v226/__init__.py | 146 ++++++ .../gmp/requests/v226/_audit_reports.py | 129 ++++++ .../gmp/requests/v226/_report_configs.py | 227 +++++++++ gvm/protocols/gmp/requests/v226/_reports.py | 171 +++++++ .../gmp/requests/v226/_resource_names.py | 117 +++++ gvm/protocols/latest.py | 4 +- gvm/protocols/next.py | 4 +- tests/protocols/gmp/requests/v226/__init__.py | 3 + .../gmp/requests/v226/test_audit_reports.py | 152 ++++++ .../gmp/requests/v226/test_reports.py | 227 +++++++++ .../gmp/requests/v226/test_resource_names.py | 431 ++++++++++++++++++ tests/protocols/gmp/test_context_manager.py | 43 +- tests/protocols/gmpv226/__init__.py | 13 + tests/protocols/gmpv226/entities/__init__.py | 4 + .../entities/audit_reports/__init__.py | 14 + .../audit_reports/test_delete_report.py | 22 + .../entities/audit_reports/test_get_report.py | 81 ++++ .../audit_reports/test_get_reports.py | 71 +++ .../gmpv226/entities/reports/__init__.py | 16 + .../entities/reports/test_delete_report.py | 22 + .../entities/reports/test_get_report.py | 81 ++++ .../entities/reports/test_get_reports.py | 69 +++ .../entities/reports/test_import_report.py | 70 +++ .../entities/resourcenames/__init__.py | 9 + .../resourcenames/test_get_resource_name.py | 246 ++++++++++ .../test_get_resource_names_list.py | 198 ++++++++ .../protocols/gmpv226/entities/test_alerts.py | 48 ++ .../gmpv226/entities/test_audit_reports.py | 23 + .../protocols/gmpv226/entities/test_audits.py | 53 +++ .../gmpv226/entities/test_credentials.py | 38 ++ .../gmpv226/entities/test_filters.py | 38 ++ .../protocols/gmpv226/entities/test_groups.py | 38 ++ .../protocols/gmpv226/entities/test_hosts.py | 33 ++ .../protocols/gmpv226/entities/test_notes.py | 38 ++ .../entities/test_operating_systems.py | 36 ++ .../gmpv226/entities/test_overrides.py | 38 ++ .../gmpv226/entities/test_permissions.py | 38 ++ .../gmpv226/entities/test_policies.py | 80 ++++ .../gmpv226/entities/test_port_lists.py | 48 ++ .../gmpv226/entities/test_report_formats.py | 51 +++ .../gmpv226/entities/test_reports.py | 28 ++ .../gmpv226/entities/test_resource_names.py | 20 + .../gmpv226/entities/test_results.py | 18 + .../protocols/gmpv226/entities/test_roles.py | 38 ++ .../gmpv226/entities/test_scan_configs.py | 80 ++++ .../gmpv226/entities/test_scanners.py | 38 ++ .../gmpv226/entities/test_schedules.py | 38 ++ .../gmpv226/entities/test_secinfo.py | 83 ++++ tests/protocols/gmpv226/entities/test_tags.py | 38 ++ .../gmpv226/entities/test_targets.py | 38 ++ .../protocols/gmpv226/entities/test_tasks.py | 65 +++ .../gmpv226/entities/test_tickets.py | 38 ++ .../gmpv226/entities/test_tls_certificates.py | 48 ++ .../protocols/gmpv226/entities/test_users.py | 38 ++ .../gmpv226/entities/test_vulnerabilities.py | 20 + tests/protocols/gmpv226/enums/__init__.py | 4 + .../gmpv226/enums/test_aggregate_statistic.py | 57 +++ .../gmpv226/enums/test_alert_condition.py | 45 ++ .../gmpv226/enums/test_alert_event.py | 45 ++ .../gmpv226/enums/test_alert_method.py | 69 +++ .../gmpv226/enums/test_alive_test.py | 61 +++ .../gmpv226/enums/test_credential_format.py | 41 ++ .../gmpv226/enums/test_credential_type.py | 49 ++ .../gmpv226/enums/test_entity_type.py | 166 +++++++ .../protocols/gmpv226/enums/test_feed_type.py | 37 ++ .../gmpv226/enums/test_filter_type.py | 138 ++++++ .../gmpv226/enums/test_help_format.py | 37 ++ .../gmpv226/enums/test_hosts_ordering.py | 33 ++ .../protocols/gmpv226/enums/test_info_type.py | 49 ++ .../enums/test_permission_subject_type.py | 33 ++ .../gmpv226/enums/test_port_range_type.py | 29 ++ .../gmpv226/enums/test_report_format_type.py | 97 ++++ .../gmpv226/enums/test_resource_type.py | 133 ++++++ .../gmpv226/enums/test_scanner_type.py | 49 ++ .../gmpv226/enums/test_snmp_algorithms.py | 52 +++ .../gmpv226/enums/test_sort_order.py | 33 ++ .../gmpv226/enums/test_ticket_status.py | 33 ++ .../gmpv226/enums/test_user_auth_type.py | 37 ++ tests/protocols/gmpv226/system/__init__.py | 4 + .../gmpv226/system/test_aggregates.py | 11 + .../gmpv226/system/test_authentication.py | 23 + tests/protocols/gmpv226/system/test_feed.py | 15 + tests/protocols/gmpv226/system/test_help.py | 11 + .../gmpv226/system/test_system_reports.py | 11 + .../protocols/gmpv226/system/test_trashcan.py | 20 + .../gmpv226/system/test_user_settings.py | 23 + .../protocols/gmpv226/system/test_versions.py | 16 + .../gmpv226/system/versions/__init__.py | 8 + .../versions/test_get_protocol_version.py | 9 + tests/protocols/gmpv226/test_gmp_types.py | 33 ++ .../protocols/gmpv226/test_with_statement.py | 18 + tests/protocols/test_latest.py | 2 +- tests/protocols/test_next.py | 2 +- 96 files changed, 5613 insertions(+), 11 deletions(-) create mode 100644 gvm/protocols/gmp/_gmp226.py create mode 100644 gvm/protocols/gmp/requests/v226/__init__.py create mode 100644 gvm/protocols/gmp/requests/v226/_audit_reports.py create mode 100644 gvm/protocols/gmp/requests/v226/_report_configs.py create mode 100644 gvm/protocols/gmp/requests/v226/_reports.py create mode 100644 gvm/protocols/gmp/requests/v226/_resource_names.py create mode 100644 tests/protocols/gmp/requests/v226/__init__.py create mode 100644 tests/protocols/gmp/requests/v226/test_audit_reports.py create mode 100644 tests/protocols/gmp/requests/v226/test_reports.py create mode 100644 tests/protocols/gmp/requests/v226/test_resource_names.py create mode 100644 tests/protocols/gmpv226/__init__.py create mode 100644 tests/protocols/gmpv226/entities/__init__.py create mode 100644 tests/protocols/gmpv226/entities/audit_reports/__init__.py create mode 100644 tests/protocols/gmpv226/entities/audit_reports/test_delete_report.py create mode 100644 tests/protocols/gmpv226/entities/audit_reports/test_get_report.py create mode 100644 tests/protocols/gmpv226/entities/audit_reports/test_get_reports.py create mode 100644 tests/protocols/gmpv226/entities/reports/__init__.py create mode 100644 tests/protocols/gmpv226/entities/reports/test_delete_report.py create mode 100644 tests/protocols/gmpv226/entities/reports/test_get_report.py create mode 100644 tests/protocols/gmpv226/entities/reports/test_get_reports.py create mode 100644 tests/protocols/gmpv226/entities/reports/test_import_report.py create mode 100644 tests/protocols/gmpv226/entities/resourcenames/__init__.py create mode 100644 tests/protocols/gmpv226/entities/resourcenames/test_get_resource_name.py create mode 100644 tests/protocols/gmpv226/entities/resourcenames/test_get_resource_names_list.py create mode 100644 tests/protocols/gmpv226/entities/test_alerts.py create mode 100644 tests/protocols/gmpv226/entities/test_audit_reports.py create mode 100644 tests/protocols/gmpv226/entities/test_audits.py create mode 100644 tests/protocols/gmpv226/entities/test_credentials.py create mode 100644 tests/protocols/gmpv226/entities/test_filters.py create mode 100644 tests/protocols/gmpv226/entities/test_groups.py create mode 100644 tests/protocols/gmpv226/entities/test_hosts.py create mode 100644 tests/protocols/gmpv226/entities/test_notes.py create mode 100644 tests/protocols/gmpv226/entities/test_operating_systems.py create mode 100644 tests/protocols/gmpv226/entities/test_overrides.py create mode 100644 tests/protocols/gmpv226/entities/test_permissions.py create mode 100644 tests/protocols/gmpv226/entities/test_policies.py create mode 100644 tests/protocols/gmpv226/entities/test_port_lists.py create mode 100644 tests/protocols/gmpv226/entities/test_report_formats.py create mode 100644 tests/protocols/gmpv226/entities/test_reports.py create mode 100644 tests/protocols/gmpv226/entities/test_resource_names.py create mode 100644 tests/protocols/gmpv226/entities/test_results.py create mode 100644 tests/protocols/gmpv226/entities/test_roles.py create mode 100644 tests/protocols/gmpv226/entities/test_scan_configs.py create mode 100644 tests/protocols/gmpv226/entities/test_scanners.py create mode 100644 tests/protocols/gmpv226/entities/test_schedules.py create mode 100644 tests/protocols/gmpv226/entities/test_secinfo.py create mode 100644 tests/protocols/gmpv226/entities/test_tags.py create mode 100644 tests/protocols/gmpv226/entities/test_targets.py create mode 100644 tests/protocols/gmpv226/entities/test_tasks.py create mode 100644 tests/protocols/gmpv226/entities/test_tickets.py create mode 100644 tests/protocols/gmpv226/entities/test_tls_certificates.py create mode 100644 tests/protocols/gmpv226/entities/test_users.py create mode 100644 tests/protocols/gmpv226/entities/test_vulnerabilities.py create mode 100644 tests/protocols/gmpv226/enums/__init__.py create mode 100644 tests/protocols/gmpv226/enums/test_aggregate_statistic.py create mode 100644 tests/protocols/gmpv226/enums/test_alert_condition.py create mode 100644 tests/protocols/gmpv226/enums/test_alert_event.py create mode 100644 tests/protocols/gmpv226/enums/test_alert_method.py create mode 100644 tests/protocols/gmpv226/enums/test_alive_test.py create mode 100644 tests/protocols/gmpv226/enums/test_credential_format.py create mode 100644 tests/protocols/gmpv226/enums/test_credential_type.py create mode 100644 tests/protocols/gmpv226/enums/test_entity_type.py create mode 100644 tests/protocols/gmpv226/enums/test_feed_type.py create mode 100644 tests/protocols/gmpv226/enums/test_filter_type.py create mode 100644 tests/protocols/gmpv226/enums/test_help_format.py create mode 100644 tests/protocols/gmpv226/enums/test_hosts_ordering.py create mode 100644 tests/protocols/gmpv226/enums/test_info_type.py create mode 100644 tests/protocols/gmpv226/enums/test_permission_subject_type.py create mode 100644 tests/protocols/gmpv226/enums/test_port_range_type.py create mode 100644 tests/protocols/gmpv226/enums/test_report_format_type.py create mode 100644 tests/protocols/gmpv226/enums/test_resource_type.py create mode 100644 tests/protocols/gmpv226/enums/test_scanner_type.py create mode 100644 tests/protocols/gmpv226/enums/test_snmp_algorithms.py create mode 100644 tests/protocols/gmpv226/enums/test_sort_order.py create mode 100644 tests/protocols/gmpv226/enums/test_ticket_status.py create mode 100644 tests/protocols/gmpv226/enums/test_user_auth_type.py create mode 100644 tests/protocols/gmpv226/system/__init__.py create mode 100644 tests/protocols/gmpv226/system/test_aggregates.py create mode 100644 tests/protocols/gmpv226/system/test_authentication.py create mode 100644 tests/protocols/gmpv226/system/test_feed.py create mode 100644 tests/protocols/gmpv226/system/test_help.py create mode 100644 tests/protocols/gmpv226/system/test_system_reports.py create mode 100644 tests/protocols/gmpv226/system/test_trashcan.py create mode 100644 tests/protocols/gmpv226/system/test_user_settings.py create mode 100644 tests/protocols/gmpv226/system/test_versions.py create mode 100644 tests/protocols/gmpv226/system/versions/__init__.py create mode 100644 tests/protocols/gmpv226/system/versions/test_get_protocol_version.py create mode 100644 tests/protocols/gmpv226/test_gmp_types.py create mode 100644 tests/protocols/gmpv226/test_with_statement.py diff --git a/gvm/protocols/gmp/__init__.py b/gvm/protocols/gmp/__init__.py index d8fd7ca7f..f98570073 100644 --- a/gvm/protocols/gmp/__init__.py +++ b/gvm/protocols/gmp/__init__.py @@ -19,6 +19,7 @@ from ._gmp import GMP from ._gmp224 import GMPv224 from ._gmp225 import GMPv225 +from ._gmp226 import GMPv226 Gmp = GMP # for backwards compatibility @@ -27,4 +28,5 @@ "Gmp", "GMPv224", "GMPv225", + "GMPv226", ) diff --git a/gvm/protocols/gmp/_gmp.py b/gvm/protocols/gmp/_gmp.py index 597f01221..0e038f293 100644 --- a/gvm/protocols/gmp/_gmp.py +++ b/gvm/protocols/gmp/_gmp.py @@ -12,9 +12,10 @@ from .._protocol import GvmProtocol, T, str_transform from ._gmp224 import GMPv224 from ._gmp225 import GMPv225 +from ._gmp226 import GMPv226 from .requests import Version -SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T]] +SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T]] class GMP(GvmProtocol[T]): @@ -30,9 +31,11 @@ class GMP(GvmProtocol[T]): from gvm.protocols.gmp import GMP with GMP(connection) as gmp: - # gmp can be an instance of gvm.protocols.gmp.GMPv224 or - # gvm.protocols.gmp.GMPv225 depending - # on the supported GMP version of the remote manager daemon + # gmp can be an instance of + # gvm.protocols.gmp.GMPv224, + # gvm.protocols.gmp.GMPv225 + # or gvm.protocols.gmp.GMPv226 + # depending on the supported GMP version of the remote manager daemon resp = gmp.get_tasks() """ @@ -88,6 +91,8 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS: gmp_class = GMPv224 elif major_version == 22 and minor_version == 5: gmp_class = GMPv225 + elif major_version == 22 and minor_version == 6: + gmp_class = GMPv226 else: raise GvmError( "Remote manager daemon uses an unsupported version of GMP. " diff --git a/gvm/protocols/gmp/_gmp226.py b/gvm/protocols/gmp/_gmp226.py new file mode 100644 index 000000000..5ffe7ed26 --- /dev/null +++ b/gvm/protocols/gmp/_gmp226.py @@ -0,0 +1,278 @@ +# SPDX-FileCopyrightText: 2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +""" +Greenbone Management Protocol (GMP) version 22.6 +""" + +from typing import Optional, Union + +from .._protocol import T +from ._gmp225 import GMPv225 +from .requests.v226 import ( + AuditReports, + EntityID, + ReportFormatType, + Reports, + ResourceNames, + ResourceType, +) + + +class GMPv226(GMPv225[T]): + """ + A class implementing the Greenbone Management Protocol (GMP) version 22.6 + + Example: + + .. code-block:: python + + from gvm.protocols.gmp import GMPv226 as GMP + + with GMP(connection) as gmp: + resp = gmp.get_tasks() + """ + + def __init__(self, *args, **kwargs): + """ + Create a new GMPv226 instance. + + Args: + connection: Connection to use to talk with the remote daemon. See + :mod:`gvm.connections` for possible connection types. + transform: Optional transform `callable`_ to convert response data. + After each request the callable gets passed the plain response data + which can be used to check the data and/or conversion into different + representations like a xml dom. + + See :mod:`gvm.transforms` for existing transforms. + + .. _callable: + https://docs.python.org/3/library/functions.html#callable + """ + super().__init__(*args, **kwargs) + + @staticmethod + def get_protocol_version() -> tuple[int, int]: + return (22, 6) + + def get_resource_names( + self, + resource_type: ResourceType, # type: ignore[override] + *, + filter_string: Optional[str] = None, + ) -> T: + """Request a list of resource names and IDs + + Arguments: + resource_type: Type must be either ALERT, CERT_BUND_ADV, + CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, + GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, + PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE, + SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE + or USER + filter_string: Filter term to use for the query + """ + return self._send_and_transform_command( + ResourceNames.get_resource_names( + resource_type, filter_string=filter_string + ) + ) + + def get_resource_name( + self, resource_id: str, resource_type: ResourceType # type: ignore[override] + ) -> T: + """Request a single resource name + + Arguments: + resource_id: ID of an existing resource + resource_type: Type must be either ALERT, CERT_BUND_ADV, + CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, + GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, + PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE, + SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE + or USER + """ + return self._send_and_transform_command( + ResourceNames.get_resource_name(resource_id, resource_type) + ) + + def delete_report(self, report_id: EntityID) -> T: + """Deletes an existing scan report + + Args: + report_id: UUID of the report to be deleted. + """ + return self._send_and_transform_command( + Reports.delete_report(report_id) + ) + + def get_report( + self, + report_id: EntityID, + *, + filter_string: Optional[str] = None, + filter_id: Optional[str] = None, + delta_report_id: Optional[EntityID] = None, + report_format_id: Optional[Union[str, ReportFormatType]] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = True, + ) -> T: + """Request a single scan report + + Args: + report_id: UUID of an existing report + filter_string: Filter term to use to filter results in the report + filter_id: UUID of filter to use to filter results in the report + delta_report_id: UUID of an existing report to compare report to. + report_format_id: UUID of report format to use + or ReportFormatType (enum) + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Request additional report information details + defaults to True + """ + return self._send_and_transform_command( + Reports.get_report( + report_id, + filter_string=filter_string, + filter_id=filter_id, + delta_report_id=delta_report_id, + report_format_id=report_format_id, + ignore_pagination=ignore_pagination, + details=details, + ) + ) + + def get_reports( + self, + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + note_details: Optional[bool] = None, + override_details: Optional[bool] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = None, + ) -> T: + """Request a list of scan reports + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + note_details: If notes are included, whether to include note details + override_details: If overrides are included, whether to include + override details + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Whether to exclude results + """ + return self._send_and_transform_command( + Reports.get_reports( + filter_string=filter_string, + filter_id=filter_id, + note_details=note_details, + override_details=override_details, + ignore_pagination=ignore_pagination, + details=details, + ) + ) + + def import_report( + self, + report: str, + task_id: EntityID, + *, + in_assets: Optional[bool] = None, + ) -> T: + """Import a scan Report from XML + + Args: + report: Report XML as string to import. This XML must contain + a :code:`` root element. + task_id: UUID of task to import report to + in_asset: Whether to create or update assets using the report + """ + return self._send_and_transform_command( + Reports.import_report(report, task_id, in_assets=in_assets) + ) + + def delete_audit_report(self, report_id: EntityID) -> T: + """Deletes an existing audit report + + Args: + report_id: UUID of the report to be deleted. + """ + return self._send_and_transform_command( + AuditReports.delete_report(report_id) + ) + + def get_audit_report( + self, + report_id: EntityID, + *, + filter_string: Optional[str] = None, + filter_id: Optional[str] = None, + delta_report_id: Optional[EntityID] = None, + report_format_id: Optional[Union[str, ReportFormatType]] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = True, + ) -> T: + """Request a single audit report + + Args: + report_id: UUID of an existing audit report + filter_string: Filter term to use to filter results in the report + filter_id: UUID of filter to use to filter results in the report + delta_report_id: UUID of an existing report to compare report to. + report_format_id: UUID of report format to use + or ReportFormatType (enum) + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Request additional report information details + defaults to True + """ + return self._send_and_transform_command( + AuditReports.get_report( + report_id, + filter_string=filter_string, + filter_id=filter_id, + delta_report_id=delta_report_id, + report_format_id=report_format_id, + ignore_pagination=ignore_pagination, + details=details, + ) + ) + + def get_audit_reports( + self, + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + note_details: Optional[bool] = None, + override_details: Optional[bool] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = None, + ) -> T: + """Request a list of audit reports + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + note_details: If notes are included, whether to include note details + override_details: If overrides are included, whether to include + override details + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Whether to exclude results + """ + return self._send_and_transform_command( + AuditReports.get_reports( + filter_string=filter_string, + filter_id=filter_id, + note_details=note_details, + override_details=override_details, + ignore_pagination=ignore_pagination, + details=details, + ) + ) diff --git a/gvm/protocols/gmp/requests/v226/__init__.py b/gvm/protocols/gmp/requests/v226/__init__.py new file mode 100644 index 000000000..0031e8bfe --- /dev/null +++ b/gvm/protocols/gmp/requests/v226/__init__.py @@ -0,0 +1,146 @@ +# SPDX-FileCopyrightText: 2018-2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +""" +GMP Request implementations for GMP version 22.6. +""" + +from .._entity_id import EntityID +from .._version import Version +from ..v225 import ( + Aggregates, + AggregateStatistic, + AlertCondition, + AlertEvent, + AlertMethod, + Alerts, + AliveTest, + Audits, + Authentication, + CertBundAdvisories, + Cpes, + CredentialFormat, + Credentials, + CredentialType, + Cves, + DfnCertAdvisories, + EntityType, + Feed, + FeedType, + Filters, + FilterType, + Groups, + Help, + HelpFormat, + Hosts, + HostsOrdering, + InfoType, + Notes, + Nvts, + OperatingSystems, + Overrides, + Permissions, + PermissionSubjectType, + Policies, + PortLists, + PortRangeType, + ReportFormats, + ReportFormatType, + Results, + Roles, + ScanConfigs, + Scanners, + ScannerType, + Schedules, + SecInfo, + Severity, + SnmpAuthAlgorithm, + SnmpPrivacyAlgorithm, + SortOrder, + SystemReports, + Tags, + Targets, + Tasks, + Tickets, + TicketStatus, + TLSCertificates, + TrashCan, + UserAuthType, + Users, + UserSettings, + Vulnerabilities, +) +from ._audit_reports import AuditReports +from ._reports import Reports +from ._resource_names import ResourceNames, ResourceType + +__all__ = ( + "Aggregates", + "AggregateStatistic", + "Alerts", + "AlertCondition", + "AlertEvent", + "AlertMethod", + "AliveTest", + "AuditReports", + "Audits", + "Authentication", + "CertBundAdvisories", + "Cpes", + "Credentials", + "CredentialFormat", + "CredentialType", + "Cves", + "DfnCertAdvisories", + "EntityID", + "EntityType", + "Feed", + "FeedType", + "Filters", + "FilterType", + "Groups", + "Help", + "HelpFormat", + "Hosts", + "HostsOrdering", + "InfoType", + "Notes", + "Nvts", + "OperatingSystems", + "Overrides", + "Permissions", + "PermissionSubjectType", + "Policies", + "PortLists", + "PortRangeType", + "ReportFormatType", + "ReportFormats", + "Reports", + "ResourceNames", + "ResourceType", + "Results", + "Roles", + "ScanConfigs", + "Scanners", + "ScannerType", + "Schedules", + "SecInfo", + "Severity", + "SortOrder", + "SnmpAuthAlgorithm", + "SnmpPrivacyAlgorithm", + "SystemReports", + "Tags", + "Targets", + "Tasks", + "Tickets", + "TicketStatus", + "TLSCertificates", + "TrashCan", + "UserAuthType", + "UserSettings", + "Users", + "Version", + "Vulnerabilities", +) diff --git a/gvm/protocols/gmp/requests/v226/_audit_reports.py b/gvm/protocols/gmp/requests/v226/_audit_reports.py new file mode 100644 index 000000000..96a0c0136 --- /dev/null +++ b/gvm/protocols/gmp/requests/v226/_audit_reports.py @@ -0,0 +1,129 @@ +# SPDX-FileCopyrightText: 2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from typing import Optional, Union + +from gvm.errors import RequiredArgument +from gvm.protocols.core import Request +from gvm.utils import to_bool +from gvm.xml import XmlCommand + +from .._entity_id import EntityID +from ..v224._report_formats import ReportFormatType + + +class AuditReports: + + @classmethod + def delete_report(cls, audit_report_id: EntityID) -> Request: + """Deletes an existing audit report + + Args: + audit_report_id: UUID of the report to be deleted. + """ + if not audit_report_id: + raise RequiredArgument( + function=cls.delete_report.__name__, argument="audit_report_id" + ) + + cmd = XmlCommand("delete_report") + cmd.set_attribute("report_id", str(audit_report_id)) + + return cmd + + @classmethod + def get_report( + cls, + report_id: EntityID, + *, + filter_string: Optional[str] = None, + filter_id: Optional[str] = None, + delta_report_id: Optional[EntityID] = None, + report_format_id: Optional[Union[str, ReportFormatType]] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = True, + ) -> Request: + """Request a single audit report + + Args: + report_id: UUID of an existing report + filter_string: Filter term to use to filter results in the report + filter_id: UUID of filter to use to filter results in the report + delta_report_id: UUID of an existing audit report to compare report to. + report_format_id: UUID of report format to use + or ReportFormatType (enum) + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Request additional report information details + defaults to True + """ + cmd = XmlCommand("get_reports") + + if not report_id: + raise RequiredArgument( + function=cls.get_report.__name__, argument="report_id" + ) + + cmd.set_attribute("report_id", str(report_id)) + cmd.set_attribute("usage_type", "audit") + + cmd.add_filter(filter_string, filter_id) + + if delta_report_id: + cmd.set_attribute("delta_report_id", str(delta_report_id)) + + if report_format_id: + cmd.set_attribute("format_id", str(report_format_id)) + + if ignore_pagination is not None: + cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) + + cmd.set_attribute("details", to_bool(details)) + + return cmd + + @staticmethod + def get_reports( + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + note_details: Optional[bool] = None, + override_details: Optional[bool] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = None, + ) -> Request: + """Request a list of audit reports + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + note_details: If notes are included, whether to include note details + override_details: If overrides are included, whether to include + override details + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Whether to exclude results + """ + cmd = XmlCommand("get_reports") + cmd.set_attribute("usage_type", "audit") + + if filter_string: + cmd.set_attribute("report_filter", filter_string) + + if filter_id: + cmd.set_attribute("report_filt_id", str(filter_id)) + + if note_details is not None: + cmd.set_attribute("note_details", to_bool(note_details)) + + if override_details is not None: + cmd.set_attribute("override_details", to_bool(override_details)) + + if details is not None: + cmd.set_attribute("details", to_bool(details)) + + if ignore_pagination is not None: + cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) + + return cmd diff --git a/gvm/protocols/gmp/requests/v226/_report_configs.py b/gvm/protocols/gmp/requests/v226/_report_configs.py new file mode 100644 index 000000000..55bdee79b --- /dev/null +++ b/gvm/protocols/gmp/requests/v226/_report_configs.py @@ -0,0 +1,227 @@ +# SPDX-FileCopyrightText: 2021-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from typing import Optional, Union + +from gvm.errors import InvalidArgument, RequiredArgument +from gvm.protocols.core import Request +from gvm.utils import to_bool +from gvm.xml import XmlCommand, XmlError + +from .._entity_id import EntityID +from ..v224._report_formats import ReportFormatType + + +class ReportConfigs: + + @classmethod + def clone_report_config(cls, report_config_id: EntityID) -> Request: + """Clone a report config from an existing one + + Args: + report_config_id: UUID of the existing report format + or ReportFormatType (enum) + """ + if not report_config_id: + raise RequiredArgument( + function=cls.clone_report_config.__name__, + argument="report_config_id", + ) + + cmd = XmlCommand("create_report_config") + cmd.add_element("copy", str(report_config_id)) + return cmd + + @classmethod + def delete_report_format( + cls, + report_format_id: Union[EntityID, ReportFormatType], + *, + ultimate: Optional[bool] = False, + ) -> Request: + """Deletes an existing report format + + Args: + report_format_id: UUID of the report format to be deleted. + or ReportFormatType (enum) + ultimate: Whether to remove entirely, or to the trashcan. + """ + if not report_format_id: + raise RequiredArgument( + function=cls.delete_report_format.__name__, + argument="report_format_id", + ) + + cmd = XmlCommand("delete_report_format") + + cmd.set_attribute("report_format_id", str(report_format_id)) + + cmd.set_attribute("ultimate", to_bool(ultimate)) + + return cmd + + @staticmethod + def get_report_formats( + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + trash: Optional[bool] = None, + alerts: Optional[bool] = None, + params: Optional[bool] = None, + details: Optional[bool] = None, + ) -> Request: + """Request a list of report formats + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + trash: Whether to get the trashcan report formats instead + alerts: Whether to include alerts that use the report format + params: Whether to include report format parameters + details: Include report format file, signature and parameters + """ + cmd = XmlCommand("get_report_formats") + + cmd.add_filter(filter_string, filter_id) + + if details is not None: + cmd.set_attribute("details", to_bool(details)) + + if alerts is not None: + cmd.set_attribute("alerts", to_bool(alerts)) + + if params is not None: + cmd.set_attribute("params", to_bool(params)) + + if trash is not None: + cmd.set_attribute("trash", to_bool(trash)) + + return cmd + + @classmethod + def get_report_format( + cls, report_format_id: Union[EntityID, ReportFormatType] + ) -> Request: + """Request a single report format + + Args: + report_format_id: UUID of an existing report format + or ReportFormatType (enum) + """ + if not report_format_id: + raise RequiredArgument( + function=cls.get_report_format.__name__, + argument="report_format_id", + ) + + cmd = XmlCommand("get_report_formats") + + cmd.set_attribute("report_format_id", str(report_format_id)) + + # for single entity always request all details + cmd.set_attribute("details", "1") + return cmd + + @classmethod + def import_report_format(cls, report_format: str) -> Request: + """Import a report format from XML + + Args: + report_format: Report format XML as string to import. This XML must + contain a :code:`` root element. + """ + if not report_format: + raise RequiredArgument( + function=cls.import_report_format.__name__, + argument="report_format", + ) + + cmd = XmlCommand("create_report_format") + + try: + cmd.append_xml_str(report_format) + except XmlError as e: + raise InvalidArgument( + function=cls.import_report_format.__name__, + argument="report_format", + ) from e + + return cmd + + @classmethod + def modify_report_format( + cls, + report_format_id: Union[EntityID, ReportFormatType], + *, + active: Optional[bool] = None, + name: Optional[str] = None, + summary: Optional[str] = None, + param_name: Optional[str] = None, + param_value: Optional[str] = None, + ) -> Request: + """Modifies an existing report format. + + Args: + report_format_id: UUID of report format to modify + or ReportFormatType (enum) + active: Whether the report format is active. + name: The name of the report format. + summary: A summary of the report format. + param_name: The name of the param. + param_value: The value of the param. + """ + if not report_format_id: + raise RequiredArgument( + function=cls.modify_report_format.__name__, + argument="report_format_id ", + ) + + cmd = XmlCommand("modify_report_format") + + cmd.set_attribute("report_format_id", str(report_format_id)) + + if active is not None: + cmd.add_element("active", to_bool(active)) + + if name: + cmd.add_element("name", name) + + if summary: + cmd.add_element("summary", summary) + + if param_name: + xml_param = cmd.add_element("param") + xml_param.add_element("name", param_name) + + if param_value is not None: + xml_param.add_element("value", param_value) + + return cmd + + @classmethod + def verify_report_format( + cls, report_format_id: Union[EntityID, ReportFormatType] + ) -> Request: + """Verify an existing report format + + Verifies the trust level of an existing report format. It will be + checked whether the signature of the report format currently matches the + report format. This includes the script and files used to generate + reports of this format. It is *not* verified if the report format works + as expected by the user. + + Args: + report_format_id: UUID of the report format to be verified + or ReportFormatType (enum) + """ + if not report_format_id: + raise RequiredArgument( + function=cls.verify_report_format.__name__, + argument="report_format_id", + ) + + cmd = XmlCommand("verify_report_format") + cmd.set_attribute("report_format_id", str(report_format_id)) + return cmd diff --git a/gvm/protocols/gmp/requests/v226/_reports.py b/gvm/protocols/gmp/requests/v226/_reports.py new file mode 100644 index 000000000..1c381f73a --- /dev/null +++ b/gvm/protocols/gmp/requests/v226/_reports.py @@ -0,0 +1,171 @@ +# SPDX-FileCopyrightText: 2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from typing import Optional, Union + +from gvm.errors import InvalidArgument, RequiredArgument +from gvm.protocols.core import Request +from gvm.utils import to_bool +from gvm.xml import XmlCommand, XmlError + +from .._entity_id import EntityID +from ..v224._report_formats import ReportFormatType + + +class Reports: + + @classmethod + def delete_report(cls, report_id: EntityID) -> Request: + """Deletes an existing report + + Args: + report_id: UUID of the report to be deleted. + """ + if not report_id: + raise RequiredArgument( + function=cls.delete_report.__name__, argument="report_id" + ) + + cmd = XmlCommand("delete_report") + cmd.set_attribute("report_id", str(report_id)) + + return cmd + + @classmethod + def get_report( + cls, + report_id: EntityID, + *, + filter_string: Optional[str] = None, + filter_id: Optional[str] = None, + delta_report_id: Optional[EntityID] = None, + report_format_id: Optional[Union[str, ReportFormatType]] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = True, + ) -> Request: + """Request a single report + + Args: + report_id: UUID of an existing report + filter_string: Filter term to use to filter results in the report + filter_id: UUID of filter to use to filter results in the report + delta_report_id: UUID of an existing report to compare report to. + report_format_id: UUID of report format to use + or ReportFormatType (enum) + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Request additional report information details + defaults to True + """ + cmd = XmlCommand("get_reports") + + if not report_id: + raise RequiredArgument( + function=cls.get_report.__name__, argument="report_id" + ) + + cmd.set_attribute("report_id", str(report_id)) + cmd.set_attribute("usage_type", "scan") + + cmd.add_filter(filter_string, filter_id) + + if delta_report_id: + cmd.set_attribute("delta_report_id", str(delta_report_id)) + + if report_format_id: + cmd.set_attribute("format_id", str(report_format_id)) + + if ignore_pagination is not None: + cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) + + cmd.set_attribute("details", to_bool(details)) + + return cmd + + @staticmethod + def get_reports( + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + note_details: Optional[bool] = None, + override_details: Optional[bool] = None, + ignore_pagination: Optional[bool] = None, + details: Optional[bool] = None, + ) -> Request: + """Request a list of reports + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + note_details: If notes are included, whether to include note details + override_details: If overrides are included, whether to include + override details + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Whether to exclude results + """ + cmd = XmlCommand("get_reports") + cmd.set_attribute("usage_type", "scan") + + if filter_string: + cmd.set_attribute("report_filter", filter_string) + + if filter_id: + cmd.set_attribute("report_filt_id", str(filter_id)) + + if note_details is not None: + cmd.set_attribute("note_details", to_bool(note_details)) + + if override_details is not None: + cmd.set_attribute("override_details", to_bool(override_details)) + + if details is not None: + cmd.set_attribute("details", to_bool(details)) + + if ignore_pagination is not None: + cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) + + return cmd + + @classmethod + def import_report( + cls, + report: str, + task_id: EntityID, + *, + in_assets: Optional[bool] = None, + ) -> Request: + """Import a Report from XML + + Args: + report: Report XML as string to import. This XML must contain + a :code:`` root element. + task_id: UUID of task to import report to + in_asset: Whether to create or update assets using the report + """ + if not report: + raise RequiredArgument( + function=cls.import_report.__name__, argument="report" + ) + + cmd = XmlCommand("create_report") + + if not task_id: + raise RequiredArgument( + function=cls.import_report.__name__, argument="task_id" + ) + + cmd.add_element("task", attrs={"id": str(task_id)}) + + if in_assets is not None: + cmd.add_element("in_assets", to_bool(in_assets)) + + try: + cmd.append_xml_str(report) + except XmlError as e: + raise InvalidArgument( + f"Invalid xml passed as report to import_report {e}" + ) from None + + return cmd diff --git a/gvm/protocols/gmp/requests/v226/_resource_names.py b/gvm/protocols/gmp/requests/v226/_resource_names.py new file mode 100644 index 000000000..a2b18462f --- /dev/null +++ b/gvm/protocols/gmp/requests/v226/_resource_names.py @@ -0,0 +1,117 @@ +# SPDX-FileCopyrightText: 2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from typing import Optional, Union + +from gvm._enum import Enum +from gvm.errors import RequiredArgument +from gvm.protocols.core import Request +from gvm.xml import XmlCommand + +from .._entity_id import EntityID + + +class ResourceType(Enum): + """Enum for resource types""" + + ALERT = "ALERT" + AUDIT = "TASK" + AUDIT_REPORT = "REPORT" + CERT_BUND_ADV = "CERT_BUND_ADV" + CONFIG = "CONFIG" + CPE = "CPE" + CREDENTIAL = "CREDENTIAL" + CVE = "CVE" + DFN_CERT_ADV = "DFN_CERT_ADV" + FILTER = "FILTER" + GROUP = "GROUP" + HOST = "HOST" + NOTE = "NOTE" + NVT = "NVT" + OS = "OS" + OVERRIDE = "OVERRIDE" + PERMISSION = "PERMISSION" + PORT_LIST = "PORT_LIST" + REPORT_FORMAT = "REPORT_FORMAT" + REPORT = "REPORT" + REPORT_CONFIG = "REPORT_CONFIG" + RESULT = "RESULT" + ROLE = "ROLE" + SCANNER = "SCANNER" + SCHEDULE = "SCHEDULE" + TARGET = "TARGET" + TASK = "TASK" + TLS_CERTIFICATE = "TLS_CERTIFICATE" + USER = "USER" + + +class ResourceNames: + @classmethod + def get_resource_names( + cls, + resource_type: Union[ResourceType, str], + *, + filter_string: Optional[str] = None, + ) -> Request: + """Request a list of resource names and IDs + + Args: + resource_type: Type must be either ALERT, CERT_BUND_ADV, + CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, + GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, + PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE, + SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE + or USER + filter_string: Filter term to use for the query + """ + cmd = XmlCommand("get_resource_names") + + if not resource_type: + raise RequiredArgument( + function=cls.get_resource_names.__name__, + argument="resource_type", + ) + + if not isinstance(resource_type, ResourceType): + resource_type = ResourceType(resource_type) + + cmd.set_attribute("type", resource_type.value) + cmd.add_filter(filter_string, None) + return cmd + + @classmethod + def get_resource_name( + cls, + resource_id: EntityID, + resource_type: Union[ResourceType, str], + ) -> Request: + """Request a single resource name + + Args: + resource_id: ID of an existing resource + resource_type: Type must be either ALERT, CERT_BUND_ADV, + CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, + GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, + PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE, + SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE + or USER + """ + if not resource_type: + raise RequiredArgument( + function=cls.get_resource_name.__name__, + argument="resource_type", + ) + + if not isinstance(resource_type, ResourceType): + resource_type = ResourceType(resource_type) + + if not resource_id: + raise RequiredArgument( + function=cls.get_resource_name.__name__, argument="resource_id" + ) + + cmd = XmlCommand("get_resource_names") + cmd.set_attribute("resource_id", str(resource_id)) + cmd.set_attribute("type", resource_type.value) + return cmd diff --git a/gvm/protocols/latest.py b/gvm/protocols/latest.py index adeab6553..c067a3a37 100644 --- a/gvm/protocols/latest.py +++ b/gvm/protocols/latest.py @@ -14,7 +14,7 @@ :py:mod:`gvm.protocols`. Exports: - - :py:class:`gvm.protocols.gmp.GMPv224` + - :py:class:`gvm.protocols.gmp.GMPv226` - :py:class:`gvm.protocols.ospv1.Osp` .. _Greenbone Management Protocol: @@ -22,7 +22,7 @@ """ from .gmp import ( - GMPv225 as Gmp, + GMPv226 as Gmp, ) from .ospv1 import Osp diff --git a/gvm/protocols/next.py b/gvm/protocols/next.py index cc2d58e8f..c067a3a37 100644 --- a/gvm/protocols/next.py +++ b/gvm/protocols/next.py @@ -14,7 +14,7 @@ :py:mod:`gvm.protocols`. Exports: - - :py:class:`gvm.protocols.gmp.GMPv225` + - :py:class:`gvm.protocols.gmp.GMPv226` - :py:class:`gvm.protocols.ospv1.Osp` .. _Greenbone Management Protocol: @@ -22,7 +22,7 @@ """ from .gmp import ( - GMPv225 as Gmp, + GMPv226 as Gmp, ) from .ospv1 import Osp diff --git a/tests/protocols/gmp/requests/v226/__init__.py b/tests/protocols/gmp/requests/v226/__init__.py new file mode 100644 index 000000000..9c0a68e73 --- /dev/null +++ b/tests/protocols/gmp/requests/v226/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later diff --git a/tests/protocols/gmp/requests/v226/test_audit_reports.py b/tests/protocols/gmp/requests/v226/test_audit_reports.py new file mode 100644 index 000000000..43f376a24 --- /dev/null +++ b/tests/protocols/gmp/requests/v226/test_audit_reports.py @@ -0,0 +1,152 @@ +# 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.v226 import AuditReports + + +class AuditReportsTestCase(unittest.TestCase): + def test_delete_report(self): + request = AuditReports.delete_report("report_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_delete_report_missing_report_id(self): + with self.assertRaises(RequiredArgument): + AuditReports.delete_report(None) + + with self.assertRaises(RequiredArgument): + AuditReports.delete_report("") + + def test_get_report(self): + request = AuditReports.get_report("report_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_filter_string(self): + request = AuditReports.get_report( + "report_id", filter_string="filter_string" + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_filter_id(self): + request = AuditReports.get_report("report_id", filter_id="filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_delta_report_id(self): + request = AuditReports.get_report( + "report_id", delta_report_id="delta_report_id" + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_report_format_id(self): + request = AuditReports.get_report( + "report_id", report_format_id="report_format_id" + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_ignore_pagination(self): + request = AuditReports.get_report("report_id", ignore_pagination=True) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_missing_report_id(self): + with self.assertRaises(RequiredArgument): + AuditReports.get_report(None) + + with self.assertRaises(RequiredArgument): + AuditReports.get_report("") + + def test_get_reports(self): + request = AuditReports.get_reports() + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_filter_string(self): + request = AuditReports.get_reports(filter_string="filter_string") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_filter_id(self): + request = AuditReports.get_reports(filter_id="filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_note_details(self): + request = AuditReports.get_reports(note_details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = AuditReports.get_reports(note_details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_override_details(self): + request = AuditReports.get_reports(override_details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = AuditReports.get_reports(override_details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_details(self): + request = AuditReports.get_reports(details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = AuditReports.get_reports(details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_ignore_pagination(self): + request = AuditReports.get_reports(ignore_pagination=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = AuditReports.get_reports(ignore_pagination=False) + self.assertEqual( + bytes(request), + b'', + ) diff --git a/tests/protocols/gmp/requests/v226/test_reports.py b/tests/protocols/gmp/requests/v226/test_reports.py new file mode 100644 index 000000000..5e6867e43 --- /dev/null +++ b/tests/protocols/gmp/requests/v226/test_reports.py @@ -0,0 +1,227 @@ +# 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.v226 import Reports + +REPORT_XML_STRING = ( + '' + '' + '' + "0.0" + '' + "132.67.253.114" + "" +) + + +class ReportsTestCase(unittest.TestCase): + def test_delete_report(self): + request = Reports.delete_report("report_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_delete_report_missing_report_id(self): + with self.assertRaises(RequiredArgument): + Reports.delete_report(None) + + with self.assertRaises(RequiredArgument): + Reports.delete_report("") + + def test_get_report(self): + request = Reports.get_report("report_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_filter_string(self): + request = Reports.get_report("report_id", filter_string="filter_string") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_filter_id(self): + request = Reports.get_report("report_id", filter_id="filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_delta_report_id(self): + request = Reports.get_report( + "report_id", delta_report_id="delta_report_id" + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_report_format_id(self): + request = Reports.get_report( + "report_id", report_format_id="report_format_id" + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_with_ignore_pagination(self): + request = Reports.get_report("report_id", ignore_pagination=True) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_missing_report_id(self): + with self.assertRaises(RequiredArgument): + Reports.get_report(None) + + with self.assertRaises(RequiredArgument): + Reports.get_report("") + + def test_get_reports(self): + request = Reports.get_reports() + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_filter_string(self): + request = Reports.get_reports(filter_string="filter_string") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_filter_id(self): + request = Reports.get_reports(filter_id="filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_note_details(self): + request = Reports.get_reports(note_details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Reports.get_reports(note_details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_override_details(self): + request = Reports.get_reports(override_details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Reports.get_reports(override_details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_details(self): + request = Reports.get_reports(details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Reports.get_reports(details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_reports_with_ignore_pagination(self): + request = Reports.get_reports(ignore_pagination=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Reports.get_reports(ignore_pagination=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_import_report(self): + request = Reports.import_report(REPORT_XML_STRING, "task_id") + self.assertEqual( + bytes(request), + b"" + b'' + b'' + b'' + b'' + b"0.0" + b'' + b"132.67.253.114" + b"" + b"", + ) + + def test_import_report_with_in_assets(self): + request = Reports.import_report( + REPORT_XML_STRING, "task_id", in_assets=False + ) + self.assertEqual( + bytes(request), + b"" + b'' + b"0" + b'' + b'' + b'' + b"0.0" + b'' + b"132.67.253.114" + b"" + b"", + ) + + request = Reports.import_report( + REPORT_XML_STRING, "task_id", in_assets=True + ) + self.assertEqual( + bytes(request), + b"" + b'' + b"1" + b'' + b'' + b'' + b"0.0" + b'' + b"132.67.253.114" + b"" + b"", + ) + + def test_import_report_missing_report(self): + with self.assertRaises(RequiredArgument): + Reports.import_report(None, "task_id") + + with self.assertRaises(RequiredArgument): + Reports.import_report("", "task_id") + + def test_import_report_missing_task_id(self): + with self.assertRaises(RequiredArgument): + Reports.import_report("report", None) + + with self.assertRaises(RequiredArgument): + Reports.import_report("report", "") diff --git a/tests/protocols/gmp/requests/v226/test_resource_names.py b/tests/protocols/gmp/requests/v226/test_resource_names.py new file mode 100644 index 000000000..ecf155de2 --- /dev/null +++ b/tests/protocols/gmp/requests/v226/test_resource_names.py @@ -0,0 +1,431 @@ +# SPDX-FileCopyrightText: 2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import unittest + +from gvm.errors import InvalidArgument, RequiredArgument +from gvm.protocols.core import Request +from gvm.protocols.gmp.requests.v226 import ResourceNames, ResourceType + + +class ResourceNamesTestCase(unittest.TestCase): + def test_get_resource_names(self) -> None: + request = ResourceNames.get_resource_names(ResourceType.ALERT) + + self.assertIsInstance(request, Request) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.CERT_BUND_ADV) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.CONFIG) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names( + resource_type=ResourceType.CPE + ) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.CREDENTIAL) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.CVE) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.DFN_CERT_ADV) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.FILTER) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.GROUP) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.HOST) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.NOTE) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.NVT) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.OS) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.OVERRIDE) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.PERMISSION) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.PORT_LIST) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.REPORT_FORMAT) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.REPORT) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.REPORT_CONFIG) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.RESULT) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.ROLE) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.SCANNER) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.SCHEDULE) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.TARGET) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.TASK) + + self.assertEqual(bytes(request), b'') + + request = ResourceNames.get_resource_names(ResourceType.TLS_CERTIFICATE) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_names(ResourceType.USER) + + self.assertEqual(bytes(request), b'') + + def test_get_resource_names_missing_resource_type(self) -> None: + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_names(resource_type=None) # type: ignore + + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_names(resource_type="") + + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_names("") + + def test_get_resource_names_invalid_resource_type(self) -> None: + with self.assertRaises(InvalidArgument): + ResourceNames.get_resource_names(resource_type="foo") + + def test_get_resource_names_with_filter_string(self) -> None: + request = ResourceNames.get_resource_names( + ResourceType.CPE, filter_string="foo=bar" + ) + + self.assertEqual( + bytes(request), b'' + ) + + def test_get_resource_name(self): + request = ResourceNames.get_resource_name( + resource_type=ResourceType.ALERT, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.CERT_BUND_ADV, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.CONFIG, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.CPE, resource_id="i1" + ) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.CREDENTIAL, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.CVE, resource_id="i1" + ) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.DFN_CERT_ADV, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.FILTER, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.GROUP, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.HOST, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.NOTE, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.NVT, resource_id="i1" + ) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.OS, resource_id="i1" + ) + + self.assertEqual( + bytes(request), b'' + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.PERMISSION, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.PORT_LIST, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.REPORT_FORMAT, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.REPORT, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.REPORT_CONFIG, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.RESULT, resource_id="i1" + ) + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.ROLE, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.SCANNER, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.SCHEDULE, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.TARGET, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.TASK, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.TLS_CERTIFICATE, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + request = ResourceNames.get_resource_name( + resource_type=ResourceType.USER, resource_id="i1" + ) + + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_resource_name_missing_resource_type(self): + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_name( + resource_id="i1", resource_type=None + ) + + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_name(resource_id="i1", resource_type="") + + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_name("i1", "") + + def test_get_resource_name_invalid_resource_type(self): + with self.assertRaises(InvalidArgument): + ResourceNames.get_resource_name( + resource_id="i1", resource_type="foo" + ) + + def test_get_resource_name_missing_resource_id(self): + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_name( + resource_id="", resource_type=ResourceType.CPE + ) + + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_name("", resource_type=ResourceType.CPE) + + with self.assertRaises(RequiredArgument): + ResourceNames.get_resource_name( + resource_id=None, resource_type=ResourceType.CPE + ) diff --git a/tests/protocols/gmp/test_context_manager.py b/tests/protocols/gmp/test_context_manager.py index 8a8661036..07b39a562 100644 --- a/tests/protocols/gmp/test_context_manager.py +++ b/tests/protocols/gmp/test_context_manager.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2019-2024 Greenbone AG +# SPDX-FileCopyrightText: 2019-2025 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -10,6 +10,7 @@ from gvm.protocols.gmp import Gmp from gvm.protocols.gmp._gmp224 import GMPv224 from gvm.protocols.gmp._gmp225 import GMPv225 +from gvm.protocols.gmp._gmp226 import GMPv226 from tests.protocols import GmpTestCase @@ -92,6 +93,46 @@ def test_select_gmpv225(self): self.assertEqual(gmp.get_protocol_version(), (22, 5)) self.assertIsInstance(gmp, GMPv225) + self.connection.read.return_value( + b'' + b"22.5" + b"" + ) + + with self.gmp as gmp: + self.assertEqual(gmp.get_protocol_version(), (22, 5)) + self.assertIsInstance(gmp, GMPv225) + + def test_select_gmpv226(self): + self.connection.read.return_value( + b'' + b"22.06" + b"" + ) + + with self.gmp as gmp: + self.assertEqual(gmp.get_protocol_version(), (22, 6)) + self.assertIsInstance(gmp, GMPv226) + + self.connection.read.return_value( + b'' + b"22.6" + b"" + ) + + with self.gmp as gmp: + self.assertEqual(gmp.get_protocol_version(), (22, 6)) + self.assertIsInstance(gmp, GMPv226) + self.connection.read.return_value( + b'' + b"22.6" + b"" + ) + + with self.gmp as gmp: + self.assertEqual(gmp.get_protocol_version(), (22, 6)) + self.assertIsInstance(gmp, GMPv226) + def test_unknown_protocol(self): self.connection.read.return_value( b'' diff --git a/tests/protocols/gmpv226/__init__.py b/tests/protocols/gmpv226/__init__.py new file mode 100644 index 000000000..3d105a7e0 --- /dev/null +++ b/tests/protocols/gmpv226/__init__.py @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +from gvm.protocols.gmp import GMPv226 + +from .. import GmpTestCase as BaseGMPTestCase + + +class GMPTestCase(BaseGMPTestCase): + gmp_class = GMPv226 diff --git a/tests/protocols/gmpv226/entities/__init__.py b/tests/protocols/gmpv226/entities/__init__.py new file mode 100644 index 000000000..baae7654d --- /dev/null +++ b/tests/protocols/gmpv226/entities/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# diff --git a/tests/protocols/gmpv226/entities/audit_reports/__init__.py b/tests/protocols/gmpv226/entities/audit_reports/__init__.py new file mode 100644 index 000000000..830bac6f7 --- /dev/null +++ b/tests/protocols/gmpv226/entities/audit_reports/__init__.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2021-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from .test_delete_report import GmpDeleteAuditReportTestMixin +from .test_get_report import GmpGetAuditReportTestMixin +from .test_get_reports import GmpGetAuditReportsTestMixin + +__all__ = ( + "GmpDeleteAuditReportTestMixin", + "GmpGetAuditReportTestMixin", + "GmpGetAuditReportsTestMixin", +) diff --git a/tests/protocols/gmpv226/entities/audit_reports/test_delete_report.py b/tests/protocols/gmpv226/entities/audit_reports/test_delete_report.py new file mode 100644 index 000000000..af7cc890d --- /dev/null +++ b/tests/protocols/gmpv226/entities/audit_reports/test_delete_report.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import GvmError + + +class GmpDeleteAuditReportTestMixin: + def test_delete(self): + self.gmp.delete_report("a1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_missing_id(self): + with self.assertRaises(GvmError): + self.gmp.delete_report(None) + + with self.assertRaises(GvmError): + self.gmp.delete_report("") diff --git a/tests/protocols/gmpv226/entities/audit_reports/test_get_report.py b/tests/protocols/gmpv226/entities/audit_reports/test_get_report.py new file mode 100644 index 000000000..6f4fc65d7 --- /dev/null +++ b/tests/protocols/gmpv226/entities/audit_reports/test_get_report.py @@ -0,0 +1,81 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument +from gvm.protocols.gmp.requests.v226 import ReportFormatType + + +class GmpGetAuditReportTestMixin: + def test_get_audit_report_without_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_audit_report(None) + + with self.assertRaises(RequiredArgument): + self.gmp.get_audit_report("") + + def test_get_audit_report_with_filter_string(self): + self.gmp.get_audit_report(report_id="r1", filter_string="name=foo") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_with_filter_id(self): + self.gmp.get_audit_report(report_id="r1", filter_id="f1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_with_report_format_id(self): + self.gmp.get_audit_report(report_id="r1", report_format_id="bar") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_with_report_format_type(self): + self.gmp.get_audit_report( + report_id="r1", report_format_id=ReportFormatType.TXT + ) + report_format_id = ReportFormatType.from_string("txt").value + + self.connection.send.has_been_called_with( + ''.encode("utf-8") + ) + + def test_get_audit_report_with_delta_report_id(self): + self.gmp.get_audit_report(report_id="r1", delta_report_id="r2") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_with_ignore_pagination(self): + self.gmp.get_audit_report(report_id="r1", ignore_pagination=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_audit_report(report_id="r1", ignore_pagination=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_with_details(self): + self.gmp.get_audit_report(report_id="r1", details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_audit_report(report_id="r1", details=False) + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpv226/entities/audit_reports/test_get_reports.py b/tests/protocols/gmpv226/entities/audit_reports/test_get_reports.py new file mode 100644 index 000000000..e17ce1fad --- /dev/null +++ b/tests/protocols/gmpv226/entities/audit_reports/test_get_reports.py @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +class GmpGetAuditReportsTestMixin: + def test_get_audit_reports(self): + self.gmp.get_audit_reports() + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_with_filter_string(self): + self.gmp.get_audit_reports( + filter_string="name=foo", ignore_pagination=1 + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_with_filter_id(self): + self.gmp.get_audit_reports(filter_id="f1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_without_note_details(self): + self.gmp.get_audit_reports(note_details=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_with_note_details(self): + self.gmp.get_audit_reports(note_details=True, ignore_pagination=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_without_override_details(self): + self.gmp.get_audit_reports(override_details=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_with_override_details(self): + self.gmp.get_audit_reports(override_details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_with_details(self): + self.gmp.get_audit_reports(details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_reports_without_details(self): + self.gmp.get_audit_reports(details=False) + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpv226/entities/reports/__init__.py b/tests/protocols/gmpv226/entities/reports/__init__.py new file mode 100644 index 000000000..4d99d19ac --- /dev/null +++ b/tests/protocols/gmpv226/entities/reports/__init__.py @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2021-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from .test_delete_report import GmpDeleteReportTestMixin +from .test_get_report import GmpGetReportTestMixin +from .test_get_reports import GmpGetReportsTestMixin +from .test_import_report import GmpImportReportTestMixin + +__all__ = ( + "GmpDeleteReportTestMixin", + "GmpGetReportTestMixin", + "GmpGetReportsTestMixin", + "GmpImportReportTestMixin", +) diff --git a/tests/protocols/gmpv226/entities/reports/test_delete_report.py b/tests/protocols/gmpv226/entities/reports/test_delete_report.py new file mode 100644 index 000000000..e86cc4831 --- /dev/null +++ b/tests/protocols/gmpv226/entities/reports/test_delete_report.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import GvmError + + +class GmpDeleteReportTestMixin: + def test_delete(self): + self.gmp.delete_report("a1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_missing_id(self): + with self.assertRaises(GvmError): + self.gmp.delete_report(None) + + with self.assertRaises(GvmError): + self.gmp.delete_report("") diff --git a/tests/protocols/gmpv226/entities/reports/test_get_report.py b/tests/protocols/gmpv226/entities/reports/test_get_report.py new file mode 100644 index 000000000..8817972ad --- /dev/null +++ b/tests/protocols/gmpv226/entities/reports/test_get_report.py @@ -0,0 +1,81 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument +from gvm.protocols.gmp.requests.v226 import ReportFormatType + + +class GmpGetReportTestMixin: + def test_get_report_without_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_report(None) + + with self.assertRaises(RequiredArgument): + self.gmp.get_report("") + + def test_get_report_with_filter_string(self): + self.gmp.get_report(report_id="r1", filter_string="name=foo") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_with_filter_id(self): + self.gmp.get_report(report_id="r1", filter_id="f1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_with_report_format_id(self): + self.gmp.get_report(report_id="r1", report_format_id="bar") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_with_report_format_type(self): + self.gmp.get_report( + report_id="r1", report_format_id=ReportFormatType.TXT + ) + report_format_id = ReportFormatType.from_string("txt").value + + self.connection.send.has_been_called_with( + ''.encode("utf-8") + ) + + def test_get_report_with_delta_report_id(self): + self.gmp.get_report(report_id="r1", delta_report_id="r2") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_with_ignore_pagination(self): + self.gmp.get_report(report_id="r1", ignore_pagination=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_report(report_id="r1", ignore_pagination=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_with_details(self): + self.gmp.get_report(report_id="r1", details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_report(report_id="r1", details=False) + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpv226/entities/reports/test_get_reports.py b/tests/protocols/gmpv226/entities/reports/test_get_reports.py new file mode 100644 index 000000000..e11221402 --- /dev/null +++ b/tests/protocols/gmpv226/entities/reports/test_get_reports.py @@ -0,0 +1,69 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +class GmpGetReportsTestMixin: + def test_get_reports(self): + self.gmp.get_reports() + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_with_filter_string(self): + self.gmp.get_reports(filter_string="name=foo", ignore_pagination=1) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_with_filter_id(self): + self.gmp.get_reports(filter_id="f1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_without_note_details(self): + self.gmp.get_reports(note_details=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_with_note_details(self): + self.gmp.get_reports(note_details=True, ignore_pagination=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_without_override_details(self): + self.gmp.get_reports(override_details=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_with_override_details(self): + self.gmp.get_reports(override_details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_with_details(self): + self.gmp.get_reports(details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_reports_without_details(self): + self.gmp.get_reports(details=False) + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpv226/entities/reports/test_import_report.py b/tests/protocols/gmpv226/entities/reports/test_import_report.py new file mode 100644 index 000000000..dc3450960 --- /dev/null +++ b/tests/protocols/gmpv226/entities/reports/test_import_report.py @@ -0,0 +1,70 @@ +# SPDX-FileCopyrightText: 2018-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import InvalidArgument, RequiredArgument + + +class GmpImportReportTestMixin: + TASK_ID = "00000000-0000-0000-0000-000000000001" + REPORT_XML_STRING = ( + '' + '' + '' + "0.0" + '' + "132.67.253.114" + "" + ) + + def test_import_report_with_task_id(self): + self.gmp.import_report(self.REPORT_XML_STRING, task_id=self.TASK_ID) + + self.connection.send.has_been_called_with( + "" + f'' + f"{self.REPORT_XML_STRING}" + "".encode("utf-8") + ) + + def test_import_report_missing_report(self): + with self.assertRaises(RequiredArgument): + self.gmp.import_report(None, task_id=self.TASK_ID) + + with self.assertRaises(RequiredArgument): + self.gmp.import_report("", task_id=self.TASK_ID) + + def test_import_report_invalid_xml(self): + with self.assertRaises(InvalidArgument): + self.gmp.import_report("Foo", task_id=self.TASK_ID) # not root tag + + with self.assertRaises(InvalidArgument): + self.gmp.import_report( + "", task_id=self.TASK_ID # missing closing tag + ) + + def test_import_report_with_in_assets(self): + self.gmp.import_report( + self.REPORT_XML_STRING, task_id=self.TASK_ID, in_assets=False + ) + + self.connection.send.has_been_called_with( + "" + f'' + "0" + f"{self.REPORT_XML_STRING}" + "".encode("utf-8") + ) + + self.gmp.import_report( + self.REPORT_XML_STRING, task_id=self.TASK_ID, in_assets=True + ) + + self.connection.send.has_been_called_with( + "" + f'' + "1" + f"{self.REPORT_XML_STRING}" + "".encode("utf-8") + ) diff --git a/tests/protocols/gmpv226/entities/resourcenames/__init__.py b/tests/protocols/gmpv226/entities/resourcenames/__init__.py new file mode 100644 index 000000000..2b3a10e8f --- /dev/null +++ b/tests/protocols/gmpv226/entities/resourcenames/__init__.py @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from .test_get_resource_name import GmpGetResourceNameTestMixin +from .test_get_resource_names_list import GmpGetResourceNamesListTestMixin + +__all__ = ("GmpGetResourceNameTestMixin", "GmpGetResourceNamesListTestMixin") diff --git a/tests/protocols/gmpv226/entities/resourcenames/test_get_resource_name.py b/tests/protocols/gmpv226/entities/resourcenames/test_get_resource_name.py new file mode 100644 index 000000000..282c6e80a --- /dev/null +++ b/tests/protocols/gmpv226/entities/resourcenames/test_get_resource_name.py @@ -0,0 +1,246 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import InvalidArgument, RequiredArgument +from gvm.protocols.gmp.requests.v226 import ResourceType + + +class GmpGetResourceNameTestMixin: + def test_get_resource_name(self): + self.gmp.get_resource_name( + resource_type=ResourceType.ALERT, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.CERT_BUND_ADV, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.CONFIG, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.CPE, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.CREDENTIAL, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.CVE, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.DFN_CERT_ADV, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.FILTER, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.GROUP, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.HOST, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.NOTE, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.NVT, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.OS, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.PERMISSION, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.PORT_LIST, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.REPORT_FORMAT, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.REPORT, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.REPORT_CONFIG, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.RESULT, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.ROLE, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.SCANNER, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.SCHEDULE, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.TARGET, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.TASK, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.TLS_CERTIFICATE, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_name( + resource_type=ResourceType.USER, resource_id="i1" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_resource_name_missing_resource_type(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_name(resource_id="i1", resource_type=None) + + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_name(resource_id="i1", resource_type="") + + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_name("i1", "") + + def test_get_resource_name_invalid_resource_type(self): + with self.assertRaises(InvalidArgument): + self.gmp.get_resource_name(resource_id="i1", resource_type="foo") + + def test_get_resource_name_missing_resource_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_name( + resource_id="", resource_type=ResourceType.CPE + ) + + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_name("", resource_type=ResourceType.CPE) + + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_name( + resource_id=None, resource_type=ResourceType.CPE + ) diff --git a/tests/protocols/gmpv226/entities/resourcenames/test_get_resource_names_list.py b/tests/protocols/gmpv226/entities/resourcenames/test_get_resource_names_list.py new file mode 100644 index 000000000..0a461f892 --- /dev/null +++ b/tests/protocols/gmpv226/entities/resourcenames/test_get_resource_names_list.py @@ -0,0 +1,198 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import InvalidArgument, RequiredArgument +from gvm.protocols.gmp.requests.v226 import ResourceType + + +class GmpGetResourceNamesListTestMixin: + def test_get_resource_names(self): + self.gmp.get_resource_names(ResourceType.ALERT) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.CERT_BUND_ADV) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.CONFIG) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(resource_type=ResourceType.CPE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.CREDENTIAL) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.CVE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.DFN_CERT_ADV) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.FILTER) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.GROUP) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.HOST) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.NOTE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.NVT) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.OS) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.OVERRIDE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.PERMISSION) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.PORT_LIST) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.REPORT_FORMAT) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.REPORT) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.REPORT_CONFIG) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.RESULT) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.ROLE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.SCANNER) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.SCHEDULE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.TARGET) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.TASK) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.TLS_CERTIFICATE) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_resource_names(ResourceType.USER) + + self.connection.send.has_been_called_with( + b'' + ) + + with self.assertRaises(AttributeError): + self.gmp.get_resource_names( + ResourceType.ALLRESOURCES # pylint: disable=no-member + ) + + def test_get_resource_names_missing_resource_type(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_names(resource_type=None) + + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_names(resource_type="") + + with self.assertRaises(RequiredArgument): + self.gmp.get_resource_names("") + + def test_get_resource_names_invalid_resource_type(self): + with self.assertRaises(InvalidArgument): + self.gmp.get_resource_names(resource_type="foo") + + def test_get_resource_names_with_filter_string(self): + self.gmp.get_resource_names(ResourceType.CPE, filter_string="foo=bar") + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpv226/entities/test_alerts.py b/tests/protocols/gmpv226/entities/test_alerts.py new file mode 100644 index 000000000..7749a5739 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_alerts.py @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.alerts import ( + GmpCloneAlertTestMixin, + GmpCreateAlertTestMixin, + GmpDeleteAlertTestMixin, + GmpGetAlertsTestMixin, + GmpGetAlertTestMixin, + GmpModifyAlertTestMixin, + GmpTestAlertTestMixin, + GmpTriggerAlertTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneAlertTestCase(GmpCloneAlertTestMixin, GMPTestCase): + pass + + +class GMPCreateAlertTestCase(GmpCreateAlertTestMixin, GMPTestCase): + pass + + +class GMPDeleteAlertTestCase(GmpDeleteAlertTestMixin, GMPTestCase): + pass + + +class GMPGetAlertTestCase(GmpGetAlertTestMixin, GMPTestCase): + pass + + +class GMPGetAlertsTestCase(GmpGetAlertsTestMixin, GMPTestCase): + pass + + +class GMPModifyAlertTestCase(GmpModifyAlertTestMixin, GMPTestCase): + pass + + +class GMPTestAlertTestCase(GmpTestAlertTestMixin, GMPTestCase): + pass + + +class GMPTriggerAlertTestCase(GmpTriggerAlertTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_audit_reports.py b/tests/protocols/gmpv226/entities/test_audit_reports.py new file mode 100644 index 000000000..04844430b --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_audit_reports.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv226 import GMPTestCase +from .audit_reports import ( + GmpDeleteAuditReportTestMixin, + GmpGetAuditReportsTestMixin, + GmpGetAuditReportTestMixin, +) + + +class GMPDeleteAuditReportTestCase(GmpDeleteAuditReportTestMixin, GMPTestCase): + pass + + +class GMPGetAuditReportTestCase(GmpGetAuditReportTestMixin, GMPTestCase): + pass + + +class GMPGetAuditReportsTestCase(GmpGetAuditReportsTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_audits.py b/tests/protocols/gmpv226/entities/test_audits.py new file mode 100644 index 000000000..cfd79fbfa --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_audits.py @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.audits import ( + GmpCloneAuditTestMixin, + GmpCreateAuditTestMixin, + GmpDeleteAuditTestMixin, + GmpGetAuditsTestMixin, + GmpGetAuditTestMixin, + GmpModifyAuditTestMixin, + GmpResumeAuditTestMixin, + GmpStartAuditTestMixin, + GmpStopAuditTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneAuditTestCase(GmpCloneAuditTestMixin, GMPTestCase): + pass + + +class GMPCreateAuditTestCase(GmpCreateAuditTestMixin, GMPTestCase): + pass + + +class GMPDeleteAuditTestCase(GmpDeleteAuditTestMixin, GMPTestCase): + pass + + +class GMPGetAuditTestCase(GmpGetAuditTestMixin, GMPTestCase): + pass + + +class GMPGetAuditsTestCase(GmpGetAuditsTestMixin, GMPTestCase): + pass + + +class GMPModifyAuditTestCase(GmpModifyAuditTestMixin, GMPTestCase): + pass + + +class GMPResumeAuditTestCase(GmpResumeAuditTestMixin, GMPTestCase): + pass + + +class GMPStartAuditTestCase(GmpStartAuditTestMixin, GMPTestCase): + pass + + +class GMPStopAuditTestCase(GmpStopAuditTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_credentials.py b/tests/protocols/gmpv226/entities/test_credentials.py new file mode 100644 index 000000000..d7eb4a2f1 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_credentials.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.credentials import ( + GmpCloneCredentialTestMixin, + GmpCreateCredentialTestMixin, + GmpDeleteCredentialTestMixin, + GmpGetCredentialsTestMixin, + GmpGetCredentialTestMixin, + GmpModifyCredentialTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneCredentialTestCase(GmpCloneCredentialTestMixin, GMPTestCase): + pass + + +class GMPCreateCredentialTestCase(GmpCreateCredentialTestMixin, GMPTestCase): + pass + + +class GMPDeleteCredentialTestCase(GmpDeleteCredentialTestMixin, GMPTestCase): + pass + + +class GMPGetCredentialTestCase(GmpGetCredentialTestMixin, GMPTestCase): + pass + + +class GMPGetCredentialsTestCase(GmpGetCredentialsTestMixin, GMPTestCase): + pass + + +class GMPModifyCredentialTestCase(GmpModifyCredentialTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_filters.py b/tests/protocols/gmpv226/entities/test_filters.py new file mode 100644 index 000000000..0a0f4b535 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_filters.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.filters import ( + GmpCloneFilterTestMixin, + GmpCreateFilterTestMixin, + GmpDeleteFilterTestMixin, + GmpGetFiltersTestMixin, + GmpGetFilterTestMixin, + GmpModifyFilterTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteFilterTestCase(GmpDeleteFilterTestMixin, GMPTestCase): + pass + + +class GMPGetFilterTestCase(GmpGetFilterTestMixin, GMPTestCase): + pass + + +class GMPGetFiltersTestCase(GmpGetFiltersTestMixin, GMPTestCase): + pass + + +class GMPCloneFilterTestCase(GmpCloneFilterTestMixin, GMPTestCase): + pass + + +class GMPCreateFilterTestCase(GmpCreateFilterTestMixin, GMPTestCase): + pass + + +class GMPModifyFilterTestCase(GmpModifyFilterTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_groups.py b/tests/protocols/gmpv226/entities/test_groups.py new file mode 100644 index 000000000..54587345d --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_groups.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.groups import ( + GmpCloneGroupTestMixin, + GmpCreateGroupTestMixin, + GmpDeleteGroupTestMixin, + GmpGetGroupsTestMixin, + GmpGetGroupTestMixin, + GmpModifyGroupTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteGroupTestCase(GmpDeleteGroupTestMixin, GMPTestCase): + pass + + +class GMPGetGroupTestCase(GmpGetGroupTestMixin, GMPTestCase): + pass + + +class GMPGetGroupsTestCase(GmpGetGroupsTestMixin, GMPTestCase): + pass + + +class GMPCloneGroupTestCase(GmpCloneGroupTestMixin, GMPTestCase): + pass + + +class GMPCreateGroupTestCase(GmpCreateGroupTestMixin, GMPTestCase): + pass + + +class GMPModifyGroupTestCase(GmpModifyGroupTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_hosts.py b/tests/protocols/gmpv226/entities/test_hosts.py new file mode 100644 index 000000000..324f9ef3a --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_hosts.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.hosts import ( + GmpCreateHostTestMixin, + GmpDeleteHostTestMixin, + GmpGetHostsTestMixin, + GmpGetHostTestMixin, + GmpModifyHostTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCreateHostTestCase(GmpCreateHostTestMixin, GMPTestCase): + pass + + +class GMPDeleteHostTestCase(GmpDeleteHostTestMixin, GMPTestCase): + pass + + +class GMPGetHostTestCase(GmpGetHostTestMixin, GMPTestCase): + pass + + +class GMPGetHostsTestCase(GmpGetHostsTestMixin, GMPTestCase): + pass + + +class GMPModifyHostTestCase(GmpModifyHostTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_notes.py b/tests/protocols/gmpv226/entities/test_notes.py new file mode 100644 index 000000000..755abbef7 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_notes.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.notes import ( + GmpCloneNoteTestMixin, + GmpCreateNoteTestMixin, + GmpDeleteNoteTestMixin, + GmpGetNotesTestMixin, + GmpGetNoteTestMixin, + GmpModifyNoteTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteNoteTestCase(GmpDeleteNoteTestMixin, GMPTestCase): + pass + + +class GMPGetNoteTestCase(GmpGetNoteTestMixin, GMPTestCase): + pass + + +class GMPGetNotesTestCase(GmpGetNotesTestMixin, GMPTestCase): + pass + + +class GMPCloneNoteTestCase(GmpCloneNoteTestMixin, GMPTestCase): + pass + + +class GMPCreateNoteTestCase(GmpCreateNoteTestMixin, GMPTestCase): + pass + + +class GMPModifyNoteTestCase(GmpModifyNoteTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_operating_systems.py b/tests/protocols/gmpv226/entities/test_operating_systems.py new file mode 100644 index 000000000..3750d76fd --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_operating_systems.py @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.operating_systems import ( + GmpDeleteOperatingSystemTestMixin, + GmpGetOperatingSystemsTestMixin, + GmpGetOperatingSystemTestMixin, + GmpModifyOperatingSystemTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteOperatingSystemTestCase( + GmpDeleteOperatingSystemTestMixin, GMPTestCase +): + pass + + +class GMPGetOperatingSystemTestCase( + GmpGetOperatingSystemTestMixin, GMPTestCase +): + pass + + +class GMPGetOperatingSystemsTestCase( + GmpGetOperatingSystemsTestMixin, GMPTestCase +): + pass + + +class GMPModifyOperatingSystemTestCase( + GmpModifyOperatingSystemTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/entities/test_overrides.py b/tests/protocols/gmpv226/entities/test_overrides.py new file mode 100644 index 000000000..2996b1470 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_overrides.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.overrides import ( + GmpCloneOverrideTestMixin, + GmpCreateOverrideTestMixin, + GmpDeleteOverrideTestMixin, + GmpGetOverridesTestMixin, + GmpGetOverrideTestMixin, + GmpModifyOverrideTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneOverrideTestCase(GmpCloneOverrideTestMixin, GMPTestCase): + pass + + +class GMPCreateOverrideTestCase(GmpCreateOverrideTestMixin, GMPTestCase): + pass + + +class GMPDeleteOverrideTestCase(GmpDeleteOverrideTestMixin, GMPTestCase): + pass + + +class GMPGetOverrideTestCase(GmpGetOverrideTestMixin, GMPTestCase): + pass + + +class GMPGetOverridesTestCase(GmpGetOverridesTestMixin, GMPTestCase): + pass + + +class GMPModifyOverrideTestCase(GmpModifyOverrideTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_permissions.py b/tests/protocols/gmpv226/entities/test_permissions.py new file mode 100644 index 000000000..151a808b4 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_permissions.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.permissions import ( + GmpClonePermissionTestMixin, + GmpCreatePermissionTestMixin, + GmpDeletePermissionTestMixin, + GmpGetPermissionsTestMixin, + GmpGetPermissionTestMixin, + GmpModifyPermissionTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeletePermissionTestCase(GmpDeletePermissionTestMixin, GMPTestCase): + pass + + +class GMPGetPermissionTestCase(GmpGetPermissionTestMixin, GMPTestCase): + pass + + +class GMPGetPermissionsTestCase(GmpGetPermissionsTestMixin, GMPTestCase): + pass + + +class GMPClonePermissionTestCase(GmpClonePermissionTestMixin, GMPTestCase): + pass + + +class GMPCreatePermissionTestCase(GmpCreatePermissionTestMixin, GMPTestCase): + pass + + +class GMPModifyPermissionTestCase(GmpModifyPermissionTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_policies.py b/tests/protocols/gmpv226/entities/test_policies.py new file mode 100644 index 000000000..f15e12b3c --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_policies.py @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.policies import ( + GmpClonePolicyTestMixin, + GmpCreatePolicyTestMixin, + GmpDeletePolicyTestMixin, + GmpGetPoliciesTestMixin, + GmpGetPolicyTestMixin, + GmpImportPolicyTestMixin, + GmpModifyPolicySetCommentTestMixin, + GmpModifyPolicySetFamilySelectionTestMixin, + GmpModifyPolicySetNameTestMixin, + GmpModifyPolicySetNvtPreferenceTestMixin, + GmpModifyPolicySetNvtSelectionTestMixin, + GmpModifyPolicySetScannerPreferenceTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPClonePolicyTestCase(GmpClonePolicyTestMixin, GMPTestCase): + pass + + +class GMPCreatePolicyTestCase(GmpCreatePolicyTestMixin, GMPTestCase): + pass + + +class GMPDeletePolicyTestCase(GmpDeletePolicyTestMixin, GMPTestCase): + pass + + +class GMPGetPolicyTestCase(GmpGetPolicyTestMixin, GMPTestCase): + pass + + +class GMPGetPoliciesTestCase(GmpGetPoliciesTestMixin, GMPTestCase): + pass + + +class GMPImportPolicyTestCase(GmpImportPolicyTestMixin, GMPTestCase): + pass + + +class GMPModifyPolicySetCommentTestCase( + GmpModifyPolicySetCommentTestMixin, GMPTestCase +): + pass + + +class GMPModifyPolicySetFamilySelectionTestCase( + GmpModifyPolicySetFamilySelectionTestMixin, GMPTestCase +): + pass + + +class GMPModifyPolicySetNvtSelectionTestCase( + GmpModifyPolicySetNvtSelectionTestMixin, GMPTestCase +): + pass + + +class GMPModifyPolicySetNameTestCase( + GmpModifyPolicySetNameTestMixin, GMPTestCase +): + pass + + +class GMPModifyPolicySetNvtPreferenceTestCase( + GmpModifyPolicySetNvtPreferenceTestMixin, GMPTestCase +): + pass + + +class GMPModifyPolicySetScannerPreferenceTestCase( + GmpModifyPolicySetScannerPreferenceTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/entities/test_port_lists.py b/tests/protocols/gmpv226/entities/test_port_lists.py new file mode 100644 index 000000000..a3e5d781c --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_port_lists.py @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.port_lists import ( + GmpClonePortListTestMixin, + GmpCreatePortListTestMixin, + GmpCreatePortRangeTestMixin, + GmpDeletePortListTestMixin, + GmpDeletePortRangeTestMixin, + GmpGetPortListsTestMixin, + GmpGetPortListTestMixin, + GmpModifyPortListTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPClonePortListTestCase(GmpClonePortListTestMixin, GMPTestCase): + pass + + +class GMPCreatePortListTestCase(GmpCreatePortListTestMixin, GMPTestCase): + pass + + +class GMPCreatePortRangeListTestCase(GmpCreatePortRangeTestMixin, GMPTestCase): + pass + + +class GMPDeletePortListTestCase(GmpDeletePortListTestMixin, GMPTestCase): + pass + + +class GMPDeletePortRangeTestCase(GmpDeletePortRangeTestMixin, GMPTestCase): + pass + + +class GMPGetPortListTestCase(GmpGetPortListTestMixin, GMPTestCase): + pass + + +class GMPGetPortListsTestCase(GmpGetPortListsTestMixin, GMPTestCase): + pass + + +class GMPModifyPortListTestCase(GmpModifyPortListTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_report_formats.py b/tests/protocols/gmpv226/entities/test_report_formats.py new file mode 100644 index 000000000..578781c77 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_report_formats.py @@ -0,0 +1,51 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.report_formats import ( + GmpCloneReportFormatTestMixin, + GmpDeleteReportFormatTestMixin, + GmpGetReportFormatsTestMixin, + GmpGetReportFormatTestMixin, + GmpImportReportFormatTestMixin, + GmpModifyReportFormatTestMixin, + GmpVerifyReportFormatTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteReportFormatTestCase( + GmpDeleteReportFormatTestMixin, GMPTestCase +): + pass + + +class GMPGetReportFormatTestCase(GmpGetReportFormatTestMixin, GMPTestCase): + pass + + +class GMPGetReportFormatsTestCase(GmpGetReportFormatsTestMixin, GMPTestCase): + pass + + +class GMPCloneReportFormatTestCase(GmpCloneReportFormatTestMixin, GMPTestCase): + pass + + +class GMPImportReportFormatTestCase( + GmpImportReportFormatTestMixin, GMPTestCase +): + pass + + +class GMPModifyReportFormatTestCase( + GmpModifyReportFormatTestMixin, GMPTestCase +): + pass + + +class GMPVerifyReportFormatTestCase( + GmpVerifyReportFormatTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/entities/test_reports.py b/tests/protocols/gmpv226/entities/test_reports.py new file mode 100644 index 000000000..497a2258b --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_reports.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv226 import GMPTestCase +from .reports import ( + GmpDeleteReportTestMixin, + GmpGetReportsTestMixin, + GmpGetReportTestMixin, + GmpImportReportTestMixin, +) + + +class GMPDeleteReportTestCase(GmpDeleteReportTestMixin, GMPTestCase): + pass + + +class GMPGetReportTestCase(GmpGetReportTestMixin, GMPTestCase): + pass + + +class GMPGetReportsTestCase(GmpGetReportsTestMixin, GMPTestCase): + pass + + +class GMPImportReportTestCase(GmpImportReportTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_resource_names.py b/tests/protocols/gmpv226/entities/test_resource_names.py new file mode 100644 index 000000000..878d31888 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_resource_names.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv226 import GMPTestCase +from .resourcenames import ( + GmpGetResourceNamesListTestMixin, + GmpGetResourceNameTestMixin, +) + + +class GMPGetResourceNamesListTestCase( + GmpGetResourceNamesListTestMixin, GMPTestCase +): + pass + + +class GMPGetResourceNameTestCase(GmpGetResourceNameTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_results.py b/tests/protocols/gmpv226/entities/test_results.py new file mode 100644 index 000000000..8946015a5 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_results.py @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.results import ( + GmpGetResultsTestMixin, + GmpGetResultTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPGetResultTestCase(GmpGetResultTestMixin, GMPTestCase): + pass + + +class GMPGetResultsTestCase(GmpGetResultsTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_roles.py b/tests/protocols/gmpv226/entities/test_roles.py new file mode 100644 index 000000000..13961435e --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_roles.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.roles import ( + GmpCloneRoleTestMixin, + GmpCreateRoleTestMixin, + GmpDeleteRoleTestMixin, + GmpGetRolesTestMixin, + GmpGetRoleTestMixin, + GmpModifyRoleTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteRoleTestCase(GmpDeleteRoleTestMixin, GMPTestCase): + pass + + +class GMPGetRoleTestCase(GmpGetRoleTestMixin, GMPTestCase): + pass + + +class GMPGetRolesTestCase(GmpGetRolesTestMixin, GMPTestCase): + pass + + +class GMPCloneRoleTestCase(GmpCloneRoleTestMixin, GMPTestCase): + pass + + +class GMPCreateRoleTestCase(GmpCreateRoleTestMixin, GMPTestCase): + pass + + +class GMPModifyRoleTestCase(GmpModifyRoleTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_scan_configs.py b/tests/protocols/gmpv226/entities/test_scan_configs.py new file mode 100644 index 000000000..4929960bc --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_scan_configs.py @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.scan_configs import ( + GmpCloneScanConfigTestMixin, + GmpCreateScanConfigTestMixin, + GmpDeleteScanConfigTestMixin, + GmpGetScanConfigsTestMixin, + GmpGetScanConfigTestMixin, + GmpImportScanConfigTestMixin, + GmpModifyScanConfigSetCommentTestMixin, + GmpModifyScanConfigSetFamilySelectionTestMixin, + GmpModifyScanConfigSetNameTestMixin, + GmpModifyScanConfigSetNvtPreferenceTestMixin, + GmpModifyScanConfigSetNvtSelectionTestMixin, + GmpModifyScanConfigSetScannerPreferenceTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneScanConfigTestCase(GmpCloneScanConfigTestMixin, GMPTestCase): + pass + + +class GMPCreateScanConfigTestCase(GmpCreateScanConfigTestMixin, GMPTestCase): + pass + + +class GMPDeleteScanConfigTestCase(GmpDeleteScanConfigTestMixin, GMPTestCase): + pass + + +class GMPGetScanConfigTestCase(GmpGetScanConfigTestMixin, GMPTestCase): + pass + + +class GMPGetScanConfigsTestCase(GmpGetScanConfigsTestMixin, GMPTestCase): + pass + + +class GMPImportScanConfigTestCase(GmpImportScanConfigTestMixin, GMPTestCase): + pass + + +class GMPModifyScanConfigSetCommentTestCase( + GmpModifyScanConfigSetCommentTestMixin, GMPTestCase +): + pass + + +class GMPModifyScanConfigSetFamilySelectionTestCase( + GmpModifyScanConfigSetFamilySelectionTestMixin, GMPTestCase +): + pass + + +class GMPModifyScanConfigSetNvtSelectionTestCase( + GmpModifyScanConfigSetNvtSelectionTestMixin, GMPTestCase +): + pass + + +class GMPModifyScanConfigSetNameTestCase( + GmpModifyScanConfigSetNameTestMixin, GMPTestCase +): + pass + + +class GMPModifyScanConfigSetNvtPreferenceTestCase( + GmpModifyScanConfigSetNvtPreferenceTestMixin, GMPTestCase +): + pass + + +class GMPModifyScanConfigSetScannerPreferenceTestCase( + GmpModifyScanConfigSetScannerPreferenceTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/entities/test_scanners.py b/tests/protocols/gmpv226/entities/test_scanners.py new file mode 100644 index 000000000..d48a2fbd2 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_scanners.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.scanners import ( + GmpCloneScannerTestMixin, + GmpCreateScannerTestMixin, + GmpDeleteScannerTestMixin, + GmpGetScannersTestMixin, + GmpGetScannerTestMixin, + GmpModifyScannerTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteScannerTestCase(GmpDeleteScannerTestMixin, GMPTestCase): + pass + + +class GMPGetScannerTestCase(GmpGetScannerTestMixin, GMPTestCase): + pass + + +class GMPGetScannersTestCase(GmpGetScannersTestMixin, GMPTestCase): + pass + + +class GMPCloneScannerTestCase(GmpCloneScannerTestMixin, GMPTestCase): + pass + + +class GMPCreateScannerTestCase(GmpCreateScannerTestMixin, GMPTestCase): + pass + + +class GMPModifyScannerTestCase(GmpModifyScannerTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_schedules.py b/tests/protocols/gmpv226/entities/test_schedules.py new file mode 100644 index 000000000..774654cc3 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_schedules.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.schedules import ( + GmpCloneScheduleTestMixin, + GmpCreateScheduleTestMixin, + GmpDeleteScheduleTestMixin, + GmpGetSchedulesTestMixin, + GmpGetScheduleTestMixin, + GmpModifyScheduleTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteScheduleTestCase(GmpDeleteScheduleTestMixin, GMPTestCase): + pass + + +class GMPGetScheduleTestCase(GmpGetScheduleTestMixin, GMPTestCase): + pass + + +class GMPGetSchedulesTestCase(GmpGetSchedulesTestMixin, GMPTestCase): + pass + + +class GMPCloneScheduleTestCase(GmpCloneScheduleTestMixin, GMPTestCase): + pass + + +class GMPCreateScheduleTestCase(GmpCreateScheduleTestMixin, GMPTestCase): + pass + + +class GMPModifyScheduleTestCase(GmpModifyScheduleTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_secinfo.py b/tests/protocols/gmpv226/entities/test_secinfo.py new file mode 100644 index 000000000..3de4a9a89 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_secinfo.py @@ -0,0 +1,83 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.secinfo import ( + GmpGetCertBundListTestMixin, + GmpGetCertBundTestMixin, + GmpGetCpeListTestMixin, + GmpGetCpeTestMixin, + GmpGetCveListTestMixin, + GmpGetCveTestMixin, + GmpGetDfnCertListTestMixin, + GmpGetDfnCertTestMixin, + GmpGetInfoListTestMixin, + GmpGetInfoTestMixin, + GmpGetNvtFamiliesTestMixin, + GmpGetNvtListTestMixin, + GmpGetNvtTestMixin, + GmpGetScanConfigNvtsTestMixin, + GmpGetScanConfigNvtTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPGetCertBundTestCase(GmpGetCertBundTestMixin, GMPTestCase): + pass + + +class GMPGetCpeTestCase(GmpGetCpeTestMixin, GMPTestCase): + pass + + +class GMPGetCveTestCase(GmpGetCveTestMixin, GMPTestCase): + pass + + +class GMPGetDfnCertCase(GmpGetDfnCertTestMixin, GMPTestCase): + pass + + +class GMPGetInfoListTestCase(GmpGetInfoListTestMixin, GMPTestCase): + pass + + +class GMPGetInfoTestCase(GmpGetInfoTestMixin, GMPTestCase): + pass + + +class GMPGetNvtTestCase(GmpGetNvtTestMixin, GMPTestCase): + pass + + +class GMPGetScanConfigNvtTestCase(GmpGetScanConfigNvtTestMixin, GMPTestCase): + pass + + +class GMPGetNvtFamiliesTestCase(GmpGetNvtFamiliesTestMixin, GMPTestCase): + pass + + +class GMPGetScanConfigNvtsTestCase(GmpGetScanConfigNvtsTestMixin, GMPTestCase): + pass + + +class GMPGetCertBundListTestCase(GmpGetCertBundListTestMixin, GMPTestCase): + pass + + +class GMPGetCpeListTestCase(GmpGetCpeListTestMixin, GMPTestCase): + pass + + +class GMPGetCveListTestCase(GmpGetCveListTestMixin, GMPTestCase): + pass + + +class GMPGetDfnCertListCase(GmpGetDfnCertListTestMixin, GMPTestCase): + pass + + +class GMPGetNvtListTestCase(GmpGetNvtListTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_tags.py b/tests/protocols/gmpv226/entities/test_tags.py new file mode 100644 index 000000000..fe02776da --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_tags.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.tags import ( + GmpCloneTagTestMixin, + GmpCreateTagTestMixin, + GmpDeleteTagTestMixin, + GmpGetTagsTestMixin, + GmpGetTagTestMixin, + GmpModifyTagTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteTagTestCase(GmpDeleteTagTestMixin, GMPTestCase): + pass + + +class GMPGetTagTestCase(GmpGetTagTestMixin, GMPTestCase): + pass + + +class GMPGetTagsTestCase(GmpGetTagsTestMixin, GMPTestCase): + pass + + +class GMPCloneTagTestCase(GmpCloneTagTestMixin, GMPTestCase): + pass + + +class GMPCreateTagTestCase(GmpCreateTagTestMixin, GMPTestCase): + pass + + +class GMPModifyTagTestCase(GmpModifyTagTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_targets.py b/tests/protocols/gmpv226/entities/test_targets.py new file mode 100644 index 000000000..378596ac3 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_targets.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.targets import ( + GmpCloneTargetTestMixin, + GmpCreateTargetTestMixin, + GmpDeleteTargetTestMixin, + GmpGetTargetsTestMixin, + GmpGetTargetTestMixin, + GmpModifyTargetTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneTargetTestCase(GmpCloneTargetTestMixin, GMPTestCase): + pass + + +class GMPCreateTargetTestCase(GmpCreateTargetTestMixin, GMPTestCase): + pass + + +class GMPDeleteTargetTestCase(GmpDeleteTargetTestMixin, GMPTestCase): + pass + + +class GMPGetTargetTestCase(GmpGetTargetTestMixin, GMPTestCase): + pass + + +class GMPGetTargetsTestCase(GmpGetTargetsTestMixin, GMPTestCase): + pass + + +class GMPModifyTargetTestCase(GmpModifyTargetTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_tasks.py b/tests/protocols/gmpv226/entities/test_tasks.py new file mode 100644 index 000000000..39c5df36b --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_tasks.py @@ -0,0 +1,65 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.tasks import ( + GmpCloneTaskTestMixin, + GmpCreateContainerTaskTestMixin, + GmpCreateTaskTestMixin, + GmpDeleteTaskTestMixin, + GmpGetTasksTestMixin, + GmpGetTaskTestMixin, + GmpModifyTaskTestMixin, + GmpMoveTaskTestMixin, + GmpResumeTaskTestMixin, + GmpStartTaskTestMixin, + GmpStopTaskTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneTaskTestCase(GmpCloneTaskTestMixin, GMPTestCase): + pass + + +class GMPCreateContainerTaskTestCase( + GmpCreateContainerTaskTestMixin, GMPTestCase +): + pass + + +class GMPCreateTaskTestCase(GmpCreateTaskTestMixin, GMPTestCase): + pass + + +class GMPDeleteTaskTestCase(GmpDeleteTaskTestMixin, GMPTestCase): + pass + + +class GMPGetTaskTestCase(GmpGetTaskTestMixin, GMPTestCase): + pass + + +class GMPGetTasksTestCase(GmpGetTasksTestMixin, GMPTestCase): + pass + + +class GMPModifyTaskTestCase(GmpModifyTaskTestMixin, GMPTestCase): + pass + + +class GMPMoveTaskTestCase(GmpMoveTaskTestMixin, GMPTestCase): + pass + + +class GMPResumeTaskTestCase(GmpResumeTaskTestMixin, GMPTestCase): + pass + + +class GMPStartTaskTestCase(GmpStartTaskTestMixin, GMPTestCase): + pass + + +class GMPStopTaskTestCase(GmpStopTaskTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_tickets.py b/tests/protocols/gmpv226/entities/test_tickets.py new file mode 100644 index 000000000..aa91b645c --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_tickets.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.tickets import ( + GmpCloneTicketTestMixin, + GmpCreateTicketTestMixin, + GmpDeleteTicketTestMixin, + GmpGetTicketsTestMixin, + GmpGetTicketTestMixin, + GmpModifyTicketTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPDeleteTicketTestCase(GmpDeleteTicketTestMixin, GMPTestCase): + pass + + +class GMPGetTicketTestCase(GmpGetTicketTestMixin, GMPTestCase): + pass + + +class GMPGetTicketsTestCase(GmpGetTicketsTestMixin, GMPTestCase): + pass + + +class GMPCloneTicketTestCase(GmpCloneTicketTestMixin, GMPTestCase): + pass + + +class GMPCreateTicketTestCase(GmpCreateTicketTestMixin, GMPTestCase): + pass + + +class GMPModifyTicketTestCase(GmpModifyTicketTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_tls_certificates.py b/tests/protocols/gmpv226/entities/test_tls_certificates.py new file mode 100644 index 000000000..59ab1d6e0 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_tls_certificates.py @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.tls_certificates import ( + GmpCloneTLSCertificateTestMixin, + GmpCreateTLSCertificateTestMixin, + GmpDeleteTLSCertificateTestMixin, + GmpGetTLSCertificatesTestMixin, + GmpGetTLSCertificateTestMixin, + GmpModifyTLSCertificateTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneTLSCertificateTestCase( + GmpCloneTLSCertificateTestMixin, GMPTestCase +): + pass + + +class GMPCreateTLSCertificateTestCase( + GmpCreateTLSCertificateTestMixin, GMPTestCase +): + pass + + +class GMPDeleteTLSCertificateTestCase( + GmpDeleteTLSCertificateTestMixin, GMPTestCase +): + pass + + +class GMPGetTLSCertificateTestCase(GmpGetTLSCertificateTestMixin, GMPTestCase): + pass + + +class GMPGetTLSCertificatesTestCase( + GmpGetTLSCertificatesTestMixin, GMPTestCase +): + pass + + +class GMPModifyTLSCertificateTestCase( + GmpModifyTLSCertificateTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/entities/test_users.py b/tests/protocols/gmpv226/entities/test_users.py new file mode 100644 index 000000000..9074b9082 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_users.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.users import ( + GmpCloneUserTestMixin, + GmpCreateUserTestMixin, + GmpDeleteUserTestMixin, + GmpGetUsersTestMixin, + GmpGetUserTestMixin, + GmpModifyUserTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPCloneUserTestCase(GmpCloneUserTestMixin, GMPTestCase): + pass + + +class GMPCreateUserTestCase(GmpCreateUserTestMixin, GMPTestCase): + pass + + +class GMPDeleteUserTestCase(GmpDeleteUserTestMixin, GMPTestCase): + pass + + +class GMPGetUserTestCase(GmpGetUserTestMixin, GMPTestCase): + pass + + +class GMPGetUsersTestCase(GmpGetUsersTestMixin, GMPTestCase): + pass + + +class GMPModifyUserTestCase(GmpModifyUserTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/entities/test_vulnerabilities.py b/tests/protocols/gmpv226/entities/test_vulnerabilities.py new file mode 100644 index 000000000..a5495c10e --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_vulnerabilities.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.entities.vulnerabilities import ( + GmpGetVulnerabilitiesTestMixin, + GmpGetVulnerabilityTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPGetVulnerabilityTestCase(GmpGetVulnerabilityTestMixin, GMPTestCase): + pass + + +class GMPGetVulnerabilitiesTestCase( + GmpGetVulnerabilitiesTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/enums/__init__.py b/tests/protocols/gmpv226/enums/__init__.py new file mode 100644 index 000000000..baae7654d --- /dev/null +++ b/tests/protocols/gmpv226/enums/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# diff --git a/tests/protocols/gmpv226/enums/test_aggregate_statistic.py b/tests/protocols/gmpv226/enums/test_aggregate_statistic.py new file mode 100644 index 000000000..788b553aa --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_aggregate_statistic.py @@ -0,0 +1,57 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import AggregateStatistic + + +class GetAggregateStatisticFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + AggregateStatistic.from_string("foo") + + def test_none_or_empty(self): + ct = AggregateStatistic.from_string(None) + self.assertIsNone(ct) + ct = AggregateStatistic.from_string("") + self.assertIsNone(ct) + + def test_count(self): + ct = AggregateStatistic.from_string("count") + self.assertEqual(ct, AggregateStatistic.COUNT) + + def test_c_count(self): + ct = AggregateStatistic.from_string("c_count") + self.assertEqual(ct, AggregateStatistic.C_COUNT) + + def test_c_sum(self): + ct = AggregateStatistic.from_string("c_sum") + self.assertEqual(ct, AggregateStatistic.C_SUM) + + def test_max(self): + ct = AggregateStatistic.from_string("max") + self.assertEqual(ct, AggregateStatistic.MAX) + + def test_mean(self): + ct = AggregateStatistic.from_string("mean") + self.assertEqual(ct, AggregateStatistic.MEAN) + + def test_min(self): + ct = AggregateStatistic.from_string("min") + self.assertEqual(ct, AggregateStatistic.MIN) + + def test_sum(self): + ct = AggregateStatistic.from_string("sum") + self.assertEqual(ct, AggregateStatistic.SUM) + + def test_text(self): + ct = AggregateStatistic.from_string("text") + self.assertEqual(ct, AggregateStatistic.TEXT) + + def test_value(self): + ct = AggregateStatistic.from_string("value") + self.assertEqual(ct, AggregateStatistic.VALUE) diff --git a/tests/protocols/gmpv226/enums/test_alert_condition.py b/tests/protocols/gmpv226/enums/test_alert_condition.py new file mode 100644 index 000000000..0e6d9b631 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_alert_condition.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import AlertCondition + + +class GetAlertConditionFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + AlertCondition.from_string("foo") + + def test_none_or_empty(self): + ct = AlertCondition.from_string(None) + self.assertIsNone(ct) + ct = AlertCondition.from_string("") + self.assertIsNone(ct) + + def test_always(self): + ct = AlertCondition.from_string("always") + self.assertEqual(ct, AlertCondition.ALWAYS) + + def test_filter_count_at_least(self): + ct = AlertCondition.from_string("filter count at least") + self.assertEqual(ct, AlertCondition.FILTER_COUNT_AT_LEAST) + + def test_filter_count_changed(self): + ct = AlertCondition.from_string("filter count changed") + self.assertEqual(ct, AlertCondition.FILTER_COUNT_CHANGED) + + def test_severity_at_least(self): + ct = AlertCondition.from_string("severity at least") + self.assertEqual(ct, AlertCondition.SEVERITY_AT_LEAST) + + def test_severity_changed(self): + ct = AlertCondition.from_string("severity changed") + self.assertEqual(ct, AlertCondition.SEVERITY_CHANGED) + + def test_error(self): + ct = AlertCondition.from_string("error") + self.assertEqual(ct, AlertCondition.ERROR) diff --git a/tests/protocols/gmpv226/enums/test_alert_event.py b/tests/protocols/gmpv226/enums/test_alert_event.py new file mode 100644 index 000000000..06bfd7b79 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_alert_event.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import AlertEvent + + +class GetAlertEventFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + AlertEvent.from_string("foo") + + def test_none_or_empty(self): + ct = AlertEvent.from_string(None) + self.assertIsNone(ct) + ct = AlertEvent.from_string("") + self.assertIsNone(ct) + + def test_task_run_status_changed(self): + ct = AlertEvent.from_string("Task run status changed") + self.assertEqual(ct, AlertEvent.TASK_RUN_STATUS_CHANGED) + + def test_new_secinfo_arrived(self): + ct = AlertEvent.from_string("New SecInfo arrived") + self.assertEqual(ct, AlertEvent.NEW_SECINFO_ARRIVED) + + def test_updated_secinfo_arrived(self): + ct = AlertEvent.from_string("Updated SecInfo arrived") + self.assertEqual(ct, AlertEvent.UPDATED_SECINFO_ARRIVED) + + def test_ticket_received(self): + ct = AlertEvent.from_string("ticket received") + self.assertEqual(ct, AlertEvent.TICKET_RECEIVED) + + def test_assigned_ticket_changed(self): + ct = AlertEvent.from_string("assigned ticket changed") + self.assertEqual(ct, AlertEvent.ASSIGNED_TICKET_CHANGED) + + def test_owned_ticket_changed(self): + ct = AlertEvent.from_string("owned ticket changed") + self.assertEqual(ct, AlertEvent.OWNED_TICKET_CHANGED) diff --git a/tests/protocols/gmpv226/enums/test_alert_method.py b/tests/protocols/gmpv226/enums/test_alert_method.py new file mode 100644 index 000000000..a1bd1159f --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_alert_method.py @@ -0,0 +1,69 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import AlertMethod + + +class GetAlertMethodFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + AlertMethod.from_string("foo") + + def test_none_or_empty(self): + ct = AlertMethod.from_string(None) + self.assertIsNone(ct) + ct = AlertMethod.from_string("") + self.assertIsNone(ct) + + def test_email(self): + ct = AlertMethod.from_string("email") + self.assertEqual(ct, AlertMethod.EMAIL) + + def test_scp(self): + ct = AlertMethod.from_string("scp") + self.assertEqual(ct, AlertMethod.SCP) + + def test_send(self): + ct = AlertMethod.from_string("send") + self.assertEqual(ct, AlertMethod.SEND) + + def test_smb(self): + ct = AlertMethod.from_string("smb") + self.assertEqual(ct, AlertMethod.SMB) + + def test_snmp(self): + ct = AlertMethod.from_string("snmp") + self.assertEqual(ct, AlertMethod.SNMP) + + def test_syslog(self): + ct = AlertMethod.from_string("syslog") + self.assertEqual(ct, AlertMethod.SYSLOG) + + def test_http_get(self): + ct = AlertMethod.from_string("HTTP Get") + self.assertEqual(ct, AlertMethod.HTTP_GET) + + def test_start_task(self): + ct = AlertMethod.from_string("Start Task") + self.assertEqual(ct, AlertMethod.START_TASK) + + def test_sourcefire_connector(self): + ct = AlertMethod.from_string("sourcefire Connector") + self.assertEqual(ct, AlertMethod.SOURCEFIRE_CONNECTOR) + + def test_verinice_connector(self): + ct = AlertMethod.from_string("verinice Connector") + self.assertEqual(ct, AlertMethod.VERINICE_CONNECTOR) + + def test_tippingpoint_sms(self): + ct = AlertMethod.from_string("Tippingpoint SMS") + self.assertEqual(ct, AlertMethod.TIPPINGPOINT_SMS) + + def test_alemba_vfire(self): + ct = AlertMethod.from_string("Alemba vFire") + self.assertEqual(ct, AlertMethod.ALEMBA_VFIRE) diff --git a/tests/protocols/gmpv226/enums/test_alive_test.py b/tests/protocols/gmpv226/enums/test_alive_test.py new file mode 100644 index 000000000..f189150cf --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_alive_test.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import AliveTest + + +class GetAliveTestFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + AliveTest.from_string("foo") + + def test_none_or_empty(self): + ct = AliveTest.from_string(None) + self.assertIsNone(ct) + ct = AliveTest.from_string("") + self.assertIsNone(ct) + + def test_scan_config_default(self): + ct = AliveTest.from_string("Scan Config Default") + self.assertEqual(ct, AliveTest.SCAN_CONFIG_DEFAULT) + + def test_icmp_ping(self): + ct = AliveTest.from_string("ICMP Ping") + self.assertEqual(ct, AliveTest.ICMP_PING) + + def test_tcp_ack_service_ping(self): + ct = AliveTest.from_string("TCP-ACK Service Ping") + self.assertEqual(ct, AliveTest.TCP_ACK_SERVICE_PING) + + def test_tcp_sync_service_ping(self): + ct = AliveTest.from_string("TCP-SYN Service Ping") + self.assertEqual(ct, AliveTest.TCP_SYN_SERVICE_PING) + + def test_arp_ping(self): + ct = AliveTest.from_string("ARP Ping") + self.assertEqual(ct, AliveTest.ARP_PING) + + def test_icmp_and_tcp_ack_service_ping(self): + ct = AliveTest.from_string("ICMP & TCP-ACK Service Ping") + self.assertEqual(ct, AliveTest.ICMP_AND_TCP_ACK_SERVICE_PING) + + def test_icmp_and_arp_ping(self): + ct = AliveTest.from_string("ICMP & ARP Ping") + self.assertEqual(ct, AliveTest.ICMP_AND_ARP_PING) + + def test_tcp_ack_service_and_arp_ping(self): + ct = AliveTest.from_string("TCP-ACK Service & ARP Ping") + self.assertEqual(ct, AliveTest.TCP_ACK_SERVICE_AND_ARP_PING) + + def test_icmp_tcp_ack_service_and_arp_ping(self): + ct = AliveTest.from_string("ICMP, TCP-ACK Service & ARP Ping") + self.assertEqual(ct, AliveTest.ICMP_TCP_ACK_SERVICE_AND_ARP_PING) + + def test_consider_alive(self): + ct = AliveTest.from_string("Consider Alive") + self.assertEqual(ct, AliveTest.CONSIDER_ALIVE) diff --git a/tests/protocols/gmpv226/enums/test_credential_format.py b/tests/protocols/gmpv226/enums/test_credential_format.py new file mode 100644 index 000000000..c40017e06 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_credential_format.py @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import CredentialFormat + + +class GetCredentialFormatFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + CredentialFormat.from_string("foo") + + def test_none_or_empty(self): + ct = CredentialFormat.from_string(None) + self.assertIsNone(ct) + ct = CredentialFormat.from_string("") + self.assertIsNone(ct) + + def test_key(self): + ct = CredentialFormat.from_string("key") + self.assertEqual(ct, CredentialFormat.KEY) + + def test_rpm(self): + ct = CredentialFormat.from_string("rpm") + self.assertEqual(ct, CredentialFormat.RPM) + + def test_deb(self): + ct = CredentialFormat.from_string("deb") + self.assertEqual(ct, CredentialFormat.DEB) + + def test_exe(self): + ct = CredentialFormat.from_string("exe") + self.assertEqual(ct, CredentialFormat.EXE) + + def test_pem(self): + ct = CredentialFormat.from_string("pem") + self.assertEqual(ct, CredentialFormat.PEM) diff --git a/tests/protocols/gmpv226/enums/test_credential_type.py b/tests/protocols/gmpv226/enums/test_credential_type.py new file mode 100644 index 000000000..bff666221 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_credential_type.py @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import CredentialType + + +class GetCredentialTypeFromStringTestCase(unittest.TestCase): + def test_invalid_type(self): + with self.assertRaises(InvalidArgument): + CredentialType.from_string("foo") + + def test_none_or_empty_type(self): + ct = CredentialType.from_string(None) + self.assertIsNone(ct) + ct = CredentialType.from_string("") + self.assertIsNone(ct) + + def test_client_certificate(self): + ct = CredentialType.from_string("client_certificate") + self.assertEqual(ct, CredentialType.CLIENT_CERTIFICATE) + + def test_snmp(self): + ct = CredentialType.from_string("snmp") + self.assertEqual(ct, CredentialType.SNMP) + + def test_username_password(self): + ct = CredentialType.from_string("username_password") + self.assertEqual(ct, CredentialType.USERNAME_PASSWORD) + + def test_username_ssh_key(self): + ct = CredentialType.from_string("username_ssh_key") + self.assertEqual(ct, CredentialType.USERNAME_SSH_KEY) + + def test_smime_certificate(self): + ct = CredentialType.from_string("smime_certificate") + self.assertEqual(ct, CredentialType.SMIME_CERTIFICATE) + + def test_pgp_encryption_key(self): + ct = CredentialType.from_string("pgp_encryption_key") + self.assertEqual(ct, CredentialType.PGP_ENCRYPTION_KEY) + + def test_password_only(self): + ct = CredentialType.from_string("password_only") + self.assertEqual(ct, CredentialType.PASSWORD_ONLY) diff --git a/tests/protocols/gmpv226/enums/test_entity_type.py b/tests/protocols/gmpv226/enums/test_entity_type.py new file mode 100644 index 000000000..c68ebda05 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_entity_type.py @@ -0,0 +1,166 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import EntityType + + +class GetEntityTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + EntityType.from_string("foo") + + def test_none_or_empty(self): + ct = EntityType.from_string(None) + self.assertIsNone(ct) + ct = EntityType.from_string("") + self.assertIsNone(ct) + + def test_audit(self): + ct = EntityType.from_string("audit") + self.assertEqual(ct, EntityType.AUDIT) + + def test_alert(self): + ct = EntityType.from_string("alert") + self.assertEqual(ct, EntityType.ALERT) + + def test_asset(self): + ct = EntityType.from_string("asset") + self.assertEqual(ct, EntityType.ASSET) + + def test_cert_bund_adv(self): + ct = EntityType.from_string("cert_bund_adv") + self.assertEqual(ct, EntityType.CERT_BUND_ADV) + + def test_cpe(self): + ct = EntityType.from_string("cpe") + self.assertEqual(ct, EntityType.CPE) + + def test_credential(self): + ct = EntityType.from_string("credential") + self.assertEqual(ct, EntityType.CREDENTIAL) + + def test_dfn_cert_adv(self): + ct = EntityType.from_string("dfn_cert_adv") + self.assertEqual(ct, EntityType.DFN_CERT_ADV) + + def test_filter(self): + ct = EntityType.from_string("filter") + self.assertEqual(ct, EntityType.FILTER) + + def test_group(self): + ct = EntityType.from_string("group") + self.assertEqual(ct, EntityType.GROUP) + + def test_host(self): + ct = EntityType.from_string("host") + self.assertEqual(ct, EntityType.HOST) + + def test_info(self): + ct = EntityType.from_string("info") + self.assertEqual(ct, EntityType.INFO) + + def test_note(self): + ct = EntityType.from_string("note") + self.assertEqual(ct, EntityType.NOTE) + + def test_nvt(self): + ct = EntityType.from_string("nvt") + self.assertEqual(ct, EntityType.NVT) + + def test_operating_system(self): + ct = EntityType.from_string("os") + self.assertEqual(ct, EntityType.OPERATING_SYSTEM) + + ct = EntityType.from_string("operating_system") + self.assertEqual(ct, EntityType.OPERATING_SYSTEM) + + def test_ovaldef(self): + ct = EntityType.from_string("ovaldef") + self.assertEqual(ct, EntityType.OVALDEF) + + def test_override(self): + ct = EntityType.from_string("override") + self.assertEqual(ct, EntityType.OVERRIDE) + + def test_permission(self): + ct = EntityType.from_string("permission") + self.assertEqual(ct, EntityType.PERMISSION) + + def test_policy(self): + ct = EntityType.from_string("policy") + self.assertEqual(ct, EntityType.POLICY) + + def test_port_list(self): + ct = EntityType.from_string("port_list") + self.assertEqual(ct, EntityType.PORT_LIST) + + def test_report(self): + ct = EntityType.from_string("report") + self.assertEqual(ct, EntityType.REPORT) + + def test_report_format(self): + ct = EntityType.from_string("report_format") + self.assertEqual(ct, EntityType.REPORT_FORMAT) + + def test_result(self): + ct = EntityType.from_string("result") + self.assertEqual(ct, EntityType.RESULT) + + def test_role(self): + ct = EntityType.from_string("role") + self.assertEqual(ct, EntityType.ROLE) + + def test_scan_config(self): + ct = EntityType.from_string("config") + self.assertEqual(ct, EntityType.SCAN_CONFIG) + + ct = EntityType.from_string("scan_config") + self.assertEqual(ct, EntityType.SCAN_CONFIG) + + def test_scanner(self): + ct = EntityType.from_string("scanner") + self.assertEqual(ct, EntityType.SCANNER) + + def test_schedule(self): + ct = EntityType.from_string("schedule") + self.assertEqual(ct, EntityType.SCHEDULE) + + def test_tag(self): + ct = EntityType.from_string("tag") + self.assertEqual(ct, EntityType.TAG) + + def test_target(self): + ct = EntityType.from_string("target") + self.assertEqual(ct, EntityType.TARGET) + + def test_task(self): + ct = EntityType.from_string("task") + self.assertEqual(ct, EntityType.TASK) + + def test_ticket(self): + ct = EntityType.from_string("ticket") + self.assertEqual(ct, EntityType.TICKET) + + def test_tls_certificate(self): + ft = EntityType.from_string("tls_certificate") + self.assertEqual(ft, EntityType.TLS_CERTIFICATE) + + def test_user(self): + ct = EntityType.from_string("user") + self.assertEqual(ct, EntityType.USER) + + def test_vulnerability(self): + ct = EntityType.from_string("vuln") + self.assertEqual(ct, EntityType.VULNERABILITY) + + ct = EntityType.from_string("vulnerability") + self.assertEqual(ct, EntityType.VULNERABILITY) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/protocols/gmpv226/enums/test_feed_type.py b/tests/protocols/gmpv226/enums/test_feed_type.py new file mode 100644 index 000000000..6ad226dc1 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_feed_type.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import FeedType + + +class GetFeedTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + FeedType.from_string("foo") + + def test_none_or_empty(self): + ct = FeedType.from_string(None) + self.assertIsNone(ct) + ct = FeedType.from_string("") + self.assertIsNone(ct) + + def test_nvt(self): + ct = FeedType.from_string("nvt") + self.assertEqual(ct, FeedType.NVT) + + def test_cert(self): + ct = FeedType.from_string("cert") + self.assertEqual(ct, FeedType.CERT) + + def test_scap(self): + ct = FeedType.from_string("scap") + self.assertEqual(ct, FeedType.SCAP) + + def test_gvmd_data(self): + ct = FeedType.from_string("gvmd_data") + self.assertEqual(ct, FeedType.GVMD_DATA) diff --git a/tests/protocols/gmpv226/enums/test_filter_type.py b/tests/protocols/gmpv226/enums/test_filter_type.py new file mode 100644 index 000000000..62490bc7d --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_filter_type.py @@ -0,0 +1,138 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import FilterType + + +class GetFilterTypeFomStringTestCase(unittest.TestCase): + def test_filter_type_alert(self): + ft = FilterType.from_string("alert") + self.assertEqual(ft, FilterType.ALERT) + + def test_filter_type_asset(self): + ft = FilterType.from_string("asset") + self.assertEqual(ft, FilterType.ASSET) + + def test_filter_type_credential(self): + ft = FilterType.from_string("credential") + self.assertEqual(ft, FilterType.CREDENTIAL) + + def test_filter_type_filter(self): + ft = FilterType.from_string("filter") + self.assertEqual(ft, FilterType.FILTER) + + def test_filter_type_group(self): + ft = FilterType.from_string("group") + self.assertEqual(ft, FilterType.GROUP) + + def test_filter_type_host(self): + ft = FilterType.from_string("host") + self.assertEqual(ft, FilterType.HOST) + + def test_filter_type_note(self): + ft = FilterType.from_string("note") + self.assertEqual(ft, FilterType.NOTE) + + def test_filter_type_override(self): + ft = FilterType.from_string("override") + self.assertEqual(ft, FilterType.OVERRIDE) + + def test_filter_type_permission(self): + ft = FilterType.from_string("permission") + self.assertEqual(ft, FilterType.PERMISSION) + + def test_filter_type_port_list(self): + ft = FilterType.from_string("port_list") + self.assertEqual(ft, FilterType.PORT_LIST) + + def test_filter_type_report(self): + ft = FilterType.from_string("report") + self.assertEqual(ft, FilterType.REPORT) + + def test_filter_type_report_format(self): + ft = FilterType.from_string("report_format") + self.assertEqual(ft, FilterType.REPORT_FORMAT) + + def test_filter_type_result(self): + ft = FilterType.from_string("result") + self.assertEqual(ft, FilterType.RESULT) + + def test_filter_type_role(self): + ft = FilterType.from_string("role") + self.assertEqual(ft, FilterType.ROLE) + + def test_filter_type_schedule(self): + ft = FilterType.from_string("schedule") + self.assertEqual(ft, FilterType.SCHEDULE) + + def test_filter_type_secinfo(self): + ft = FilterType.from_string("secinfo") + self.assertEqual(ft, FilterType.ALL_SECINFO) + + def test_filter_type_all_secinfo(self): + ft = FilterType.from_string("all_secinfo") + self.assertEqual(ft, FilterType.ALL_SECINFO) + + def test_filter_type_tag(self): + ft = FilterType.from_string("tag") + self.assertEqual(ft, FilterType.TAG) + + def test_filter_type_task(self): + ft = FilterType.from_string("task") + self.assertEqual(ft, FilterType.TASK) + + def test_filter_type_target(self): + ft = FilterType.from_string("target") + self.assertEqual(ft, FilterType.TARGET) + + def test_filter_type_ticket(self): + ft = FilterType.from_string("ticket") + self.assertEqual(ft, FilterType.TICKET) + + def test_filter_type_tls_certificate(self): + ft = FilterType.from_string("tls_certificate") + self.assertEqual(ft, FilterType.TLS_CERTIFICATE) + + def test_filter_type_operating_system(self): + ft = FilterType.from_string("operating_system") + self.assertEqual(ft, FilterType.OPERATING_SYSTEM) + + def test_filter_type_user(self): + ft = FilterType.from_string("user") + self.assertEqual(ft, FilterType.USER) + + def test_filter_type_vuln(self): + ft = FilterType.from_string("vuln") + self.assertEqual(ft, FilterType.VULNERABILITY) + + def test_filter_type_vulnerability(self): + ft = FilterType.from_string("vulnerability") + self.assertEqual(ft, FilterType.VULNERABILITY) + + def test_filter_type_config(self): + ft = FilterType.from_string("config") + self.assertEqual(ft, FilterType.SCAN_CONFIG) + + def test_filter_type_scan_config(self): + ft = FilterType.from_string("scan_config") + self.assertEqual(ft, FilterType.SCAN_CONFIG) + + def test_filter_type_os(self): + ft = FilterType.from_string("os") + self.assertEqual(ft, FilterType.OPERATING_SYSTEM) + + def test_invalid_filter_type(self): + with self.assertRaises(InvalidArgument): + FilterType.from_string("foo") + + def test_non_or_empty_filter_type(self): + ft = FilterType.from_string(None) + self.assertIsNone(ft) + + ft = FilterType.from_string("") + self.assertIsNone(ft) diff --git a/tests/protocols/gmpv226/enums/test_help_format.py b/tests/protocols/gmpv226/enums/test_help_format.py new file mode 100644 index 000000000..2b67dda65 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_help_format.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import HelpFormat + + +class GetHelpFormatFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + HelpFormat.from_string("foo") + + def test_none_or_empty(self): + ct = HelpFormat.from_string(None) + self.assertIsNone(ct) + ct = HelpFormat.from_string("") + self.assertIsNone(ct) + + def test_task_run_status_changed(self): + ct = HelpFormat.from_string("HtMl") + self.assertEqual(ct, HelpFormat.HTML) + + def test_new_secinfo_arrived(self): + ct = HelpFormat.from_string("rNc") + self.assertEqual(ct, HelpFormat.RNC) + + def test_updated_secinfo_arrived(self): + ct = HelpFormat.from_string("tExT") + self.assertEqual(ct, HelpFormat.TEXT) + + def test_ticket_received(self): + ct = HelpFormat.from_string("XmL") + self.assertEqual(ct, HelpFormat.XML) diff --git a/tests/protocols/gmpv226/enums/test_hosts_ordering.py b/tests/protocols/gmpv226/enums/test_hosts_ordering.py new file mode 100644 index 000000000..281aefa5b --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_hosts_ordering.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import HostsOrdering + + +class GetHostsOrderingFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + HostsOrdering.from_string("foo") + + def test_none_or_empty(self): + ct = HostsOrdering.from_string(None) + self.assertIsNone(ct) + ct = HostsOrdering.from_string("") + self.assertIsNone(ct) + + def test_sequential(self): + ct = HostsOrdering.from_string("sequential") + self.assertEqual(ct, HostsOrdering.SEQUENTIAL) + + def test_random(self): + ct = HostsOrdering.from_string("random") + self.assertEqual(ct, HostsOrdering.RANDOM) + + def test_reverse(self): + ct = HostsOrdering.from_string("reverse") + self.assertEqual(ct, HostsOrdering.REVERSE) diff --git a/tests/protocols/gmpv226/enums/test_info_type.py b/tests/protocols/gmpv226/enums/test_info_type.py new file mode 100644 index 000000000..dc5e96ff1 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_info_type.py @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import InfoType + + +class GetInfoTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + InfoType.from_string("foo") + + def test_none_or_empty(self): + ct = InfoType.from_string(None) + self.assertIsNone(ct) + ct = InfoType.from_string("") + self.assertIsNone(ct) + + def test_cert_bund_adv(self): + ct = InfoType.from_string("cert_bund_adv") + self.assertEqual(ct, InfoType.CERT_BUND_ADV) + + def test_cpe(self): + ct = InfoType.from_string("cpe") + self.assertEqual(ct, InfoType.CPE) + + def test_cve(self): + ct = InfoType.from_string("cve") + self.assertEqual(ct, InfoType.CVE) + + def test_dfn_cert_adv(self): + ct = InfoType.from_string("dfn_cert_adv") + self.assertEqual(ct, InfoType.DFN_CERT_ADV) + + def test_nvt(self): + ct = InfoType.from_string("nvt") + self.assertEqual(ct, InfoType.NVT) + + def test_ovaldef(self): + ct = InfoType.from_string("ovaldef") + self.assertEqual(ct, InfoType.OVALDEF) + + def test_allinfo(self): + with self.assertRaises(InvalidArgument): + InfoType.from_string("allinfo") diff --git a/tests/protocols/gmpv226/enums/test_permission_subject_type.py b/tests/protocols/gmpv226/enums/test_permission_subject_type.py new file mode 100644 index 000000000..22ada99e0 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_permission_subject_type.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import PermissionSubjectType + + +class GetPermissionSubjectTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + PermissionSubjectType.from_string("foo") + + def test_none_or_empty(self): + ct = PermissionSubjectType.from_string(None) + self.assertIsNone(ct) + ct = PermissionSubjectType.from_string("") + self.assertIsNone(ct) + + def test_user(self): + ct = PermissionSubjectType.from_string("user") + self.assertEqual(ct, PermissionSubjectType.USER) + + def test_role(self): + ct = PermissionSubjectType.from_string("role") + self.assertEqual(ct, PermissionSubjectType.ROLE) + + def test_group(self): + ct = PermissionSubjectType.from_string("group") + self.assertEqual(ct, PermissionSubjectType.GROUP) diff --git a/tests/protocols/gmpv226/enums/test_port_range_type.py b/tests/protocols/gmpv226/enums/test_port_range_type.py new file mode 100644 index 000000000..72779422a --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_port_range_type.py @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import PortRangeType + + +class GetPortRangeTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + PortRangeType.from_string("foo") + + def test_none_or_empty(self): + ct = PortRangeType.from_string(None) + self.assertIsNone(ct) + ct = PortRangeType.from_string("") + self.assertIsNone(ct) + + def test_tcp(self): + ct = PortRangeType.from_string("tcp") + self.assertEqual(ct, PortRangeType.TCP) + + def test_udp(self): + ct = PortRangeType.from_string("udp") + self.assertEqual(ct, PortRangeType.UDP) diff --git a/tests/protocols/gmpv226/enums/test_report_format_type.py b/tests/protocols/gmpv226/enums/test_report_format_type.py new file mode 100644 index 000000000..e0b135fe7 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_report_format_type.py @@ -0,0 +1,97 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import ReportFormatType + + +class GetPortRangeTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + ReportFormatType.from_string("foo") + + def test_none_or_empty(self): + ct = ReportFormatType.from_string(None) + self.assertIsNone(ct) + ct = ReportFormatType.from_string("") + self.assertIsNone(ct) + + def test_anonymous_pdf(self): + ct = ReportFormatType.from_string("anonymous xml") + self.assertEqual(ct, ReportFormatType.ANONYMOUS_XML) + + def test_arf(self): + ct = ReportFormatType.from_string("arf") + self.assertEqual(ct, ReportFormatType.ARF) + + def test_(self): + ct = ReportFormatType.from_string("cpe") + self.assertEqual(ct, ReportFormatType.CPE) + + def test_csv_hosts(self): + ct = ReportFormatType.from_string("csv hosts") + self.assertEqual(ct, ReportFormatType.CSV_HOSTS) + + def test_csv_results(self): + ct = ReportFormatType.from_string("csv results") + self.assertEqual(ct, ReportFormatType.CSV_RESULTS) + + def test_gcr_pdf(self): + ct = ReportFormatType.from_string("gcr pdf") + self.assertEqual(ct, ReportFormatType.GCR_PDF) + + def test_gsr_html(self): + ct = ReportFormatType.from_string("gsr html") + self.assertEqual(ct, ReportFormatType.GSR_HTML) + + def test_gsr_pdf(self): + ct = ReportFormatType.from_string("gsr pdf") + self.assertEqual(ct, ReportFormatType.GSR_PDF) + + def test_gxcr_pdf(self): + ct = ReportFormatType.from_string("gxcr pdf") + self.assertEqual(ct, ReportFormatType.GXCR_PDF) + + def test_gxr_pdf(self): + ct = ReportFormatType.from_string("gxr pdf") + self.assertEqual(ct, ReportFormatType.GXR_PDF) + + def test_itg(self): + ct = ReportFormatType.from_string("itg") + self.assertEqual(ct, ReportFormatType.ITG) + + def test_latex(self): + ct = ReportFormatType.from_string("latex") + self.assertEqual(ct, ReportFormatType.LATEX) + + def test_nbe(self): + ct = ReportFormatType.from_string("nbe") + self.assertEqual(ct, ReportFormatType.NBE) + + def test_pdf(self): + ct = ReportFormatType.from_string("pdf") + self.assertEqual(ct, ReportFormatType.PDF) + + def test_svg(self): + ct = ReportFormatType.from_string("svg") + self.assertEqual(ct, ReportFormatType.SVG) + + def test_txt(self): + ct = ReportFormatType.from_string("txt") + self.assertEqual(ct, ReportFormatType.TXT) + + def test_verinice_ism(self): + ct = ReportFormatType.from_string("verinice ism") + self.assertEqual(ct, ReportFormatType.VERINICE_ISM) + + def test_verinice_itg(self): + ct = ReportFormatType.from_string("verinice itg") + self.assertEqual(ct, ReportFormatType.VERINICE_ITG) + + def test_xml(self): + ct = ReportFormatType.from_string("xml") + self.assertEqual(ct, ReportFormatType.XML) diff --git a/tests/protocols/gmpv226/enums/test_resource_type.py b/tests/protocols/gmpv226/enums/test_resource_type.py new file mode 100644 index 000000000..121125c40 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_resource_type.py @@ -0,0 +1,133 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import ResourceType + + +class GetResourceTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + ResourceType.from_string("foo") + + def test_none_or_empty(self): + ct = ResourceType.from_string(None) + self.assertIsNone(ct) + ct = ResourceType.from_string("") + self.assertIsNone(ct) + + def test_alert(self): + ct = ResourceType.from_string("alert") + self.assertEqual(ct, ResourceType.ALERT) + + def test_cert_bund_adv(self): + ct = ResourceType.from_string("cert_bund_adv") + self.assertEqual(ct, ResourceType.CERT_BUND_ADV) + + def test_config(self): + ct = ResourceType.from_string("config") + self.assertEqual(ct, ResourceType.CONFIG) + + def test_cpe(self): + ct = ResourceType.from_string("cpe") + self.assertEqual(ct, ResourceType.CPE) + + def test_credential(self): + ct = ResourceType.from_string("credential") + self.assertEqual(ct, ResourceType.CREDENTIAL) + + def test_cve(self): + ct = ResourceType.from_string("cve") + self.assertEqual(ct, ResourceType.CVE) + + def test_dfn_cert_adv(self): + ct = ResourceType.from_string("dfn_cert_adv") + self.assertEqual(ct, ResourceType.DFN_CERT_ADV) + + def test_filter(self): + ct = ResourceType.from_string("filter") + self.assertEqual(ct, ResourceType.FILTER) + + def test_group(self): + ct = ResourceType.from_string("group") + self.assertEqual(ct, ResourceType.GROUP) + + def test_host(self): + ct = ResourceType.from_string("host") + self.assertEqual(ct, ResourceType.HOST) + + def test_note(self): + ct = ResourceType.from_string("note") + self.assertEqual(ct, ResourceType.NOTE) + + def test_nvt(self): + ct = ResourceType.from_string("nvt") + self.assertEqual(ct, ResourceType.NVT) + + def test_os(self): + ct = ResourceType.from_string("os") + self.assertEqual(ct, ResourceType.OS) + + def test_override(self): + ct = ResourceType.from_string("override") + self.assertEqual(ct, ResourceType.OVERRIDE) + + def test_permission(self): + ct = ResourceType.from_string("permission") + self.assertEqual(ct, ResourceType.PERMISSION) + + def test_port_list(self): + ct = ResourceType.from_string("port_list") + self.assertEqual(ct, ResourceType.PORT_LIST) + + def test_report_format(self): + ct = ResourceType.from_string("report_format") + self.assertEqual(ct, ResourceType.REPORT_FORMAT) + + def test_report(self): + ct = ResourceType.from_string("report") + self.assertEqual(ct, ResourceType.REPORT) + + def test_report_config(self): + ct = ResourceType.from_string("report_config") + self.assertEqual(ct, ResourceType.REPORT_CONFIG) + + def test_result(self): + ct = ResourceType.from_string("result") + self.assertEqual(ct, ResourceType.RESULT) + + def test_role(self): + ct = ResourceType.from_string("role") + self.assertEqual(ct, ResourceType.ROLE) + + def test_scanner(self): + ct = ResourceType.from_string("scanner") + self.assertEqual(ct, ResourceType.SCANNER) + + def test_schedule(self): + ct = ResourceType.from_string("schedule") + self.assertEqual(ct, ResourceType.SCHEDULE) + + def test_target(self): + ct = ResourceType.from_string("target") + self.assertEqual(ct, ResourceType.TARGET) + + def test_task(self): + ct = ResourceType.from_string("task") + self.assertEqual(ct, ResourceType.TASK) + + def test_tls_certificate(self): + ct = ResourceType.from_string("tls_certificate") + self.assertEqual(ct, ResourceType.TLS_CERTIFICATE) + + def test_user(self): + ct = ResourceType.from_string("user") + self.assertEqual(ct, ResourceType.USER) + + def test_allresources(self): + with self.assertRaises(InvalidArgument): + ResourceType.from_string("allresources") diff --git a/tests/protocols/gmpv226/enums/test_scanner_type.py b/tests/protocols/gmpv226/enums/test_scanner_type.py new file mode 100644 index 000000000..aee135b1d --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_scanner_type.py @@ -0,0 +1,49 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import ScannerType + + +class GetScannerTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + ScannerType.from_string("foo") + + def test_none_or_empty(self): + ct = ScannerType.from_string(None) + self.assertIsNone(ct) + ct = ScannerType.from_string("") + self.assertIsNone(ct) + + def test_openvas_scanner(self): + ct = ScannerType.from_string("2") + self.assertEqual(ct, ScannerType.OPENVAS_SCANNER_TYPE) + + ct = ScannerType.from_string("openvas") + self.assertEqual(ct, ScannerType.OPENVAS_SCANNER_TYPE) + + def test_cve_scanner(self): + ct = ScannerType.from_string("3") + self.assertEqual(ct, ScannerType.CVE_SCANNER_TYPE) + + ct = ScannerType.from_string("cve") + self.assertEqual(ct, ScannerType.CVE_SCANNER_TYPE) + + def test_gmp_scanner(self): + with self.assertRaises(InvalidArgument): + ScannerType.from_string("4") + + with self.assertRaises(InvalidArgument): + ScannerType.from_string("gmp") + + def test_greenbone_sensor_scanner(self): + ct = ScannerType.from_string("5") + self.assertEqual(ct, ScannerType.GREENBONE_SENSOR_SCANNER_TYPE) + + ct = ScannerType.from_string("greenbone") + self.assertEqual(ct, ScannerType.GREENBONE_SENSOR_SCANNER_TYPE) diff --git a/tests/protocols/gmpv226/enums/test_snmp_algorithms.py b/tests/protocols/gmpv226/enums/test_snmp_algorithms.py new file mode 100644 index 000000000..1aad8b4da --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_snmp_algorithms.py @@ -0,0 +1,52 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import ( + SnmpAuthAlgorithm, + SnmpPrivacyAlgorithm, +) + + +class GetSnmpAuthAlgorithmFromStringTestCase(unittest.TestCase): + def test_invalid_status(self): + with self.assertRaises(InvalidArgument): + SnmpAuthAlgorithm.from_string("foo") + + def test_none_or_empty_type(self): + ts = SnmpAuthAlgorithm.from_string(None) + self.assertIsNone(ts) + ts = SnmpAuthAlgorithm.from_string("") + self.assertIsNone(ts) + + def test_sha1(self): + ts = SnmpAuthAlgorithm.from_string("sha1") + self.assertEqual(ts, SnmpAuthAlgorithm.SHA1) + + def test_md5(self): + ts = SnmpAuthAlgorithm.from_string("md5") + self.assertEqual(ts, SnmpAuthAlgorithm.MD5) + + +class GetSnmpPrivacyAlgorithmFromStringTestCase(unittest.TestCase): + def test_invalid_status(self): + with self.assertRaises(InvalidArgument): + SnmpPrivacyAlgorithm.from_string("foo") + + def test_none_or_empty_type(self): + ts = SnmpPrivacyAlgorithm.from_string(None) + self.assertIsNone(ts) + ts = SnmpPrivacyAlgorithm.from_string("") + self.assertIsNone(ts) + + def test_aes(self): + ts = SnmpPrivacyAlgorithm.from_string("aes") + self.assertEqual(ts, SnmpPrivacyAlgorithm.AES) + + def test_des(self): + ts = SnmpPrivacyAlgorithm.from_string("des") + self.assertEqual(ts, SnmpPrivacyAlgorithm.DES) diff --git a/tests/protocols/gmpv226/enums/test_sort_order.py b/tests/protocols/gmpv226/enums/test_sort_order.py new file mode 100644 index 000000000..464788d0f --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_sort_order.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import SortOrder + + +class GetSortOrderFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + SortOrder.from_string("foo") + + def test_none_or_empty(self): + ct = SortOrder.from_string(None) + self.assertIsNone(ct) + ct = SortOrder.from_string("") + self.assertIsNone(ct) + + def test_ascending(self): + ct = SortOrder.from_string("ascending") + self.assertEqual(ct, SortOrder.ASCENDING) + + def test_descending(self): + ct = SortOrder.from_string("descending") + self.assertEqual(ct, SortOrder.DESCENDING) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/protocols/gmpv226/enums/test_ticket_status.py b/tests/protocols/gmpv226/enums/test_ticket_status.py new file mode 100644 index 000000000..cac6f68c3 --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_ticket_status.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import TicketStatus + + +class GetTicketStatusFromStringTestCase(unittest.TestCase): + def test_invalid_status(self): + with self.assertRaises(InvalidArgument): + TicketStatus.from_string("foo") + + def test_none_or_empty_type(self): + ts = TicketStatus.from_string(None) + self.assertIsNone(ts) + ts = TicketStatus.from_string("") + self.assertIsNone(ts) + + def test_ticket_status_open(self): + ts = TicketStatus.from_string("open") + self.assertEqual(ts, TicketStatus.OPEN) + + def test_ticket_status_fixed(self): + ts = TicketStatus.from_string("fixed") + self.assertEqual(ts, TicketStatus.FIXED) + + def test_ticket_status_closed(self): + ts = TicketStatus.from_string("closed") + self.assertEqual(ts, TicketStatus.CLOSED) diff --git a/tests/protocols/gmpv226/enums/test_user_auth_type.py b/tests/protocols/gmpv226/enums/test_user_auth_type.py new file mode 100644 index 000000000..cec6e7a5d --- /dev/null +++ b/tests/protocols/gmpv226/enums/test_user_auth_type.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmp.requests.v226 import UserAuthType + + +class GetUserAuthTypeFromStringTestCase(unittest.TestCase): + def test_invalid(self): + with self.assertRaises(InvalidArgument): + UserAuthType.from_string("foo") + + def test_none_or_empty(self): + ct = UserAuthType.from_string(None) + self.assertIsNone(ct) + ct = UserAuthType.from_string("") + self.assertIsNone(ct) + + def test_file(self): + ct = UserAuthType.from_string("file") + self.assertEqual(ct, UserAuthType.FILE) + + def test_radius_connect(self): + ct = UserAuthType.from_string("radius_connect") + self.assertEqual(ct, UserAuthType.RADIUS_CONNECT) + + def test_ldap_connect(self): + ct = UserAuthType.from_string("ldap_connect") + self.assertEqual(ct, UserAuthType.LDAP_CONNECT) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/protocols/gmpv226/system/__init__.py b/tests/protocols/gmpv226/system/__init__.py new file mode 100644 index 000000000..baae7654d --- /dev/null +++ b/tests/protocols/gmpv226/system/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# diff --git a/tests/protocols/gmpv226/system/test_aggregates.py b/tests/protocols/gmpv226/system/test_aggregates.py new file mode 100644 index 000000000..c9d1d6eee --- /dev/null +++ b/tests/protocols/gmpv226/system/test_aggregates.py @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.aggregates import GmpGetAggregatesTestMixin +from ...gmpv226 import GMPTestCase + + +class GMPGetAggregatesTestCase(GmpGetAggregatesTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/test_authentication.py b/tests/protocols/gmpv226/system/test_authentication.py new file mode 100644 index 000000000..955c73d00 --- /dev/null +++ b/tests/protocols/gmpv226/system/test_authentication.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.authentication import ( + GmpAuthenticateTestMixin, + GmpDescribeAuthTestMixin, + GmpModifyAuthTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPAuthenticateTestCase(GmpAuthenticateTestMixin, GMPTestCase): + pass + + +class GMPModifyAuthTestCase(GmpModifyAuthTestMixin, GMPTestCase): + pass + + +class GMPDescribeAuthCommandTestCase(GmpDescribeAuthTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/test_feed.py b/tests/protocols/gmpv226/system/test_feed.py new file mode 100644 index 000000000..b5564d1a1 --- /dev/null +++ b/tests/protocols/gmpv226/system/test_feed.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.feed import GmpGetFeedsTestMixin, GmpGetFeedTestMixin +from ...gmpv226 import GMPTestCase + + +class GMPGetFeedTestCase(GmpGetFeedTestMixin, GMPTestCase): + pass + + +class GMPGetFeedsTestCase(GmpGetFeedsTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/test_help.py b/tests/protocols/gmpv226/system/test_help.py new file mode 100644 index 000000000..25020eec4 --- /dev/null +++ b/tests/protocols/gmpv226/system/test_help.py @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.help import GmpHelpTestMixin +from ...gmpv226 import GMPTestCase + + +class GMPHelpTestCase(GmpHelpTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/test_system_reports.py b/tests/protocols/gmpv226/system/test_system_reports.py new file mode 100644 index 000000000..61c9cee05 --- /dev/null +++ b/tests/protocols/gmpv226/system/test_system_reports.py @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.system_reports import GmpGetSystemReportsTestMixin +from ...gmpv226 import GMPTestCase + + +class GMPGetSystemReportsTestCase(GmpGetSystemReportsTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/test_trashcan.py b/tests/protocols/gmpv226/system/test_trashcan.py new file mode 100644 index 000000000..0ca834a08 --- /dev/null +++ b/tests/protocols/gmpv226/system/test_trashcan.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.trashcan import ( + GmpEmptyTrashcanTestMixin, + GmpRestoreFromTrashcanTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPEmptyTrashcanTestCase(GmpEmptyTrashcanTestMixin, GMPTestCase): + pass + + +class GMPRestoreFromTrashcanTestCase( + GmpRestoreFromTrashcanTestMixin, GMPTestCase +): + pass diff --git a/tests/protocols/gmpv226/system/test_user_settings.py b/tests/protocols/gmpv226/system/test_user_settings.py new file mode 100644 index 000000000..c2af2170f --- /dev/null +++ b/tests/protocols/gmpv226/system/test_user_settings.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.user_settings import ( + GmpGetUserSettingsTestMixin, + GmpGetUserSettingTestMixin, + GmpModifyUserSettingTestMixin, +) +from ...gmpv226 import GMPTestCase + + +class GMPGetUserSettingTestCase(GmpGetUserSettingTestMixin, GMPTestCase): + pass + + +class GMPGetUserSettingsTestCase(GmpGetUserSettingsTestMixin, GMPTestCase): + pass + + +class GMPModifyUserSettingTestCase(GmpModifyUserSettingTestMixin, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/test_versions.py b/tests/protocols/gmpv226/system/test_versions.py new file mode 100644 index 000000000..26e58aaa7 --- /dev/null +++ b/tests/protocols/gmpv226/system/test_versions.py @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv224.system.versions import GmpGetVersionTestCase +from ...gmpv226 import GMPTestCase +from .versions import GmpGetProtocolVersionTestCase + + +class GMPGetVersionCommandTestCase(GmpGetVersionTestCase, GMPTestCase): + pass + + +class GMPGetProtocolVersionTestCase(GmpGetProtocolVersionTestCase, GMPTestCase): + pass diff --git a/tests/protocols/gmpv226/system/versions/__init__.py b/tests/protocols/gmpv226/system/versions/__init__.py new file mode 100644 index 000000000..a9d0bff86 --- /dev/null +++ b/tests/protocols/gmpv226/system/versions/__init__.py @@ -0,0 +1,8 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from .test_get_protocol_version import GmpGetProtocolVersionTestCase + +__all__ = ("GmpGetProtocolVersionTestCase",) diff --git a/tests/protocols/gmpv226/system/versions/test_get_protocol_version.py b/tests/protocols/gmpv226/system/versions/test_get_protocol_version.py new file mode 100644 index 000000000..9b663008b --- /dev/null +++ b/tests/protocols/gmpv226/system/versions/test_get_protocol_version.py @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +class GmpGetProtocolVersionTestCase: + def test_protocol_version(self): + self.assertEqual(self.gmp.get_protocol_version(), (22, 6)) diff --git a/tests/protocols/gmpv226/test_gmp_types.py b/tests/protocols/gmpv226/test_gmp_types.py new file mode 100644 index 000000000..739dde102 --- /dev/null +++ b/tests/protocols/gmpv226/test_gmp_types.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.protocols.gmp.requests.v225 import HostsOrdering + +from . import GMPTestCase + + +class GmpWithStatementTestCase(GMPTestCase): + def test_types(self): + with self.gmp: + # Test that the values are equal + self.assertEqual( + self.gmp.types.AlertEvent.TASK_RUN_STATUS_CHANGED.value, + "Task run status changed", + ) + self.assertEqual( + self.gmp.types.PermissionSubjectType.USER.value, "user" + ) + self.assertEqual( + self.gmp.types.HostsOrdering.RANDOM.value, "random" + ) + + # Test usability of from_string + self.assertEqual( + self.gmp.types.HostsOrdering.from_string("reverse"), + self.gmp.types.HostsOrdering.REVERSE, + ) + + # Test, that the Enum class types are equal + self.assertEqual(self.gmp.types.HostsOrdering, HostsOrdering) diff --git a/tests/protocols/gmpv226/test_with_statement.py b/tests/protocols/gmpv226/test_with_statement.py new file mode 100644 index 000000000..80b4d8d32 --- /dev/null +++ b/tests/protocols/gmpv226/test_with_statement.py @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from . import GMPTestCase + + +class GMPWithStatementTestCase(GMPTestCase): + def test_with_statement(self): + self.connection.connect.has_not_been_called() + self.connection.disconnect.has_not_been_called() + + with self.gmp: + pass + + self.connection.connect.has_been_called() + self.connection.disconnect.has_been_called() diff --git a/tests/protocols/test_latest.py b/tests/protocols/test_latest.py index c8ae605f6..3e7a6e93f 100644 --- a/tests/protocols/test_latest.py +++ b/tests/protocols/test_latest.py @@ -12,7 +12,7 @@ class LatestProtocolsTestCase(unittest.TestCase): def test_gmp_version(self): - self.assertEqual(Gmp.get_protocol_version(), (22, 5)) + self.assertEqual(Gmp.get_protocol_version(), (22, 6)) def test_osp_version(self): self.assertEqual(Osp.get_protocol_version(), (1, 2)) diff --git a/tests/protocols/test_next.py b/tests/protocols/test_next.py index 1e5514f7f..496f14137 100644 --- a/tests/protocols/test_next.py +++ b/tests/protocols/test_next.py @@ -12,7 +12,7 @@ class LatestProtocolsTestCase(unittest.TestCase): def test_gmp_version(self): - self.assertEqual(Gmp.get_protocol_version(), (22, 5)) + self.assertEqual(Gmp.get_protocol_version(), (22, 6)) def test_osp_version(self): self.assertEqual(Osp.get_protocol_version(), (1, 2)) From 30c232be152b478007a3da089bcec40f4fad469e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 28 Jan 2025 10:49:24 +0100 Subject: [PATCH 2/6] Implement the new filter types audit report and report config Support both new filter types. --- gvm/protocols/gmp/_gmp226.py | 60 ++++- gvm/protocols/gmp/requests/v226/__init__.py | 5 +- gvm/protocols/gmp/requests/v226/_filters.py | 248 ++++++++++++++++++ .../gmp/requests/v226/test_filter_type.py | 110 ++++++++ .../gmp/requests/v226/test_filters.py | 247 +++++++++++++++++ .../gmpv226/enums/test_filter_type.py | 10 +- 6 files changed, 675 insertions(+), 5 deletions(-) create mode 100644 gvm/protocols/gmp/requests/v226/_filters.py create mode 100644 tests/protocols/gmp/requests/v226/test_filter_type.py create mode 100644 tests/protocols/gmp/requests/v226/test_filters.py diff --git a/gvm/protocols/gmp/_gmp226.py b/gvm/protocols/gmp/_gmp226.py index 5ffe7ed26..91554c694 100644 --- a/gvm/protocols/gmp/_gmp226.py +++ b/gvm/protocols/gmp/_gmp226.py @@ -13,6 +13,8 @@ from .requests.v226 import ( AuditReports, EntityID, + Filters, + FilterType, ReportFormatType, Reports, ResourceNames, @@ -81,7 +83,9 @@ def get_resource_names( ) def get_resource_name( - self, resource_id: str, resource_type: ResourceType # type: ignore[override] + self, + resource_id: str, + resource_type: ResourceType, # type: ignore[override] ) -> T: """Request a single resource name @@ -276,3 +280,57 @@ def get_audit_reports( details=details, ) ) + + def create_filter( + self, + name: str, + *, + filter_type: Optional[FilterType] = None, # type: ignore[override] + comment: Optional[str] = None, + term: Optional[str] = None, + ) -> T: + """Create a new filter + + Args: + name: Name of the new filter + filter_type: Filter for entity type + comment: Comment for the filter + term: Filter term e.g. 'name=foo' + """ + # override create_filter because of the different FilterType enum + # this avoids warnings with type checkers + return self._send_and_transform_command( + Filters.create_filter( + name, filter_type=filter_type, comment=comment, term=term + ) + ) + + def modify_filter( + self, + filter_id: EntityID, + *, + comment: Optional[str] = None, + name: Optional[str] = None, + term: Optional[str] = None, + filter_type: Optional[FilterType] = None, # type: ignore[override] + ) -> T: + """Modifies an existing filter. + + Args: + filter_id: UUID of the filter to be modified + comment: Comment on filter. + name: Name of filter. + term: Filter term. + filter_type: Resource type filter applies to. + """ + # override create_filter because of the different FilterType enum + # this avoids warnings with type checkers + return self._send_and_transform_command( + Filters.modify_filter( + filter_id, + comment=comment, + name=name, + term=term, + filter_type=filter_type, + ) + ) diff --git a/gvm/protocols/gmp/requests/v226/__init__.py b/gvm/protocols/gmp/requests/v226/__init__.py index 0031e8bfe..514584418 100644 --- a/gvm/protocols/gmp/requests/v226/__init__.py +++ b/gvm/protocols/gmp/requests/v226/__init__.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2018-2025 Greenbone AG +# SPDX-FileCopyrightText: 2025 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -28,8 +28,6 @@ EntityType, Feed, FeedType, - Filters, - FilterType, Groups, Help, HelpFormat, @@ -72,6 +70,7 @@ Vulnerabilities, ) from ._audit_reports import AuditReports +from ._filters import Filters, FilterType from ._reports import Reports from ._resource_names import ResourceNames, ResourceType diff --git a/gvm/protocols/gmp/requests/v226/_filters.py b/gvm/protocols/gmp/requests/v226/_filters.py new file mode 100644 index 000000000..3663d98a0 --- /dev/null +++ b/gvm/protocols/gmp/requests/v226/_filters.py @@ -0,0 +1,248 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from typing import Optional + +from gvm._enum import Enum +from gvm.errors import RequiredArgument +from gvm.protocols.core import Request +from gvm.utils import to_bool +from gvm.xml import XmlCommand + +from .._entity_id import EntityID + +__all__ = ( + "Filters", + "FilterType", +) + + +class FilterType(Enum): + """Enum for filter types""" + + ALERT = "alert" + ALL_SECINFO = "secinfo" + ASSET = "asset" + AUDIT_REPORT = "audit_report" + CREDENTIAL = "credential" + FILTER = "filter" + GROUP = "group" + HOST = "host" + NOTE = "note" + OPERATING_SYSTEM = "os" + OVERRIDE = "override" + PERMISSION = "permission" + PORT_LIST = "port_list" + REPORT = "report" + REPORT_CONFIG = "report_config" + REPORT_FORMAT = "report_format" + RESULT = "result" + ROLE = "role" + SCAN_CONFIG = "config" + SCHEDULE = "schedule" + TAG = "tag" + TARGET = "target" + TASK = "task" + TICKET = "ticket" + TLS_CERTIFICATE = "tls_certificate" + USER = "user" + VULNERABILITY = "vuln" + + @classmethod + def from_string( + cls, + filter_type: Optional[str], + ) -> Optional["FilterType"]: + """Convert a filter type string to an actual FilterType instance + + Args: + filter_type (str): Filter type string to convert to a FilterType + """ + if filter_type == "vuln": + return cls.VULNERABILITY + + if filter_type == "os": + return cls.OPERATING_SYSTEM + + if filter_type == "config": + return cls.SCAN_CONFIG + + if filter_type == "secinfo": + return cls.ALL_SECINFO + + return super().from_string(filter_type) + + +class Filters: + @classmethod + def clone_filter(cls, filter_id: EntityID) -> Request: + """Clone a filter + + Args: + filter_id: ID of the filter to clone + """ + if not filter_id: + raise RequiredArgument( + function=cls.clone_filter.__name__, argument="filter_id" + ) + + cmd = XmlCommand("create_filter") + cmd.add_element("copy", str(filter_id)) + return cmd + + @classmethod + def create_filter( + cls, + name: str, + *, + filter_type: Optional[FilterType] = None, + comment: Optional[str] = None, + term: Optional[str] = None, + ) -> Request: + """Create a new filter + + Args: + name: Name of the new filter + filter_type: Filter for entity type + comment: Comment for the filter + term: Filter term e.g. 'name=foo' + """ + if not name: + raise RequiredArgument( + function=cls.create_filter.__name__, argument="name" + ) + + cmd = XmlCommand("create_filter") + cmd.add_element("name", name) + + if comment: + cmd.add_element("comment", comment) + + if term: + cmd.add_element("term", term) + + if filter_type: + if not isinstance(filter_type, FilterType): + filter_type = FilterType(filter_type) + + cmd.add_element("type", filter_type.value) + + return cmd + + @classmethod + def delete_filter( + cls, filter_id: EntityID, *, ultimate: Optional[bool] = False + ) -> Request: + """Deletes an existing filter + + Args: + filter_id: UUID of the filter to be deleted. + ultimate: Whether to remove entirely, or to the trashcan. + """ + if not filter_id: + raise RequiredArgument( + function=cls.delete_filter.__name__, argument="filter_id" + ) + + cmd = XmlCommand("delete_filter") + cmd.set_attribute("filter_id", str(filter_id)) + cmd.set_attribute("ultimate", to_bool(ultimate)) + + return cmd + + @staticmethod + def get_filters( + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + trash: Optional[bool] = None, + alerts: Optional[bool] = None, + ) -> Request: + """Request a list of filters + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + trash: Whether to get the trashcan filters instead + alerts: Whether to include list of alerts that use the filter. + """ + cmd = XmlCommand("get_filters") + + cmd.add_filter(filter_string, filter_id) + + if trash is not None: + cmd.set_attribute("trash", to_bool(trash)) + + if alerts is not None: + cmd.set_attribute("alerts", to_bool(alerts)) + + return cmd + + @classmethod + def get_filter( + cls, filter_id: EntityID, *, alerts: Optional[bool] = None + ) -> Request: + """Request a single filter + + Args: + filter_id: UUID of an existing filter + alerts: Whether to include list of alerts that use the filter. + """ + cmd = XmlCommand("get_filters") + + if not filter_id: + raise RequiredArgument( + function=cls.get_filter.__name__, argument="filter_id" + ) + + cmd.set_attribute("filter_id", str(filter_id)) + + if alerts is not None: + cmd.set_attribute("alerts", to_bool(alerts)) + + return cmd + + @classmethod + def modify_filter( + cls, + filter_id: EntityID, + *, + comment: Optional[str] = None, + name: Optional[str] = None, + term: Optional[str] = None, + filter_type: Optional[FilterType] = None, + ) -> Request: + """Modifies an existing filter. + + Args: + filter_id: UUID of the filter to be modified + comment: Comment on filter. + name: Name of filter. + term: Filter term. + filter_type: Resource type filter applies to. + """ + if not filter_id: + raise RequiredArgument( + function=cls.modify_filter.__name__, argument="filter_id" + ) + + cmd = XmlCommand("modify_filter") + cmd.set_attribute("filter_id", str(filter_id)) + + if comment: + cmd.add_element("comment", comment) + + if name: + cmd.add_element("name", name) + + if term: + cmd.add_element("term", term) + + if filter_type: + if not isinstance(filter_type, FilterType): + filter_type = FilterType(filter_type) + + cmd.add_element("type", filter_type.value) + + return cmd diff --git a/tests/protocols/gmp/requests/v226/test_filter_type.py b/tests/protocols/gmp/requests/v226/test_filter_type.py new file mode 100644 index 000000000..29a47162c --- /dev/null +++ b/tests/protocols/gmp/requests/v226/test_filter_type.py @@ -0,0 +1,110 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import unittest + +from gvm.protocols.gmp.requests.v226 import FilterType + + +class FilterTypeTestsCase(unittest.TestCase): + def test_filter_type_all_secinfo(self): + self.assertEqual(FilterType.ALL_SECINFO.value, "secinfo") + + def test_filter_type_alert(self): + self.assertEqual(FilterType.ALERT.value, "alert") + + def test_filter_type_audit_report(self): + self.assertEqual(FilterType.AUDIT_REPORT.value, "audit_report") + + def test_filter_type_asset(self): + self.assertEqual(FilterType.ASSET.value, "asset") + + def test_filter_type_credential(self): + self.assertEqual(FilterType.CREDENTIAL.value, "credential") + + def test_filter_type_filter(self): + self.assertEqual(FilterType.FILTER.value, "filter") + + def test_filter_type_group(self): + self.assertEqual(FilterType.GROUP.value, "group") + + def test_filter_type_host(self): + self.assertEqual(FilterType.HOST.value, "host") + + def test_filter_type_note(self): + self.assertEqual(FilterType.NOTE.value, "note") + + def test_filter_type_operating_system(self): + self.assertEqual(FilterType.OPERATING_SYSTEM.value, "os") + + def test_filter_type_override(self): + self.assertEqual(FilterType.OVERRIDE.value, "override") + + def test_filter_type_permission(self): + self.assertEqual(FilterType.PERMISSION.value, "permission") + + def test_filter_type_port_list(self): + self.assertEqual(FilterType.PORT_LIST.value, "port_list") + + def test_filter_type_report(self): + self.assertEqual(FilterType.REPORT.value, "report") + + def test_filter_type_report_config(self): + self.assertEqual(FilterType.REPORT_CONFIG.value, "report_config") + + def test_filter_type_report_format(self): + self.assertEqual(FilterType.REPORT_FORMAT.value, "report_format") + + def test_filter_type_result(self): + self.assertEqual(FilterType.RESULT.value, "result") + + def test_filter_type_role(self): + self.assertEqual(FilterType.ROLE.value, "role") + + def test_filter_type_scan_config(self): + self.assertEqual(FilterType.SCAN_CONFIG.value, "config") + + def test_filter_type_schedule(self): + self.assertEqual(FilterType.SCHEDULE.value, "schedule") + + def test_filter_type_tag(self): + self.assertEqual(FilterType.TAG.value, "tag") + + def test_filter_type_target(self): + self.assertEqual(FilterType.TARGET.value, "target") + + def test_filter_type_task(self): + self.assertEqual(FilterType.TASK.value, "task") + + def test_filter_type_ticket(self): + self.assertEqual(FilterType.TICKET.value, "ticket") + + def test_filter_type_tls_certificate(self): + self.assertEqual(FilterType.TLS_CERTIFICATE.value, "tls_certificate") + + def test_filter_type_user(self): + self.assertEqual(FilterType.USER.value, "user") + + def test_filter_type_vulnerability(self): + self.assertEqual(FilterType.VULNERABILITY.value, "vuln") + + def test_filter_type_from_string_vuln(self): + self.assertEqual( + FilterType.from_string("vuln"), FilterType.VULNERABILITY + ) + + def test_filter_type_from_string_os(self): + self.assertEqual( + FilterType.from_string("os"), FilterType.OPERATING_SYSTEM + ) + + def test_filter_type_from_string_config(self): + self.assertEqual( + FilterType.from_string("config"), FilterType.SCAN_CONFIG + ) + + def test_filter_type_from_string_secinfo(self): + self.assertEqual( + FilterType.from_string("secinfo"), FilterType.ALL_SECINFO + ) diff --git a/tests/protocols/gmp/requests/v226/test_filters.py b/tests/protocols/gmp/requests/v226/test_filters.py new file mode 100644 index 000000000..7856065ef --- /dev/null +++ b/tests/protocols/gmp/requests/v226/test_filters.py @@ -0,0 +1,247 @@ +# 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.v226 import Filters, FilterType + + +class FilterTestsCase(unittest.TestCase): + def test_clone_filter(self): + request = Filters.clone_filter("filter_id") + self.assertEqual( + bytes(request), + b"filter_id", + ) + + def test_clone_filter_missing_filter_id(self): + with self.assertRaises(RequiredArgument): + Filters.clone_filter(None) + + with self.assertRaises(RequiredArgument): + Filters.clone_filter("") + + def test_create_filter(self): + request = Filters.create_filter("filter_name") + self.assertEqual( + bytes(request), + b"filter_name", + ) + + def test_create_filter_with_comment(self): + request = Filters.create_filter("filter_name", comment="comment") + self.assertEqual( + bytes(request), + b"" + b"filter_name" + b"comment" + b"", + ) + + def test_create_filter_with_term(self): + request = Filters.create_filter("filter_name", term="term") + self.assertEqual( + bytes(request), + b"" + b"filter_name" + b"term" + b"", + ) + + def test_create_filter_with_filter_type(self): + request = Filters.create_filter( + "filter_name", filter_type=FilterType.ALERT + ) + self.assertEqual( + bytes(request), + b"" + b"filter_name" + b"alert" + b"", + ) + + request = Filters.create_filter( + "filter_name", + filter_type="alert", + ) + self.assertEqual( + bytes(request), + b"" + b"filter_name" + b"alert" + b"", + ) + + def test_create_filter_invalid_filter_type(self): + with self.assertRaises(InvalidArgument): + Filters.create_filter("filter_name", filter_type="invalid") + + def test_create_filter_missing_name(self): + with self.assertRaises(RequiredArgument): + Filters.create_filter(None) + + with self.assertRaises(RequiredArgument): + Filters.create_filter("") + + def test_delete_filter(self): + request = Filters.delete_filter("filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_delete_filter_with_ultimate(self): + request = Filters.delete_filter("filter_id", ultimate=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Filters.delete_filter("filter_id", ultimate=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_delete_filter_missing_filter_id(self): + with self.assertRaises(RequiredArgument): + Filters.delete_filter(None) + + with self.assertRaises(RequiredArgument): + Filters.delete_filter("") + + def test_get_filters(self): + request = Filters.get_filters() + self.assertEqual( + bytes(request), + b"", + ) + + def test_get_filters_with_filter_string(self): + request = Filters.get_filters(filter_string="filter_string") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_filters_with_filter_id(self): + request = Filters.get_filters(filter_id="filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_filters_with_trash(self): + request = Filters.get_filters(trash=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Filters.get_filters(trash=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_filters_with_alerts(self): + request = Filters.get_filters(alerts=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Filters.get_filters(alerts=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_filter(self): + request = Filters.get_filter("filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_filter_with_alerts(self): + request = Filters.get_filter("filter_id", alerts=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = Filters.get_filter("filter_id", alerts=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_filter_missing_filter_id(self): + with self.assertRaises(RequiredArgument): + Filters.get_filter(None) + + with self.assertRaises(RequiredArgument): + Filters.get_filter("") + + def test_modify_filter(self): + request = Filters.modify_filter("filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_modify_filter_with_comment(self): + request = Filters.modify_filter("filter_id", comment="comment") + self.assertEqual( + bytes(request), + b'' + b"comment" + b"", + ) + + def test_modify_filter_with_name(self): + request = Filters.modify_filter("filter_id", name="name") + self.assertEqual( + bytes(request), + b'' + b"name" + b"", + ) + + def test_modify_filter_with_term(self): + request = Filters.modify_filter("filter_id", term="term") + self.assertEqual( + bytes(request), + b'' + b"term" + b"", + ) + + def test_modify_filter_with_type(self): + request = Filters.modify_filter( + "filter_id", filter_type=FilterType.ALERT + ) + self.assertEqual( + bytes(request), + b'' + b"alert" + b"", + ) + + request = Filters.modify_filter("filter_id", filter_type="alert") + self.assertEqual( + bytes(request), + b'' + b"alert" + b"", + ) + + def test_modify_filter_missing_filter_id(self): + with self.assertRaises(RequiredArgument): + Filters.modify_filter(None) + + with self.assertRaises(RequiredArgument): + Filters.modify_filter("") diff --git a/tests/protocols/gmpv226/enums/test_filter_type.py b/tests/protocols/gmpv226/enums/test_filter_type.py index 62490bc7d..3abe1262a 100644 --- a/tests/protocols/gmpv226/enums/test_filter_type.py +++ b/tests/protocols/gmpv226/enums/test_filter_type.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# SPDX-FileCopyrightText: 2025 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -126,6 +126,14 @@ def test_filter_type_os(self): ft = FilterType.from_string("os") self.assertEqual(ft, FilterType.OPERATING_SYSTEM) + def test_filter_type_report_config(self): + ft = FilterType.from_string("report_config") + self.assertEqual(ft, FilterType.REPORT_CONFIG) + + def test_filter_type_audit_report(self): + ft = FilterType.from_string("audit_report") + self.assertEqual(ft, FilterType.AUDIT_REPORT) + def test_invalid_filter_type(self): with self.assertRaises(InvalidArgument): FilterType.from_string("foo") From 8fe9f0eb038d867f133fbcf101b84947696d20d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 28 Jan 2025 11:00:30 +0100 Subject: [PATCH 3/6] Rename Gmpv225TestCase to GMPTestCase The version is already encoded into the module name. For implementing a new protocol version it's easier when the version in not included in all test class names. --- tests/protocols/gmpv225/__init__.py | 2 +- .../protocols/gmpv225/entities/test_alerts.py | 18 +++++----- .../protocols/gmpv225/entities/test_audits.py | 20 +++++------ .../gmpv225/entities/test_credentials.py | 18 ++++------ .../gmpv225/entities/test_filters.py | 14 ++++---- .../protocols/gmpv225/entities/test_groups.py | 14 ++++---- .../protocols/gmpv225/entities/test_hosts.py | 12 +++---- .../protocols/gmpv225/entities/test_notes.py | 14 ++++---- .../entities/test_operating_systems.py | 10 +++--- .../gmpv225/entities/test_overrides.py | 20 ++++------- .../gmpv225/entities/test_permissions.py | 18 ++++------ .../gmpv225/entities/test_policies.py | 26 +++++++------- .../gmpv225/entities/test_port_lists.py | 26 +++++--------- .../gmpv225/entities/test_report_formats.py | 18 +++++----- .../gmpv225/entities/test_reports.py | 10 +++--- .../gmpv225/entities/test_resource_names.py | 8 ++--- .../gmpv225/entities/test_results.py | 6 ++-- .../protocols/gmpv225/entities/test_roles.py | 14 ++++---- .../gmpv225/entities/test_scan_configs.py | 30 +++++++--------- .../gmpv225/entities/test_scanners.py | 14 ++++---- .../gmpv225/entities/test_schedules.py | 20 ++++------- .../gmpv225/entities/test_secinfo.py | 36 +++++++++---------- tests/protocols/gmpv225/entities/test_tags.py | 14 ++++---- .../gmpv225/entities/test_targets.py | 14 ++++---- .../protocols/gmpv225/entities/test_tasks.py | 24 ++++++------- .../gmpv225/entities/test_tickets.py | 14 ++++---- .../gmpv225/entities/test_tls_certificates.py | 14 ++++---- .../protocols/gmpv225/entities/test_users.py | 14 ++++---- .../gmpv225/entities/test_vulnerabilities.py | 6 ++-- .../gmpv225/system/test_aggregates.py | 4 +-- .../gmpv225/system/test_authentication.py | 10 +++--- tests/protocols/gmpv225/system/test_feed.py | 6 ++-- tests/protocols/gmpv225/system/test_help.py | 4 +-- .../gmpv225/system/test_system_reports.py | 4 +-- .../protocols/gmpv225/system/test_trashcan.py | 6 ++-- .../gmpv225/system/test_user_settings.py | 12 +++---- .../protocols/gmpv225/system/test_versions.py | 6 ++-- tests/protocols/gmpv225/test_gmp_types.py | 4 +-- .../protocols/gmpv225/test_with_statement.py | 4 +-- 39 files changed, 241 insertions(+), 287 deletions(-) diff --git a/tests/protocols/gmpv225/__init__.py b/tests/protocols/gmpv225/__init__.py index 78f43d4df..8946dae7d 100644 --- a/tests/protocols/gmpv225/__init__.py +++ b/tests/protocols/gmpv225/__init__.py @@ -9,5 +9,5 @@ from .. import GmpTestCase -class Gmpv225TestCase(GmpTestCase): +class GMPTestCase(GmpTestCase): gmp_class = GMPv225 diff --git a/tests/protocols/gmpv225/entities/test_alerts.py b/tests/protocols/gmpv225/entities/test_alerts.py index 65af4096c..43d4d89b9 100644 --- a/tests/protocols/gmpv225/entities/test_alerts.py +++ b/tests/protocols/gmpv225/entities/test_alerts.py @@ -13,36 +13,36 @@ GmpTestAlertTestMixin, GmpTriggerAlertTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneAlertTestCase(GmpCloneAlertTestMixin, Gmpv225TestCase): +class Gmpv225CloneAlertTestCase(GmpCloneAlertTestMixin, GMPTestCase): pass -class Gmpv225CreateAlertTestCase(GmpCreateAlertTestMixin, Gmpv225TestCase): +class Gmpv225CreateAlertTestCase(GmpCreateAlertTestMixin, GMPTestCase): pass -class Gmpv225DeleteAlertTestCase(GmpDeleteAlertTestMixin, Gmpv225TestCase): +class Gmpv225DeleteAlertTestCase(GmpDeleteAlertTestMixin, GMPTestCase): pass -class Gmpv225GetAlertTestCase(GmpGetAlertTestMixin, Gmpv225TestCase): +class Gmpv225GetAlertTestCase(GmpGetAlertTestMixin, GMPTestCase): pass -class Gmpv225GetAlertsTestCase(GmpGetAlertsTestMixin, Gmpv225TestCase): +class Gmpv225GetAlertsTestCase(GmpGetAlertsTestMixin, GMPTestCase): pass -class Gmpv225ModifyAlertTestCase(GmpModifyAlertTestMixin, Gmpv225TestCase): +class Gmpv225ModifyAlertTestCase(GmpModifyAlertTestMixin, GMPTestCase): pass -class Gmpv225TestAlertTestCase(GmpTestAlertTestMixin, Gmpv225TestCase): +class Gmpv225TestAlertTestCase(GmpTestAlertTestMixin, GMPTestCase): pass -class Gmpv225TriggerAlertTestCase(GmpTriggerAlertTestMixin, Gmpv225TestCase): +class Gmpv225TriggerAlertTestCase(GmpTriggerAlertTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_audits.py b/tests/protocols/gmpv225/entities/test_audits.py index 3c994a9b2..9b787849e 100644 --- a/tests/protocols/gmpv225/entities/test_audits.py +++ b/tests/protocols/gmpv225/entities/test_audits.py @@ -14,40 +14,40 @@ GmpStartAuditTestMixin, GmpStopAuditTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneAuditTestCase(GmpCloneAuditTestMixin, Gmpv225TestCase): +class Gmpv225CloneAuditTestCase(GmpCloneAuditTestMixin, GMPTestCase): pass -class Gmpv225CreateAuditTestCase(GmpCreateAuditTestMixin, Gmpv225TestCase): +class Gmpv225CreateAuditTestCase(GmpCreateAuditTestMixin, GMPTestCase): pass -class Gmpv225DeleteAuditTestCase(GmpDeleteAuditTestMixin, Gmpv225TestCase): +class Gmpv225DeleteAuditTestCase(GmpDeleteAuditTestMixin, GMPTestCase): pass -class Gmpv225GetAuditTestCase(GmpGetAuditTestMixin, Gmpv225TestCase): +class Gmpv225GetAuditTestCase(GmpGetAuditTestMixin, GMPTestCase): pass -class Gmpv225GetAuditsTestCase(GmpGetAuditsTestMixin, Gmpv225TestCase): +class Gmpv225GetAuditsTestCase(GmpGetAuditsTestMixin, GMPTestCase): pass -class Gmpv225ModifyAuditTestCase(GmpModifyAuditTestMixin, Gmpv225TestCase): +class Gmpv225ModifyAuditTestCase(GmpModifyAuditTestMixin, GMPTestCase): pass -class Gmpv225ResumeAuditTestCase(GmpResumeAuditTestMixin, Gmpv225TestCase): +class Gmpv225ResumeAuditTestCase(GmpResumeAuditTestMixin, GMPTestCase): pass -class Gmpv225StartAuditTestCase(GmpStartAuditTestMixin, Gmpv225TestCase): +class Gmpv225StartAuditTestCase(GmpStartAuditTestMixin, GMPTestCase): pass -class Gmpv225StopAuditTestCase(GmpStopAuditTestMixin, Gmpv225TestCase): +class Gmpv225StopAuditTestCase(GmpStopAuditTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_credentials.py b/tests/protocols/gmpv225/entities/test_credentials.py index 67b02b897..1c73b5eda 100644 --- a/tests/protocols/gmpv225/entities/test_credentials.py +++ b/tests/protocols/gmpv225/entities/test_credentials.py @@ -11,38 +11,34 @@ GmpGetCredentialTestMixin, GmpModifyCredentialTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneCredentialTestCase( - GmpCloneCredentialTestMixin, Gmpv225TestCase -): +class Gmpv225CloneCredentialTestCase(GmpCloneCredentialTestMixin, GMPTestCase): pass class Gmpv225CreateCredentialTestCase( - GmpCreateCredentialTestMixin, Gmpv225TestCase + GmpCreateCredentialTestMixin, GMPTestCase ): pass class Gmpv225DeleteCredentialTestCase( - GmpDeleteCredentialTestMixin, Gmpv225TestCase + GmpDeleteCredentialTestMixin, GMPTestCase ): pass -class Gmpv225GetCredentialTestCase(GmpGetCredentialTestMixin, Gmpv225TestCase): +class Gmpv225GetCredentialTestCase(GmpGetCredentialTestMixin, GMPTestCase): pass -class Gmpv225GetCredentialsTestCase( - GmpGetCredentialsTestMixin, Gmpv225TestCase -): +class Gmpv225GetCredentialsTestCase(GmpGetCredentialsTestMixin, GMPTestCase): pass class Gmpv225ModifyCredentialTestCase( - GmpModifyCredentialTestMixin, Gmpv225TestCase + GmpModifyCredentialTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_filters.py b/tests/protocols/gmpv225/entities/test_filters.py index 6f1e7a7db..f54957d40 100644 --- a/tests/protocols/gmpv225/entities/test_filters.py +++ b/tests/protocols/gmpv225/entities/test_filters.py @@ -11,28 +11,28 @@ GmpGetFilterTestMixin, GmpModifyFilterTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteFilterTestCase(GmpDeleteFilterTestMixin, Gmpv225TestCase): +class Gmpv225DeleteFilterTestCase(GmpDeleteFilterTestMixin, GMPTestCase): pass -class Gmpv225GetFilterTestCase(GmpGetFilterTestMixin, Gmpv225TestCase): +class Gmpv225GetFilterTestCase(GmpGetFilterTestMixin, GMPTestCase): pass -class Gmpv225GetFiltersTestCase(GmpGetFiltersTestMixin, Gmpv225TestCase): +class Gmpv225GetFiltersTestCase(GmpGetFiltersTestMixin, GMPTestCase): pass -class Gmpv225CloneFilterTestCase(GmpCloneFilterTestMixin, Gmpv225TestCase): +class Gmpv225CloneFilterTestCase(GmpCloneFilterTestMixin, GMPTestCase): pass -class Gmpv225CreateFilterTestCase(GmpCreateFilterTestMixin, Gmpv225TestCase): +class Gmpv225CreateFilterTestCase(GmpCreateFilterTestMixin, GMPTestCase): pass -class Gmpv225ModifyFilterTestCase(GmpModifyFilterTestMixin, Gmpv225TestCase): +class Gmpv225ModifyFilterTestCase(GmpModifyFilterTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_groups.py b/tests/protocols/gmpv225/entities/test_groups.py index 0dadc6a31..6bc12d40f 100644 --- a/tests/protocols/gmpv225/entities/test_groups.py +++ b/tests/protocols/gmpv225/entities/test_groups.py @@ -11,28 +11,28 @@ GmpGetGroupTestMixin, GmpModifyGroupTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteGroupTestCase(GmpDeleteGroupTestMixin, Gmpv225TestCase): +class Gmpv225DeleteGroupTestCase(GmpDeleteGroupTestMixin, GMPTestCase): pass -class Gmpv225GetGroupTestCase(GmpGetGroupTestMixin, Gmpv225TestCase): +class Gmpv225GetGroupTestCase(GmpGetGroupTestMixin, GMPTestCase): pass -class Gmpv225GetGroupsTestCase(GmpGetGroupsTestMixin, Gmpv225TestCase): +class Gmpv225GetGroupsTestCase(GmpGetGroupsTestMixin, GMPTestCase): pass -class Gmpv225CloneGroupTestCase(GmpCloneGroupTestMixin, Gmpv225TestCase): +class Gmpv225CloneGroupTestCase(GmpCloneGroupTestMixin, GMPTestCase): pass -class Gmpv225CreateGroupTestCase(GmpCreateGroupTestMixin, Gmpv225TestCase): +class Gmpv225CreateGroupTestCase(GmpCreateGroupTestMixin, GMPTestCase): pass -class Gmpv225ModifyGroupTestCase(GmpModifyGroupTestMixin, Gmpv225TestCase): +class Gmpv225ModifyGroupTestCase(GmpModifyGroupTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_hosts.py b/tests/protocols/gmpv225/entities/test_hosts.py index aeeb0813a..77d6d3b56 100644 --- a/tests/protocols/gmpv225/entities/test_hosts.py +++ b/tests/protocols/gmpv225/entities/test_hosts.py @@ -10,24 +10,24 @@ GmpGetHostTestMixin, GmpModifyHostTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CreateHostTestCase(GmpCreateHostTestMixin, Gmpv225TestCase): +class Gmpv225CreateHostTestCase(GmpCreateHostTestMixin, GMPTestCase): pass -class Gmpv225DeleteHostTestCase(GmpDeleteHostTestMixin, Gmpv225TestCase): +class Gmpv225DeleteHostTestCase(GmpDeleteHostTestMixin, GMPTestCase): pass -class Gmpv225GetHostTestCase(GmpGetHostTestMixin, Gmpv225TestCase): +class Gmpv225GetHostTestCase(GmpGetHostTestMixin, GMPTestCase): pass -class Gmpv225GetHostsTestCase(GmpGetHostsTestMixin, Gmpv225TestCase): +class Gmpv225GetHostsTestCase(GmpGetHostsTestMixin, GMPTestCase): pass -class Gmpv225ModifyHostTestCase(GmpModifyHostTestMixin, Gmpv225TestCase): +class Gmpv225ModifyHostTestCase(GmpModifyHostTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_notes.py b/tests/protocols/gmpv225/entities/test_notes.py index 119b15800..2f1292aa3 100644 --- a/tests/protocols/gmpv225/entities/test_notes.py +++ b/tests/protocols/gmpv225/entities/test_notes.py @@ -11,28 +11,28 @@ GmpGetNoteTestMixin, GmpModifyNoteTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteNoteTestCase(GmpDeleteNoteTestMixin, Gmpv225TestCase): +class Gmpv225DeleteNoteTestCase(GmpDeleteNoteTestMixin, GMPTestCase): pass -class Gmpv225GetNoteTestCase(GmpGetNoteTestMixin, Gmpv225TestCase): +class Gmpv225GetNoteTestCase(GmpGetNoteTestMixin, GMPTestCase): pass -class Gmpv225GetNotesTestCase(GmpGetNotesTestMixin, Gmpv225TestCase): +class Gmpv225GetNotesTestCase(GmpGetNotesTestMixin, GMPTestCase): pass -class Gmpv225CloneNoteTestCase(GmpCloneNoteTestMixin, Gmpv225TestCase): +class Gmpv225CloneNoteTestCase(GmpCloneNoteTestMixin, GMPTestCase): pass -class Gmpv225CreateNoteTestCase(GmpCreateNoteTestMixin, Gmpv225TestCase): +class Gmpv225CreateNoteTestCase(GmpCreateNoteTestMixin, GMPTestCase): pass -class Gmpv225ModifyNoteTestCase(GmpModifyNoteTestMixin, Gmpv225TestCase): +class Gmpv225ModifyNoteTestCase(GmpModifyNoteTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_operating_systems.py b/tests/protocols/gmpv225/entities/test_operating_systems.py index 5852988b1..7463b8690 100644 --- a/tests/protocols/gmpv225/entities/test_operating_systems.py +++ b/tests/protocols/gmpv225/entities/test_operating_systems.py @@ -9,28 +9,28 @@ GmpGetOperatingSystemTestMixin, GmpModifyOperatingSystemTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase class Gmpv225DeleteOperatingSystemTestCase( - GmpDeleteOperatingSystemTestMixin, Gmpv225TestCase + GmpDeleteOperatingSystemTestMixin, GMPTestCase ): pass class Gmpv225GetOperatingSystemTestCase( - GmpGetOperatingSystemTestMixin, Gmpv225TestCase + GmpGetOperatingSystemTestMixin, GMPTestCase ): pass class Gmpv225GetOperatingSystemsTestCase( - GmpGetOperatingSystemsTestMixin, Gmpv225TestCase + GmpGetOperatingSystemsTestMixin, GMPTestCase ): pass class Gmpv225ModifyOperatingSystemTestCase( - GmpModifyOperatingSystemTestMixin, Gmpv225TestCase + GmpModifyOperatingSystemTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_overrides.py b/tests/protocols/gmpv225/entities/test_overrides.py index 1077ff59a..dac603320 100644 --- a/tests/protocols/gmpv225/entities/test_overrides.py +++ b/tests/protocols/gmpv225/entities/test_overrides.py @@ -11,34 +11,28 @@ GmpGetOverrideTestMixin, GmpModifyOverrideTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneOverrideTestCase(GmpCloneOverrideTestMixin, Gmpv225TestCase): +class Gmpv225CloneOverrideTestCase(GmpCloneOverrideTestMixin, GMPTestCase): pass -class Gmpv225CreateOverrideTestCase( - GmpCreateOverrideTestMixin, Gmpv225TestCase -): +class Gmpv225CreateOverrideTestCase(GmpCreateOverrideTestMixin, GMPTestCase): pass -class Gmpv225DeleteOverrideTestCase( - GmpDeleteOverrideTestMixin, Gmpv225TestCase -): +class Gmpv225DeleteOverrideTestCase(GmpDeleteOverrideTestMixin, GMPTestCase): pass -class Gmpv225GetOverrideTestCase(GmpGetOverrideTestMixin, Gmpv225TestCase): +class Gmpv225GetOverrideTestCase(GmpGetOverrideTestMixin, GMPTestCase): pass -class Gmpv225GetOverridesTestCase(GmpGetOverridesTestMixin, Gmpv225TestCase): +class Gmpv225GetOverridesTestCase(GmpGetOverridesTestMixin, GMPTestCase): pass -class Gmpv225ModifyOverrideTestCase( - GmpModifyOverrideTestMixin, Gmpv225TestCase -): +class Gmpv225ModifyOverrideTestCase(GmpModifyOverrideTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_permissions.py b/tests/protocols/gmpv225/entities/test_permissions.py index 3f73595cc..02fbf9c5d 100644 --- a/tests/protocols/gmpv225/entities/test_permissions.py +++ b/tests/protocols/gmpv225/entities/test_permissions.py @@ -11,38 +11,34 @@ GmpGetPermissionTestMixin, GmpModifyPermissionTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase class Gmpv225DeletePermissionTestCase( - GmpDeletePermissionTestMixin, Gmpv225TestCase + GmpDeletePermissionTestMixin, GMPTestCase ): pass -class Gmpv225GetPermissionTestCase(GmpGetPermissionTestMixin, Gmpv225TestCase): +class Gmpv225GetPermissionTestCase(GmpGetPermissionTestMixin, GMPTestCase): pass -class Gmpv225GetPermissionsTestCase( - GmpGetPermissionsTestMixin, Gmpv225TestCase -): +class Gmpv225GetPermissionsTestCase(GmpGetPermissionsTestMixin, GMPTestCase): pass -class Gmpv225ClonePermissionTestCase( - GmpClonePermissionTestMixin, Gmpv225TestCase -): +class Gmpv225ClonePermissionTestCase(GmpClonePermissionTestMixin, GMPTestCase): pass class Gmpv225CreatePermissionTestCase( - GmpCreatePermissionTestMixin, Gmpv225TestCase + GmpCreatePermissionTestMixin, GMPTestCase ): pass class Gmpv225ModifyPermissionTestCase( - GmpModifyPermissionTestMixin, Gmpv225TestCase + GmpModifyPermissionTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_policies.py b/tests/protocols/gmpv225/entities/test_policies.py index ac0d460fa..a45e5bf74 100644 --- a/tests/protocols/gmpv225/entities/test_policies.py +++ b/tests/protocols/gmpv225/entities/test_policies.py @@ -17,64 +17,64 @@ GmpModifyPolicySetNvtSelectionTestMixin, GmpModifyPolicySetScannerPreferenceTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225ClonePolicyTestCase(GmpClonePolicyTestMixin, Gmpv225TestCase): +class Gmpv225ClonePolicyTestCase(GmpClonePolicyTestMixin, GMPTestCase): pass -class Gmpv225CreatePolicyTestCase(GmpCreatePolicyTestMixin, Gmpv225TestCase): +class Gmpv225CreatePolicyTestCase(GmpCreatePolicyTestMixin, GMPTestCase): pass -class Gmpv225DeletePolicyTestCase(GmpDeletePolicyTestMixin, Gmpv225TestCase): +class Gmpv225DeletePolicyTestCase(GmpDeletePolicyTestMixin, GMPTestCase): pass -class Gmpv225GetPolicyTestCase(GmpGetPolicyTestMixin, Gmpv225TestCase): +class Gmpv225GetPolicyTestCase(GmpGetPolicyTestMixin, GMPTestCase): pass -class Gmpv225GetPoliciesTestCase(GmpGetPoliciesTestMixin, Gmpv225TestCase): +class Gmpv225GetPoliciesTestCase(GmpGetPoliciesTestMixin, GMPTestCase): pass -class Gmpv225ImportPolicyTestCase(GmpImportPolicyTestMixin, Gmpv225TestCase): +class Gmpv225ImportPolicyTestCase(GmpImportPolicyTestMixin, GMPTestCase): pass class Gmpv225ModifyPolicySetCommentTestCase( - GmpModifyPolicySetCommentTestMixin, Gmpv225TestCase + GmpModifyPolicySetCommentTestMixin, GMPTestCase ): pass class Gmpv225ModifyPolicySetFamilySelectionTestCase( - GmpModifyPolicySetFamilySelectionTestMixin, Gmpv225TestCase + GmpModifyPolicySetFamilySelectionTestMixin, GMPTestCase ): pass class Gmpv225ModifyPolicySetNvtSelectionTestCase( - GmpModifyPolicySetNvtSelectionTestMixin, Gmpv225TestCase + GmpModifyPolicySetNvtSelectionTestMixin, GMPTestCase ): pass class Gmpv225ModifyPolicySetNameTestCase( - GmpModifyPolicySetNameTestMixin, Gmpv225TestCase + GmpModifyPolicySetNameTestMixin, GMPTestCase ): pass class Gmpv225ModifyPolicySetNvtPreferenceTestCase( - GmpModifyPolicySetNvtPreferenceTestMixin, Gmpv225TestCase + GmpModifyPolicySetNvtPreferenceTestMixin, GMPTestCase ): pass class Gmpv225ModifyPolicySetScannerPreferenceTestCase( - GmpModifyPolicySetScannerPreferenceTestMixin, Gmpv225TestCase + GmpModifyPolicySetScannerPreferenceTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_port_lists.py b/tests/protocols/gmpv225/entities/test_port_lists.py index 2e3d06c30..04aa381dc 100644 --- a/tests/protocols/gmpv225/entities/test_port_lists.py +++ b/tests/protocols/gmpv225/entities/test_port_lists.py @@ -13,46 +13,38 @@ GmpGetPortListTestMixin, GmpModifyPortListTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225ClonePortListTestCase(GmpClonePortListTestMixin, Gmpv225TestCase): +class Gmpv225ClonePortListTestCase(GmpClonePortListTestMixin, GMPTestCase): pass -class Gmpv225CreatePortListTestCase( - GmpCreatePortListTestMixin, Gmpv225TestCase -): +class Gmpv225CreatePortListTestCase(GmpCreatePortListTestMixin, GMPTestCase): pass class Gmpv225CreatePortRangeListTestCase( - GmpCreatePortRangeTestMixin, Gmpv225TestCase + GmpCreatePortRangeTestMixin, GMPTestCase ): pass -class Gmpv225DeletePortListTestCase( - GmpDeletePortListTestMixin, Gmpv225TestCase -): +class Gmpv225DeletePortListTestCase(GmpDeletePortListTestMixin, GMPTestCase): pass -class Gmpv225DeletePortRangeTestCase( - GmpDeletePortRangeTestMixin, Gmpv225TestCase -): +class Gmpv225DeletePortRangeTestCase(GmpDeletePortRangeTestMixin, GMPTestCase): pass -class Gmpv225GetPortListTestCase(GmpGetPortListTestMixin, Gmpv225TestCase): +class Gmpv225GetPortListTestCase(GmpGetPortListTestMixin, GMPTestCase): pass -class Gmpv225GetPortListsTestCase(GmpGetPortListsTestMixin, Gmpv225TestCase): +class Gmpv225GetPortListsTestCase(GmpGetPortListsTestMixin, GMPTestCase): pass -class Gmpv225ModifyPortListTestCase( - GmpModifyPortListTestMixin, Gmpv225TestCase -): +class Gmpv225ModifyPortListTestCase(GmpModifyPortListTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_report_formats.py b/tests/protocols/gmpv225/entities/test_report_formats.py index ba5803f21..e452d39d9 100644 --- a/tests/protocols/gmpv225/entities/test_report_formats.py +++ b/tests/protocols/gmpv225/entities/test_report_formats.py @@ -12,46 +12,44 @@ GmpModifyReportFormatTestMixin, GmpVerifyReportFormatTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase class Gmpv225DeleteReportFormatTestCase( - GmpDeleteReportFormatTestMixin, Gmpv225TestCase + GmpDeleteReportFormatTestMixin, GMPTestCase ): pass -class Gmpv225GetReportFormatTestCase( - GmpGetReportFormatTestMixin, Gmpv225TestCase -): +class Gmpv225GetReportFormatTestCase(GmpGetReportFormatTestMixin, GMPTestCase): pass class Gmpv225GetReportFormatsTestCase( - GmpGetReportFormatsTestMixin, Gmpv225TestCase + GmpGetReportFormatsTestMixin, GMPTestCase ): pass class Gmpv225CloneReportFormatTestCase( - GmpCloneReportFormatTestMixin, Gmpv225TestCase + GmpCloneReportFormatTestMixin, GMPTestCase ): pass class Gmpv225ImportReportFormatTestCase( - GmpImportReportFormatTestMixin, Gmpv225TestCase + GmpImportReportFormatTestMixin, GMPTestCase ): pass class Gmpv225ModifyReportFormatTestCase( - GmpModifyReportFormatTestMixin, Gmpv225TestCase + GmpModifyReportFormatTestMixin, GMPTestCase ): pass class Gmpv225VerifyReportFormatTestCase( - GmpVerifyReportFormatTestMixin, Gmpv225TestCase + GmpVerifyReportFormatTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_reports.py b/tests/protocols/gmpv225/entities/test_reports.py index 60d645f26..519f9f3e5 100644 --- a/tests/protocols/gmpv225/entities/test_reports.py +++ b/tests/protocols/gmpv225/entities/test_reports.py @@ -9,20 +9,20 @@ GmpGetReportTestMixin, GmpImportReportTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteReportTestCase(GmpDeleteReportTestMixin, Gmpv225TestCase): +class Gmpv225DeleteReportTestCase(GmpDeleteReportTestMixin, GMPTestCase): pass -class Gmpv225GetReportTestCase(GmpGetReportTestMixin, Gmpv225TestCase): +class Gmpv225GetReportTestCase(GmpGetReportTestMixin, GMPTestCase): pass -class Gmpv225GetReportsTestCase(GmpGetReportsTestMixin, Gmpv225TestCase): +class Gmpv225GetReportsTestCase(GmpGetReportsTestMixin, GMPTestCase): pass -class Gmpv225ImportReportTestCase(GmpImportReportTestMixin, Gmpv225TestCase): +class Gmpv225ImportReportTestCase(GmpImportReportTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_resource_names.py b/tests/protocols/gmpv225/entities/test_resource_names.py index 74b549aef..f852ca33e 100644 --- a/tests/protocols/gmpv225/entities/test_resource_names.py +++ b/tests/protocols/gmpv225/entities/test_resource_names.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase from .resourcenames import ( GmpGetResourceNamesListTestMixin, GmpGetResourceNameTestMixin, @@ -11,12 +11,10 @@ class Gmpv225GetResourceNamesListTestCase( - GmpGetResourceNamesListTestMixin, Gmpv225TestCase + GmpGetResourceNamesListTestMixin, GMPTestCase ): pass -class Gmpv225GetResourceNameTestCase( - GmpGetResourceNameTestMixin, Gmpv225TestCase -): +class Gmpv225GetResourceNameTestCase(GmpGetResourceNameTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_results.py b/tests/protocols/gmpv225/entities/test_results.py index 9e88cf12d..1f970dfa1 100644 --- a/tests/protocols/gmpv225/entities/test_results.py +++ b/tests/protocols/gmpv225/entities/test_results.py @@ -7,12 +7,12 @@ GmpGetResultsTestMixin, GmpGetResultTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225GetResultTestCase(GmpGetResultTestMixin, Gmpv225TestCase): +class Gmpv225GetResultTestCase(GmpGetResultTestMixin, GMPTestCase): pass -class Gmpv225GetResultsTestCase(GmpGetResultsTestMixin, Gmpv225TestCase): +class Gmpv225GetResultsTestCase(GmpGetResultsTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_roles.py b/tests/protocols/gmpv225/entities/test_roles.py index 0dda8438b..2d6c8bbe8 100644 --- a/tests/protocols/gmpv225/entities/test_roles.py +++ b/tests/protocols/gmpv225/entities/test_roles.py @@ -11,28 +11,28 @@ GmpGetRoleTestMixin, GmpModifyRoleTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteRoleTestCase(GmpDeleteRoleTestMixin, Gmpv225TestCase): +class Gmpv225DeleteRoleTestCase(GmpDeleteRoleTestMixin, GMPTestCase): pass -class Gmpv225GetRoleTestCase(GmpGetRoleTestMixin, Gmpv225TestCase): +class Gmpv225GetRoleTestCase(GmpGetRoleTestMixin, GMPTestCase): pass -class Gmpv225GetRolesTestCase(GmpGetRolesTestMixin, Gmpv225TestCase): +class Gmpv225GetRolesTestCase(GmpGetRolesTestMixin, GMPTestCase): pass -class Gmpv225CloneRoleTestCase(GmpCloneRoleTestMixin, Gmpv225TestCase): +class Gmpv225CloneRoleTestCase(GmpCloneRoleTestMixin, GMPTestCase): pass -class Gmpv225CreateRoleTestCase(GmpCreateRoleTestMixin, Gmpv225TestCase): +class Gmpv225CreateRoleTestCase(GmpCreateRoleTestMixin, GMPTestCase): pass -class Gmpv225ModifyRoleTestCase(GmpModifyRoleTestMixin, Gmpv225TestCase): +class Gmpv225ModifyRoleTestCase(GmpModifyRoleTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_scan_configs.py b/tests/protocols/gmpv225/entities/test_scan_configs.py index 3d0e6aa49..5adc201ba 100644 --- a/tests/protocols/gmpv225/entities/test_scan_configs.py +++ b/tests/protocols/gmpv225/entities/test_scan_configs.py @@ -17,74 +17,70 @@ GmpModifyScanConfigSetNvtSelectionTestMixin, GmpModifyScanConfigSetScannerPreferenceTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneScanConfigTestCase( - GmpCloneScanConfigTestMixin, Gmpv225TestCase -): +class Gmpv225CloneScanConfigTestCase(GmpCloneScanConfigTestMixin, GMPTestCase): pass class Gmpv225CreateScanConfigTestCase( - GmpCreateScanConfigTestMixin, Gmpv225TestCase + GmpCreateScanConfigTestMixin, GMPTestCase ): pass class Gmpv225DeleteScanConfigTestCase( - GmpDeleteScanConfigTestMixin, Gmpv225TestCase + GmpDeleteScanConfigTestMixin, GMPTestCase ): pass -class Gmpv225GetScanConfigTestCase(GmpGetScanConfigTestMixin, Gmpv225TestCase): +class Gmpv225GetScanConfigTestCase(GmpGetScanConfigTestMixin, GMPTestCase): pass -class Gmpv225GetScanConfigsTestCase( - GmpGetScanConfigsTestMixin, Gmpv225TestCase -): +class Gmpv225GetScanConfigsTestCase(GmpGetScanConfigsTestMixin, GMPTestCase): pass class Gmpv225ImportScanConfigTestCase( - GmpImportScanConfigTestMixin, Gmpv225TestCase + GmpImportScanConfigTestMixin, GMPTestCase ): pass class Gmpv225ModifyScanConfigSetCommentTestCase( - GmpModifyScanConfigSetCommentTestMixin, Gmpv225TestCase + GmpModifyScanConfigSetCommentTestMixin, GMPTestCase ): pass class Gmpv225ModifyScanConfigSetFamilySelectionTestCase( - GmpModifyScanConfigSetFamilySelectionTestMixin, Gmpv225TestCase + GmpModifyScanConfigSetFamilySelectionTestMixin, GMPTestCase ): pass class Gmpv225ModifyScanConfigSetNvtSelectionTestCase( - GmpModifyScanConfigSetNvtSelectionTestMixin, Gmpv225TestCase + GmpModifyScanConfigSetNvtSelectionTestMixin, GMPTestCase ): pass class Gmpv225ModifyScanConfigSetNameTestCase( - GmpModifyScanConfigSetNameTestMixin, Gmpv225TestCase + GmpModifyScanConfigSetNameTestMixin, GMPTestCase ): pass class Gmpv225ModifyScanConfigSetNvtPreferenceTestCase( - GmpModifyScanConfigSetNvtPreferenceTestMixin, Gmpv225TestCase + GmpModifyScanConfigSetNvtPreferenceTestMixin, GMPTestCase ): pass class Gmpv225ModifyScanConfigSetScannerPreferenceTestCase( - GmpModifyScanConfigSetScannerPreferenceTestMixin, Gmpv225TestCase + GmpModifyScanConfigSetScannerPreferenceTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_scanners.py b/tests/protocols/gmpv225/entities/test_scanners.py index 7632f8ec3..9fcafe602 100644 --- a/tests/protocols/gmpv225/entities/test_scanners.py +++ b/tests/protocols/gmpv225/entities/test_scanners.py @@ -11,28 +11,28 @@ GmpGetScannerTestMixin, GmpModifyScannerTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteScannerTestCase(GmpDeleteScannerTestMixin, Gmpv225TestCase): +class Gmpv225DeleteScannerTestCase(GmpDeleteScannerTestMixin, GMPTestCase): pass -class Gmpv225GetScannerTestCase(GmpGetScannerTestMixin, Gmpv225TestCase): +class Gmpv225GetScannerTestCase(GmpGetScannerTestMixin, GMPTestCase): pass -class Gmpv225GetScannersTestCase(GmpGetScannersTestMixin, Gmpv225TestCase): +class Gmpv225GetScannersTestCase(GmpGetScannersTestMixin, GMPTestCase): pass -class Gmpv225CloneScannerTestCase(GmpCloneScannerTestMixin, Gmpv225TestCase): +class Gmpv225CloneScannerTestCase(GmpCloneScannerTestMixin, GMPTestCase): pass -class Gmpv225CreateScannerTestCase(GmpCreateScannerTestMixin, Gmpv225TestCase): +class Gmpv225CreateScannerTestCase(GmpCreateScannerTestMixin, GMPTestCase): pass -class Gmpv225ModifyScannerTestCase(GmpModifyScannerTestMixin, Gmpv225TestCase): +class Gmpv225ModifyScannerTestCase(GmpModifyScannerTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_schedules.py b/tests/protocols/gmpv225/entities/test_schedules.py index 4b42b528a..dd75cbb05 100644 --- a/tests/protocols/gmpv225/entities/test_schedules.py +++ b/tests/protocols/gmpv225/entities/test_schedules.py @@ -11,34 +11,28 @@ GmpGetScheduleTestMixin, GmpModifyScheduleTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteScheduleTestCase( - GmpDeleteScheduleTestMixin, Gmpv225TestCase -): +class Gmpv225DeleteScheduleTestCase(GmpDeleteScheduleTestMixin, GMPTestCase): pass -class Gmpv225GetScheduleTestCase(GmpGetScheduleTestMixin, Gmpv225TestCase): +class Gmpv225GetScheduleTestCase(GmpGetScheduleTestMixin, GMPTestCase): pass -class Gmpv225GetSchedulesTestCase(GmpGetSchedulesTestMixin, Gmpv225TestCase): +class Gmpv225GetSchedulesTestCase(GmpGetSchedulesTestMixin, GMPTestCase): pass -class Gmpv225CloneScheduleTestCase(GmpCloneScheduleTestMixin, Gmpv225TestCase): +class Gmpv225CloneScheduleTestCase(GmpCloneScheduleTestMixin, GMPTestCase): pass -class Gmpv225CreateScheduleTestCase( - GmpCreateScheduleTestMixin, Gmpv225TestCase -): +class Gmpv225CreateScheduleTestCase(GmpCreateScheduleTestMixin, GMPTestCase): pass -class Gmpv225ModifyScheduleTestCase( - GmpModifyScheduleTestMixin, Gmpv225TestCase -): +class Gmpv225ModifyScheduleTestCase(GmpModifyScheduleTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_secinfo.py b/tests/protocols/gmpv225/entities/test_secinfo.py index 2084d01f4..cb439e382 100644 --- a/tests/protocols/gmpv225/entities/test_secinfo.py +++ b/tests/protocols/gmpv225/entities/test_secinfo.py @@ -20,72 +20,68 @@ GmpGetScanConfigNvtsTestMixin, GmpGetScanConfigNvtTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225GetCertBundTestCase(GmpGetCertBundTestMixin, Gmpv225TestCase): +class Gmpv225GetCertBundTestCase(GmpGetCertBundTestMixin, GMPTestCase): pass -class Gmpv225GetCpeTestCase(GmpGetCpeTestMixin, Gmpv225TestCase): +class Gmpv225GetCpeTestCase(GmpGetCpeTestMixin, GMPTestCase): pass -class Gmpv225GetCveTestCase(GmpGetCveTestMixin, Gmpv225TestCase): +class Gmpv225GetCveTestCase(GmpGetCveTestMixin, GMPTestCase): pass -class Gmpv225GetDfnCertCase(GmpGetDfnCertTestMixin, Gmpv225TestCase): +class Gmpv225GetDfnCertCase(GmpGetDfnCertTestMixin, GMPTestCase): pass -class Gmpv225GetInfoListTestCase(GmpGetInfoListTestMixin, Gmpv225TestCase): +class Gmpv225GetInfoListTestCase(GmpGetInfoListTestMixin, GMPTestCase): pass -class Gmpv225GetInfoTestCase(GmpGetInfoTestMixin, Gmpv225TestCase): +class Gmpv225GetInfoTestCase(GmpGetInfoTestMixin, GMPTestCase): pass -class Gmpv225GetNvtTestCase(GmpGetNvtTestMixin, Gmpv225TestCase): +class Gmpv225GetNvtTestCase(GmpGetNvtTestMixin, GMPTestCase): pass class Gmpv225GetScanConfigNvtTestCase( - GmpGetScanConfigNvtTestMixin, Gmpv225TestCase + GmpGetScanConfigNvtTestMixin, GMPTestCase ): pass -class Gmpv225GetNvtFamiliesTestCase( - GmpGetNvtFamiliesTestMixin, Gmpv225TestCase -): +class Gmpv225GetNvtFamiliesTestCase(GmpGetNvtFamiliesTestMixin, GMPTestCase): pass class Gmpv225GetScanConfigNvtsTestCase( - GmpGetScanConfigNvtsTestMixin, Gmpv225TestCase + GmpGetScanConfigNvtsTestMixin, GMPTestCase ): pass -class Gmpv225GetCertBundListTestCase( - GmpGetCertBundListTestMixin, Gmpv225TestCase -): +class Gmpv225GetCertBundListTestCase(GmpGetCertBundListTestMixin, GMPTestCase): pass -class Gmpv225GetCpeListTestCase(GmpGetCpeListTestMixin, Gmpv225TestCase): +class Gmpv225GetCpeListTestCase(GmpGetCpeListTestMixin, GMPTestCase): pass -class Gmpv225GetCveListTestCase(GmpGetCveListTestMixin, Gmpv225TestCase): +class Gmpv225GetCveListTestCase(GmpGetCveListTestMixin, GMPTestCase): pass -class Gmpv225GetDfnCertListCase(GmpGetDfnCertListTestMixin, Gmpv225TestCase): +class Gmpv225GetDfnCertListCase(GmpGetDfnCertListTestMixin, GMPTestCase): pass -class Gmpv225GetNvtListTestCase(GmpGetNvtListTestMixin, Gmpv225TestCase): +class Gmpv225GetNvtListTestCase(GmpGetNvtListTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_tags.py b/tests/protocols/gmpv225/entities/test_tags.py index 7e9258382..3dd6bee47 100644 --- a/tests/protocols/gmpv225/entities/test_tags.py +++ b/tests/protocols/gmpv225/entities/test_tags.py @@ -11,28 +11,28 @@ GmpGetTagTestMixin, GmpModifyTagTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteTagTestCase(GmpDeleteTagTestMixin, Gmpv225TestCase): +class Gmpv225DeleteTagTestCase(GmpDeleteTagTestMixin, GMPTestCase): pass -class Gmpv225GetTagTestCase(GmpGetTagTestMixin, Gmpv225TestCase): +class Gmpv225GetTagTestCase(GmpGetTagTestMixin, GMPTestCase): pass -class Gmpv225GetTagsTestCase(GmpGetTagsTestMixin, Gmpv225TestCase): +class Gmpv225GetTagsTestCase(GmpGetTagsTestMixin, GMPTestCase): pass -class Gmpv225CloneTagTestCase(GmpCloneTagTestMixin, Gmpv225TestCase): +class Gmpv225CloneTagTestCase(GmpCloneTagTestMixin, GMPTestCase): pass -class Gmpv225CreateTagTestCase(GmpCreateTagTestMixin, Gmpv225TestCase): +class Gmpv225CreateTagTestCase(GmpCreateTagTestMixin, GMPTestCase): pass -class Gmpv225ModifyTagTestCase(GmpModifyTagTestMixin, Gmpv225TestCase): +class Gmpv225ModifyTagTestCase(GmpModifyTagTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_targets.py b/tests/protocols/gmpv225/entities/test_targets.py index c41413e89..83ffdc902 100644 --- a/tests/protocols/gmpv225/entities/test_targets.py +++ b/tests/protocols/gmpv225/entities/test_targets.py @@ -11,28 +11,28 @@ GmpGetTargetTestMixin, GmpModifyTargetTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneTargetTestCase(GmpCloneTargetTestMixin, Gmpv225TestCase): +class Gmpv225CloneTargetTestCase(GmpCloneTargetTestMixin, GMPTestCase): pass -class Gmpv225CreateTargetTestCase(GmpCreateTargetTestMixin, Gmpv225TestCase): +class Gmpv225CreateTargetTestCase(GmpCreateTargetTestMixin, GMPTestCase): pass -class Gmpv225DeleteTargetTestCase(GmpDeleteTargetTestMixin, Gmpv225TestCase): +class Gmpv225DeleteTargetTestCase(GmpDeleteTargetTestMixin, GMPTestCase): pass -class Gmpv225GetTargetTestCase(GmpGetTargetTestMixin, Gmpv225TestCase): +class Gmpv225GetTargetTestCase(GmpGetTargetTestMixin, GMPTestCase): pass -class Gmpv225GetTargetsTestCase(GmpGetTargetsTestMixin, Gmpv225TestCase): +class Gmpv225GetTargetsTestCase(GmpGetTargetsTestMixin, GMPTestCase): pass -class Gmpv225ModifyTargetTestCase(GmpModifyTargetTestMixin, Gmpv225TestCase): +class Gmpv225ModifyTargetTestCase(GmpModifyTargetTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_tasks.py b/tests/protocols/gmpv225/entities/test_tasks.py index 910535561..2995fabab 100644 --- a/tests/protocols/gmpv225/entities/test_tasks.py +++ b/tests/protocols/gmpv225/entities/test_tasks.py @@ -16,50 +16,50 @@ GmpStartTaskTestMixin, GmpStopTaskTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneTaskTestCase(GmpCloneTaskTestMixin, Gmpv225TestCase): +class Gmpv225CloneTaskTestCase(GmpCloneTaskTestMixin, GMPTestCase): pass class Gmpv225CreateContainerTaskTestCase( - GmpCreateContainerTaskTestMixin, Gmpv225TestCase + GmpCreateContainerTaskTestMixin, GMPTestCase ): pass -class Gmpv225CreateTaskTestCase(GmpCreateTaskTestMixin, Gmpv225TestCase): +class Gmpv225CreateTaskTestCase(GmpCreateTaskTestMixin, GMPTestCase): pass -class Gmpv225DeleteTaskTestCase(GmpDeleteTaskTestMixin, Gmpv225TestCase): +class Gmpv225DeleteTaskTestCase(GmpDeleteTaskTestMixin, GMPTestCase): pass -class Gmpv225GetTaskTestCase(GmpGetTaskTestMixin, Gmpv225TestCase): +class Gmpv225GetTaskTestCase(GmpGetTaskTestMixin, GMPTestCase): pass -class Gmpv225GetTasksTestCase(GmpGetTasksTestMixin, Gmpv225TestCase): +class Gmpv225GetTasksTestCase(GmpGetTasksTestMixin, GMPTestCase): pass -class Gmpv225ModifyTaskTestCase(GmpModifyTaskTestMixin, Gmpv225TestCase): +class Gmpv225ModifyTaskTestCase(GmpModifyTaskTestMixin, GMPTestCase): pass -class Gmpv225MoveTaskTestCase(GmpMoveTaskTestMixin, Gmpv225TestCase): +class Gmpv225MoveTaskTestCase(GmpMoveTaskTestMixin, GMPTestCase): pass -class Gmpv225ResumeTaskTestCase(GmpResumeTaskTestMixin, Gmpv225TestCase): +class Gmpv225ResumeTaskTestCase(GmpResumeTaskTestMixin, GMPTestCase): pass -class Gmpv225StartTaskTestCase(GmpStartTaskTestMixin, Gmpv225TestCase): +class Gmpv225StartTaskTestCase(GmpStartTaskTestMixin, GMPTestCase): pass -class Gmpv225StopTaskTestCase(GmpStopTaskTestMixin, Gmpv225TestCase): +class Gmpv225StopTaskTestCase(GmpStopTaskTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_tickets.py b/tests/protocols/gmpv225/entities/test_tickets.py index 42ee86307..797c4d548 100644 --- a/tests/protocols/gmpv225/entities/test_tickets.py +++ b/tests/protocols/gmpv225/entities/test_tickets.py @@ -11,28 +11,28 @@ GmpGetTicketTestMixin, GmpModifyTicketTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225DeleteTicketTestCase(GmpDeleteTicketTestMixin, Gmpv225TestCase): +class Gmpv225DeleteTicketTestCase(GmpDeleteTicketTestMixin, GMPTestCase): pass -class Gmpv225GetTicketTestCase(GmpGetTicketTestMixin, Gmpv225TestCase): +class Gmpv225GetTicketTestCase(GmpGetTicketTestMixin, GMPTestCase): pass -class Gmpv225GetTicketsTestCase(GmpGetTicketsTestMixin, Gmpv225TestCase): +class Gmpv225GetTicketsTestCase(GmpGetTicketsTestMixin, GMPTestCase): pass -class Gmpv225CloneTicketTestCase(GmpCloneTicketTestMixin, Gmpv225TestCase): +class Gmpv225CloneTicketTestCase(GmpCloneTicketTestMixin, GMPTestCase): pass -class Gmpv225CreateTicketTestCase(GmpCreateTicketTestMixin, Gmpv225TestCase): +class Gmpv225CreateTicketTestCase(GmpCreateTicketTestMixin, GMPTestCase): pass -class Gmpv225ModifyTicketTestCase(GmpModifyTicketTestMixin, Gmpv225TestCase): +class Gmpv225ModifyTicketTestCase(GmpModifyTicketTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_tls_certificates.py b/tests/protocols/gmpv225/entities/test_tls_certificates.py index 244adec1e..5c972762a 100644 --- a/tests/protocols/gmpv225/entities/test_tls_certificates.py +++ b/tests/protocols/gmpv225/entities/test_tls_certificates.py @@ -11,40 +11,40 @@ GmpGetTLSCertificateTestMixin, GmpModifyTLSCertificateTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase class Gmpv225CloneTLSCertificateTestCase( - GmpCloneTLSCertificateTestMixin, Gmpv225TestCase + GmpCloneTLSCertificateTestMixin, GMPTestCase ): pass class Gmpv225CreateTLSCertificateTestCase( - GmpCreateTLSCertificateTestMixin, Gmpv225TestCase + GmpCreateTLSCertificateTestMixin, GMPTestCase ): pass class Gmpv225DeleteTLSCertificateTestCase( - GmpDeleteTLSCertificateTestMixin, Gmpv225TestCase + GmpDeleteTLSCertificateTestMixin, GMPTestCase ): pass class Gmpv225GetTLSCertificateTestCase( - GmpGetTLSCertificateTestMixin, Gmpv225TestCase + GmpGetTLSCertificateTestMixin, GMPTestCase ): pass class Gmpv225GetTLSCertificatesTestCase( - GmpGetTLSCertificatesTestMixin, Gmpv225TestCase + GmpGetTLSCertificatesTestMixin, GMPTestCase ): pass class Gmpv225ModifyTLSCertificateTestCase( - GmpModifyTLSCertificateTestMixin, Gmpv225TestCase + GmpModifyTLSCertificateTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/entities/test_users.py b/tests/protocols/gmpv225/entities/test_users.py index 011c31609..7bc4ce8fa 100644 --- a/tests/protocols/gmpv225/entities/test_users.py +++ b/tests/protocols/gmpv225/entities/test_users.py @@ -11,28 +11,28 @@ GmpGetUserTestMixin, GmpModifyUserTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225CloneUserTestCase(GmpCloneUserTestMixin, Gmpv225TestCase): +class Gmpv225CloneUserTestCase(GmpCloneUserTestMixin, GMPTestCase): pass -class Gmpv225CreateUserTestCase(GmpCreateUserTestMixin, Gmpv225TestCase): +class Gmpv225CreateUserTestCase(GmpCreateUserTestMixin, GMPTestCase): pass -class Gmpv225DeleteUserTestCase(GmpDeleteUserTestMixin, Gmpv225TestCase): +class Gmpv225DeleteUserTestCase(GmpDeleteUserTestMixin, GMPTestCase): pass -class Gmpv225GetUserTestCase(GmpGetUserTestMixin, Gmpv225TestCase): +class Gmpv225GetUserTestCase(GmpGetUserTestMixin, GMPTestCase): pass -class Gmpv225GetUsersTestCase(GmpGetUsersTestMixin, Gmpv225TestCase): +class Gmpv225GetUsersTestCase(GmpGetUsersTestMixin, GMPTestCase): pass -class Gmpv225ModifyUserTestCase(GmpModifyUserTestMixin, Gmpv225TestCase): +class Gmpv225ModifyUserTestCase(GmpModifyUserTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/entities/test_vulnerabilities.py b/tests/protocols/gmpv225/entities/test_vulnerabilities.py index c9a70a4cf..841afd7b5 100644 --- a/tests/protocols/gmpv225/entities/test_vulnerabilities.py +++ b/tests/protocols/gmpv225/entities/test_vulnerabilities.py @@ -7,16 +7,16 @@ GmpGetVulnerabilitiesTestMixin, GmpGetVulnerabilityTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase class Gmpv225GetVulnerabilityTestCase( - GmpGetVulnerabilityTestMixin, Gmpv225TestCase + GmpGetVulnerabilityTestMixin, GMPTestCase ): pass class Gmpv225GetVulnerabilitiesTestCase( - GmpGetVulnerabilitiesTestMixin, Gmpv225TestCase + GmpGetVulnerabilitiesTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/system/test_aggregates.py b/tests/protocols/gmpv225/system/test_aggregates.py index 902461275..4584aaeae 100644 --- a/tests/protocols/gmpv225/system/test_aggregates.py +++ b/tests/protocols/gmpv225/system/test_aggregates.py @@ -4,8 +4,8 @@ # from ...gmpv224.system.aggregates import GmpGetAggregatesTestMixin -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225GetAggregatesTestCase(GmpGetAggregatesTestMixin, Gmpv225TestCase): +class Gmpv225GetAggregatesTestCase(GmpGetAggregatesTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/system/test_authentication.py b/tests/protocols/gmpv225/system/test_authentication.py index ce6616ec8..09dde2ca6 100644 --- a/tests/protocols/gmpv225/system/test_authentication.py +++ b/tests/protocols/gmpv225/system/test_authentication.py @@ -8,18 +8,16 @@ GmpDescribeAuthTestMixin, GmpModifyAuthTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225AuthenticateTestCase(GmpAuthenticateTestMixin, Gmpv225TestCase): +class Gmpv225AuthenticateTestCase(GmpAuthenticateTestMixin, GMPTestCase): pass -class Gmpv225ModifyAuthTestCase(GmpModifyAuthTestMixin, Gmpv225TestCase): +class Gmpv225ModifyAuthTestCase(GmpModifyAuthTestMixin, GMPTestCase): pass -class Gmpv225DescribeAuthCommandTestCase( - GmpDescribeAuthTestMixin, Gmpv225TestCase -): +class Gmpv225DescribeAuthCommandTestCase(GmpDescribeAuthTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/system/test_feed.py b/tests/protocols/gmpv225/system/test_feed.py index 7149816f8..bc784f298 100644 --- a/tests/protocols/gmpv225/system/test_feed.py +++ b/tests/protocols/gmpv225/system/test_feed.py @@ -4,12 +4,12 @@ # from ...gmpv224.system.feed import GmpGetFeedsTestMixin, GmpGetFeedTestMixin -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225GetFeedTestCase(GmpGetFeedTestMixin, Gmpv225TestCase): +class Gmpv225GetFeedTestCase(GmpGetFeedTestMixin, GMPTestCase): pass -class Gmpv225GetFeedsTestCase(GmpGetFeedsTestMixin, Gmpv225TestCase): +class Gmpv225GetFeedsTestCase(GmpGetFeedsTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/system/test_help.py b/tests/protocols/gmpv225/system/test_help.py index 031466118..a437de411 100644 --- a/tests/protocols/gmpv225/system/test_help.py +++ b/tests/protocols/gmpv225/system/test_help.py @@ -4,8 +4,8 @@ # from ...gmpv224.system.help import GmpHelpTestMixin -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225HelpTestCase(GmpHelpTestMixin, Gmpv225TestCase): +class Gmpv225HelpTestCase(GmpHelpTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/system/test_system_reports.py b/tests/protocols/gmpv225/system/test_system_reports.py index 294768379..79cf5b78f 100644 --- a/tests/protocols/gmpv225/system/test_system_reports.py +++ b/tests/protocols/gmpv225/system/test_system_reports.py @@ -4,10 +4,10 @@ # from ...gmpv224.system.system_reports import GmpGetSystemReportsTestMixin -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase class Gmpv225GetSystemReportsTestCase( - GmpGetSystemReportsTestMixin, Gmpv225TestCase + GmpGetSystemReportsTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/system/test_trashcan.py b/tests/protocols/gmpv225/system/test_trashcan.py index 556d5acd0..680449d9e 100644 --- a/tests/protocols/gmpv225/system/test_trashcan.py +++ b/tests/protocols/gmpv225/system/test_trashcan.py @@ -7,14 +7,14 @@ GmpEmptyTrashcanTestMixin, GmpRestoreFromTrashcanTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225EmptyTrashcanTestCase(GmpEmptyTrashcanTestMixin, Gmpv225TestCase): +class Gmpv225EmptyTrashcanTestCase(GmpEmptyTrashcanTestMixin, GMPTestCase): pass class Gmpv225RestoreFromTrashcanTestCase( - GmpRestoreFromTrashcanTestMixin, Gmpv225TestCase + GmpRestoreFromTrashcanTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/system/test_user_settings.py b/tests/protocols/gmpv225/system/test_user_settings.py index 4c0f66113..3d01dc5dd 100644 --- a/tests/protocols/gmpv225/system/test_user_settings.py +++ b/tests/protocols/gmpv225/system/test_user_settings.py @@ -8,22 +8,18 @@ GmpGetUserSettingTestMixin, GmpModifyUserSettingTestMixin, ) -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase -class Gmpv225GetUserSettingTestCase( - GmpGetUserSettingTestMixin, Gmpv225TestCase -): +class Gmpv225GetUserSettingTestCase(GmpGetUserSettingTestMixin, GMPTestCase): pass -class Gmpv225GetUserSettingsTestCase( - GmpGetUserSettingsTestMixin, Gmpv225TestCase -): +class Gmpv225GetUserSettingsTestCase(GmpGetUserSettingsTestMixin, GMPTestCase): pass class Gmpv225ModifyUserSettingTestCase( - GmpModifyUserSettingTestMixin, Gmpv225TestCase + GmpModifyUserSettingTestMixin, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/system/test_versions.py b/tests/protocols/gmpv225/system/test_versions.py index aeb7c980e..2c4a9071e 100644 --- a/tests/protocols/gmpv225/system/test_versions.py +++ b/tests/protocols/gmpv225/system/test_versions.py @@ -4,15 +4,15 @@ # from ...gmpv224.system.versions import GmpGetVersionTestCase -from ...gmpv225 import Gmpv225TestCase +from ...gmpv225 import GMPTestCase from .versions import GmpGetProtocolVersionTestCase -class Gmpv225GetVersionCommandTestCase(GmpGetVersionTestCase, Gmpv225TestCase): +class Gmpv225GetVersionCommandTestCase(GmpGetVersionTestCase, GMPTestCase): pass class Gmpv225GmpGetProtocolVersionTestCase( - GmpGetProtocolVersionTestCase, Gmpv225TestCase + GmpGetProtocolVersionTestCase, GMPTestCase ): pass diff --git a/tests/protocols/gmpv225/test_gmp_types.py b/tests/protocols/gmpv225/test_gmp_types.py index 36aad27c6..7bbba903b 100644 --- a/tests/protocols/gmpv225/test_gmp_types.py +++ b/tests/protocols/gmpv225/test_gmp_types.py @@ -5,7 +5,7 @@ from gvm.protocols.gmp.requests.v225 import HostsOrdering -from . import Gmpv225TestCase +from . import GMPTestCase class GmpWithStatementTestMixin: @@ -33,5 +33,5 @@ def test_types(self): self.assertEqual(self.gmp.types.HostsOrdering, HostsOrdering) -class Gmpv225WithStatementTestCase(GmpWithStatementTestMixin, Gmpv225TestCase): +class Gmpv225WithStatementTestCase(GmpWithStatementTestMixin, GMPTestCase): pass diff --git a/tests/protocols/gmpv225/test_with_statement.py b/tests/protocols/gmpv225/test_with_statement.py index eea3ad0c8..bba71e153 100644 --- a/tests/protocols/gmpv225/test_with_statement.py +++ b/tests/protocols/gmpv225/test_with_statement.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later # -from . import Gmpv225TestCase +from . import GMPTestCase class GmpWithStatementTestMixin: @@ -18,5 +18,5 @@ def test_with_statement(self): self.connection.disconnect.has_been_called() -class Gmpv225WithStatementTestCase(GmpWithStatementTestMixin, Gmpv225TestCase): +class Gmpv225WithStatementTestCase(GmpWithStatementTestMixin, GMPTestCase): pass From 24183a316a1f53e69ce372e222096799934522c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 28 Jan 2025 11:29:18 +0100 Subject: [PATCH 4/6] Improve docstrings of XmlCommand and XmlCommandElement --- gvm/xml.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/gvm/xml.py b/gvm/xml.py index b07b418ec..33291793b 100644 --- a/gvm/xml.py +++ b/gvm/xml.py @@ -82,6 +82,12 @@ def parse_xml(xml: AnyStr) -> Element: class XmlCommandElement: + """ + Base class for XML commands + + It's used to create XML command requests for the XML based protocols. + """ + def __init__(self, element: Element): self._element = element @@ -97,14 +103,20 @@ def add_element( return XmlCommandElement(node) def set_attribute(self, name: str, value: str) -> "XmlCommandElement": + """Set an attribute on the element. + + Args: + name: Name of the attribute + value: Value of the attribute + """ self._element.set(name, value) return self def set_attributes(self, attrs: dict[str, str]) -> "XmlCommandElement": """Set several attributes at once. - Arguments: - attrs (dict): Attributes to be set on the element + Args: + attrs: Attributes to be set on the element """ for key, value in attrs.items(): self._element.set(key, value) @@ -116,21 +128,46 @@ def append_xml_str(self, xml_text: str) -> None: node = parse_xml(xml_text) self._element.append(node) - def to_string(self) -> str: - return self.to_bytes().decode("utf-8") + def to_string(self, *, encoding: str = "utf-8") -> str: + """ + Convert the XML element to a string + + Args: + encoding: The encoding to use for the string. Default is 'utf-8'. + """ + return self.to_bytes().decode(encoding) def to_bytes(self) -> bytes: + """ + Convert the XML element to a bytes object + """ return xml_to_string(self._element) def __str__(self) -> str: + """ + Convert the XML element to a string using the default encoding. + """ return self.to_string() def __bytes__(self) -> bytes: + """ + Convert the XML element to a bytes object + """ return self.to_bytes() class XmlCommand(XmlCommandElement): + """ + Class to create XML commands + """ + def __init__(self, name: str) -> None: + """ + Create a new XML command + + Args: + name: The name of the root element of the command. + """ super().__init__(create_element(name)) def add_filter( @@ -138,6 +175,13 @@ def add_filter( filter_string: Optional[str], filter_id: Optional[Union[str, UUID]], ) -> "XmlCommand": + """ + Add a filter to the command. + + Args: + filter_string: The filter string to be added. + filter_id: The filter ID to be added. + """ if filter_string: self.set_attribute("filter", filter_string) From 132dd2a09c077f91fad3cacc6cdb9b28f51d4c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 28 Jan 2025 11:47:44 +0100 Subject: [PATCH 5/6] Add: Allow to set and reset the text on an XML command object Not every XML element will have a value/text. Therefore it should be possible to set it optionally. --- gvm/xml.py | 9 +++++++++ tests/xml/test_xml_command.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gvm/xml.py b/gvm/xml.py index 33291793b..2944fe51a 100644 --- a/gvm/xml.py +++ b/gvm/xml.py @@ -123,6 +123,15 @@ def set_attributes(self, attrs: dict[str, str]) -> "XmlCommandElement": return self + def set_text(self, text: Optional[str]) -> "XmlCommandElement": + """Set the text of the element. + + Args: + text: Text to be set on the element. None to remove the text. + """ + self._element.text = text + return self + def append_xml_str(self, xml_text: str) -> None: """Append a xml element in string format.""" node = parse_xml(xml_text) diff --git a/tests/xml/test_xml_command.py b/tests/xml/test_xml_command.py index 9519f3273..41ef90058 100644 --- a/tests/xml/test_xml_command.py +++ b/tests/xml/test_xml_command.py @@ -39,6 +39,18 @@ def test_should_allow_to_set_attributes(self): self.assertEqual(cmd.to_string(), '') + def test_should_allow_to_set_text(self): + cmd = XmlCommand("foo") + cmd.set_text("bar") + self.assertEqual(cmd.to_string(), "bar") + + def test_should_allow_to_reset_text(self): + cmd = XmlCommand("foo") + sub_cmd = cmd.add_element("bar", "baz") + sub_cmd.set_text("qux") + + self.assertEqual(cmd.to_string(), "qux") + def test_should_convert_to_string(self): cmd = XmlCommand("foo") From 3abd3ae8942e01cb1038612494d453174189a3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 28 Jan 2025 15:00:58 +0100 Subject: [PATCH 6/6] Implement report config commands Extend GMP classed to support all report config commands. --- gvm/protocols/gmp/_gmp.py | 14 +- gvm/protocols/gmp/_gmp226.py | 116 ++++++- gvm/protocols/gmp/requests/v226/__init__.py | 3 + .../gmp/requests/v226/_report_configs.py | 292 +++++++++++------- .../gmp/requests/v226/test_report_configs.py | 251 +++++++++++++++ .../entities/report_configs/__init__.py | 20 ++ .../test_clone_report_config.py | 24 ++ .../test_create_report_config.py | 65 ++++ .../test_delete_report_config.py | 36 +++ .../report_configs/test_get_report_config.py | 22 ++ .../report_configs/test_get_report_configs.py | 41 +++ .../test_modify_report_config.py | 60 ++++ .../gmpv226/entities/test_report_configs.py | 44 +++ 13 files changed, 872 insertions(+), 116 deletions(-) create mode 100644 tests/protocols/gmp/requests/v226/test_report_configs.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/__init__.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/test_clone_report_config.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/test_create_report_config.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/test_delete_report_config.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/test_get_report_config.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/test_get_report_configs.py create mode 100644 tests/protocols/gmpv226/entities/report_configs/test_modify_report_config.py create mode 100644 tests/protocols/gmpv226/entities/test_report_configs.py diff --git a/gvm/protocols/gmp/_gmp.py b/gvm/protocols/gmp/_gmp.py index 0e038f293..5325d3be2 100644 --- a/gvm/protocols/gmp/_gmp.py +++ b/gvm/protocols/gmp/_gmp.py @@ -2,9 +2,11 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +import warnings from types import TracebackType from typing import Callable, Optional, Type, Union +from gvm.__version__ import __version__ from gvm.connections import GvmConnection from gvm.errors import GvmError from gvm.protocols.core import Response @@ -16,6 +18,7 @@ from .requests import Version SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T]] +_SUPPORTED_GMP_VERSION_STRINGS = ["22.4", "22.5", "22.6"] class GMP(GvmProtocol[T]): @@ -91,12 +94,21 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS: gmp_class = GMPv224 elif major_version == 22 and minor_version == 5: gmp_class = GMPv225 - elif major_version == 22 and minor_version == 6: + elif major_version == 22 and minor_version >= 6: gmp_class = GMPv226 + if minor_version > 6: + warnings.warn( + "Remote manager daemon uses a newer GMP version then " + f"supported by python-gvm {__version__}. Please update to " + "a newer release of python-gvm if possible. " + f"Remote GMP version is {major_version}.{minor_version}. " + f"Supported GMP versions are {', '.join(_SUPPORTED_GMP_VERSION_STRINGS)}." + ) else: raise GvmError( "Remote manager daemon uses an unsupported version of GMP. " f"The GMP version was {major_version}.{minor_version}" + f"Supported GMP versions are {', '.join(_SUPPORTED_GMP_VERSION_STRINGS)}." ) return gmp_class(self._connection, transform=self._transform_callable) # type: ignore[arg-type] diff --git a/gvm/protocols/gmp/_gmp226.py b/gvm/protocols/gmp/_gmp226.py index 91554c694..73b9ecc52 100644 --- a/gvm/protocols/gmp/_gmp226.py +++ b/gvm/protocols/gmp/_gmp226.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2024 Greenbone AG +# SPDX-FileCopyrightText: 2025 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later @@ -6,7 +6,7 @@ Greenbone Management Protocol (GMP) version 22.6 """ -from typing import Optional, Union +from typing import Optional, Sequence, Union from .._protocol import T from ._gmp225 import GMPv225 @@ -15,6 +15,8 @@ EntityID, Filters, FilterType, + ReportConfigParameter, + ReportConfigs, ReportFormatType, Reports, ResourceNames, @@ -334,3 +336,113 @@ def modify_filter( filter_type=filter_type, ) ) + + def clone_report_config(self, report_config_id: EntityID) -> T: + """Clone a report config from an existing one + + Args: + report_config_id: UUID of the existing report config + """ + return self._send_and_transform_command( + ReportConfigs.clone_report_config(report_config_id) + ) + + def delete_report_config( + self, + report_config_id: EntityID, + *, + ultimate: Optional[bool] = False, + ) -> T: + """Deletes an existing report config + + Args: + report_config_id: UUID of the report config to be deleted. + ultimate: Whether to remove entirely, or to the trashcan. + """ + return self._send_and_transform_command( + ReportConfigs.delete_report_config( + report_config_id, ultimate=ultimate + ) + ) + + def get_report_configs( + self, + *, + filter_string: Optional[str] = None, + filter_id: Optional[EntityID] = None, + trash: Optional[bool] = None, + details: Optional[bool] = None, + ) -> T: + """Request a list of report configs + + Args: + filter_string: Filter term to use for the query + filter_id: UUID of an existing filter to use for the query + trash: Whether to get the trashcan report configs instead + details: Include report config details + """ + return self._send_and_transform_command( + ReportConfigs.get_report_configs( + filter_string=filter_string, + filter_id=filter_id, + trash=trash, + details=details, + ) + ) + + def get_report_config( + self, + report_config_id: EntityID, + ) -> T: + """Request a single report config + + Args: + report_config_id: UUID of an existing report config + """ + return self._send_and_transform_command( + ReportConfigs.get_report_config(report_config_id) + ) + + def create_report_config( + self, + name: str, + report_format_id: Union[EntityID, ReportFormatType], + *, + comment: Optional[str] = None, + params: Optional[Sequence[ReportConfigParameter]] = None, + ) -> T: + """Create a report config + + Args: + name: Name of the new report config + report_format_id: UUID of the report format to be used or ReportFormatType. + comment: An optional comment for the report config. + params: A list of report config parameters. + """ + return self._send_and_transform_command( + ReportConfigs.create_report_config( + name, report_format_id, comment=comment, params=params + ) + ) + + def modify_report_config( + self, + report_config_id: EntityID, + *, + name: Optional[str] = None, + comment: Optional[str] = None, + params: Optional[Sequence[ReportConfigParameter]] = None, + ) -> T: + """Create a report config + + Args: + name: Name of the report config + report_config_id: UUID of the report config to be modified. + comment: An optional comment for the report config. + params: A list of report config parameters. + """ + return self._send_and_transform_command( + ReportConfigs.modify_report_config( + report_config_id, name=name, comment=comment, params=params + ) + ) diff --git a/gvm/protocols/gmp/requests/v226/__init__.py b/gvm/protocols/gmp/requests/v226/__init__.py index 514584418..268e2a07e 100644 --- a/gvm/protocols/gmp/requests/v226/__init__.py +++ b/gvm/protocols/gmp/requests/v226/__init__.py @@ -71,6 +71,7 @@ ) from ._audit_reports import AuditReports from ._filters import Filters, FilterType +from ._report_configs import ReportConfigParameter, ReportConfigs from ._reports import Reports from ._resource_names import ResourceNames, ResourceType @@ -113,6 +114,8 @@ "Policies", "PortLists", "PortRangeType", + "ReportConfigs", + "ReportConfigParameter", "ReportFormatType", "ReportFormats", "Reports", diff --git a/gvm/protocols/gmp/requests/v226/_report_configs.py b/gvm/protocols/gmp/requests/v226/_report_configs.py index 55bdee79b..4f4268784 100644 --- a/gvm/protocols/gmp/requests/v226/_report_configs.py +++ b/gvm/protocols/gmp/requests/v226/_report_configs.py @@ -1,28 +1,51 @@ -# SPDX-FileCopyrightText: 2021-2024 Greenbone AG +# SPDX-FileCopyrightText: 2025 Greenbone AG # # SPDX-License-Identifier: GPL-3.0-or-later # -from typing import Optional, Union +from dataclasses import dataclass +from typing import Optional, Sequence, Union -from gvm.errors import InvalidArgument, RequiredArgument +from gvm.errors import RequiredArgument from gvm.protocols.core import Request from gvm.utils import to_bool -from gvm.xml import XmlCommand, XmlError +from gvm.xml import XmlCommand from .._entity_id import EntityID from ..v224._report_formats import ReportFormatType -class ReportConfigs: +@dataclass +class ReportConfigParameter: + """ + A class to represent a parameter for a report configuration. + + Args: + name: The name of the parameter. + value: The value of the parameter. + use_default (optional): A flag indicating whether to use the default value (default is False). + """ + + name: str + value: Optional[str] = None + use_default: bool = False + +class ReportConfigs: @classmethod def clone_report_config(cls, report_config_id: EntityID) -> Request: """Clone a report config from an existing one Args: - report_config_id: UUID of the existing report format - or ReportFormatType (enum) + report_config_id: UUID of the existing report config + + Example: + + .. code-block:: python + + from gvm.protocols.gmp.requests.v226 import ReportConfigs + + request = ReportConfigs.clone_report_config("report_config_id") """ if not report_config_id: raise RequiredArgument( @@ -35,193 +58,236 @@ def clone_report_config(cls, report_config_id: EntityID) -> Request: return cmd @classmethod - def delete_report_format( + def delete_report_config( cls, - report_format_id: Union[EntityID, ReportFormatType], + report_config_id: EntityID, *, ultimate: Optional[bool] = False, ) -> Request: - """Deletes an existing report format + """Deletes an existing report config Args: - report_format_id: UUID of the report format to be deleted. - or ReportFormatType (enum) + report_config_id: UUID of the report config to be deleted. ultimate: Whether to remove entirely, or to the trashcan. + + Example: + + .. code-block:: python + + from gvm.protocols.gmp.requests.v226 import ReportConfigs + + request = ReportConfigs.delete_report_config("report_config_id", ultimate=True) """ - if not report_format_id: + if not report_config_id: raise RequiredArgument( - function=cls.delete_report_format.__name__, - argument="report_format_id", + function=cls.delete_report_config.__name__, + argument="report_config_id", ) - cmd = XmlCommand("delete_report_format") + cmd = XmlCommand("delete_report_config") - cmd.set_attribute("report_format_id", str(report_format_id)) + cmd.set_attribute("report_config_id", str(report_config_id)) cmd.set_attribute("ultimate", to_bool(ultimate)) return cmd @staticmethod - def get_report_formats( + def get_report_configs( *, filter_string: Optional[str] = None, filter_id: Optional[EntityID] = None, trash: Optional[bool] = None, - alerts: Optional[bool] = None, - params: Optional[bool] = None, details: Optional[bool] = None, ) -> Request: - """Request a list of report formats + """Request a list of report configs Args: filter_string: Filter term to use for the query filter_id: UUID of an existing filter to use for the query - trash: Whether to get the trashcan report formats instead - alerts: Whether to include alerts that use the report format - params: Whether to include report format parameters - details: Include report format file, signature and parameters + trash: Whether to get the trashcan report configs instead + details: Include report config details + + Examples: + + .. code-block:: python + + from gvm.protocols.gmp.requests.v226 import ReportConfigs + + request = ReportConfigs.get_report_configs() + + .. code-block:: python + + from gvm.protocols.gmp.requests.v226 import ReportConfigs + + request = ReportConfigs.get_report_configs(filter_string="name=foo", details=True) """ - cmd = XmlCommand("get_report_formats") + cmd = XmlCommand("get_report_configs") cmd.add_filter(filter_string, filter_id) if details is not None: cmd.set_attribute("details", to_bool(details)) - if alerts is not None: - cmd.set_attribute("alerts", to_bool(alerts)) - - if params is not None: - cmd.set_attribute("params", to_bool(params)) - if trash is not None: cmd.set_attribute("trash", to_bool(trash)) return cmd @classmethod - def get_report_format( - cls, report_format_id: Union[EntityID, ReportFormatType] + def get_report_config( + cls, + report_config_id: EntityID, ) -> Request: - """Request a single report format + """Request a single report config Args: - report_format_id: UUID of an existing report format - or ReportFormatType (enum) + report_config_id: UUID of an existing report config + + Example: + + .. code-block:: python + + from gvm.protocols.gmp.requests.v226 import ReportConfigs + + request = ReportConfigs.get_report_config("report_config_id") """ - if not report_format_id: + if not report_config_id: raise RequiredArgument( - function=cls.get_report_format.__name__, - argument="report_format_id", + function=cls.get_report_config.__name__, + argument="report_config_id", ) - cmd = XmlCommand("get_report_formats") + cmd = XmlCommand("get_report_configs") - cmd.set_attribute("report_format_id", str(report_format_id)) + cmd.set_attribute("report_config_id", str(report_config_id)) # for single entity always request all details cmd.set_attribute("details", "1") return cmd @classmethod - def import_report_format(cls, report_format: str) -> Request: - """Import a report format from XML + def create_report_config( + cls, + name: str, + report_format_id: Union[EntityID, ReportFormatType], + *, + comment: Optional[str] = None, + params: Optional[Sequence[ReportConfigParameter]] = None, + ) -> Request: + """Create a report config Args: - report_format: Report format XML as string to import. This XML must - contain a :code:`` root element. + name: The name of the report config. + report_format_id: UUID of the report format to be used or ReportFormatType. + comment: An optional comment for the report config. + params: A list of report config parameters. + + Example: + + .. code-block:: python + + from gvm.protocols.gmp.requests.v226 import ReportConfigs, ReportFormatType + + request = ReportConfigs.create_report_config( + "Adjusted Node Distance", + ReportFormatType.SVG, + params=[ + ReportConfigParameter("Graph Type", use_default=True), + ReportConfigParameter("Node Distance", "5"), + ], + ) """ - if not report_format: + if not name: raise RequiredArgument( - function=cls.import_report_format.__name__, - argument="report_format", + function=cls.create_report_config.__name__, + argument="name", + ) + if not report_format_id: + raise RequiredArgument( + function=cls.create_report_config.__name__, + argument="report_format_id", ) - cmd = XmlCommand("create_report_format") - - try: - cmd.append_xml_str(report_format) - except XmlError as e: - raise InvalidArgument( - function=cls.import_report_format.__name__, - argument="report_format", - ) from e + cmd = XmlCommand("create_report_config") + cmd.add_element("name", name) + cmd.add_element("report_format", attrs={"id": str(report_format_id)}) + if comment: + cmd.add_element("comment", comment) + + if params: + for param in params: + xml_param = cmd.add_element("param") + xml_param.add_element("name", param.name) + value = xml_param.add_element("value") + value.set_attribute("use_default", to_bool(param.use_default)) + if param.value is not None and not param.use_default: + value.set_text(param.value) return cmd @classmethod - def modify_report_format( + def modify_report_config( cls, - report_format_id: Union[EntityID, ReportFormatType], + report_config_id: EntityID, *, - active: Optional[bool] = None, name: Optional[str] = None, - summary: Optional[str] = None, - param_name: Optional[str] = None, - param_value: Optional[str] = None, + comment: Optional[str] = None, + params: Optional[Sequence[ReportConfigParameter]] = None, ) -> Request: - """Modifies an existing report format. + """Create a report config Args: - report_format_id: UUID of report format to modify - or ReportFormatType (enum) - active: Whether the report format is active. - name: The name of the report format. - summary: A summary of the report format. - param_name: The name of the param. - param_value: The value of the param. - """ - if not report_format_id: - raise RequiredArgument( - function=cls.modify_report_format.__name__, - argument="report_format_id ", - ) + name: The name of the report config. + report_config_id: UUID of the report config to be modified. + comment: An optional comment for the report config. + params: A list of report config parameters. - cmd = XmlCommand("modify_report_format") + Examples: - cmd.set_attribute("report_format_id", str(report_format_id)) + .. code-block:: python - if active is not None: - cmd.add_element("active", to_bool(active)) + from gvm.protocols.gmp.requests.v226 import ReportConfigs - if name: - cmd.add_element("name", name) + request = ReportConfigs.create_report_config( + report_config_id, + params=[ + ReportConfigParameter("Graph Type", use_default=True), + ReportConfigParameter("Node Distance", "5"), + ], + ) - if summary: - cmd.add_element("summary", summary) + .. code-block:: python - if param_name: - xml_param = cmd.add_element("param") - xml_param.add_element("name", param_name) + from gvm.protocols.gmp.requests.v226 import ReportConfigs - if param_value is not None: - xml_param.add_element("value", param_value) + request = ReportConfigs.create_report_config( + report_config_id, + name="Modified Report Config", + ) + """ + if not report_config_id: + raise RequiredArgument( + function=cls.modify_report_config.__name__, + argument="report_config_id", + ) - return cmd + cmd = XmlCommand("modify_report_config") + cmd.set_attribute("report_config_id", str(report_config_id)) - @classmethod - def verify_report_format( - cls, report_format_id: Union[EntityID, ReportFormatType] - ) -> Request: - """Verify an existing report format + if name: + cmd.add_element("name", name) - Verifies the trust level of an existing report format. It will be - checked whether the signature of the report format currently matches the - report format. This includes the script and files used to generate - reports of this format. It is *not* verified if the report format works - as expected by the user. + if comment: + cmd.add_element("comment", comment) - Args: - report_format_id: UUID of the report format to be verified - or ReportFormatType (enum) - """ - if not report_format_id: - raise RequiredArgument( - function=cls.verify_report_format.__name__, - argument="report_format_id", - ) + if params: + for param in params: + xml_param = cmd.add_element("param") + xml_param.add_element("name", param.name) + value = xml_param.add_element("value") + value.set_attribute("use_default", to_bool(param.use_default)) + if param.value is not None and not param.use_default: + value.set_text(param.value) - cmd = XmlCommand("verify_report_format") - cmd.set_attribute("report_format_id", str(report_format_id)) return cmd diff --git a/tests/protocols/gmp/requests/v226/test_report_configs.py b/tests/protocols/gmp/requests/v226/test_report_configs.py new file mode 100644 index 000000000..0604b14b2 --- /dev/null +++ b/tests/protocols/gmp/requests/v226/test_report_configs.py @@ -0,0 +1,251 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + +import unittest + +from gvm.errors import RequiredArgument +from gvm.protocols.gmp.requests.v226 import ReportConfigs, ReportFormatType +from gvm.protocols.gmp.requests.v226._report_configs import ( + ReportConfigParameter, +) + + +class ReportConfigsTestCase(unittest.TestCase): + def test_create_report_config(self): + request = ReportConfigs.create_report_config( + "report-config1", "report_format_id" + ) + self.assertEqual( + bytes(request), + b"" + b"report-config1" + b'' + b"", + ) + + def test_create_report_config_with_comment(self): + request = ReportConfigs.create_report_config( + "report-config1", "report_format_id", comment="foo" + ) + self.assertEqual( + bytes(request), + b"" + b"report-config1" + b'' + b"foo" + b"", + ) + + def test_create_report_config_with_params(self): + request = ReportConfigs.create_report_config( + "report-config1", + "report_format_id", + params=[ + ReportConfigParameter("name", "value"), + ReportConfigParameter("name2", "value2", use_default=True), + ReportConfigParameter("name3", use_default=True), + ], + ) + self.assertEqual( + bytes(request), + b"" + b"report-config1" + b'' + b'namevalue' + b'name2' + b'name3' + b"", + ) + + def test_create_report_config_missing_name(self): + with self.assertRaises(RequiredArgument): + ReportConfigs.create_report_config(None, "report_format_id") + + with self.assertRaises(RequiredArgument): + ReportConfigs.create_report_config("", "report_format_id") + + def test_create_report_config_missing_report_format_id(self): + with self.assertRaises(RequiredArgument): + ReportConfigs.create_report_config("foo", None) + + with self.assertRaises(RequiredArgument): + ReportConfigs.create_report_config("foo", "") + + def test_clone_report_config(self): + request = ReportConfigs.clone_report_config("report_config_id") + self.assertEqual( + bytes(request), + b"" + b"report_config_id" + b"", + ) + + request = ReportConfigs.clone_report_config(ReportFormatType.PDF) + self.assertEqual( + bytes(request), + b"" + b"c402cc3e-b531-11e1-9163-406186ea4fc5" + b"", + ) + + def test_clone_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + ReportConfigs.clone_report_config(None) + + with self.assertRaises(RequiredArgument): + ReportConfigs.clone_report_config("") + + def test_delete_report_config(self): + request = ReportConfigs.delete_report_config("report_config_id") + self.assertEqual( + bytes(request), + b'', + ) + + request = ReportConfigs.delete_report_config(ReportFormatType.PDF) + self.assertEqual( + bytes(request), + b'', + ) + + def test_delete_report_config_with_ultimate(self): + request = ReportConfigs.delete_report_config( + "report_config_id", ultimate=True + ) + self.assertEqual( + bytes(request), + b'', + ) + + request = ReportConfigs.delete_report_config( + ReportFormatType.PDF, ultimate=False + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_delete_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + ReportConfigs.delete_report_config(None) + + with self.assertRaises(RequiredArgument): + ReportConfigs.delete_report_config("") + + def test_get_report_configs(self): + request = ReportConfigs.get_report_configs() + self.assertEqual( + bytes(request), + b"", + ) + + def test_get_report_configs_with_filter_string(self): + request = ReportConfigs.get_report_configs( + filter_string="filter_string" + ) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_configs_with_filter_id(self): + request = ReportConfigs.get_report_configs(filter_id="filter_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_configs_with_details(self): + request = ReportConfigs.get_report_configs(details=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = ReportConfigs.get_report_configs(details=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_configs_with_trash(self): + request = ReportConfigs.get_report_configs(trash=True) + self.assertEqual( + bytes(request), + b'', + ) + + request = ReportConfigs.get_report_configs(trash=False) + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_config(self): + request = ReportConfigs.get_report_config("report_config_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_get_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + ReportConfigs.get_report_config(None) + + with self.assertRaises(RequiredArgument): + ReportConfigs.get_report_config("") + + def test_modify_report_config(self): + request = ReportConfigs.modify_report_config("report_config_id") + self.assertEqual( + bytes(request), + b'', + ) + + def test_modify_report_config_with_name(self): + request = ReportConfigs.modify_report_config( + "report_config_id", name="foo" + ) + self.assertEqual( + bytes(request), + b'' + b"foo" + b"", + ) + + def test_modify_report_config_with_comment(self): + request = ReportConfigs.modify_report_config( + "report_config_id", comment="foo" + ) + self.assertEqual( + bytes(request), + b'' + b"foo" + b"", + ) + + def test_modify_report_config_with_params(self): + request = ReportConfigs.modify_report_config( + "report_config_id", + params=[ + ReportConfigParameter("name", "value"), + ReportConfigParameter("name2", "value2", use_default=True), + ReportConfigParameter("name3", use_default=True), + ], + ) + self.assertEqual( + bytes(request), + b'' + b'namevalue' + b'name2' + b'name3' + b"", + ) + + def test_modify_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + ReportConfigs.modify_report_config(None) + + with self.assertRaises(RequiredArgument): + ReportConfigs.modify_report_config("") diff --git a/tests/protocols/gmpv226/entities/report_configs/__init__.py b/tests/protocols/gmpv226/entities/report_configs/__init__.py new file mode 100644 index 000000000..99c394b67 --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/__init__.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from .test_clone_report_config import GMPCloneReportConfigTestMixin +from .test_create_report_config import GMPCreateReportConfigTestMixin +from .test_delete_report_config import GMPDeleteReportConfigTestMixin +from .test_get_report_config import GMPGetReportConfigTestMixin +from .test_get_report_configs import GMPGetReportConfigsTestMixin +from .test_modify_report_config import GMPModifyReportConfigTestMixin + +__all__ = ( + "GMPCloneReportConfigTestMixin", + "GMPCreateReportConfigTestMixin", + "GMPDeleteReportConfigTestMixin", + "GMPGetReportConfigTestMixin", + "GMPGetReportConfigsTestMixin", + "GMPModifyReportConfigTestMixin", +) diff --git a/tests/protocols/gmpv226/entities/report_configs/test_clone_report_config.py b/tests/protocols/gmpv226/entities/report_configs/test_clone_report_config.py new file mode 100644 index 000000000..8b332f4c9 --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/test_clone_report_config.py @@ -0,0 +1,24 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument + + +class GMPCloneReportConfigTestMixin: + def test_clone_report_config(self): + self.gmp.clone_report_config("report_config_id") + + self.connection.send.has_been_called_with( + b"" + b"report_config_id" + b"", + ) + + def test_clone_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.clone_report_config(None) + + with self.assertRaises(RequiredArgument): + self.gmp.clone_report_config("") diff --git a/tests/protocols/gmpv226/entities/report_configs/test_create_report_config.py b/tests/protocols/gmpv226/entities/report_configs/test_create_report_config.py new file mode 100644 index 000000000..176ef8a26 --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/test_create_report_config.py @@ -0,0 +1,65 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument +from gvm.protocols.gmp._gmp226 import ReportConfigParameter + + +class GMPCreateReportConfigTestMixin: + def test_create_report_config(self): + self.gmp.create_report_config("r1", "report_format_id") + + self.connection.send.has_been_called_with( + b"" + b"r1" + b'' + b"" + ) + + def test_create_report_config_with_comment(self): + self.gmp.create_report_config("r1", "report_format_id", comment="foo") + + self.connection.send.has_been_called_with( + b"" + b"r1" + b'' + b"foo" + b"" + ) + + def test_create_report_config_with_params(self): + self.gmp.create_report_config( + "r1", + "report_format_id", + params=[ + ReportConfigParameter("name", "value"), + ReportConfigParameter("name2", "value2", use_default=True), + ReportConfigParameter("name3", use_default=True), + ], + ) + + self.connection.send.has_been_called_with( + b"" + b"r1" + b'' + b'namevalue' + b'name2' + b'name3' + b"", + ) + + def test_create_report_config_missing_name(self): + with self.assertRaises(RequiredArgument): + self.gmp.create_report_config(None, "report_format_id") + + with self.assertRaises(RequiredArgument): + self.gmp.create_report_config("", "report_format_id") + + def test_create_report_config_missing_report_format_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.create_report_config("r1", None) + + with self.assertRaises(RequiredArgument): + self.gmp.create_report_config("r1", "") diff --git a/tests/protocols/gmpv226/entities/report_configs/test_delete_report_config.py b/tests/protocols/gmpv226/entities/report_configs/test_delete_report_config.py new file mode 100644 index 000000000..c6722ac19 --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/test_delete_report_config.py @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +from gvm.errors import GvmError + + +class GMPDeleteReportConfigTestMixin: + def test_delete(self): + self.gmp.delete_report_config("a1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_delete_with_ultimate(self): + self.gmp.delete_report_config("a1", ultimate=False) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.delete_report_config("a1", ultimate=True) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_missing_id(self): + with self.assertRaises(GvmError): + self.gmp.delete_report_config(None) + + with self.assertRaises(GvmError): + self.gmp.delete_report_config("") diff --git a/tests/protocols/gmpv226/entities/report_configs/test_get_report_config.py b/tests/protocols/gmpv226/entities/report_configs/test_get_report_config.py new file mode 100644 index 000000000..35f189585 --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/test_get_report_config.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +from gvm.errors import RequiredArgument + + +class GMPGetReportConfigTestMixin: + def test_get_report_config(self): + self.gmp.get_report_config("report_config_id") + + self.connection.send.has_been_called_with( + b'', + ) + + def test_get_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_report_config(None) + with self.assertRaises(RequiredArgument): + self.gmp.get_report_config("") diff --git a/tests/protocols/gmpv226/entities/report_configs/test_get_report_configs.py b/tests/protocols/gmpv226/entities/report_configs/test_get_report_configs.py new file mode 100644 index 000000000..fd88b1616 --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/test_get_report_configs.py @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +class GMPGetReportConfigsTestMixin: + def test_get_report_configs(self): + self.gmp.get_report_configs() + + self.connection.send.has_been_called_with( + b"", + ) + + def test_get_report_configs_with_filter_string(self): + self.gmp.get_report_configs(filter_string="filter_string") + + self.connection.send.has_been_called_with( + b'', + ) + + def test_get_report_configs_with_filter_id(self): + self.gmp.get_report_configs(filter_id="filter_id") + + self.connection.send.has_been_called_with( + b'', + ) + + def test_get_report_configs_with_details(self): + self.gmp.get_report_configs(details=True) + + self.connection.send.has_been_called_with( + b'', + ) + + def test_get_report_configs_with_trash(self): + self.gmp.get_report_configs(trash=True) + + self.connection.send.has_been_called_with( + b'', + ) diff --git a/tests/protocols/gmpv226/entities/report_configs/test_modify_report_config.py b/tests/protocols/gmpv226/entities/report_configs/test_modify_report_config.py new file mode 100644 index 000000000..8083ebeae --- /dev/null +++ b/tests/protocols/gmpv226/entities/report_configs/test_modify_report_config.py @@ -0,0 +1,60 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + + +from gvm.errors import RequiredArgument +from gvm.protocols.gmp._gmp226 import ReportConfigParameter + + +class GMPModifyReportConfigTestMixin: + def test_modify_report_config(self): + self.gmp.modify_report_config("report_config_id") + + self.connection.send.has_been_called_with( + b'', + ) + + def test_modify_report_config_with_name(self): + self.gmp.modify_report_config("report_config_id", name="foo") + + self.connection.send.has_been_called_with( + b'' + b"foo" + b"", + ) + + def test_modify_report_config_with_comment(self): + self.gmp.modify_report_config("report_config_id", comment="foo") + + self.connection.send.has_been_called_with( + b'' + b"foo" + b"", + ) + + def test_modify_report_config_with_params(self): + self.gmp.modify_report_config( + "report_config_id", + params=[ + ReportConfigParameter("name", "value"), + ReportConfigParameter("name2", "value2", use_default=True), + ReportConfigParameter("name3", use_default=True), + ], + ) + + self.connection.send.has_been_called_with( + b'' + b'namevalue' + b'name2' + b'name3' + b"", + ) + + def test_modify_report_config_missing_report_config_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.modify_report_config(None) + + with self.assertRaises(RequiredArgument): + self.gmp.modify_report_config("") diff --git a/tests/protocols/gmpv226/entities/test_report_configs.py b/tests/protocols/gmpv226/entities/test_report_configs.py new file mode 100644 index 000000000..2e055f0b6 --- /dev/null +++ b/tests/protocols/gmpv226/entities/test_report_configs.py @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: 2023-2024 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpv226 import GMPTestCase +from .report_configs import ( + GMPCloneReportConfigTestMixin, + GMPCreateReportConfigTestMixin, + GMPDeleteReportConfigTestMixin, + GMPGetReportConfigsTestMixin, + GMPGetReportConfigTestMixin, + GMPModifyReportConfigTestMixin, +) + + +class GMPCloneReportConfigTestCase(GMPCloneReportConfigTestMixin, GMPTestCase): + pass + + +class GMPCreateReportConfigTestCase( + GMPCreateReportConfigTestMixin, GMPTestCase +): + pass + + +class GMPDeleteReportConfigTestCase( + GMPDeleteReportConfigTestMixin, GMPTestCase +): + pass + + +class GMPGetReportConfigTestCase(GMPGetReportConfigTestMixin, GMPTestCase): + pass + + +class GMPGetReportConfigsTestCase(GMPGetReportConfigsTestMixin, GMPTestCase): + pass + + +class GMPModifyReportConfigTestCase( + GMPModifyReportConfigTestMixin, GMPTestCase +): + pass