From c24c793bcbe59acdac97b819e649c8dceca103fe Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sat, 26 Aug 2017 15:28:09 -0700 Subject: [PATCH] CAA unit tests for provider support --- octodns/provider/powerdns.py | 2 +- tests/config/unit.tests.yaml | 5 +++++ tests/fixtures/powerdns-full-data.json | 12 ++++++++++ tests/test_octodns_provider_dyn.py | 22 +++++++++++++++++-- tests/test_octodns_provider_ns1.py | 14 ++++++++++++ tests/test_octodns_provider_powerdns.py | 6 ++--- tests/test_octodns_provider_route53.py | 29 ++++++++++++++++++------- tests/test_octodns_provider_yaml.py | 2 +- 8 files changed, 77 insertions(+), 15 deletions(-) diff --git a/octodns/provider/powerdns.py b/octodns/provider/powerdns.py index 55ca0b1..20cfe8b 100644 --- a/octodns/provider/powerdns.py +++ b/octodns/provider/powerdns.py @@ -68,7 +68,7 @@ class PowerDnsBaseProvider(BaseProvider): values.append({ 'flags': flags, 'tag': tag, - 'value': value, + 'value': value[1:-1], }) return { 'type': rrset['type'], diff --git a/tests/config/unit.tests.yaml b/tests/config/unit.tests.yaml index 8be1614..5241406 100644 --- a/tests/config/unit.tests.yaml +++ b/tests/config/unit.tests.yaml @@ -31,6 +31,11 @@ values: - 6.2.3.4. - 7.2.3.4. + - type: CAA + values: + - flags: 0 + tag: issue + value: ca.unit.tests _srv._tcp: ttl: 600 type: SRV diff --git a/tests/fixtures/powerdns-full-data.json b/tests/fixtures/powerdns-full-data.json index 72ce016..b8f8bf3 100644 --- a/tests/fixtures/powerdns-full-data.json +++ b/tests/fixtures/powerdns-full-data.json @@ -230,6 +230,18 @@ ], "ttl": 300, "type": "A" + }, + { + "comments": [], + "name": "unit.tests.", + "records": [ + { + "content": "0 issue \"ca.unit.tests\"", + "disabled": false + } + ], + "ttl": 3600, + "type": "CAA" } ], "serial": 2017012803, diff --git a/tests/test_octodns_provider_dyn.py b/tests/test_octodns_provider_dyn.py index bebd3e3..9be253d 100644 --- a/tests/test_octodns_provider_dyn.py +++ b/tests/test_octodns_provider_dyn.py @@ -109,6 +109,14 @@ class TestDynProvider(TestCase): 'weight': 22, 'port': 20, 'target': 'foo-2.unit.tests.' + }]}), + ('', { + 'type': 'CAA', + 'ttl': 308, + 'values': [{ + 'flags': 0, + 'tag': 'issue', + 'value': 'ca.unit.tests' }]})): expected.add_record(Record.new(expected, name, data)) @@ -321,6 +329,16 @@ class TestDynProvider(TestCase): 'ttl': 307, 'zone': 'unit.tests', }], + 'caa_records': [{ + 'fqdn': 'unit.tests', + 'rdata': {'flags': 0, + 'tag': 'issue', + 'value': 'ca.unit.tests'}, + 'record_id': 12, + 'record_type': 'cAA', + 'ttl': 308, + 'zone': 'unit.tests', + }], }} ] got = Zone('unit.tests.', []) @@ -414,10 +432,10 @@ class TestDynProvider(TestCase): update_mock.assert_called() add_mock.assert_called() # Once for each dyn record (8 Records, 2 of which have dual values) - self.assertEquals(14, len(add_mock.call_args_list)) + self.assertEquals(15, len(add_mock.call_args_list)) execute_mock.assert_has_calls([call('/Zone/unit.tests/', 'GET', {}), call('/Zone/unit.tests/', 'GET', {})]) - self.assertEquals(9, len(plan.changes)) + self.assertEquals(10, len(plan.changes)) execute_mock.reset_mock() diff --git a/tests/test_octodns_provider_ns1.py b/tests/test_octodns_provider_ns1.py index 4df56b3..cde23b0 100644 --- a/tests/test_octodns_provider_ns1.py +++ b/tests/test_octodns_provider_ns1.py @@ -96,6 +96,15 @@ class TestNs1Provider(TestCase): 'type': 'NS', 'values': ['ns3.unit.tests.', 'ns4.unit.tests.'], })) + expected.add(Record.new(zone, '', { + 'ttl': 40, + 'type': 'CAA', + 'value': { + 'flags': 0, + 'tag': 'issue', + 'value': 'ca.unit.tests', + }, + })) nsone_records = [{ 'type': 'A', @@ -141,6 +150,11 @@ class TestNs1Provider(TestCase): 'ttl': 39, 'short_answers': ['ns3.unit.tests.', 'ns4.unit.tests.'], 'domain': 'sub.unit.tests.', + }, { + 'type': 'CAA', + 'ttl': 40, + 'short_answers': ['0 issue ca.unit.tests'], + 'domain': 'unit.tests.', }] @patch('nsone.NSONE.loadZone') diff --git a/tests/test_octodns_provider_powerdns.py b/tests/test_octodns_provider_powerdns.py index 5fcd80a..b6e02ff 100644 --- a/tests/test_octodns_provider_powerdns.py +++ b/tests/test_octodns_provider_powerdns.py @@ -79,7 +79,7 @@ class TestPowerDnsProvider(TestCase): source = YamlProvider('test', join(dirname(__file__), 'config')) source.populate(expected) expected_n = len(expected.records) - 1 - self.assertEquals(14, expected_n) + self.assertEquals(15, expected_n) # No diffs == no changes with requests_mock() as mock: @@ -87,7 +87,7 @@ class TestPowerDnsProvider(TestCase): zone = Zone('unit.tests.', []) provider.populate(zone) - self.assertEquals(14, len(zone.records)) + self.assertEquals(15, len(zone.records)) changes = expected.changes(zone, provider) self.assertEquals(0, len(changes)) @@ -167,7 +167,7 @@ class TestPowerDnsProvider(TestCase): expected = Zone('unit.tests.', []) source = YamlProvider('test', join(dirname(__file__), 'config')) source.populate(expected) - self.assertEquals(15, len(expected.records)) + self.assertEquals(16, len(expected.records)) # A small change to a single record with requests_mock() as mock: diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 97dae4f..1cd4548 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -77,6 +77,12 @@ class TestRoute53Provider(TestCase): {'ttl': 67, 'type': 'NS', 'values': ['8.2.3.4.', '9.2.3.4.']}), ('sub', {'ttl': 68, 'type': 'NS', 'values': ['5.2.3.4.', '6.2.3.4.']}), + ('', + {'ttl': 69, 'type': 'CAA', 'value': { + 'flags': 0, + 'tag': 'issue', + 'value': 'ca.unit.tests' + }}), ): record = Record.new(expected, name, data) expected.add_record(record) @@ -300,6 +306,13 @@ class TestRoute53Provider(TestCase): 'Value': 'ns1.unit.tests.', }], 'TTL': 69, + }, { + 'Name': 'unit.tests.', + 'Type': 'CAA', + 'ResourceRecords': [{ + 'Value': '0 issue "ca.unit.tests"', + }], + 'TTL': 69, }], 'IsTruncated': False, 'MaxItems': '100', @@ -347,7 +360,7 @@ class TestRoute53Provider(TestCase): {'HostedZoneId': 'z42'}) plan = provider.plan(self.expected) - self.assertEquals(8, len(plan.changes)) + self.assertEquals(9, len(plan.changes)) for change in plan.changes: self.assertIsInstance(change, Create) stubber.assert_no_pending_responses() @@ -366,7 +379,7 @@ class TestRoute53Provider(TestCase): 'SubmittedAt': '2017-01-29T01:02:03Z', }}, {'HostedZoneId': 'z42', 'ChangeBatch': ANY}) - self.assertEquals(8, provider.apply(plan)) + self.assertEquals(9, provider.apply(plan)) stubber.assert_no_pending_responses() # Delete by monkey patching in a populate that includes an extra record @@ -579,7 +592,7 @@ class TestRoute53Provider(TestCase): {}) plan = provider.plan(self.expected) - self.assertEquals(8, len(plan.changes)) + self.assertEquals(9, len(plan.changes)) for change in plan.changes: self.assertIsInstance(change, Create) stubber.assert_no_pending_responses() @@ -626,7 +639,7 @@ class TestRoute53Provider(TestCase): 'SubmittedAt': '2017-01-29T01:02:03Z', }}, {'HostedZoneId': 'z42', 'ChangeBatch': ANY}) - self.assertEquals(8, provider.apply(plan)) + self.assertEquals(9, provider.apply(plan)) stubber.assert_no_pending_responses() def test_health_checks_pagination(self): @@ -1174,16 +1187,16 @@ class TestRoute53Provider(TestCase): @patch('octodns.provider.route53.Route53Provider._really_apply') def test_apply_1(self, really_apply_mock): - # 17 RRs with max of 18 should only get applied in one call - provider, plan = self._get_test_plan(18) + # 18 RRs with max of 19 should only get applied in one call + provider, plan = self._get_test_plan(19) provider.apply(plan) really_apply_mock.assert_called_once() @patch('octodns.provider.route53.Route53Provider._really_apply') def test_apply_2(self, really_apply_mock): - # 17 RRs with max of 17 should only get applied in two calls - provider, plan = self._get_test_plan(17) + # 18 RRs with max of 17 should only get applied in two calls + provider, plan = self._get_test_plan(18) provider.apply(plan) self.assertEquals(2, really_apply_mock.call_count) diff --git a/tests/test_octodns_provider_yaml.py b/tests/test_octodns_provider_yaml.py index 9438f01..36cd8d6 100644 --- a/tests/test_octodns_provider_yaml.py +++ b/tests/test_octodns_provider_yaml.py @@ -30,7 +30,7 @@ class TestYamlProvider(TestCase): # without it we see everything source.populate(zone) - self.assertEquals(15, len(zone.records)) + self.assertEquals(16, len(zone.records)) # Assumption here is that a clean round-trip means that everything # worked as expected, data that went in came back out and could be