Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cover empty AdvancedDataTypes internet_address and internet_port #23756

Merged
merged 2 commits into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/unit_tests/advanced_data_type/types_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ def test_cidr_func_invalid_ip():
assert internet_address.translate_type(cidr_request) == cidr_response


def test_cidr_func_empty_ip():
"""Test to see if the cidr_func behaves as expected when no IP is passed in"""
cidr_request: AdvancedDataTypeRequest = {
"advanced_data_type": "cidr",
"values": [""],
}
cidr_response: AdvancedDataTypeResponse = {
"values": [""],
"error_message": "",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}

assert internet_address.translate_type(cidr_request) == cidr_response


def test_port_translation_func_valid_port_number():
"""Test to see if the port_translation_func behaves as expected when a valid port number
is passed in"""
Expand Down Expand Up @@ -175,6 +198,30 @@ def test_port_translation_func_invalid_port_number():
assert port.translate_type(port_request) == port_response


def test_port_translation_func_empty_port_number():
"""Test to see if the port_translation_func behaves as expected when no port
number is passed in"""
port_request: AdvancedDataTypeRequest = {
"advanced_data_type": "port",
"values": [""],
}
port_response: AdvancedDataTypeResponse = {
"values": [[""]],
"error_message": "",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}

assert port.translate_type(port_request) == port_response


def test_cidr_translate_filter_func_equals():
"""Test to see if the cidr_translate_filter_func behaves as expected when the EQUALS
operator is used"""
Expand Down