diff --git a/gvm/protocols/gmpv208/__init__.py b/gvm/protocols/gmpv208/__init__.py index a295a0c36..0a9b6aca5 100644 --- a/gvm/protocols/gmpv208/__init__.py +++ b/gvm/protocols/gmpv208/__init__.py @@ -35,39 +35,32 @@ AlertEvent, AlertMethod, AlertsMixin, - get_alert_condition_from_string, - get_alert_event_from_string, - get_alert_method_from_string, ) from gvm.protocols.gmpv208.entities.audits import AuditsMixin from gvm.protocols.gmpv208.entities.credentials import ( CredentialFormat, CredentialsMixin, CredentialType, - get_credential_format_from_string, - get_credential_type_from_string, - get_snmp_auth_algorithm_from_string, - get_snmp_privacy_algorithm_from_string, SnmpAuthAlgorithm, SnmpPrivacyAlgorithm, ) from gvm.protocols.gmpv208.entities.entities import ( EntityType, - get_entity_type_from_string, ) from gvm.protocols.gmpv208.entities.filter import ( FiltersMixin, FilterType, - get_filter_type_from_string, ) from gvm.protocols.gmpv208.entities.groups import GroupsMixin from gvm.protocols.gmpv208.entities.hosts import ( HostsMixin, HostsOrdering, - get_hosts_ordering_from_string, +) +from gvm.protocols.gmpv208.entities.permissions import ( + PermissionsMixin, + PermissionSubjectType, ) from gvm.protocols.gmpv208.entities.port_lists import ( - get_port_range_type_from_string, PortListMixin, PortRangeType, ) @@ -77,72 +70,56 @@ OperatingSystemsMixin, ) from gvm.protocols.gmpv208.entities.overrides import OverridesMixin -from gvm.protocols.gmpv208.entities.permissions import ( - PermissionsMixin, - PermissionSubjectType, - get_permission_subject_type_from_string, -) from gvm.protocols.gmpv208.entities.policies import PoliciesMixin from gvm.protocols.gmpv208.entities.results import ResultsMixin from gvm.protocols.gmpv208.entities.report_formats import ( ReportFormatType, ReportFormatsMixin, - get_report_format_id_from_string, ) from gvm.protocols.gmpv208.entities.roles import RolesMixin from gvm.protocols.gmpv208.entities.scan_configs import ScanConfigsMixin from gvm.protocols.gmpv208.entities.scanners import ( ScannersMixin, ScannerType, - get_scanner_type_from_string, ) from gvm.protocols.gmpv208.entities.schedules import SchedulesMixin from gvm.protocols.gmpv208.entities.secinfo import ( - get_info_type_from_string, InfoType, SecInfoMixin, ) from gvm.protocols.gmpv208.entities.severity import ( SeverityLevel, - get_severity_level_from_string, ) from gvm.protocols.gmpv208.entities.tags import TagsMixin from gvm.protocols.gmpv208.entities.targets import ( AliveTest, - get_alive_test_from_string, TargetsMixin, ) from gvm.protocols.gmpv208.entities.tasks import TasksMixin from gvm.protocols.gmpv208.entities.tickets import ( TicketsMixin, TicketStatus, - get_ticket_status_from_string, ) from gvm.protocols.gmpv208.entities.tls_certificates import TLSCertificateMixin from gvm.protocols.gmpv208.entities.users import ( UserAuthType, UsersMixin, - get_user_auth_type_from_string, ) from gvm.protocols.gmpv208.entities.vulnerabilities import VulnerabilitiesMixin from gvm.protocols.gmpv208.system.aggregates import ( AggregatesMixin, AggregateStatistic, - get_aggregate_statistic_from_string, SortOrder, - get_sort_order_from_string, ) from gvm.protocols.gmpv208.system.authentication import AuthenticationMixin from gvm.protocols.gmpv208.system.feed import ( FeedType, FeedMixin, - get_feed_type_from_string, ) from gvm.protocols.gmpv208.system.help import ( HelpFormat, HelpMixin, - get_help_format_from_string, ) from gvm.protocols.gmpv208.system.system_reports import SystemReportsMixin from gvm.protocols.gmpv208.system.trashcan import TrashcanMixin diff --git a/gvm/protocols/gmpv208/entities/alerts.py b/gvm/protocols/gmpv208/entities/alerts.py index 7e045bf45..97d91ded1 100644 --- a/gvm/protocols/gmpv208/entities/alerts.py +++ b/gvm/protocols/gmpv208/entities/alerts.py @@ -37,21 +37,22 @@ class AlertEvent(Enum): ASSIGNED_TICKET_CHANGED = 'Assigned ticket changed' OWNED_TICKET_CHANGED = 'Owned ticket changed' - -def get_alert_event_from_string( - alert_event: Optional[str], -) -> Optional[AlertEvent]: - """Convert an alert event string into a AlertEvent instance""" - if not alert_event: - return None - - try: - return AlertEvent[alert_event.replace(' ', '_').upper()] - except KeyError: - raise InvalidArgument( - argument='alert_event', - function=get_alert_event_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + alert_event: Optional[str], + ) -> Optional["AlertEvent"]: + """Convert an alert event string into a AlertEvent instance""" + if not alert_event: + return None + + try: + return cls[alert_event.replace(' ', '_').upper()] + except KeyError: + raise InvalidArgument( + argument='alert_event', + function=cls.from_string.__name__, + ) from None class AlertCondition(Enum): @@ -64,21 +65,21 @@ class AlertCondition(Enum): FILTER_COUNT_CHANGED = 'Filter count changed' FILTER_COUNT_AT_LEAST = 'Filter count at least' - -def get_alert_condition_from_string( - alert_condition: Optional[str], -) -> Optional[AlertCondition]: - """Convert an alert condition string into a AlertCondition instance""" - if not alert_condition: - return None - - try: - return AlertCondition[alert_condition.replace(' ', '_').upper()] - except KeyError: - raise InvalidArgument( - argument='alert_condition', - function=get_alert_condition_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, alert_condition: Optional[str] + ) -> Optional["AlertCondition"]: + """Convert an alert condition string into a AlertCondition instance""" + if not alert_condition: + return None + + try: + return cls[alert_condition.replace(' ', '_').upper()] + except KeyError: + raise InvalidArgument( + argument='alert_condition', + function=cls.from_string.__name__, + ) from None class AlertMethod(Enum): @@ -97,21 +98,22 @@ class AlertMethod(Enum): TIPPINGPOINT_SMS = "TippingPoint SMS" ALEMBA_VFIRE = "Alemba vFire" - -def get_alert_method_from_string( - alert_method: Optional[str], -) -> Optional[AlertMethod]: - """Convert an alert method string into a AlertCondition instance""" - if not alert_method: - return None - - try: - return AlertMethod[alert_method.replace(' ', '_').upper()] - except KeyError: - raise InvalidArgument( - argument='alert_method', - function=get_alert_method_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + alert_method: Optional[str], + ) -> Optional["AlertMethod"]: + """Convert an alert method string into a AlertCondition instance""" + if not alert_method: + return None + + try: + return cls[alert_method.replace(' ', '_').upper()] + except KeyError: + raise InvalidArgument( + argument='alert_method', + function=cls.from_string.__name__, + ) from None def _check_event( diff --git a/gvm/protocols/gmpv208/entities/credentials.py b/gvm/protocols/gmpv208/entities/credentials.py index ba33a617e..196d615b4 100644 --- a/gvm/protocols/gmpv208/entities/credentials.py +++ b/gvm/protocols/gmpv208/entities/credentials.py @@ -34,20 +34,21 @@ class CredentialFormat(Enum): EXE = 'exe' PEM = 'pem' - -def get_credential_format_from_string( - credential_format: Optional[str], -) -> Optional[CredentialFormat]: - if not credential_format: - return None - - try: - return CredentialFormat[credential_format.upper()] - except KeyError: - raise InvalidArgument( - argument='credential_format', - function=get_credential_format_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + credential_format: Optional[str], + ) -> Optional["CredentialFormat"]: + if not credential_format: + return None + + try: + return cls[credential_format.upper()] + except KeyError: + raise InvalidArgument( + argument='credential_format', + function=cls.from_string.__name__, + ) from None class CredentialType(Enum): @@ -61,21 +62,22 @@ class CredentialType(Enum): PGP_ENCRYPTION_KEY = 'pgp' PASSWORD_ONLY = 'pw' - -def get_credential_type_from_string( - credential_type: Optional[str], -) -> Optional[CredentialType]: - """Convert a credential type string into a CredentialType instance""" - if not credential_type: - return None - - try: - return CredentialType[credential_type.upper()] - except KeyError: - raise InvalidArgument( - argument='credential_type', - function=get_credential_type_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + credential_type: Optional[str], + ) -> Optional["CredentialType"]: + """Convert a credential type string into a CredentialType instance""" + if not credential_type: + return None + + try: + return cls[credential_type.upper()] + except KeyError: + raise InvalidArgument( + argument='credential_type', + function=cls.from_string.__name__, + ) from None class SnmpAuthAlgorithm(Enum): @@ -84,21 +86,23 @@ class SnmpAuthAlgorithm(Enum): SHA1 = 'sha1' MD5 = 'md5' - -def get_snmp_auth_algorithm_from_string( - algorithm: Optional[str], -) -> Optional[SnmpAuthAlgorithm]: - """Convert a SNMP auth algorithm string into a SnmpAuthAlgorithm instance""" - if not algorithm: - return None - - try: - return SnmpAuthAlgorithm[algorithm.upper()] - except KeyError: - raise InvalidArgument( - argument='algorithm', - function=get_snmp_auth_algorithm_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + algorithm: Optional[str], + ) -> Optional["SnmpAuthAlgorithm"]: + """Convert a SNMP auth algorithm string into a + SnmpAuthAlgorithm instance""" + if not algorithm: + return None + + try: + return cls[algorithm.upper()] + except KeyError: + raise InvalidArgument( + argument='algorithm', + function=cls.from_string.__name__, + ) from None class SnmpPrivacyAlgorithm(Enum): @@ -107,23 +111,24 @@ class SnmpPrivacyAlgorithm(Enum): AES = 'aes' DES = 'des' - -def get_snmp_privacy_algorithm_from_string( - algorithm: Optional[str], -) -> Optional[SnmpPrivacyAlgorithm]: - """Convert a SNMP privacy algorithm string into a SnmpPrivacyAlgorithm - instance - """ - if not algorithm: - return None - - try: - return SnmpPrivacyAlgorithm[algorithm.upper()] - except KeyError: - raise InvalidArgument( - argument='algorithm', - function=get_snmp_privacy_algorithm_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + algorithm: Optional[str], + ) -> Optional["SnmpPrivacyAlgorithm"]: + """Convert a SNMP privacy algorithm string into a SnmpPrivacyAlgorithm + instance + """ + if not algorithm: + return None + + try: + return cls[algorithm.upper()] + except KeyError: + raise InvalidArgument( + argument='algorithm', + function=cls.from_string.__name__, + ) from None class CredentialsMixin: diff --git a/gvm/protocols/gmpv208/entities/entities.py b/gvm/protocols/gmpv208/entities/entities.py index 672fab478..fdb89869d 100644 --- a/gvm/protocols/gmpv208/entities/entities.py +++ b/gvm/protocols/gmpv208/entities/entities.py @@ -60,34 +60,35 @@ class EntityType(Enum): USER = "user" VULNERABILITY = "vuln" + @classmethod + def from_string( + cls, + entity_type: Optional[str], + ) -> Optional["EntityType"]: + """Convert a entity type string to an actual EntityType instance -def get_entity_type_from_string( - entity_type: Optional[str], -) -> Optional[EntityType]: - """Convert a entity type string to an actual EntityType instance + Arguments: + entity_type: Entity type string to convert to a EntityType + """ + if not entity_type: + return None - Arguments: - entity_type: Entity type string to convert to a EntityType - """ - if not entity_type: - return None + if entity_type == 'vuln': + return cls.VULNERABILITY - if entity_type == 'vuln': - return EntityType.VULNERABILITY + if entity_type == 'os': + return cls.OPERATING_SYSTEM - if entity_type == 'os': - return EntityType.OPERATING_SYSTEM + if entity_type == 'config': + return cls.SCAN_CONFIG - if entity_type == 'config': - return EntityType.SCAN_CONFIG + if entity_type == 'tls_certificate': + return cls.TLS_CERTIFICATE - if entity_type == 'tls_certificate': - return EntityType.TLS_CERTIFICATE - - try: - return EntityType[entity_type.upper()] - except KeyError: - raise InvalidArgument( - argument='entity_type', - function=get_entity_type_from_string.__name__, - ) from None + try: + return cls[entity_type.upper()] + except KeyError: + raise InvalidArgument( + argument='entity_type', + function=cls.from_string.__name__, + ) from None diff --git a/gvm/protocols/gmpv208/entities/filter.py b/gvm/protocols/gmpv208/entities/filter.py index 2c03a9caf..58def9bb3 100644 --- a/gvm/protocols/gmpv208/entities/filter.py +++ b/gvm/protocols/gmpv208/entities/filter.py @@ -53,37 +53,38 @@ class FilterType(Enum): 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 -def get_filter_type_from_string( - filter_type: Optional[str], -) -> Optional[FilterType]: - """Convert a filter type string to an actual FilterType instance - - Arguments: - filter_type (str): Filter type string to convert to a FilterType - """ - if not filter_type: - return None + Arguments: + filter_type (str): Filter type string to convert to a FilterType + """ + if not filter_type: + return None - if filter_type == 'vuln': - return FilterType.VULNERABILITY + if filter_type == 'vuln': + return cls.VULNERABILITY - if filter_type == 'os': - return FilterType.OPERATING_SYSTEM + if filter_type == 'os': + return cls.OPERATING_SYSTEM - if filter_type == 'config': - return FilterType.SCAN_CONFIG + if filter_type == 'config': + return cls.SCAN_CONFIG - if filter_type == 'secinfo': - return FilterType.ALL_SECINFO + if filter_type == 'secinfo': + return cls.ALL_SECINFO - try: - return FilterType[filter_type.upper()] - except KeyError: - raise InvalidArgument( - argument='filter_type', - function=get_filter_type_from_string.__name__, - ) from None + try: + return cls[filter_type.upper()] + except KeyError: + raise InvalidArgument( + argument='filter_type', + function=cls.from_string.__name__, + ) from None class FiltersMixin: diff --git a/gvm/protocols/gmpv208/entities/hosts.py b/gvm/protocols/gmpv208/entities/hosts.py index 221a29d37..e468c346d 100644 --- a/gvm/protocols/gmpv208/entities/hosts.py +++ b/gvm/protocols/gmpv208/entities/hosts.py @@ -32,24 +32,25 @@ class HostsOrdering(Enum): RANDOM = "random" REVERSE = "reverse" + @classmethod + def from_string( + cls, + hosts_ordering: Optional[str], + ) -> Optional["HostsOrdering"]: + """Convert a hosts ordering string to an actual HostsOrdering instance -def get_hosts_ordering_from_string( - hosts_ordering: Optional[str], -) -> Optional[HostsOrdering]: - """Convert a hosts ordering string to an actual HostsOrdering instance - - Arguments: - hosts_ordering: Host ordering string to convert to a HostsOrdering - """ - if not hosts_ordering: - return None - try: - return HostsOrdering[hosts_ordering.upper()] - except KeyError: - raise InvalidArgument( - argument='hosts_ordering', - function=get_hosts_ordering_from_string.__name__, - ) from None + Arguments: + hosts_ordering: Host ordering string to convert to a HostsOrdering + """ + if not hosts_ordering: + return None + try: + return cls[hosts_ordering.upper()] + except KeyError: + raise InvalidArgument( + argument='hosts_ordering', + function=cls.from_string.__name__, + ) from None class HostsMixin: diff --git a/gvm/protocols/gmpv208/entities/permissions.py b/gvm/protocols/gmpv208/entities/permissions.py index 47c2230c4..aec48ab8f 100644 --- a/gvm/protocols/gmpv208/entities/permissions.py +++ b/gvm/protocols/gmpv208/entities/permissions.py @@ -32,27 +32,28 @@ class PermissionSubjectType(Enum): GROUP = 'group' ROLE = 'role' + @classmethod + def from_string( + cls, + subject_type: Optional[str], + ) -> Optional["PermissionSubjectType"]: + """Convert a permission subject type string to an actual + PermissionSubjectType instance -def get_permission_subject_type_from_string( - subject_type: Optional[str], -) -> Optional[PermissionSubjectType]: - """Convert a permission subject type string to an actual - PermissionSubjectType instance - - Arguments: - subject_type: Permission subject type string to convert to a - PermissionSubjectType - """ - if not subject_type: - return None - - try: - return PermissionSubjectType[subject_type.upper()] - except KeyError: - raise InvalidArgument( - argument='subject_type', - function=get_permission_subject_type_from_string.__name__, - ) from None + Arguments: + subject_type: Permission subject type string to convert to a + PermissionSubjectType + """ + if not subject_type: + return None + + try: + return cls[subject_type.upper()] + except KeyError: + raise InvalidArgument( + argument='subject_type', + function=cls.from_string.__name__, + ) from None class PermissionsMixin: diff --git a/gvm/protocols/gmpv208/entities/port_lists.py b/gvm/protocols/gmpv208/entities/port_lists.py index c5b9af733..97f544af8 100644 --- a/gvm/protocols/gmpv208/entities/port_lists.py +++ b/gvm/protocols/gmpv208/entities/port_lists.py @@ -31,25 +31,28 @@ class PortRangeType(Enum): TCP = 'TCP' UDP = 'UDP' + @classmethod + def from_string( + cls, + port_range_type: Optional[str], + ) -> Optional["PortRangeType"]: + """Convert a port range type string to an actual + PortRangeType instance -def get_port_range_type_from_string( - port_range_type: Optional[str], -) -> Optional[PortRangeType]: - """Convert a port range type string to an actual PortRangeType instance - - Arguments: - port_range_type: Port range type string to convert to a PortRangeType - """ - if not port_range_type: - return None - - try: - return PortRangeType[port_range_type.upper()] - except KeyError: - raise InvalidArgument( - argument='port_range_type', - function=get_port_range_type_from_string.__name__, - ) from None + Arguments: + port_range_type: Port range type string to + convert to a PortRangeType + """ + if not port_range_type: + return None + + try: + return cls[port_range_type.upper()] + except KeyError: + raise InvalidArgument( + argument='port_range_type', + function=cls.from_string.__name__, + ) from None class PortListMixin: diff --git a/gvm/protocols/gmpv208/entities/report_formats.py b/gvm/protocols/gmpv208/entities/report_formats.py index e1ced8ac8..dfdb27a28 100644 --- a/gvm/protocols/gmpv208/entities/report_formats.py +++ b/gvm/protocols/gmpv208/entities/report_formats.py @@ -48,21 +48,22 @@ class ReportFormatType(Enum): VERINICE_ITG = '50c9950a-f326-11e4-800c-28d24461215b' XML = 'a994b278-1f62-11e1-96ac-406186ea4fc5' + @classmethod + def from_string( + cls, + report_format: Optional[str], + ) -> Optional["ReportFormatType"]: + """Convert an report format name into a ReportFormatType instance""" + if not report_format: + return None -def get_report_format_id_from_string( - report_format: Optional[str], -) -> Optional[ReportFormatType]: - """Convert an report format name into a ReportFormatType instance""" - if not report_format: - return None - - try: - return ReportFormatType[report_format.replace(' ', '_').upper()] - except KeyError: - raise InvalidArgument( - argument='report_format', - function=get_report_format_id_from_string.__name__, - ) from KeyError + try: + return cls[report_format.replace(' ', '_').upper()] + except KeyError: + raise InvalidArgument( + argument='report_format', + function=cls.from_string.__name__, + ) from KeyError class ReportFormatsMixin: diff --git a/gvm/protocols/gmpv208/entities/scanners.py b/gvm/protocols/gmpv208/entities/scanners.py index 8ee50db14..f89ce87e1 100644 --- a/gvm/protocols/gmpv208/entities/scanners.py +++ b/gvm/protocols/gmpv208/entities/scanners.py @@ -33,53 +33,45 @@ class ScannerType(Enum): GMP_SCANNER_TYPE = "4" # formerly slave scanner GREENBONE_SENSOR_SCANNER_TYPE = "5" + @classmethod + def from_string( + cls, + scanner_type: Optional[str], + ) -> Optional["ScannerType"]: + """Convert a scanner type string to an actual ScannerType instance -def get_scanner_type_from_string( - scanner_type: Optional[str], -) -> Optional[ScannerType]: - """Convert a scanner type string to an actual ScannerType instance - - Arguments: - scanner_type: Scanner type string to convert to a ScannerType - """ - if not scanner_type: - return None - - scanner_type = scanner_type.lower() - - if ( - scanner_type == ScannerType.OSP_SCANNER_TYPE.value - or scanner_type == 'osp' - ): - return ScannerType.OSP_SCANNER_TYPE - - if ( - scanner_type == ScannerType.OPENVAS_SCANNER_TYPE.value - or scanner_type == 'openvas' - ): - return ScannerType.OPENVAS_SCANNER_TYPE - - if ( - scanner_type == ScannerType.CVE_SCANNER_TYPE.value - or scanner_type == 'cve' - ): - return ScannerType.CVE_SCANNER_TYPE - - if ( - scanner_type == ScannerType.GMP_SCANNER_TYPE.value - or scanner_type == 'gmp' - ): - return ScannerType.GMP_SCANNER_TYPE - - if ( - scanner_type == ScannerType.GREENBONE_SENSOR_SCANNER_TYPE.value - or scanner_type == 'greenbone' - ): - return ScannerType.GREENBONE_SENSOR_SCANNER_TYPE - - raise InvalidArgument( - argument='scanner_type', function=get_scanner_type_from_string.__name__ - ) + Arguments: + scanner_type: Scanner type string to convert to a ScannerType + """ + if not scanner_type: + return None + + scanner_type = scanner_type.lower() + + if scanner_type == cls.OSP_SCANNER_TYPE.value or scanner_type == 'osp': + return cls.OSP_SCANNER_TYPE + + if ( + scanner_type == cls.OPENVAS_SCANNER_TYPE.value + or scanner_type == 'openvas' + ): + return cls.OPENVAS_SCANNER_TYPE + + if scanner_type == cls.CVE_SCANNER_TYPE.value or scanner_type == 'cve': + return cls.CVE_SCANNER_TYPE + + if scanner_type == cls.GMP_SCANNER_TYPE.value or scanner_type == 'gmp': + return cls.GMP_SCANNER_TYPE + + if ( + scanner_type == cls.GREENBONE_SENSOR_SCANNER_TYPE.value + or scanner_type == 'greenbone' + ): + return cls.GREENBONE_SENSOR_SCANNER_TYPE + + raise InvalidArgument( + argument='scanner_type', function=cls.from_string.__name__ + ) class ScannersMixin: diff --git a/gvm/protocols/gmpv208/entities/secinfo.py b/gvm/protocols/gmpv208/entities/secinfo.py index fc07a8275..a355a6d5a 100644 --- a/gvm/protocols/gmpv208/entities/secinfo.py +++ b/gvm/protocols/gmpv208/entities/secinfo.py @@ -34,21 +34,21 @@ class InfoType(Enum): OVALDEF = "OVALDEF" NVT = "NVT" + @classmethod + def from_string(cls, info_type: Optional[str]) -> Optional["InfoType"]: + """Convert a info type string to an actual InfoType instance -def get_info_type_from_string(info_type: Optional[str]) -> Optional[InfoType]: - """Convert a info type string to an actual InfoType instance - - Arguments: - info_type: Info type string to convert to a InfoType - """ - if not info_type: - return None - try: - return InfoType[info_type.upper()] - except KeyError: - raise InvalidArgument( - argument='info_type', function=get_info_type_from_string.__name__ - ) from None + Arguments: + info_type: Info type string to convert to a InfoType + """ + if not info_type: + return None + try: + return cls[info_type.upper()] + except KeyError: + raise InvalidArgument( + argument='info_type', function=cls.from_string.__name__ + ) from None class SecInfoMixin: diff --git a/gvm/protocols/gmpv208/entities/severity.py b/gvm/protocols/gmpv208/entities/severity.py index 724784add..19dee78a1 100644 --- a/gvm/protocols/gmpv208/entities/severity.py +++ b/gvm/protocols/gmpv208/entities/severity.py @@ -36,18 +36,19 @@ class SeverityLevel(Enum): ALARM = "Alarm" DEBUG = "Debug" - -def get_severity_level_from_string( - severity_level: Optional[str], -) -> Optional[SeverityLevel]: - """Convert a severity level string into a SeverityLevel instance""" - if not severity_level: - return None - - try: - return SeverityLevel[severity_level.upper()] - except KeyError: - raise InvalidArgument( - argument='severity_level', - function=get_severity_level_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + severity_level: Optional[str], + ) -> Optional["SeverityLevel"]: + """Convert a severity level string into a SeverityLevel instance""" + if not severity_level: + return None + + try: + return cls[severity_level.upper()] + except KeyError: + raise InvalidArgument( + argument='severity_level', + function=cls.from_string.__name__, + ) from None diff --git a/gvm/protocols/gmpv208/entities/targets.py b/gvm/protocols/gmpv208/entities/targets.py index 0541e0fe1..313e30a6b 100644 --- a/gvm/protocols/gmpv208/entities/targets.py +++ b/gvm/protocols/gmpv208/entities/targets.py @@ -42,29 +42,30 @@ class AliveTest(Enum): ) CONSIDER_ALIVE = 'Consider Alive' - -def get_alive_test_from_string( - alive_test: Optional[str], -) -> Optional[AliveTest]: - """Convert an alive test string into a AliveTest instance""" - if not alive_test: - return None - - alive_test = alive_test.lower() - - try: - return AliveTest[ - alive_test.replace(',', '') - .replace(' ', '_') - .replace('-', '_') - .replace('&', 'and') - .upper() - ] - except KeyError: - raise InvalidArgument( - argument='alive_test', - function=get_alive_test_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + alive_test: Optional[str], + ) -> Optional["AliveTest"]: + """Convert an alive test string into a AliveTest instance""" + if not alive_test: + return None + + alive_test = alive_test.lower() + + try: + return cls[ + alive_test.replace(',', '') + .replace(' ', '_') + .replace('-', '_') + .replace('&', 'and') + .upper() + ] + except KeyError: + raise InvalidArgument( + argument='alive_test', + function=cls.from_string.__name__, + ) from None class TargetsMixin: @@ -130,7 +131,7 @@ def create_target( """ cmd = XmlCommand("create_target") - _xmlname = cmd.add_element("name", name) + cmd.add_element("name", name) if not name: raise RequiredArgument( diff --git a/gvm/protocols/gmpv208/entities/tickets.py b/gvm/protocols/gmpv208/entities/tickets.py index 57c9f6d39..786c6e65e 100644 --- a/gvm/protocols/gmpv208/entities/tickets.py +++ b/gvm/protocols/gmpv208/entities/tickets.py @@ -32,21 +32,22 @@ class TicketStatus(Enum): FIXED = 'Fixed' CLOSED = 'Closed' - -def get_ticket_status_from_string( - ticket_status: Optional[str], -) -> Optional[TicketStatus]: - """Convert a ticket status string into a TicketStatus instance""" - if not ticket_status: - return None - - try: - return TicketStatus[ticket_status.upper()] - except KeyError: - raise InvalidArgument( - argument='ticket_status', - function=get_ticket_status_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + ticket_status: Optional[str], + ) -> Optional["TicketStatus"]: + """Convert a ticket status string into a TicketStatus instance""" + if not ticket_status: + return None + + try: + return cls[ticket_status.upper()] + except KeyError: + raise InvalidArgument( + argument='ticket_status', + function=cls.from_string.__name__, + ) from None class TicketsMixin: diff --git a/gvm/protocols/gmpv208/entities/users.py b/gvm/protocols/gmpv208/entities/users.py index 71a0c4924..0a998da00 100644 --- a/gvm/protocols/gmpv208/entities/users.py +++ b/gvm/protocols/gmpv208/entities/users.py @@ -32,21 +32,22 @@ class UserAuthType(Enum): LDAP_CONNECT = 'ldap_connect' RADIUS_CONNECT = 'radius_connect' - -def get_user_auth_type_from_string( - user_auth_type: Optional[str], -) -> Optional[UserAuthType]: - """Convert a user auth type string into a UserAuthType instance""" - if not user_auth_type: - return None - - try: - return UserAuthType[user_auth_type.upper()] - except KeyError: - raise InvalidArgument( - argument='user_auth_type', - function=get_user_auth_type_from_string.__name__, - ) from None + @classmethod + def from_string( + cls, + user_auth_type: Optional[str], + ) -> Optional["UserAuthType"]: + """Convert a user auth type string into a UserAuthType instance""" + if not user_auth_type: + return None + + try: + return cls[user_auth_type.upper()] + except KeyError: + raise InvalidArgument( + argument='user_auth_type', + function=cls.from_string.__name__, + ) from None class UsersMixin: diff --git a/gvm/protocols/gmpv208/system/aggregates.py b/gvm/protocols/gmpv208/system/aggregates.py index 8111cb5c4..023128e8a 100644 --- a/gvm/protocols/gmpv208/system/aggregates.py +++ b/gvm/protocols/gmpv208/system/aggregates.py @@ -40,28 +40,29 @@ class AggregateStatistic(Enum): TEXT = "text" # Text column value VALUE = "value" # Group or subgroup column value + @classmethod + def from_string( + cls, + aggregate_statistic: Optional[str], + ) -> Optional["AggregateStatistic"]: + """ + Convert a aggregate statistic string to an actual AggregateStatistic + instance. + + Arguments: + aggregate_statistic: Aggregate statistic string to convert to a + AggregateStatistic + """ + if not aggregate_statistic: + return None -def get_aggregate_statistic_from_string( - aggregate_statistic: Optional[str], -) -> Optional[AggregateStatistic]: - """ - Convert a aggregate statistic string to an actual AggregateStatistic - instance. - - Arguments: - aggregate_statistic: Aggregate statistic string to convert to a - AggregateStatistic - """ - if not aggregate_statistic: - return None - - try: - return AggregateStatistic[aggregate_statistic.upper()] - except KeyError: - raise InvalidArgument( - argument='aggregate_statistic', - function=get_aggregate_statistic_from_string.__name__, - ) from None + try: + return cls[aggregate_statistic.upper()] + except KeyError: + raise InvalidArgument( + argument='aggregate_statistic', + function=cls.from_string.__name__, + ) from None class SortOrder(Enum): @@ -70,25 +71,26 @@ class SortOrder(Enum): ASCENDING = "ascending" DESCENDING = "descending" + @classmethod + def from_string( + cls, + sort_order: Optional[str], + ) -> Optional["SortOrder"]: + """ + Convert a sort order string to an actual SortOrder instance. -def get_sort_order_from_string( - sort_order: Optional[str], -) -> Optional[SortOrder]: - """ - Convert a sort order string to an actual SortOrder instance. - - Arguments: - sort_order: Sort order string to convert to a SortOrder - """ - if not sort_order: - return None + Arguments: + sort_order: Sort order string to convert to a SortOrder + """ + if not sort_order: + return None - try: - return SortOrder[sort_order.upper()] - except KeyError: - raise InvalidArgument( - argument='sort_order', function=get_sort_order_from_string.__name__ - ) from None + try: + return cls[sort_order.upper()] + except KeyError: + raise InvalidArgument( + argument='sort_order', function=cls.from_string.__name__ + ) from None class AggregatesMixin: @@ -202,14 +204,14 @@ def get_aggregates( if isinstance(sort['stat'], AggregateStatistic): sort_elem.set_attribute('stat', sort['stat'].value) else: - stat = get_aggregate_statistic_from_string(sort['stat']) + stat = AggregateStatistic.from_string(sort['stat']) sort_elem.set_attribute('stat', stat.value) if sort.get('order'): if isinstance(sort['order'], SortOrder): sort_elem.set_attribute('order', sort['order'].value) else: - so = get_sort_order_from_string(sort['order']) + so = SortOrder.from_string(sort['order']) sort_elem.set_attribute('order', so.value) if data_columns is not None: diff --git a/gvm/protocols/gmpv208/system/feed.py b/gvm/protocols/gmpv208/system/feed.py index 19c49bbe4..f3ee21903 100644 --- a/gvm/protocols/gmpv208/system/feed.py +++ b/gvm/protocols/gmpv208/system/feed.py @@ -32,18 +32,18 @@ class FeedType(Enum): SCAP = "SCAP" GVMD_DATA = "GVMD_DATA" - -def get_feed_type_from_string(feed_type: Optional[str]) -> Optional[FeedType]: - """Convert a feed type string into a FeedType instance""" - if not feed_type: - return None - - try: - return FeedType[feed_type.upper()] - except KeyError: - raise InvalidArgument( - argument='feed_type', function=get_feed_type_from_string.__name__ - ) from None + @classmethod + def from_string(cls, feed_type: Optional[str]) -> Optional["FeedType"]: + """Convert a feed type string into a FeedType instance""" + if not feed_type: + return None + + try: + return cls[feed_type.upper()] + except KeyError: + raise InvalidArgument( + argument='feed_type', function=cls.from_string.__name__ + ) from None class FeedMixin: diff --git a/gvm/protocols/gmpv208/system/help.py b/gvm/protocols/gmpv208/system/help.py index 32b3a2e42..6a63aa717 100644 --- a/gvm/protocols/gmpv208/system/help.py +++ b/gvm/protocols/gmpv208/system/help.py @@ -31,25 +31,26 @@ class HelpFormat(Enum): TEXT = "text" XML = "xml" + @classmethod + def from_string( + cls, + sort_order: Optional[str], + ) -> Optional["HelpFormat"]: + """ + Convert a sort order string to an actual SortOrder instance. -def get_help_format_from_string( - sort_order: Optional[str], -) -> Optional[HelpFormat]: - """ - Convert a sort order string to an actual SortOrder instance. - - Arguments: - sort_order: Sort order string to convert to a SortOrder - """ - if not sort_order: - return None - - try: - return HelpFormat[sort_order.upper()] - except KeyError: - raise InvalidArgument( - argument='sort_order', function=get_help_format_from_string.__name__ - ) from None + Arguments: + sort_order: Sort order string to convert to a SortOrder + """ + if not sort_order: + return None + + try: + return cls[sort_order.upper()] + except KeyError: + raise InvalidArgument( + argument='sort_order', function=cls.from_string.__name__ + ) from None class HelpMixin: diff --git a/gvm/protocols/gmpv214/__init__.py b/gvm/protocols/gmpv214/__init__.py index 683e0e3f7..7e6720fbf 100644 --- a/gvm/protocols/gmpv214/__init__.py +++ b/gvm/protocols/gmpv214/__init__.py @@ -36,36 +36,26 @@ AlertEvent, AlertMethod, AlertsMixin, - get_alert_condition_from_string, - get_alert_event_from_string, - get_alert_method_from_string, ) from gvm.protocols.gmpv208.entities.audits import AuditsMixin from gvm.protocols.gmpv208.entities.credentials import ( CredentialFormat, CredentialsMixin, CredentialType, - get_credential_format_from_string, - get_credential_type_from_string, - get_snmp_auth_algorithm_from_string, - get_snmp_privacy_algorithm_from_string, SnmpAuthAlgorithm, SnmpPrivacyAlgorithm, ) from gvm.protocols.gmpv208.entities.entities import ( EntityType, - get_entity_type_from_string, ) from gvm.protocols.gmpv208.entities.filter import ( FiltersMixin, FilterType, - get_filter_type_from_string, ) from gvm.protocols.gmpv208.entities.groups import GroupsMixin from gvm.protocols.gmpv208.entities.hosts import ( HostsMixin, HostsOrdering, - get_hosts_ordering_from_string, ) from gvm.protocols.gmpv208.entities.operating_systems import ( OperatingSystemsMixin, @@ -73,64 +63,53 @@ from gvm.protocols.gmpv208.entities.permissions import ( PermissionsMixin, PermissionSubjectType, - get_permission_subject_type_from_string, ) from gvm.protocols.gmpv208.entities.policies import PoliciesMixin from gvm.protocols.gmpv208.entities.port_lists import ( PortListMixin, PortRangeType, - get_port_range_type_from_string, ) from gvm.protocols.gmpv208.entities.reports import ReportsMixin from gvm.protocols.gmpv208.entities.report_formats import ( ReportFormatType, ReportFormatsMixin, - get_report_format_id_from_string, ) from gvm.protocols.gmpv208.entities.results import ResultsMixin from gvm.protocols.gmpv208.entities.roles import RolesMixin from gvm.protocols.gmpv208.entities.scan_configs import ScanConfigsMixin from gvm.protocols.gmpv208.entities.schedules import SchedulesMixin from gvm.protocols.gmpv208.entities.secinfo import ( - get_info_type_from_string, InfoType, SecInfoMixin, ) from gvm.protocols.gmpv208.entities.severity import ( SeverityLevel, - get_severity_level_from_string, ) from gvm.protocols.gmpv208.entities.tags import TagsMixin from gvm.protocols.gmpv208.entities.tasks import TasksMixin from gvm.protocols.gmpv208.entities.tickets import ( TicketStatus, TicketsMixin, - get_ticket_status_from_string, ) from gvm.protocols.gmpv208.entities.tls_certificates import TLSCertificateMixin from gvm.protocols.gmpv208.entities.users import ( UserAuthType, - get_user_auth_type_from_string, ) from gvm.protocols.gmpv208.entities.vulnerabilities import VulnerabilitiesMixin from gvm.protocols.gmpv208.system.aggregates import ( AggregatesMixin, AggregateStatistic, - get_aggregate_statistic_from_string, SortOrder, - get_sort_order_from_string, ) from gvm.protocols.gmpv208.system.authentication import AuthenticationMixin from gvm.protocols.gmpv208.system.feed import ( FeedType, FeedMixin, - get_feed_type_from_string, ) from gvm.protocols.gmpv208.system.help import ( HelpFormat, HelpMixin, - get_help_format_from_string, ) from gvm.protocols.gmpv208.system.system_reports import SystemReportsMixin from gvm.protocols.gmpv208.system.user_settings import UserSettingsMixin @@ -142,11 +121,9 @@ from gvm.protocols.gmpv214.entities.scanners import ( ScannerType, ScannersMixin, - get_scanner_type_from_string, ) from gvm.protocols.gmpv214.entities.targets import ( AliveTest, - get_alive_test_from_string, TargetsMixin, ) from gvm.protocols.gmpv214.entities.users import UsersMixin diff --git a/gvm/protocols/gmpv214/entities/scanners.py b/gvm/protocols/gmpv214/entities/scanners.py index 9947cfd5e..db73c8d2e 100644 --- a/gvm/protocols/gmpv214/entities/scanners.py +++ b/gvm/protocols/gmpv214/entities/scanners.py @@ -35,47 +35,42 @@ class ScannerType(Enum): CVE_SCANNER_TYPE = "3" GREENBONE_SENSOR_SCANNER_TYPE = "5" + @classmethod + def from_string( + cls, + scanner_type: Optional[str], + ) -> Optional["ScannerType"]: + """Convert a scanner type string to an actual ScannerType instance -def get_scanner_type_from_string( - scanner_type: Optional[str], -) -> Optional[ScannerType]: - """Convert a scanner type string to an actual ScannerType instance - - Arguments: - scanner_type: Scanner type string to convert to a ScannerType - """ - if not scanner_type: - return None - - scanner_type = scanner_type.lower() - - if ( - scanner_type == ScannerType.OSP_SCANNER_TYPE.value - or scanner_type == 'osp' - ): - return ScannerType.OSP_SCANNER_TYPE - - if ( - scanner_type == ScannerType.OPENVAS_SCANNER_TYPE.value - or scanner_type == 'openvas' - ): - return ScannerType.OPENVAS_SCANNER_TYPE - - if ( - scanner_type == ScannerType.CVE_SCANNER_TYPE.value - or scanner_type == 'cve' - ): - return ScannerType.CVE_SCANNER_TYPE - - if ( - scanner_type == ScannerType.GREENBONE_SENSOR_SCANNER_TYPE.value - or scanner_type == 'greenbone' - ): - return ScannerType.GREENBONE_SENSOR_SCANNER_TYPE - - raise InvalidArgument( - argument='scanner_type', function=get_scanner_type_from_string.__name__ - ) + Arguments: + scanner_type: Scanner type string to convert to a ScannerType + """ + if not scanner_type: + return None + + scanner_type = scanner_type.lower() + + if scanner_type == cls.OSP_SCANNER_TYPE.value or scanner_type == 'osp': + return cls.OSP_SCANNER_TYPE + + if ( + scanner_type == cls.OPENVAS_SCANNER_TYPE.value + or scanner_type == 'openvas' + ): + return cls.OPENVAS_SCANNER_TYPE + + if scanner_type == cls.CVE_SCANNER_TYPE.value or scanner_type == 'cve': + return cls.CVE_SCANNER_TYPE + + if ( + scanner_type == cls.GREENBONE_SENSOR_SCANNER_TYPE.value + or scanner_type == 'greenbone' + ): + return cls.GREENBONE_SENSOR_SCANNER_TYPE + + raise InvalidArgument( + argument='scanner_type', function=cls.from_string.__name__ + ) class ScannersMixin(Gmp208ScannersMixin): diff --git a/gvm/protocols/gmpv214/entities/targets.py b/gvm/protocols/gmpv214/entities/targets.py index fcf1147d8..0deea1714 100644 --- a/gvm/protocols/gmpv214/entities/targets.py +++ b/gvm/protocols/gmpv214/entities/targets.py @@ -22,7 +22,6 @@ from gvm.errors import RequiredArgument, InvalidArgumentType from gvm.protocols.gmpv208.entities.targets import ( - get_alive_test_from_string, TargetsMixin as Gmp208TargetsMixin, AliveTest, ) @@ -82,7 +81,7 @@ def create_target( ) cmd = XmlCommand("create_target") - _xmlname = cmd.add_element("name", name) + cmd.add_element("name", name) if asset_hosts_filter: cmd.add_element( diff --git a/gvm/protocols/latest.py b/gvm/protocols/latest.py index ec75a45a1..bd7951730 100644 --- a/gvm/protocols/latest.py +++ b/gvm/protocols/latest.py @@ -60,29 +60,6 @@ SortOrder, TicketStatus, UserAuthType, - get_aggregate_statistic_from_string, - get_alert_condition_from_string, - get_alert_event_from_string, - get_alert_method_from_string, - get_alive_test_from_string, - get_credential_format_from_string, - get_credential_type_from_string, - get_entity_type_from_string, - get_feed_type_from_string, - get_filter_type_from_string, - get_help_format_from_string, - get_hosts_ordering_from_string, - get_info_type_from_string, - get_permission_subject_type_from_string, - get_port_range_type_from_string, - get_report_format_id_from_string, - get_scanner_type_from_string, - get_severity_level_from_string, - get_snmp_auth_algorithm_from_string, - get_snmp_privacy_algorithm_from_string, - get_sort_order_from_string, - get_ticket_status_from_string, - get_user_auth_type_from_string, ) from .ospv1 import Osp @@ -112,27 +89,4 @@ "SortOrder", "TicketStatus", "UserAuthType", - "get_aggregate_statistic_from_string", - "get_alert_condition_from_string", - "get_alert_event_from_string", - "get_alert_method_from_string", - "get_alive_test_from_string", - "get_credential_format_from_string", - "get_credential_type_from_string", - "get_entity_type_from_string", - "get_feed_type_from_string", - "get_filter_type_from_string", - "get_help_format_from_string", - "get_hosts_ordering_from_string", - "get_info_type_from_string", - "get_permission_subject_type_from_string", - "get_port_range_type_from_string", - "get_report_format_id_from_string", - "get_scanner_type_from_string", - "get_severity_level_from_string", - "get_snmp_auth_algorithm_from_string", - "get_snmp_privacy_algorithm_from_string", - "get_sort_order_from_string", - "get_ticket_status_from_string", - "get_user_auth_type_from_string", ] diff --git a/gvm/protocols/next.py b/gvm/protocols/next.py index dae4afb03..e9de7a05a 100644 --- a/gvm/protocols/next.py +++ b/gvm/protocols/next.py @@ -60,29 +60,6 @@ SortOrder, TicketStatus, UserAuthType, - get_aggregate_statistic_from_string, - get_alert_condition_from_string, - get_alert_event_from_string, - get_alert_method_from_string, - get_alive_test_from_string, - get_credential_format_from_string, - get_credential_type_from_string, - get_entity_type_from_string, - get_feed_type_from_string, - get_filter_type_from_string, - get_help_format_from_string, - get_hosts_ordering_from_string, - get_info_type_from_string, - get_permission_subject_type_from_string, - get_port_range_type_from_string, - get_report_format_id_from_string, - get_scanner_type_from_string, - get_severity_level_from_string, - get_snmp_auth_algorithm_from_string, - get_snmp_privacy_algorithm_from_string, - get_sort_order_from_string, - get_ticket_status_from_string, - get_user_auth_type_from_string, ) from .ospv1 import Osp @@ -112,27 +89,4 @@ "SortOrder", "TicketStatus", "UserAuthType", - "get_aggregate_statistic_from_string", - "get_alert_condition_from_string", - "get_alert_event_from_string", - "get_alert_method_from_string", - "get_alive_test_from_string", - "get_credential_format_from_string", - "get_credential_type_from_string", - "get_entity_type_from_string", - "get_feed_type_from_string", - "get_filter_type_from_string", - "get_help_format_from_string", - "get_hosts_ordering_from_string", - "get_info_type_from_string", - "get_permission_subject_type_from_string", - "get_port_range_type_from_string", - "get_report_format_id_from_string", - "get_scanner_type_from_string", - "get_severity_level_from_string", - "get_snmp_auth_algorithm_from_string", - "get_snmp_privacy_algorithm_from_string", - "get_sort_order_from_string", - "get_ticket_status_from_string", - "get_user_auth_type_from_string", ] diff --git a/tests/protocols/gmpv208/entities/alerts/test_trigger_alert.py b/tests/protocols/gmpv208/entities/alerts/test_trigger_alert.py index 9f45ff866..c0ea082b7 100644 --- a/tests/protocols/gmpv208/entities/alerts/test_trigger_alert.py +++ b/tests/protocols/gmpv208/entities/alerts/test_trigger_alert.py @@ -17,10 +17,7 @@ # along with this program. If not, see . from gvm.errors import RequiredArgument -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpTriggerAlertTestMixin: @@ -75,7 +72,7 @@ def test_trigger_alert_with_report_format_type(self): alert_id="a1", report_id='r1', report_format_id=ReportFormatType.SVG ) - report_format_id = get_report_format_id_from_string('svg').value + report_format_id = ReportFormatType.from_string('svg').value self.connection.send.has_been_called_with( '. from gvm.errors import RequiredArgument -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpCloneReportFormatTestMixin: @@ -41,7 +38,7 @@ def test_missing_id(self): def test_clone_with_type(self): self.gmp.clone_report_format(ReportFormatType.SVG) - report_format_id = get_report_format_id_from_string('svg').value + report_format_id = ReportFormatType.from_string('svg').value self.connection.send.has_been_called_with( '' diff --git a/tests/protocols/gmpv208/entities/report_formats/test_delete_report_format.py b/tests/protocols/gmpv208/entities/report_formats/test_delete_report_format.py index 228ee49a9..62df99687 100644 --- a/tests/protocols/gmpv208/entities/report_formats/test_delete_report_format.py +++ b/tests/protocols/gmpv208/entities/report_formats/test_delete_report_format.py @@ -17,10 +17,7 @@ # along with this program. If not, see . from gvm.errors import GvmError -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpDeleteReportFormatTestMixin: @@ -48,7 +45,7 @@ def test_missing_id(self): def test_delete_with_type(self): self.gmp.delete_report_format(ReportFormatType.SVG) - report_format_id = get_report_format_id_from_string('svg').value + report_format_id = ReportFormatType.from_string('svg').value self.connection.send.has_been_called_with( '' diff --git a/tests/protocols/gmpv208/entities/report_formats/test_get_report_format.py b/tests/protocols/gmpv208/entities/report_formats/test_get_report_format.py index b462d5466..a4cf84bf3 100644 --- a/tests/protocols/gmpv208/entities/report_formats/test_get_report_format.py +++ b/tests/protocols/gmpv208/entities/report_formats/test_get_report_format.py @@ -17,10 +17,7 @@ # along with this program. If not, see . from gvm.errors import RequiredArgument -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpGetReportFormatTestMixin: @@ -46,7 +43,7 @@ def test_get_report_format_missing_report_format_id(self): def test_get_report_format_type(self): self.gmp.get_report_format(ReportFormatType.PDF) - report_format_id = get_report_format_id_from_string('pdf').value + report_format_id = ReportFormatType.from_string('pdf').value self.connection.send.has_been_called_with( '' diff --git a/tests/protocols/gmpv208/entities/report_formats/test_modify_report_format.py b/tests/protocols/gmpv208/entities/report_formats/test_modify_report_format.py index 2edc2be1b..e9deabee6 100644 --- a/tests/protocols/gmpv208/entities/report_formats/test_modify_report_format.py +++ b/tests/protocols/gmpv208/entities/report_formats/test_modify_report_format.py @@ -17,10 +17,7 @@ # along with this program. If not, see . from gvm.errors import RequiredArgument -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpModifyReportFormatTestMixin: @@ -64,7 +61,7 @@ def test_modify_report_format_with_name_and_type(self): report_format_id=ReportFormatType.XML, name='foo' ) - report_format_id = get_report_format_id_from_string('xml').value + report_format_id = ReportFormatType.from_string('xml').value self.connection.send.has_been_called_with( f'' 'foo' diff --git a/tests/protocols/gmpv208/entities/report_formats/test_verify_report_format.py b/tests/protocols/gmpv208/entities/report_formats/test_verify_report_format.py index 75fb965c4..1bdf242c6 100644 --- a/tests/protocols/gmpv208/entities/report_formats/test_verify_report_format.py +++ b/tests/protocols/gmpv208/entities/report_formats/test_verify_report_format.py @@ -17,10 +17,7 @@ # along with this program. If not, see . from gvm.errors import GvmError -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpVerifyReportFormatTestMixin: @@ -41,7 +38,7 @@ def test_missing_id(self): def test_verify_with_type(self): self.gmp.verify_report_format(ReportFormatType.SVG) - report_format_id = get_report_format_id_from_string('svg').value + report_format_id = ReportFormatType.from_string('svg').value self.connection.send.has_been_called_with( f'' ) diff --git a/tests/protocols/gmpv208/entities/reports/test_get_report.py b/tests/protocols/gmpv208/entities/reports/test_get_report.py index 581b33f48..d9c96613a 100644 --- a/tests/protocols/gmpv208/entities/reports/test_get_report.py +++ b/tests/protocols/gmpv208/entities/reports/test_get_report.py @@ -17,10 +17,7 @@ # along with this program. If not, see . from gvm.errors import RequiredArgument -from gvm.protocols.gmpv208.entities.report_formats import ( - ReportFormatType, - get_report_format_id_from_string, -) +from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType class GmpGetReportTestMixin: @@ -56,7 +53,7 @@ def test_get_report_with_report_format_type(self): self.gmp.get_report( report_id='r1', report_format_id=ReportFormatType.TXT ) - report_format_id = get_report_format_id_from_string('txt').value + report_format_id = ReportFormatType.from_string('txt').value self.connection.send.has_been_called_with( '. + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmpv214 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) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/protocols/gmpv214/enums/test_credential_format.py b/tests/protocols/gmpv214/enums/test_credential_format.py new file mode 100644 index 000000000..df710d4e2 --- /dev/null +++ b/tests/protocols/gmpv214/enums/test_credential_format.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmpv214 import CredentialFormat + + +class GetCredentialFromatFromStringTestCase(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) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/protocols/gmpv214/enums/test_credential_type.py b/tests/protocols/gmpv214/enums/test_credential_type.py index 2f951c979..831046df7 100644 --- a/tests/protocols/gmpv214/enums/test_credential_type.py +++ b/tests/protocols/gmpv214/enums/test_credential_type.py @@ -19,47 +19,44 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import ( - CredentialType, - get_credential_type_from_string, -) +from gvm.protocols.gmpv214 import CredentialType class GetCredentialTypeFromStringTestCase(unittest.TestCase): def test_invalid_type(self): with self.assertRaises(InvalidArgument): - get_credential_type_from_string('foo') + CredentialType.from_string('foo') def test_none_or_empty_type(self): - ct = get_credential_type_from_string(None) + ct = CredentialType.from_string(None) self.assertIsNone(ct) - ct = get_credential_type_from_string('') + ct = CredentialType.from_string('') self.assertIsNone(ct) def test_client_certificate(self): - ct = get_credential_type_from_string('client_certificate') + ct = CredentialType.from_string('client_certificate') self.assertEqual(ct, CredentialType.CLIENT_CERTIFICATE) def test_snmp(self): - ct = get_credential_type_from_string('snmp') + ct = CredentialType.from_string('snmp') self.assertEqual(ct, CredentialType.SNMP) def test_username_password(self): - ct = get_credential_type_from_string('username_password') + ct = CredentialType.from_string('username_password') self.assertEqual(ct, CredentialType.USERNAME_PASSWORD) def test_username_ssh_key(self): - ct = get_credential_type_from_string('username_ssh_key') + ct = CredentialType.from_string('username_ssh_key') self.assertEqual(ct, CredentialType.USERNAME_SSH_KEY) def test_smime_certificate(self): - ct = get_credential_type_from_string('smime_certificate') + ct = CredentialType.from_string('smime_certificate') self.assertEqual(ct, CredentialType.SMIME_CERTIFICATE) def test_pgp_encryption_key(self): - ct = get_credential_type_from_string('pgp_encryption_key') + ct = CredentialType.from_string('pgp_encryption_key') self.assertEqual(ct, CredentialType.PGP_ENCRYPTION_KEY) def test_password_only(self): - ct = get_credential_type_from_string('password_only') + ct = CredentialType.from_string('password_only') self.assertEqual(ct, CredentialType.PASSWORD_ONLY) diff --git a/tests/protocols/gmpv214/enums/test_entity_type.py b/tests/protocols/gmpv214/enums/test_entity_type.py index 5f1590c81..862df0948 100644 --- a/tests/protocols/gmpv214/enums/test_entity_type.py +++ b/tests/protocols/gmpv214/enums/test_entity_type.py @@ -19,159 +19,159 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import EntityType, get_entity_type_from_string +from gvm.protocols.gmpv214 import EntityType class GetEntityTypeFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_entity_type_from_string('foo') + EntityType.from_string('foo') def test_none_or_empty(self): - ct = get_entity_type_from_string(None) + ct = EntityType.from_string(None) self.assertIsNone(ct) - ct = get_entity_type_from_string('') + ct = EntityType.from_string('') self.assertIsNone(ct) def test_audit(self): - ct = get_entity_type_from_string('audit') + ct = EntityType.from_string('audit') self.assertEqual(ct, EntityType.AUDIT) def test_alert(self): - ct = get_entity_type_from_string('alert') + ct = EntityType.from_string('alert') self.assertEqual(ct, EntityType.ALERT) def test_asset(self): - ct = get_entity_type_from_string('asset') + ct = EntityType.from_string('asset') self.assertEqual(ct, EntityType.ASSET) def test_cert_bund_adv(self): - ct = get_entity_type_from_string('cert_bund_adv') + ct = EntityType.from_string('cert_bund_adv') self.assertEqual(ct, EntityType.CERT_BUND_ADV) def test_cpe(self): - ct = get_entity_type_from_string('cpe') + ct = EntityType.from_string('cpe') self.assertEqual(ct, EntityType.CPE) def test_credential(self): - ct = get_entity_type_from_string('credential') + ct = EntityType.from_string('credential') self.assertEqual(ct, EntityType.CREDENTIAL) def test_dfn_cert_adv(self): - ct = get_entity_type_from_string('dfn_cert_adv') + ct = EntityType.from_string('dfn_cert_adv') self.assertEqual(ct, EntityType.DFN_CERT_ADV) def test_filter(self): - ct = get_entity_type_from_string('filter') + ct = EntityType.from_string('filter') self.assertEqual(ct, EntityType.FILTER) def test_group(self): - ct = get_entity_type_from_string('group') + ct = EntityType.from_string('group') self.assertEqual(ct, EntityType.GROUP) def test_host(self): - ct = get_entity_type_from_string('host') + ct = EntityType.from_string('host') self.assertEqual(ct, EntityType.HOST) def test_info(self): - ct = get_entity_type_from_string('info') + ct = EntityType.from_string('info') self.assertEqual(ct, EntityType.INFO) def test_note(self): - ct = get_entity_type_from_string('note') + ct = EntityType.from_string('note') self.assertEqual(ct, EntityType.NOTE) def test_nvt(self): - ct = get_entity_type_from_string('nvt') + ct = EntityType.from_string('nvt') self.assertEqual(ct, EntityType.NVT) def test_operating_system(self): - ct = get_entity_type_from_string('os') + ct = EntityType.from_string('os') self.assertEqual(ct, EntityType.OPERATING_SYSTEM) - ct = get_entity_type_from_string('operating_system') + ct = EntityType.from_string('operating_system') self.assertEqual(ct, EntityType.OPERATING_SYSTEM) def test_ovaldef(self): - ct = get_entity_type_from_string('ovaldef') + ct = EntityType.from_string('ovaldef') self.assertEqual(ct, EntityType.OVALDEF) def test_override(self): - ct = get_entity_type_from_string('override') + ct = EntityType.from_string('override') self.assertEqual(ct, EntityType.OVERRIDE) def test_permission(self): - ct = get_entity_type_from_string('permission') + ct = EntityType.from_string('permission') self.assertEqual(ct, EntityType.PERMISSION) def test_policy(self): - ct = get_entity_type_from_string('policy') + ct = EntityType.from_string('policy') self.assertEqual(ct, EntityType.POLICY) def test_port_list(self): - ct = get_entity_type_from_string('port_list') + ct = EntityType.from_string('port_list') self.assertEqual(ct, EntityType.PORT_LIST) def test_report(self): - ct = get_entity_type_from_string('report') + ct = EntityType.from_string('report') self.assertEqual(ct, EntityType.REPORT) def test_report_format(self): - ct = get_entity_type_from_string('report_format') + ct = EntityType.from_string('report_format') self.assertEqual(ct, EntityType.REPORT_FORMAT) def test_result(self): - ct = get_entity_type_from_string('result') + ct = EntityType.from_string('result') self.assertEqual(ct, EntityType.RESULT) def test_role(self): - ct = get_entity_type_from_string('role') + ct = EntityType.from_string('role') self.assertEqual(ct, EntityType.ROLE) def test_scan_config(self): - ct = get_entity_type_from_string('config') + ct = EntityType.from_string('config') self.assertEqual(ct, EntityType.SCAN_CONFIG) - ct = get_entity_type_from_string('scan_config') + ct = EntityType.from_string('scan_config') self.assertEqual(ct, EntityType.SCAN_CONFIG) def test_scanner(self): - ct = get_entity_type_from_string('scanner') + ct = EntityType.from_string('scanner') self.assertEqual(ct, EntityType.SCANNER) def test_schedule(self): - ct = get_entity_type_from_string('schedule') + ct = EntityType.from_string('schedule') self.assertEqual(ct, EntityType.SCHEDULE) def test_tag(self): - ct = get_entity_type_from_string('tag') + ct = EntityType.from_string('tag') self.assertEqual(ct, EntityType.TAG) def test_target(self): - ct = get_entity_type_from_string('target') + ct = EntityType.from_string('target') self.assertEqual(ct, EntityType.TARGET) def test_task(self): - ct = get_entity_type_from_string('task') + ct = EntityType.from_string('task') self.assertEqual(ct, EntityType.TASK) def test_ticket(self): - ct = get_entity_type_from_string('ticket') + ct = EntityType.from_string('ticket') self.assertEqual(ct, EntityType.TICKET) def test_tls_certificate(self): - ft = get_entity_type_from_string('tls_certificate') + ft = EntityType.from_string('tls_certificate') self.assertEqual(ft, EntityType.TLS_CERTIFICATE) def test_user(self): - ct = get_entity_type_from_string('user') + ct = EntityType.from_string('user') self.assertEqual(ct, EntityType.USER) def test_vulnerability(self): - ct = get_entity_type_from_string('vuln') + ct = EntityType.from_string('vuln') self.assertEqual(ct, EntityType.VULNERABILITY) - ct = get_entity_type_from_string('vulnerability') + ct = EntityType.from_string('vulnerability') self.assertEqual(ct, EntityType.VULNERABILITY) diff --git a/tests/protocols/gmpv214/enums/test_feed_type.py b/tests/protocols/gmpv214/enums/test_feed_type.py new file mode 100644 index 000000000..226e6c5b0 --- /dev/null +++ b/tests/protocols/gmpv214/enums/test_feed_type.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmpv214 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) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/protocols/gmpv214/enums/test_filter_type.py b/tests/protocols/gmpv214/enums/test_filter_type.py index 521ee389c..df541868f 100644 --- a/tests/protocols/gmpv214/enums/test_filter_type.py +++ b/tests/protocols/gmpv214/enums/test_filter_type.py @@ -19,133 +19,133 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import FilterType, get_filter_type_from_string +from gvm.protocols.gmpv214 import FilterType class GetFilterTypeFomStringTestCase(unittest.TestCase): def test_filter_type_alert(self): - ft = get_filter_type_from_string('alert') + ft = FilterType.from_string('alert') self.assertEqual(ft, FilterType.ALERT) def test_filter_type_asset(self): - ft = get_filter_type_from_string('asset') + ft = FilterType.from_string('asset') self.assertEqual(ft, FilterType.ASSET) def test_filter_type_credential(self): - ft = get_filter_type_from_string('credential') + ft = FilterType.from_string('credential') self.assertEqual(ft, FilterType.CREDENTIAL) def test_filter_type_filter(self): - ft = get_filter_type_from_string('filter') + ft = FilterType.from_string('filter') self.assertEqual(ft, FilterType.FILTER) def test_filter_type_group(self): - ft = get_filter_type_from_string('group') + ft = FilterType.from_string('group') self.assertEqual(ft, FilterType.GROUP) def test_filter_type_host(self): - ft = get_filter_type_from_string('host') + ft = FilterType.from_string('host') self.assertEqual(ft, FilterType.HOST) def test_filter_type_note(self): - ft = get_filter_type_from_string('note') + ft = FilterType.from_string('note') self.assertEqual(ft, FilterType.NOTE) def test_filter_type_override(self): - ft = get_filter_type_from_string('override') + ft = FilterType.from_string('override') self.assertEqual(ft, FilterType.OVERRIDE) def test_filter_type_permission(self): - ft = get_filter_type_from_string('permission') + ft = FilterType.from_string('permission') self.assertEqual(ft, FilterType.PERMISSION) def test_filter_type_port_list(self): - ft = get_filter_type_from_string('port_list') + ft = FilterType.from_string('port_list') self.assertEqual(ft, FilterType.PORT_LIST) def test_filter_type_report(self): - ft = get_filter_type_from_string('report') + ft = FilterType.from_string('report') self.assertEqual(ft, FilterType.REPORT) def test_filter_type_report_format(self): - ft = get_filter_type_from_string('report_format') + ft = FilterType.from_string('report_format') self.assertEqual(ft, FilterType.REPORT_FORMAT) def test_filter_type_result(self): - ft = get_filter_type_from_string('result') + ft = FilterType.from_string('result') self.assertEqual(ft, FilterType.RESULT) def test_filter_type_role(self): - ft = get_filter_type_from_string('role') + ft = FilterType.from_string('role') self.assertEqual(ft, FilterType.ROLE) def test_filter_type_schedule(self): - ft = get_filter_type_from_string('schedule') + ft = FilterType.from_string('schedule') self.assertEqual(ft, FilterType.SCHEDULE) def test_filter_type_secinfo(self): - ft = get_filter_type_from_string('secinfo') + ft = FilterType.from_string('secinfo') self.assertEqual(ft, FilterType.ALL_SECINFO) def test_filter_type_all_secinfo(self): - ft = get_filter_type_from_string('all_secinfo') + ft = FilterType.from_string('all_secinfo') self.assertEqual(ft, FilterType.ALL_SECINFO) def test_filter_type_tag(self): - ft = get_filter_type_from_string('tag') + ft = FilterType.from_string('tag') self.assertEqual(ft, FilterType.TAG) def test_filter_type_task(self): - ft = get_filter_type_from_string('task') + ft = FilterType.from_string('task') self.assertEqual(ft, FilterType.TASK) def test_filter_type_target(self): - ft = get_filter_type_from_string('target') + ft = FilterType.from_string('target') self.assertEqual(ft, FilterType.TARGET) def test_filter_type_ticket(self): - ft = get_filter_type_from_string('ticket') + ft = FilterType.from_string('ticket') self.assertEqual(ft, FilterType.TICKET) def test_filter_type_tls_certificate(self): - ft = get_filter_type_from_string('tls_certificate') + ft = FilterType.from_string('tls_certificate') self.assertEqual(ft, FilterType.TLS_CERTIFICATE) def test_filter_type_operating_system(self): - ft = get_filter_type_from_string('operating_system') + ft = FilterType.from_string('operating_system') self.assertEqual(ft, FilterType.OPERATING_SYSTEM) def test_filter_type_user(self): - ft = get_filter_type_from_string('user') + ft = FilterType.from_string('user') self.assertEqual(ft, FilterType.USER) def test_filter_type_vuln(self): - ft = get_filter_type_from_string('vuln') + ft = FilterType.from_string('vuln') self.assertEqual(ft, FilterType.VULNERABILITY) def test_filter_type_vulnerability(self): - ft = get_filter_type_from_string('vulnerability') + ft = FilterType.from_string('vulnerability') self.assertEqual(ft, FilterType.VULNERABILITY) def test_filter_type_config(self): - ft = get_filter_type_from_string('config') + ft = FilterType.from_string('config') self.assertEqual(ft, FilterType.SCAN_CONFIG) def test_filter_type_scan_config(self): - ft = get_filter_type_from_string('scan_config') + ft = FilterType.from_string('scan_config') self.assertEqual(ft, FilterType.SCAN_CONFIG) def test_filter_type_os(self): - ft = get_filter_type_from_string('os') + ft = FilterType.from_string('os') self.assertEqual(ft, FilterType.OPERATING_SYSTEM) def test_invalid_filter_type(self): with self.assertRaises(InvalidArgument): - get_filter_type_from_string('foo') + FilterType.from_string('foo') def test_non_or_empty_filter_type(self): - ft = get_filter_type_from_string(None) + ft = FilterType.from_string(None) self.assertIsNone(ft) - ft = get_filter_type_from_string('') + ft = FilterType.from_string('') self.assertIsNone(ft) diff --git a/tests/protocols/gmpv214/enums/test_help_format.py b/tests/protocols/gmpv214/enums/test_help_format.py index bcc78d99c..1967cb3ea 100644 --- a/tests/protocols/gmpv214/enums/test_help_format.py +++ b/tests/protocols/gmpv214/enums/test_help_format.py @@ -19,34 +19,34 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import HelpFormat, get_help_format_from_string +from gvm.protocols.gmpv214 import HelpFormat class GetHelpFormatFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_help_format_from_string('foo') + HelpFormat.from_string('foo') def test_none_or_empty(self): - ct = get_help_format_from_string(None) + ct = HelpFormat.from_string(None) self.assertIsNone(ct) - ct = get_help_format_from_string('') + ct = HelpFormat.from_string('') self.assertIsNone(ct) def test_task_run_status_changed(self): - ct = get_help_format_from_string('HtMl') + ct = HelpFormat.from_string('HtMl') self.assertEqual(ct, HelpFormat.HTML) def test_new_secinfo_arrived(self): - ct = get_help_format_from_string('rNc') + ct = HelpFormat.from_string('rNc') self.assertEqual(ct, HelpFormat.RNC) def test_updated_secinfo_arrived(self): - ct = get_help_format_from_string('tExT') + ct = HelpFormat.from_string('tExT') self.assertEqual(ct, HelpFormat.TEXT) def test_ticket_received(self): - ct = get_help_format_from_string('XmL') + ct = HelpFormat.from_string('XmL') self.assertEqual(ct, HelpFormat.XML) diff --git a/tests/protocols/gmpv214/enums/test_hosts_ordering.py b/tests/protocols/gmpv214/enums/test_hosts_ordering.py index f91c38553..d2e680075 100644 --- a/tests/protocols/gmpv214/enums/test_hosts_ordering.py +++ b/tests/protocols/gmpv214/enums/test_hosts_ordering.py @@ -19,28 +19,28 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import HostsOrdering, get_hosts_ordering_from_string +from gvm.protocols.gmpv214 import HostsOrdering class GetHostsOrderingFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_hosts_ordering_from_string('foo') + HostsOrdering.from_string('foo') def test_none_or_empty(self): - ct = get_hosts_ordering_from_string(None) + ct = HostsOrdering.from_string(None) self.assertIsNone(ct) - ct = get_hosts_ordering_from_string('') + ct = HostsOrdering.from_string('') self.assertIsNone(ct) def test_sequential(self): - ct = get_hosts_ordering_from_string("sequential") + ct = HostsOrdering.from_string("sequential") self.assertEqual(ct, HostsOrdering.SEQUENTIAL) def test_random(self): - ct = get_hosts_ordering_from_string("random") + ct = HostsOrdering.from_string("random") self.assertEqual(ct, HostsOrdering.RANDOM) def test_reverse(self): - ct = get_hosts_ordering_from_string("reverse") + ct = HostsOrdering.from_string("reverse") self.assertEqual(ct, HostsOrdering.REVERSE) diff --git a/tests/protocols/gmpv214/enums/test_info_type.py b/tests/protocols/gmpv214/enums/test_info_type.py index 1e988368f..bd68a7d48 100644 --- a/tests/protocols/gmpv214/enums/test_info_type.py +++ b/tests/protocols/gmpv214/enums/test_info_type.py @@ -19,47 +19,47 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import InfoType, get_info_type_from_string +from gvm.protocols.gmpv214 import InfoType class GetInfoTypeFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_info_type_from_string('foo') + InfoType.from_string('foo') def test_none_or_empty(self): - ct = get_info_type_from_string(None) + ct = InfoType.from_string(None) self.assertIsNone(ct) - ct = get_info_type_from_string('') + ct = InfoType.from_string('') self.assertIsNone(ct) def test_cert_bund_adv(self): - ct = get_info_type_from_string('cert_bund_adv') + ct = InfoType.from_string('cert_bund_adv') self.assertEqual(ct, InfoType.CERT_BUND_ADV) def test_cpe(self): - ct = get_info_type_from_string('cpe') + ct = InfoType.from_string('cpe') self.assertEqual(ct, InfoType.CPE) def test_cve(self): - ct = get_info_type_from_string('cve') + ct = InfoType.from_string('cve') self.assertEqual(ct, InfoType.CVE) def test_dfn_cert_adv(self): - ct = get_info_type_from_string('dfn_cert_adv') + ct = InfoType.from_string('dfn_cert_adv') self.assertEqual(ct, InfoType.DFN_CERT_ADV) def test_nvt(self): - ct = get_info_type_from_string('nvt') + ct = InfoType.from_string('nvt') self.assertEqual(ct, InfoType.NVT) def test_ovaldef(self): - ct = get_info_type_from_string('ovaldef') + ct = InfoType.from_string('ovaldef') self.assertEqual(ct, InfoType.OVALDEF) def test_allinfo(self): with self.assertRaises(InvalidArgument): - get_info_type_from_string('allinfo') + InfoType.from_string('allinfo') if __name__ == '__main__': diff --git a/tests/protocols/gmpv214/enums/test_permission_subject_type.py b/tests/protocols/gmpv214/enums/test_permission_subject_type.py new file mode 100644 index 000000000..4571f4573 --- /dev/null +++ b/tests/protocols/gmpv214/enums/test_permission_subject_type.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmpv214 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) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/protocols/gmpv214/enums/test_port_range_type.py b/tests/protocols/gmpv214/enums/test_port_range_type.py index f2c41d6c9..a7bb99edf 100644 --- a/tests/protocols/gmpv214/enums/test_port_range_type.py +++ b/tests/protocols/gmpv214/enums/test_port_range_type.py @@ -19,26 +19,26 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import PortRangeType, get_port_range_type_from_string +from gvm.protocols.gmpv214 import PortRangeType class GetPortRangeTypeFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_port_range_type_from_string('foo') + PortRangeType.from_string('foo') def test_none_or_empty(self): - ct = get_port_range_type_from_string(None) + ct = PortRangeType.from_string(None) self.assertIsNone(ct) - ct = get_port_range_type_from_string('') + ct = PortRangeType.from_string('') self.assertIsNone(ct) def test_tcp(self): - ct = get_port_range_type_from_string('tcp') + ct = PortRangeType.from_string('tcp') self.assertEqual(ct, PortRangeType.TCP) def test_udp(self): - ct = get_port_range_type_from_string('udp') + ct = PortRangeType.from_string('udp') self.assertEqual(ct, PortRangeType.UDP) diff --git a/tests/protocols/gmpv214/enums/test_report_format_type.py b/tests/protocols/gmpv214/enums/test_report_format_type.py new file mode 100644 index 000000000..212866fb4 --- /dev/null +++ b/tests/protocols/gmpv214/enums/test_report_format_type.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmpv214 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) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/protocols/gmpv214/enums/test_scanner_type.py b/tests/protocols/gmpv214/enums/test_scanner_type.py index c60adcea1..326a684ba 100644 --- a/tests/protocols/gmpv214/enums/test_scanner_type.py +++ b/tests/protocols/gmpv214/enums/test_scanner_type.py @@ -19,53 +19,53 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import ScannerType, get_scanner_type_from_string +from gvm.protocols.gmpv214 import ScannerType class GetScannerTypeFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_scanner_type_from_string('foo') + ScannerType.from_string('foo') def test_none_or_empty(self): - ct = get_scanner_type_from_string(None) + ct = ScannerType.from_string(None) self.assertIsNone(ct) - ct = get_scanner_type_from_string('') + ct = ScannerType.from_string('') self.assertIsNone(ct) def test_osp_scanner(self): - ct = get_scanner_type_from_string('1') + ct = ScannerType.from_string('1') self.assertEqual(ct, ScannerType.OSP_SCANNER_TYPE) - ct = get_scanner_type_from_string('osp') + ct = ScannerType.from_string('osp') self.assertEqual(ct, ScannerType.OSP_SCANNER_TYPE) def test_openvas_scanner(self): - ct = get_scanner_type_from_string('2') + ct = ScannerType.from_string('2') self.assertEqual(ct, ScannerType.OPENVAS_SCANNER_TYPE) - ct = get_scanner_type_from_string('openvas') + ct = ScannerType.from_string('openvas') self.assertEqual(ct, ScannerType.OPENVAS_SCANNER_TYPE) def test_cve_scanner(self): - ct = get_scanner_type_from_string('3') + ct = ScannerType.from_string('3') self.assertEqual(ct, ScannerType.CVE_SCANNER_TYPE) - ct = get_scanner_type_from_string('cve') + ct = ScannerType.from_string('cve') self.assertEqual(ct, ScannerType.CVE_SCANNER_TYPE) def test_gmp_scanner(self): with self.assertRaises(InvalidArgument): - get_scanner_type_from_string('4') + ScannerType.from_string('4') with self.assertRaises(InvalidArgument): - get_scanner_type_from_string('gmp') + ScannerType.from_string('gmp') def test_greenbone_sensor_scanner(self): - ct = get_scanner_type_from_string('5') + ct = ScannerType.from_string('5') self.assertEqual(ct, ScannerType.GREENBONE_SENSOR_SCANNER_TYPE) - ct = get_scanner_type_from_string('greenbone') + ct = ScannerType.from_string('greenbone') self.assertEqual(ct, ScannerType.GREENBONE_SENSOR_SCANNER_TYPE) diff --git a/tests/protocols/gmpv214/enums/test_severity_level.py b/tests/protocols/gmpv214/enums/test_severity_level.py index 1589a85af..e6b824204 100644 --- a/tests/protocols/gmpv214/enums/test_severity_level.py +++ b/tests/protocols/gmpv214/enums/test_severity_level.py @@ -19,38 +19,38 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import SeverityLevel, get_severity_level_from_string +from gvm.protocols.gmpv214 import SeverityLevel class GetSeverityLevelFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_severity_level_from_string('foo') + SeverityLevel.from_string('foo') def test_none_or_empty(self): - ct = get_severity_level_from_string(None) + ct = SeverityLevel.from_string(None) self.assertIsNone(ct) - ct = get_severity_level_from_string('') + ct = SeverityLevel.from_string('') self.assertIsNone(ct) def test_high(self): - ct = get_severity_level_from_string('High') + ct = SeverityLevel.from_string('High') self.assertEqual(ct, SeverityLevel.HIGH) def test_medium(self): - ct = get_severity_level_from_string('Medium') + ct = SeverityLevel.from_string('Medium') self.assertEqual(ct, SeverityLevel.MEDIUM) def test_low(self): - ct = get_severity_level_from_string('Low') + ct = SeverityLevel.from_string('Low') self.assertEqual(ct, SeverityLevel.LOW) def test_log(self): - ct = get_severity_level_from_string('Log') + ct = SeverityLevel.from_string('Log') self.assertEqual(ct, SeverityLevel.LOG) def test_alarm(self): - ct = get_severity_level_from_string('Alarm') + ct = SeverityLevel.from_string('Alarm') self.assertEqual(ct, SeverityLevel.ALARM) diff --git a/tests/protocols/gmpv214/enums/test_snmp_algorithms.py b/tests/protocols/gmpv214/enums/test_snmp_algorithms.py index f2f7293df..1ed655b94 100644 --- a/tests/protocols/gmpv214/enums/test_snmp_algorithms.py +++ b/tests/protocols/gmpv214/enums/test_snmp_algorithms.py @@ -22,46 +22,44 @@ from gvm.protocols.gmpv214 import ( SnmpAuthAlgorithm, SnmpPrivacyAlgorithm, - get_snmp_auth_algorithm_from_string, - get_snmp_privacy_algorithm_from_string, ) class GetSnmpAuthAlgorithmFromStringTestCase(unittest.TestCase): def test_invalid_status(self): with self.assertRaises(InvalidArgument): - get_snmp_auth_algorithm_from_string('foo') + SnmpAuthAlgorithm.from_string('foo') def test_none_or_empty_type(self): - ts = get_snmp_auth_algorithm_from_string(None) + ts = SnmpAuthAlgorithm.from_string(None) self.assertIsNone(ts) - ts = get_snmp_auth_algorithm_from_string('') + ts = SnmpAuthAlgorithm.from_string('') self.assertIsNone(ts) def test_sha1(self): - ts = get_snmp_auth_algorithm_from_string('sha1') + ts = SnmpAuthAlgorithm.from_string('sha1') self.assertEqual(ts, SnmpAuthAlgorithm.SHA1) def test_md5(self): - ts = get_snmp_auth_algorithm_from_string('md5') + ts = SnmpAuthAlgorithm.from_string('md5') self.assertEqual(ts, SnmpAuthAlgorithm.MD5) class GetSnmpPrivacyAlgorithmFromStringTestCase(unittest.TestCase): def test_invalid_status(self): with self.assertRaises(InvalidArgument): - get_snmp_privacy_algorithm_from_string('foo') + SnmpPrivacyAlgorithm.from_string('foo') def test_none_or_empty_type(self): - ts = get_snmp_privacy_algorithm_from_string(None) + ts = SnmpPrivacyAlgorithm.from_string(None) self.assertIsNone(ts) - ts = get_snmp_privacy_algorithm_from_string('') + ts = SnmpPrivacyAlgorithm.from_string('') self.assertIsNone(ts) def test_aes(self): - ts = get_snmp_privacy_algorithm_from_string('aes') + ts = SnmpPrivacyAlgorithm.from_string('aes') self.assertEqual(ts, SnmpPrivacyAlgorithm.AES) def test_des(self): - ts = get_snmp_privacy_algorithm_from_string('des') + ts = SnmpPrivacyAlgorithm.from_string('des') self.assertEqual(ts, SnmpPrivacyAlgorithm.DES) diff --git a/tests/protocols/gmpv214/enums/test_sort_order.py b/tests/protocols/gmpv214/enums/test_sort_order.py index 89a454e05..6e2c532f3 100644 --- a/tests/protocols/gmpv214/enums/test_sort_order.py +++ b/tests/protocols/gmpv214/enums/test_sort_order.py @@ -19,26 +19,26 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import SortOrder, get_sort_order_from_string +from gvm.protocols.gmpv214 import SortOrder class GetSortOrderFromStringTestCase(unittest.TestCase): def test_invalid(self): with self.assertRaises(InvalidArgument): - get_sort_order_from_string('foo') + SortOrder.from_string('foo') def test_none_or_empty(self): - ct = get_sort_order_from_string(None) + ct = SortOrder.from_string(None) self.assertIsNone(ct) - ct = get_sort_order_from_string('') + ct = SortOrder.from_string('') self.assertIsNone(ct) def test_ascending(self): - ct = get_sort_order_from_string('ascending') + ct = SortOrder.from_string('ascending') self.assertEqual(ct, SortOrder.ASCENDING) def test_descending(self): - ct = get_sort_order_from_string('descending') + ct = SortOrder.from_string('descending') self.assertEqual(ct, SortOrder.DESCENDING) diff --git a/tests/protocols/gmpv214/enums/test_ticket_status.py b/tests/protocols/gmpv214/enums/test_ticket_status.py index 27231d2a4..eb4854868 100644 --- a/tests/protocols/gmpv214/enums/test_ticket_status.py +++ b/tests/protocols/gmpv214/enums/test_ticket_status.py @@ -19,28 +19,28 @@ import unittest from gvm.errors import InvalidArgument -from gvm.protocols.gmpv214 import TicketStatus, get_ticket_status_from_string +from gvm.protocols.gmpv214 import TicketStatus class GetTicketStatusFromStringTestCase(unittest.TestCase): def test_invalid_status(self): with self.assertRaises(InvalidArgument): - get_ticket_status_from_string('foo') + TicketStatus.from_string('foo') def test_none_or_empty_type(self): - ts = get_ticket_status_from_string(None) + ts = TicketStatus.from_string(None) self.assertIsNone(ts) - ts = get_ticket_status_from_string('') + ts = TicketStatus.from_string('') self.assertIsNone(ts) def test_ticket_status_open(self): - ts = get_ticket_status_from_string('open') + ts = TicketStatus.from_string('open') self.assertEqual(ts, TicketStatus.OPEN) def test_ticket_status_fixed(self): - ts = get_ticket_status_from_string('fixed') + ts = TicketStatus.from_string('fixed') self.assertEqual(ts, TicketStatus.FIXED) def test_ticket_status_closed(self): - ts = get_ticket_status_from_string('closed') + ts = TicketStatus.from_string('closed') self.assertEqual(ts, TicketStatus.CLOSED) diff --git a/tests/protocols/gmpv214/enums/test_user_auth_type.py b/tests/protocols/gmpv214/enums/test_user_auth_type.py new file mode 100644 index 000000000..4dd0b3bd6 --- /dev/null +++ b/tests/protocols/gmpv214/enums/test_user_auth_type.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019-2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from gvm.errors import InvalidArgument +from gvm.protocols.gmpv214 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()