Beispiel #1
0
 def setUp(self):
     CloudFlareDNSDriver.connectionCls.conn_class = CloudFlareMockHttp
     CloudFlareDNSDriver.ZONES_PAGE_SIZE = 5
     CloudFlareDNSDriver.RECORDS_PAGE_SIZE = 5
     CloudFlareDNSDriver.MEMBERSHIPS_PAGE_SIZE = 5
     CloudFlareMockHttp.type = None
     CloudFlareMockHttp.use_param = "a"
     self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)
Beispiel #2
0
 def setUp(self):
     CloudFlareDNSDriver.connectionCls.conn_class = CloudFlareMockHttp
     CloudFlareMockHttp.type = None
     CloudFlareMockHttp.use_param = 'a'
     self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)
Beispiel #3
0
class CloudFlareDNSDriverTestCase(unittest.TestCase):
    def setUp(self):
        CloudFlareDNSDriver.connectionCls.conn_class = CloudFlareMockHttp
        CloudFlareMockHttp.type = None
        CloudFlareMockHttp.use_param = 'a'
        self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 9)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        zone = zones[0]
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

        for attribute_name in ZONE_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in zone.extra)

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 18)

        record = records[0]
        self.assertEqual(record.id, '364797364')
        self.assertEqual(record.name, None)
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '192.30.252.153')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = records[4]
        self.assertEqual(record.id, '364982413')
        self.assertEqual(record.name, 'yesyes')
        self.assertEqual(record.type, 'CNAME')
        self.assertEqual(record.data, 'verify.bing.com')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id='1234')
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

    def test_get_zone_zone_doesnt_exist(self):
        self.assertRaises(ZoneDoesNotExistError,
                          self.driver.get_zone,
                          zone_id='doenstexist')

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(name='test5',
                                           zone=zone,
                                           type='A',
                                           data='127.0.0.3')
        self.assertEqual(record.id, '412561327')
        self.assertEqual(record.name, 'test5')
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '127.0.0.3')

    def test_update_records(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        updated_record = self.driver.update_record(record=record,
                                                   data='127.0.0.4')

        self.assertEqual(updated_record.name, 'test6')
        self.assertEqual(updated_record.type, 'A')
        self.assertEqual(updated_record.data, '127.0.0.4')
        self.assertEqual(updated_record.ttl, 120)

    def test_delete_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        result = self.driver.delete_record(record=record)
        self.assertTrue(result)

    def test_delete_zone(self):
        zone = self.driver.list_zones()[0]
        self.assertRaises(NotImplementedError,
                          self.driver.delete_zone,
                          zone=zone)

    def test_ex_get_zone_stats(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_get_zone_stats(zone=zone)
        self.assertTrue('trafficBreakdown' in result)
        self.assertTrue('bandwidthServed' in result)
        self.assertTrue('requestsServed' in result)
        self.assertTrue('pro_zone' in result)
        self.assertTrue('userSecuritySetting' in result)

    def test_ex_zone_check(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_zone_check(zones=[zone])
        self.assertEqual(result, {'example.com': 4025956})

    def test_ex_get_ip_threat_score(self):
        result = self.driver.ex_get_ip_threat_score(ip='127.0.0.1')
        self.assertEqual(result, {'127.0.0.1': False})

    def test_get_ex_zone_settings(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_get_zone_settings(zone=zone)
        self.assertTrue('dnssec' in result)
        self.assertTrue('ddos' in result)
        self.assertTrue('email_filter' in result)
        self.assertTrue('secureheader_settings' in result)

    def test_ex_set_one_security_level(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_set_zone_security_level(zone=zone, level='med')
        self.assertTrue(result)

    def test_ex_set_zone_cache_level(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_set_zone_cache_level(zone=zone, level='agg')
        self.assertTrue(result)

    def test_ex_enable_development_mode(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_enable_development_mode(zone=zone)
        self.assertTrue(result)

    def test_ex_disable_development_mode(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_disable_development_mode(zone=zone)
        self.assertTrue(result)

    def test_ex_purge_cached_files(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_purge_cached_files(zone=zone)
        self.assertTrue(result)

    def test_ex_purge_cached_file(self):
        zone = self.driver.list_zones()[0]
        url = 'https://www.example.com/test.html'
        result = self.driver.ex_purge_cached_file(zone=zone, url=url)
        self.assertTrue(result)

    def test_ex_whitelist_ip(self):
        zone = self.driver.list_zones()[0]
        ip = '127.0.0.1'
        result = self.driver.ex_whitelist_ip(zone=zone, ip=ip)
        self.assertTrue(result)

    def test_ex_blacklist_ip(self):
        zone = self.driver.list_zones()[0]
        ip = '127.0.0.1'
        result = self.driver.ex_blacklist_ip(zone=zone, ip=ip)
        self.assertTrue(result)

    def test_ex_unlist_ip(self):
        zone = self.driver.list_zones()[0]
        ip = '127.0.0.1'
        result = self.driver.ex_unlist_ip(zone=zone, ip=ip)
        self.assertTrue(result)

    def test_enable_ipv6_support(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_enable_development_mode(zone=zone)
        self.assertTrue(result)

    def test_ex_disable_ipv6_support(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_disable_development_mode(zone=zone)
        self.assertTrue(result)
Beispiel #4
0
 def test_auth_token(self):
     driver = CloudFlareDNSDriver("sometoken")
     self.assertEqual(driver.connectionCls, TokenDNSConnection)
Beispiel #5
0
 def test_auth_key(self):
     driver = CloudFlareDNSDriver("*****@*****.**", "key")
     self.assertEqual(driver.connectionCls, GlobalAPIKeyDNSConnection)
Beispiel #6
0
class CloudFlareDNSDriverTestCase(unittest.TestCase):
    def setUp(self):
        CloudFlareDNSDriver.connectionCls.conn_class = CloudFlareMockHttp
        CloudFlareDNSDriver.ZONES_PAGE_SIZE = 5
        CloudFlareDNSDriver.RECORDS_PAGE_SIZE = 5
        CloudFlareDNSDriver.MEMBERSHIPS_PAGE_SIZE = 5
        CloudFlareMockHttp.type = None
        CloudFlareMockHttp.use_param = "a"
        self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)

    def test_auth_key(self):
        driver = CloudFlareDNSDriver("*****@*****.**", "key")
        self.assertEqual(driver.connectionCls, GlobalAPIKeyDNSConnection)

    def test_auth_token(self):
        driver = CloudFlareDNSDriver("sometoken")
        self.assertEqual(driver.connectionCls, TokenDNSConnection)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 9)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        zone = zones[0]
        self.assertEqual(zone.id, "1234")
        self.assertEqual(zone.domain, "example.com")
        self.assertEqual(zone.type, "master")

        for attribute_name in ZONE_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in zone.extra)

    def test_get_record(self):
        record = self.driver.get_record("1234", "364797364")

        self.assertEqual(record.id, "364797364")
        self.assertIsNone(record.name)
        self.assertEqual(record.type, "A")
        self.assertEqual(record.data, "192.30.252.153")

    def test_get_record_record_doesnt_exist(self):
        with self.assertRaises(RecordDoesNotExistError):
            self.driver.get_record("1234", "0000")

    def test_get_record_record_is_invalid(self):
        with self.assertRaises(LibcloudError):
            self.driver.get_record("1234", "invalid")

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 11)

        record = records[0]
        self.assertEqual(record.id, "364797364")
        self.assertIsNone(record.name)
        self.assertEqual(record.type, "A")
        self.assertEqual(record.data, "192.30.252.153")
        self.assertEqual(record.extra["priority"], None)

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = records[4]
        self.assertEqual(record.id, "364982413")
        self.assertEqual(record.name, "yesyes")
        self.assertEqual(record.type, "CNAME")
        self.assertEqual(record.data, "verify.bing.com")

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = [r for r in records if r.type == "MX"][0]
        self.assertEqual(record.id, "78526")
        self.assertIsNone(record.name)
        self.assertEqual(record.type, "MX")
        self.assertEqual(record.data, "aspmx3.googlemail.com")
        self.assertEqual(record.extra["priority"], 30)

        record = records[-1]
        self.assertEqual(record.id, "r8")
        self.assertEqual(record.name, "test1")
        self.assertEqual(record.type, "CAA")
        self.assertEqual(record.data, "0 issue test.example.com")

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id="1234")
        self.assertEqual(zone.id, "1234")
        self.assertEqual(zone.domain, "example.com")
        self.assertEqual(zone.type, "master")

    def test_get_zone_zone_doesnt_exist(self):
        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.get_zone("0000")

    def test_get_zone_zone_is_invalid(self):
        with self.assertRaises(LibcloudError):
            self.driver.get_zone("invalid")

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(
            name="test5",
            zone=zone,
            type=RecordType.A,
            data="127.0.0.3",
            extra={"proxied": True},
        )
        self.assertEqual(record.id, "412561327")
        self.assertEqual(record.name, "test5")
        self.assertEqual(record.type, "A")
        self.assertEqual(record.data, "127.0.0.3")

    def test_create_record_SSHFP_record_type(self):
        zone = self.driver.list_zones()[0]

        CloudFlareMockHttp.type = "sshfp_record_type"
        record = self.driver.create_record(name="test_sshfp",
                                           zone=zone,
                                           type=RecordType.SSHFP,
                                           data="2 1 ABCDEF12345")
        self.assertEqual(record.id, "200")
        self.assertEqual(record.name, "test_sshfp")
        self.assertEqual(record.type, "SSHFP")
        self.assertEqual(record.data, "2 1 ABCDEF12345")

    def test_create_record_CAA_record_type(self):
        zone = self.driver.list_zones()[0]

        CloudFlareMockHttp.type = "caa_record_type"
        record = self.driver.create_record(name="test5",
                                           zone=zone,
                                           type=RecordType.CAA,
                                           data="0 issue caa.example.com")
        self.assertEqual(record.id, "412561327")
        self.assertEqual(record.name, "test5")
        self.assertEqual(record.type, "A")
        self.assertEqual(record.data, "127.0.0.3")

    def test_create_record_error_with_error_chain(self):
        zone = self.driver.list_zones()[0]

        CloudFlareMockHttp.type = "error_chain_error"

        expected_msg = r".*1004: DNS Validation Error \(error chain: 9011: Length of content is invalid\)"

        self.assertRaisesRegex(
            LibcloudError,
            expected_msg,
            self.driver.create_record,
            name="test5",
            zone=zone,
            type=RecordType.CAA,
            data="caa.foo.com",
        )

    def test_create_record_with_property_that_cant_be_set(self):
        zone = self.driver.list_zones()[0]

        record = self.driver.create_record(
            name="test5",
            zone=zone,
            type=RecordType.A,
            data="127.0.0.3",
            extra={"locked": True},
        )

        self.assertNotEqual(record.extra["locked"], True)

    def test_update_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        updated_record = self.driver.update_record(
            record=record,
            name="test6",
            type=RecordType.A,
            data="127.0.0.4",
            extra={"proxied": True},
        )

        self.assertEqual(updated_record.name, "test6")
        self.assertEqual(updated_record.type, "A")
        self.assertEqual(updated_record.data, "127.0.0.4")
        self.assertEqual(updated_record.extra["proxied"], True)

    def test_update_record_with_property_that_cant_be_updated(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]

        updated_record = self.driver.update_record(record=record,
                                                   data="127.0.0.4",
                                                   extra={"locked": True})

        self.assertNotEqual(updated_record.extra["locked"], True)

    def test_delete_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        result = self.driver.delete_record(record=record)
        self.assertTrue(result)

    def test_delete_zone(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.delete_zone(zone=zone)
        self.assertTrue(result)

    def test_create_zone(self):
        zone = self.driver.create_zone(domain="example2.com",
                                       extra={"jump_start": False})
        self.assertEqual(zone.id, "6789")
        self.assertEqual(zone.domain, "example2.com")

    def test_create_zone_with_explicit_account(self):
        zone = self.driver.create_zone(
            domain="example2.com",
            extra={"account": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"})
        self.assertEqual(zone.id, "6789")
        self.assertEqual(zone.domain, "example2.com")

    def test_update_zone(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone=zone,
                                               domain="",
                                               extra={"paused": True})

        self.assertEqual(zone.id, updated_zone.id)
        self.assertEqual(zone.domain, updated_zone.domain)
        self.assertEqual(zone.type, updated_zone.type)
        self.assertEqual(zone.ttl, updated_zone.ttl)

        for key in set(zone.extra) | set(updated_zone.extra):
            if key in ("paused", "modified_on"):
                self.assertNotEqual(zone.extra[key], updated_zone.extra[key])
            else:
                self.assertEqual(zone.extra[key], updated_zone.extra[key])

    def test_update_zone_with_property_that_cant_be_updated(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone,
                                               domain="",
                                               extra={"owner": "owner"})

        self.assertEqual(zone, updated_zone)

    def test_update_zone_with_no_property(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone, domain="", extra=None)

        self.assertEqual(zone, updated_zone)

    def test_update_zone_with_more_than_one_property(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone,
                                               domain="",
                                               extra={
                                                   "paused": True,
                                                   "plan": None
                                               })

        self.assertEqual(zone, updated_zone)

    def test_caa_normalize_record_data_for_api(self):
        content, data = self.driver._normalize_record_data_for_api(
            RecordType.CAA, "0 issue foo.bar")
        self.assertEqual(content, "0\tissue\tfoo.bar")
        self.assertEqual(data, {})

    def test_sshfp_normalize_record_data_for_api(self):
        content, data = self.driver._normalize_record_data_for_api(
            RecordType.SSHFP, "2 1 ABCDEF12345")
        self.assertIsNone(content)
        self.assertEqual(data, {
            "algorithm": "2",
            "type": "1",
            "fingerprint": "ABCDEF12345"
        })

    def test_normalize_record_data_from_apu(self):
        result = self.driver._normalize_record_data_from_api(
            RecordType.CAA, "0\tissue\tfoo.bar")
        self.assertEqual(result, "0 issue foo.bar")
Beispiel #7
0
class CloudFlareDNSDriverTestCase(unittest.TestCase):
    def setUp(self):
        CloudFlareDNSDriver.connectionCls.conn_class = CloudFlareMockHttp
        CloudFlareDNSDriver.ZONES_PAGE_SIZE = 5
        CloudFlareDNSDriver.RECORDS_PAGE_SIZE = 5
        CloudFlareDNSDriver.MEMBERSHIPS_PAGE_SIZE = 5
        CloudFlareMockHttp.type = None
        CloudFlareMockHttp.use_param = 'a'
        self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 9)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        zone = zones[0]
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

        for attribute_name in ZONE_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in zone.extra)

    def test_get_record(self):
        record = self.driver.get_record('1234', '364797364')

        self.assertEqual(record.id, '364797364')
        self.assertIsNone(record.name)
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '192.30.252.153')

    def test_get_record_record_doesnt_exist(self):
        with self.assertRaises(RecordDoesNotExistError):
            self.driver.get_record('1234', '0000')

    def test_get_record_record_is_invalid(self):
        with self.assertRaises(LibcloudError):
            self.driver.get_record('1234', 'invalid')

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 11)

        record = records[0]
        self.assertEqual(record.id, '364797364')
        self.assertIsNone(record.name)
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '192.30.252.153')
        self.assertEqual(record.extra['priority'], None)

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = records[4]
        self.assertEqual(record.id, '364982413')
        self.assertEqual(record.name, 'yesyes')
        self.assertEqual(record.type, 'CNAME')
        self.assertEqual(record.data, 'verify.bing.com')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = [r for r in records if r.type == 'MX'][0]
        self.assertEqual(record.id, '78526')
        self.assertIsNone(record.name)
        self.assertEqual(record.type, 'MX')
        self.assertEqual(record.data, 'aspmx3.googlemail.com')
        self.assertEqual(record.extra['priority'], 30)

        record = records[-1]
        self.assertEqual(record.id, 'r8')
        self.assertEqual(record.name, 'test1')
        self.assertEqual(record.type, 'CAA')
        self.assertEqual(record.data, '0 issue test.example.com')

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id='1234')
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

    def test_get_zone_zone_doesnt_exist(self):
        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.get_zone('0000')

    def test_get_zone_zone_is_invalid(self):
        with self.assertRaises(LibcloudError):
            self.driver.get_zone('invalid')

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(name='test5',
                                           zone=zone,
                                           type=RecordType.A,
                                           data='127.0.0.3',
                                           extra={'proxied': True})
        self.assertEqual(record.id, '412561327')
        self.assertEqual(record.name, 'test5')
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '127.0.0.3')

    def test_create_record_CAA_record_type(self):
        zone = self.driver.list_zones()[0]

        CloudFlareMockHttp.type = 'caa_record_type'
        record = self.driver.create_record(name='test5',
                                           zone=zone,
                                           type=RecordType.CAA,
                                           data='0 issue caa.example.com')
        self.assertEqual(record.id, '412561327')
        self.assertEqual(record.name, 'test5')
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '127.0.0.3')

    def test_create_record_error_with_error_chain(self):
        zone = self.driver.list_zones()[0]

        CloudFlareMockHttp.type = 'error_chain_error'

        expected_msg = r'.*1004: DNS Validation Error \(error chain: 9011: Length of content is invalid\)'

        self.assertRaisesRegex(LibcloudError,
                               expected_msg,
                               self.driver.create_record,
                               name='test5',
                               zone=zone,
                               type=RecordType.CAA,
                               data='caa.foo.com')

    def test_create_record_with_property_that_cant_be_set(self):
        zone = self.driver.list_zones()[0]

        record = self.driver.create_record(name='test5',
                                           zone=zone,
                                           type=RecordType.A,
                                           data='127.0.0.3',
                                           extra={'locked': True})

        self.assertNotEqual(record.extra['locked'], True)

    def test_update_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        updated_record = self.driver.update_record(record=record,
                                                   name='test6',
                                                   type=RecordType.A,
                                                   data='127.0.0.4',
                                                   extra={'proxied': True})

        self.assertEqual(updated_record.name, 'test6')
        self.assertEqual(updated_record.type, 'A')
        self.assertEqual(updated_record.data, '127.0.0.4')
        self.assertEqual(updated_record.extra['proxied'], True)

    def test_update_record_with_property_that_cant_be_updated(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]

        updated_record = self.driver.update_record(record=record,
                                                   data='127.0.0.4',
                                                   extra={'locked': True})

        self.assertNotEqual(updated_record.extra['locked'], True)

    def test_delete_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        result = self.driver.delete_record(record=record)
        self.assertTrue(result)

    def test_delete_zone(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.delete_zone(zone=zone)
        self.assertTrue(result)

    def test_create_zone(self):
        zone = self.driver.create_zone(domain='example2.com',
                                       extra={'jump_start': False})
        self.assertEqual(zone.id, '6789')
        self.assertEqual(zone.domain, 'example2.com')

    def test_create_zone_with_explicit_account(self):
        zone = self.driver.create_zone(
            domain='example2.com',
            extra={'account': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
        self.assertEqual(zone.id, '6789')
        self.assertEqual(zone.domain, 'example2.com')

    def test_update_zone(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone=zone,
                                               domain='',
                                               extra={'paused': True})

        self.assertEqual(zone.id, updated_zone.id)
        self.assertEqual(zone.domain, updated_zone.domain)
        self.assertEqual(zone.type, updated_zone.type)
        self.assertEqual(zone.ttl, updated_zone.ttl)

        for key in set(zone.extra) | set(updated_zone.extra):
            if key in ('paused', 'modified_on'):
                self.assertNotEqual(zone.extra[key], updated_zone.extra[key])
            else:
                self.assertEqual(zone.extra[key], updated_zone.extra[key])

    def test_update_zone_with_property_that_cant_be_updated(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone,
                                               domain='',
                                               extra={'owner': 'owner'})

        self.assertEqual(zone, updated_zone)

    def test_update_zone_with_no_property(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone, domain='', extra=None)

        self.assertEqual(zone, updated_zone)

    def test_update_zone_with_more_than_one_property(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone,
                                               domain='',
                                               extra={
                                                   'paused': True,
                                                   'plan': None
                                               })

        self.assertEqual(zone, updated_zone)

    def test_normalize_record_data_for_api(self):
        result = self.driver._normalize_record_data_for_api(
            RecordType.CAA, '0 issue foo.bar')
        self.assertEqual(result, '0\tissue\tfoo.bar')

    def test_normalize_record_data_from_apu(self):
        result = self.driver._normalize_record_data_from_api(
            RecordType.CAA, '0\tissue\tfoo.bar')
        self.assertEqual(result, '0 issue foo.bar')
Beispiel #8
0
class CloudFlareDNSDriverTestCase(unittest.TestCase):
    def setUp(self):
        CloudFlareDNSDriver.connectionCls.conn_class = CloudFlareMockHttp
        CloudFlareDNSDriver.ZONES_PAGE_SIZE = 5
        CloudFlareDNSDriver.RECORDS_PAGE_SIZE = 5
        CloudFlareDNSDriver.MEMBERSHIPS_PAGE_SIZE = 5
        CloudFlareMockHttp.type = None
        CloudFlareMockHttp.use_param = 'a'
        self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 9)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        zone = zones[0]
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

        for attribute_name in ZONE_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in zone.extra)

    def test_get_record(self):
        record = self.driver.get_record('1234', '364797364')

        self.assertEqual(record.id, '364797364')
        self.assertIsNone(record.name)
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '192.30.252.153')

    def test_get_record_record_doesnt_exist(self):
        with self.assertRaises(RecordDoesNotExistError):
            self.driver.get_record('1234', '0000')

    def test_get_record_record_is_invalid(self):
        with self.assertRaises(LibcloudError):
            self.driver.get_record('1234', 'invalid')

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 9)

        record = records[0]
        self.assertEqual(record.id, '364797364')
        self.assertIsNone(record.name)
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '192.30.252.153')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = records[4]
        self.assertEqual(record.id, '364982413')
        self.assertEqual(record.name, 'yesyes')
        self.assertEqual(record.type, 'CNAME')
        self.assertEqual(record.data, 'verify.bing.com')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id='1234')
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

    def test_get_zone_zone_doesnt_exist(self):
        with self.assertRaises(ZoneDoesNotExistError):
            self.driver.get_zone('0000')

    def test_get_zone_zone_is_invalid(self):
        with self.assertRaises(LibcloudError):
            self.driver.get_zone('invalid')

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(name='test5',
                                           zone=zone,
                                           type=RecordType.A,
                                           data='127.0.0.3',
                                           extra={'proxied': True})
        self.assertEqual(record.id, '412561327')
        self.assertEqual(record.name, 'test5')
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '127.0.0.3')

    def test_create_record_with_property_that_cant_be_set(self):
        zone = self.driver.list_zones()[0]

        record = self.driver.create_record(name='test5',
                                           zone=zone,
                                           type=RecordType.A,
                                           data='127.0.0.3',
                                           extra={'locked': True})

        self.assertNotEqual(record.extra['locked'], True)

    def test_update_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        updated_record = self.driver.update_record(record=record,
                                                   name='test6',
                                                   type=RecordType.A,
                                                   data='127.0.0.4',
                                                   extra={'proxied': True})

        self.assertEqual(updated_record.name, 'test6')
        self.assertEqual(updated_record.type, 'A')
        self.assertEqual(updated_record.data, '127.0.0.4')
        self.assertEqual(updated_record.extra['proxied'], True)

    def test_update_record_with_property_that_cant_be_updated(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]

        updated_record = self.driver.update_record(record=record,
                                                   data='127.0.0.4',
                                                   extra={'locked': True})

        self.assertNotEqual(updated_record.extra['locked'], True)

    def test_delete_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        result = self.driver.delete_record(record=record)
        self.assertTrue(result)

    def test_delete_zone(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.delete_zone(zone=zone)
        self.assertTrue(result)

    def test_create_zone(self):
        zone = self.driver.create_zone(domain='example2.com',
                                       extra={'jump_start': False})
        self.assertEqual(zone.id, '6789')
        self.assertEqual(zone.domain, 'example2.com')

    def test_create_zone_with_explicit_account(self):
        zone = self.driver.create_zone(
            domain='example2.com',
            extra={'account': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
        self.assertEqual(zone.id, '6789')
        self.assertEqual(zone.domain, 'example2.com')

    def test_update_zone(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone=zone,
                                               domain='',
                                               extra={'paused': True})

        self.assertEqual(zone.id, updated_zone.id)
        self.assertEqual(zone.domain, updated_zone.domain)
        self.assertEqual(zone.type, updated_zone.type)
        self.assertEqual(zone.ttl, updated_zone.ttl)

        for key in set(zone.extra) | set(updated_zone.extra):
            if key in ('paused', 'modified_on'):
                self.assertNotEqual(zone.extra[key], updated_zone.extra[key])
            else:
                self.assertEqual(zone.extra[key], updated_zone.extra[key])

    def test_update_zone_with_property_that_cant_be_updated(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone,
                                               domain='',
                                               extra={'owner': 'owner'})

        self.assertEqual(zone, updated_zone)

    def test_update_zone_with_no_property(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone, domain='', extra=None)

        self.assertEqual(zone, updated_zone)

    def test_update_zone_with_more_than_one_property(self):
        zone = self.driver.list_zones()[0]

        updated_zone = self.driver.update_zone(zone,
                                               domain='',
                                               extra={
                                                   'paused': True,
                                                   'plan': None
                                               })

        self.assertEqual(zone, updated_zone)
Beispiel #9
0
 def setUp(self):
     CloudFlareDNSDriver.connectionCls.conn_classes = (
         CloudFlareMockHttp, CloudFlareMockHttp)
     CloudFlareMockHttp.type = None
     CloudFlareMockHttp.use_param = 'a'
     self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)
Beispiel #10
0
class CloudFlareDNSDriverTestCase(unittest.TestCase):

    def setUp(self):
        CloudFlareDNSDriver.connectionCls.conn_classes = (
            CloudFlareMockHttp, CloudFlareMockHttp)
        CloudFlareMockHttp.type = None
        CloudFlareMockHttp.use_param = 'a'
        self.driver = CloudFlareDNSDriver(*DNS_PARAMS_CLOUDFLARE)

    def test_list_record_types(self):
        record_types = self.driver.list_record_types()
        self.assertEqual(len(record_types), 9)
        self.assertTrue(RecordType.A in record_types)

    def test_list_zones(self):
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        zone = zones[0]
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

        for attribute_name in ZONE_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in zone.extra)

    def test_list_records(self):
        zone = self.driver.list_zones()[0]
        records = self.driver.list_records(zone=zone)
        self.assertEqual(len(records), 18)

        record = records[0]
        self.assertEqual(record.id, '364797364')
        self.assertEqual(record.name, None)
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '192.30.252.153')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

        record = records[4]
        self.assertEqual(record.id, '364982413')
        self.assertEqual(record.name, 'yesyes')
        self.assertEqual(record.type, 'CNAME')
        self.assertEqual(record.data, 'verify.bing.com')

        for attribute_name in RECORD_EXTRA_ATTRIBUTES:
            self.assertTrue(attribute_name in record.extra)

    def test_get_zone(self):
        zone = self.driver.get_zone(zone_id='1234')
        self.assertEqual(zone.id, '1234')
        self.assertEqual(zone.domain, 'example.com')
        self.assertEqual(zone.type, 'master')

    def test_get_zone_zone_doesnt_exist(self):
        self.assertRaises(ZoneDoesNotExistError, self.driver.get_zone,
                          zone_id='doenstexist')

    def test_create_record(self):
        zone = self.driver.list_zones()[0]
        record = self.driver.create_record(name='test5', zone=zone, type='A',
                                           data='127.0.0.3')
        self.assertEqual(record.id, '412561327')
        self.assertEqual(record.name, 'test5')
        self.assertEqual(record.type, 'A')
        self.assertEqual(record.data, '127.0.0.3')

    def test_update_records(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        updated_record = self.driver.update_record(record=record,
                                                   data='127.0.0.4')

        self.assertEqual(updated_record.name, 'test6')
        self.assertEqual(updated_record.type, 'A')
        self.assertEqual(updated_record.data, '127.0.0.4')
        self.assertEqual(updated_record.ttl, 120)

    def test_delete_record(self):
        zone = self.driver.list_zones()[0]
        record = zone.list_records()[0]
        result = self.driver.delete_record(record=record)
        self.assertTrue(result)

    def test_delete_zone(self):
        zone = self.driver.list_zones()[0]
        self.assertRaises(NotImplementedError, self.driver.delete_zone,
                          zone=zone)

    def test_ex_get_zone_stats(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_get_zone_stats(zone=zone)
        self.assertTrue('trafficBreakdown' in result)
        self.assertTrue('bandwidthServed' in result)
        self.assertTrue('requestsServed' in result)
        self.assertTrue('pro_zone' in result)
        self.assertTrue('userSecuritySetting' in result)

    def test_ex_zone_check(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_zone_check(zones=[zone])
        self.assertEqual(result, {'example.com': 4025956})

    def test_ex_get_ip_threat_score(self):
        result = self.driver.ex_get_ip_threat_score(ip='127.0.0.1')
        self.assertEqual(result, {'127.0.0.1': False})

    def test_get_ex_zone_settings(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_get_zone_settings(zone=zone)
        self.assertTrue('dnssec' in result)
        self.assertTrue('ddos' in result)
        self.assertTrue('email_filter' in result)
        self.assertTrue('secureheader_settings' in result)

    def test_ex_set_one_security_level(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_set_zone_security_level(zone=zone, level='med')
        self.assertTrue(result)

    def test_ex_set_zone_cache_level(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_set_zone_cache_level(zone=zone, level='agg')
        self.assertTrue(result)

    def test_ex_enable_development_mode(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_enable_development_mode(zone=zone)
        self.assertTrue(result)

    def test_ex_disable_development_mode(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_disable_development_mode(zone=zone)
        self.assertTrue(result)

    def test_ex_purge_cached_files(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_purge_cached_files(zone=zone)
        self.assertTrue(result)

    def test_ex_purge_cached_file(self):
        zone = self.driver.list_zones()[0]
        url = 'https://www.example.com/test.html'
        result = self.driver.ex_purge_cached_file(zone=zone, url=url)
        self.assertTrue(result)

    def test_ex_whitelist_ip(self):
        zone = self.driver.list_zones()[0]
        ip = '127.0.0.1'
        result = self.driver.ex_whitelist_ip(zone=zone, ip=ip)
        self.assertTrue(result)

    def test_ex_blacklist_ip(self):
        zone = self.driver.list_zones()[0]
        ip = '127.0.0.1'
        result = self.driver.ex_blacklist_ip(zone=zone, ip=ip)
        self.assertTrue(result)

    def test_ex_unlist_ip(self):
        zone = self.driver.list_zones()[0]
        ip = '127.0.0.1'
        result = self.driver.ex_unlist_ip(zone=zone, ip=ip)
        self.assertTrue(result)

    def test_enable_ipv6_support(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_enable_development_mode(zone=zone)
        self.assertTrue(result)

    def test_ex_disable_ipv6_support(self):
        zone = self.driver.list_zones()[0]
        result = self.driver.ex_disable_development_mode(zone=zone)
        self.assertTrue(result)