Skip to content

Commit

Permalink
Merge pull request #603 from verterok/trusted_netowrks_tests
Browse files Browse the repository at this point in the history
Add tests for trusted networks config
  • Loading branch information
verterok authored May 29, 2024
2 parents 8d5d549 + 8a39ddf commit 5b01ab3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#

import sys
from ipaddress import ip_network
from subprocess import check_output as run
import textwrap

Expand Down Expand Up @@ -273,3 +274,46 @@ def test_setup_py(tmpdir, capsys):
assert rev == '1.0'
out, err = capsys.readouterr()
assert err == ''


def test_network():
assert_config({'TALISKER_NETWORKS': ''}, networks=[])
assert_config(
{'TALISKER_NETWORKS': '10.1.2.0/24'},
networks=[ip_network('10.1.2.0/24')]
)
assert_config(
{'TALISKER_NETWORKS': '10.1.2.0/24 10.2.3.0/24'},
networks=[ip_network('10.1.2.0/24'), ip_network('10.2.3.0/24')]
)
assert_config(
{'TALISKER_NETWORKS': '2620:2d:4000:2001::/64'},
networks=[ip_network('2620:2d:4000:2001::/64')]
)
assert_config(
{'TALISKER_NETWORKS': '2620:2d:4000:2001::/64 2620:3d:4000:2001::/64'},
networks=[
ip_network('2620:2d:4000:2001::/64'),
ip_network('2620:3d:4000:2001::/64')
]
)
assert_config(
{'TALISKER_NETWORKS': '2620:2d:4000:2001::/64 10.1.2.0/24'},
networks=[
ip_network('2620:2d:4000:2001::/64'), ip_network('10.1.2.0/24')
]
)


def test_is_trusted_addr():
cfg = assert_config({'TALISKER_NETWORKS': ''}, networks=[])
assert not cfg.is_trusted_addr('2620:2d:4000:2001::11b')
assert not cfg.is_trusted_addr('10.1.2.128')
cfg = assert_config(
{'TALISKER_NETWORKS': '2620:2d:4000:2001::/64 10.1.2.0/24'},
networks=[
ip_network('2620:2d:4000:2001::/64'), ip_network('10.1.2.0/24')
]
)
assert cfg.is_trusted_addr('2620:2d:4000:2001::11b')
assert cfg.is_trusted_addr('10.1.2.128')

0 comments on commit 5b01ab3

Please sign in to comment.