|
24 | 24 | sys.path[0:0] = [""] |
25 | 25 |
|
26 | 26 | from test import unittest |
27 | | -from unittest.mock import MagicMock, patch |
| 27 | +from unittest.mock import patch |
28 | 28 |
|
29 | 29 | from bson.binary import JAVA_LEGACY |
30 | 30 | from pymongo import ReadPreference |
|
37 | 37 | ) |
38 | 38 |
|
39 | 39 |
|
40 | | -def run_initial_dns_seedlist_discovery_prose_tests(self, test_cases): |
41 | | - for case in test_cases: |
42 | | - with patch("dns.resolver.resolve") as mock_resolver: |
43 | | - |
44 | | - def mock_resolve(query, record_type, *args, **kwargs): |
45 | | - mock_srv = MagicMock() |
46 | | - mock_srv.target.to_text.return_value = case["mock_target"] |
47 | | - return [mock_srv] |
48 | | - |
49 | | - mock_resolver.side_effect = mock_resolve |
50 | | - domain = case["query"].split("._tcp.")[1] |
51 | | - connection_string = f"mongodb+srv://{domain}" |
52 | | - try: |
53 | | - parse_uri(connection_string) |
54 | | - except ConfigurationError as e: |
55 | | - self.assertIn(case["expected_error"], str(e)) |
56 | | - else: |
57 | | - self.fail(f"ConfigurationError was not raised for query: {case['query']}") |
58 | | - |
59 | | - |
60 | 40 | class TestURI(unittest.TestCase): |
61 | 41 | def test_validate_userinfo(self): |
62 | 42 | self.assertRaises(InvalidURI, parse_userinfo, "foo@") |
@@ -574,71 +554,6 @@ def test_port_with_whitespace(self): |
574 | 554 | with self.assertRaisesRegex(ValueError, r"Port contains whitespace character: '\\n'"): |
575 | 555 | parse_uri("mongodb://localhost:27\n017") |
576 | 556 |
|
577 | | - # Initial DNS Seedlist Discovery prose tests |
578 | | - # https://github.com/mongodb/specifications/blob/0a7a8b5/source/initial-dns-seedlist-discovery/tests/README.md#prose-tests |
579 | | - |
580 | | - def test_1_allow_srv_hosts_with_fewer_than_three_dot_separated_parts(self): |
581 | | - with patch("dns.resolver.resolve"): |
582 | | - parse_uri("mongodb+srv://localhost/") |
583 | | - parse_uri("mongodb+srv://mongo.local/") |
584 | | - |
585 | | - def test_2_throw_when_return_address_does_not_end_with_srv_domain(self): |
586 | | - test_cases = [ |
587 | | - { |
588 | | - "query": "_mongodb._tcp.localhost", |
589 | | - "mock_target": "localhost.mongodb", |
590 | | - "expected_error": "Invalid SRV host", |
591 | | - }, |
592 | | - { |
593 | | - "query": "_mongodb._tcp.blogs.mongodb.com", |
594 | | - "mock_target": "blogs.evil.com", |
595 | | - "expected_error": "Invalid SRV host", |
596 | | - }, |
597 | | - { |
598 | | - "query": "_mongodb._tcp.blogs.mongo.local", |
599 | | - "mock_target": "test_1.evil.com", |
600 | | - "expected_error": "Invalid SRV host", |
601 | | - }, |
602 | | - ] |
603 | | - run_initial_dns_seedlist_discovery_prose_tests(self, test_cases) |
604 | | - |
605 | | - def test_3_throw_when_return_address_is_identical_to_srv_hostname(self): |
606 | | - test_cases = [ |
607 | | - { |
608 | | - "query": "_mongodb._tcp.localhost", |
609 | | - "mock_target": "localhost", |
610 | | - "expected_error": "Invalid SRV host", |
611 | | - }, |
612 | | - { |
613 | | - "query": "_mongodb._tcp.mongo.local", |
614 | | - "mock_target": "mongo.local", |
615 | | - "expected_error": "Invalid SRV host", |
616 | | - }, |
617 | | - ] |
618 | | - run_initial_dns_seedlist_discovery_prose_tests(self, test_cases) |
619 | | - |
620 | | - def test_4_throw_when_return_address_does_not_contain_dot_separating_shared_part_of_domain( |
621 | | - self |
622 | | - ): |
623 | | - test_cases = [ |
624 | | - { |
625 | | - "query": "_mongodb._tcp.localhost", |
626 | | - "mock_target": "test_1.cluster_1localhost", |
627 | | - "expected_error": "Invalid SRV host", |
628 | | - }, |
629 | | - { |
630 | | - "query": "_mongodb._tcp.mongo.local", |
631 | | - "mock_target": "test_1.my_hostmongo.local", |
632 | | - "expected_error": "Invalid SRV host", |
633 | | - }, |
634 | | - { |
635 | | - "query": "_mongodb._tcp.blogs.mongodb.com", |
636 | | - "mock_target": "cluster.testmongodb.com", |
637 | | - "expected_error": "Invalid SRV host", |
638 | | - }, |
639 | | - ] |
640 | | - run_initial_dns_seedlist_discovery_prose_tests(self, test_cases) |
641 | | - |
642 | 557 |
|
643 | 558 | if __name__ == "__main__": |
644 | 559 | unittest.main() |
0 commit comments