Skip to content

Commit

Permalink
Added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johannwagner committed Dec 12, 2022
1 parent dc99f02 commit 54b030d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
28 changes: 28 additions & 0 deletions wanda/tests/test_as.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from wanda.autonomous_system.autonomous_system import AutonomousSystem


@pytest.mark.unit
class TestAutonomousSystem:

@pytest.mark.parametrize(
"asn,name,irr_names,expected_irr_names",
[
(9136, "WOBCOM", "AS-WOBCOM", ["AS-WOBCOM"]),
(208395, "WDZ", "", ["AS208395"]),
(1299, "Twelve99", "RIPE::AS-TELIANET RIPE::AS-TELIANET-V6", ["AS-TELIANET", "AS-TELIANET-V6"])
]
)
def test_irr_name(self, asn, name, irr_names, expected_irr_names):
autos = AutonomousSystem(
asn=asn,
name=name,
irr_as_set=irr_names
)

irr_names_set = set(autos.get_irr_names())
expected_irr_names_set = set(expected_irr_names)

assert len(irr_names_set) > 0
assert irr_names_set == expected_irr_names_set
86 changes: 86 additions & 0 deletions wanda/tests/test_as_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import pytest

from wanda.as_filter.as_filter import ASFilter
from wanda.autonomous_system.autonomous_system import AutonomousSystem
from wanda.irrd_client import IRRDClient


def get_asfilter(**kwargs):
autos = AutonomousSystem(
asn=9136,
name="WOBCOM",
irr_as_set="AS-WOBCOM"
)

irrd_client = IRRDClient(
irrd_url="rr.example.com"
)

return ASFilter(
irrd_client=irrd_client,
autos=autos,
**kwargs
)


AS_PATH_MOCK = """
as-path-group AS9136 {
as-path a0 "^9136(9136)*$";
as-path a1 "^9136(.)*(112|248|250)$";
}
"""

WOBCOM_PREFIX_LIST_MOCK_V4 = [
"203.0.113.0/26",
"203.0.113.32/26"
]

WOBCOM_PREFIX_LIST_MOCK_V6 = [
"2001:db8::a/32"
]

WOBCOM_EXPECTED_PREFIX_LIST = """
prefix-list AS9136_V4 {
203.0.113.0/26;
203.0.113.32/26
}
prefix-list AS9136_V6 {
2001:db8::a/32
}
"""


@pytest.mark.unit
class TestASFilter:

@pytest.mark.parametrize(
"asfilter,enable_extended_filters",
[
(get_asfilter(enable_extended_filters=True), True),
(get_asfilter(enable_extended_filters=False), False)
]
)
def test_prefix_lists(self, mocker, asfilter, enable_extended_filters):
mocker.patch(
'wanda.irrd_client.IRRDClient.generate_prefix_lists',
return_value=(WOBCOM_PREFIX_LIST_MOCK_V4, WOBCOM_PREFIX_LIST_MOCK_V6)
)

mocker.patch(
'wanda.irrd_client.IRRDClient.generate_input_aspath_access_list',
return_value=AS_PATH_MOCK
)

file_content = asfilter.get_filter_lists()

assert len(file_content) > 0

assert "policy-statement POLICY_AS9136_V4 {" in file_content
assert "policy-statement POLICY_AS9136_V6 {" in file_content
assert "as-path-group AS9136;"

if enable_extended_filters:
assert WOBCOM_EXPECTED_PREFIX_LIST in file_content
assert "prefix-list-filter AS9136_V4 orlonger;"
assert "prefix-list-filter AS9136_V6 orlonger;"

0 comments on commit 54b030d

Please sign in to comment.