aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_rdap.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_rdap.py')
-rw-r--r--tests/test_rdap.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_rdap.py b/tests/test_rdap.py
index 3fc2c65..14a1fd4 100644
--- a/tests/test_rdap.py
+++ b/tests/test_rdap.py
@@ -125,5 +125,56 @@ class Bootstrap(unittest.TestCase):
rdap.bootstrap("ipv4", cache_root=self.cache, fetch=fetch)
+class ServerSelection(unittest.TestCase):
+ IPV4 = {
+ "services": [
+ [["192.0.2.0/24"], ["https://wide.example.invalid/"]],
+ [["192.0.2.128/25"], ["https://narrow.example.invalid/"]],
+ [["198.51.100.0/24"], ["https://other.example.invalid/"]],
+ ]
+ }
+ DNS = {
+ "services": [
+ [["invalid"], ["https://registry.example.invalid/"]],
+ [["test"], ["https://test.example.invalid/"]],
+ ]
+ }
+
+ def test_an_address_selects_its_range(self):
+ self.assertEqual(
+ rdap.server_for_ip("198.51.100.7", self.IPV4),
+ "https://other.example.invalid/",
+ )
+
+ def test_the_longest_prefix_wins(self):
+ """192.0.2.200 is in both /24 and /25; the /25 is more specific.
+
+ Choosing the wider range would ask a registry that has delegated
+ the block away, and its answer would name the wrong operator.
+ """
+ self.assertEqual(
+ rdap.server_for_ip("192.0.2.200", self.IPV4),
+ "https://narrow.example.invalid/",
+ )
+
+ def test_an_unlisted_address_selects_nothing(self):
+ self.assertIsNone(rdap.server_for_ip("203.0.113.9", self.IPV4))
+
+ def test_a_tld_selects_its_registry(self):
+ self.assertEqual(
+ rdap.server_for_tld("invalid", self.DNS),
+ "https://registry.example.invalid/",
+ )
+
+ def test_tld_matching_ignores_case(self):
+ self.assertEqual(
+ rdap.server_for_tld("INVALID", self.DNS),
+ "https://registry.example.invalid/",
+ )
+
+ def test_an_unlisted_tld_selects_nothing(self):
+ self.assertIsNone(rdap.server_for_tld("example", self.DNS))
+
+
if __name__ == "__main__":
unittest.main()