def test_parse_records(self):
     path = pathlib.Path(__file__).parent / "resources" / "record_page.html"
     with path.open() as f:
         html = f.read()
     records = RecordParser.parse(html)
     self.assertEqual(2, len(records))
     expected = Record()
     expected.target = "2a04:dd00::327b:8888"
     expected.ttl = 14440
     expected.name = "IPV6"
     expected.type = RecordType.AAAA
     self.assertIn(expected, records)
Exemplo n.º 2
0
    def test_update_record_fail(self):
        domain = Domain()
        domain.id = TEST_DOMAIN_ID
        domain.name = TEST_DOMAIN_NAME

        record = Record()
        record.domain = domain
        record.name = "TESTUPDATEBUG"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = 14440

        self.test_login()
        cleanup = self.add_record_if_missing(record)
        original_record = copy(record)
        records_before = self.freenom.list_records(domain)
        record.target = "185.45.193.%d" % random.randint(
            1000, 3500)  # this is an invalid ip address
        try:
            self.freenom.update_record(record)
        except UpdateError as e:
            self.assertEqual(1, len(e.msgs))
            self.assertIn('Error occured: Invalid value in dnsrecord', e.msgs)
            self.assertEqual(record, e.record)
            self.assertListEqual(records_before, e.old_record_list)
        else:
            self.fail("exception %s expected " % UpdateError.__name__)
        finally:
            if cleanup:
                self.freenom.remove_record(original_record)
Exemplo n.º 3
0
    def test_update_record_fail(self):
        domain = Domain()
        domain.id = '1012700019'
        domain.name = 'freenom-dns-updater.cf'

        record = Record()
        record.domain = domain
        record.name = "TESTUPDATEBUG"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = 14440

        self.test_login()
        self.add_record_if_missing(record)
        records_before = self.freenom.list_records(domain)
        record.target = "185.45.193.%d" % random.randint(1000, 3500)
        try:
            self.freenom.update_record(record)
        except UpdateError as e:
            self.assertEqual(1, len(e.msgs))
            self.assertIn('Error occured: Invalid value in dnsrecord', e.msgs)
            self.assertEqual(record, e.record)
            self.assertListEqual(records_before, e.old_record_list)
        else:
            self.fail("exception %s expected " % UpdateError.__name__)
        finally:
            self.freenom.remove_record(record)
Exemplo n.º 4
0
    def test_update_record_fail(self):
        domain = Domain()
        domain.id = "1012700019"
        domain.name = "freenom-dns-updater.cf"

        record = Record()
        record.domain = domain
        record.name = "TESTUPDATEBUG"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = 14440

        self.test_login()
        self.add_record_if_missing(record)
        records_before = self.freenom.list_records(domain)
        record.target = "185.45.193.%d" % random.randint(1000, 3500)
        try:
            self.freenom.update_record(record)
        except UpdateError as e:
            self.assertEqual(1, len(e.msgs))
            self.assertIn("Error occured: Invalid value in dnsrecord", e.msgs)
            self.assertEqual(record, e.record)
            self.assertListEqual(records_before, e.old_record_list)
        else:
            self.fail("exception %s expected " % UpdateError.__name__)
        finally:
            self.freenom.remove_record(record)
Exemplo n.º 5
0
 def test_parse_records(self):
     path = pathlib.Path(__file__).parent / "resources" / "record_page.html"
     html = path.read_text()
     records = RecordParser.parse(html)
     self.assertEqual(2, len(records))
     expected = Record()
     expected.target = "2a04:dd00::327b:8888"
     expected.ttl = 800
     expected.name = "IPV6"
     expected.type = RecordType.AAAA
     self.assertIn(expected, records)
Exemplo n.º 6
0
    def test_update_record(self):
        domain = Domain()
        domain.id = TEST_DOMAIN_ID
        domain.name = TEST_DOMAIN_NAME

        record = Record()
        record.domain = domain
        record.name = "TESTUPDATE"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = 14440

        self.test_login()
        self.add_record_if_missing(record)
        record.ttl = 14440 * 2
        try:
            res = self.freenom.update_record(record)
            self.assertTrue(bool(res))
            self.assertIn(record, self.freenom.list_records(domain))
        finally:
            self.freenom.remove_record(record)
Exemplo n.º 7
0
    def test_remove_record(self):
        domain = Domain()
        domain.id = '1012700019'
        domain.name = 'freenom-dns-updater.cf'

        record = Record()
        record.domain = domain
        record.name = "TESTREMOVE"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = 14440

        self.test_login()
        self.add_record_if_missing(record)

        res = self.freenom.remove_record(record)
        self.assertTrue(res)
        self.assertNotIn(record, self.freenom.list_records(domain))
Exemplo n.º 8
0
    def test_add_record(self):
        domain = Domain()
        domain.id = TEST_DOMAIN_ID
        domain.name = TEST_DOMAIN_NAME

        record = Record()
        record.domain = domain
        record.name = "TESTADD"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = random.choice((14440, 14440 / 2, 14440 * 2))

        self.test_login()
        self.remove_record_if_exists(record)
        try:
            res = self.freenom.add_record(record)
            self.assertTrue(bool(res))
            records = self.freenom.list_records(domain)
            self.assertIn(record, records)
        finally:
            self.freenom.remove_record(record)
Exemplo n.º 9
0
    def test_update_record(self):
        domain = Domain()
        domain.id = "1012700019"
        domain.name = "freenom-dns-updater.cf"

        record = Record()
        record.domain = domain
        record.name = "TESTUPDATE"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = 14440

        self.test_login()
        self.add_record_if_missing(record)
        record.ttl = 14440 * 2
        try:
            res = self.freenom.update_record(record)
            self.assertTrue(bool(res))
            self.assertIn(record, self.freenom.list_records(domain))
        finally:
            self.freenom.remove_record(record)
Exemplo n.º 10
0
    def test_add_record(self):
        domain = Domain()
        domain.id = "1012700019"
        domain.name = "freenom-dns-updater.cf"

        record = Record()
        record.domain = domain
        record.name = "TESTADD"
        record.type = RecordType.A
        record.target = "185.45.193.%d" % random.randint(5, 200)
        record.ttl = random.choice((14440, 14440 / 2, 14440 * 2))

        self.test_login()
        self.remove_record_if_exists(record)
        try:
            res = self.freenom.add_record(record)
            self.assertTrue(bool(res))
            records = self.freenom.list_records(domain)
            self.assertIn(record, records)
        finally:
            self.freenom.remove_record(record)
Exemplo n.º 11
0
    def test_get_records(self):
        httpretty.register_uri(httpretty.GET,
                               'http://v6.ipv6-test.com/api/myip.php?json',
                               body=json.dumps({
                                   "address": "fd2b:1c1b:3641:1cd8::",
                                   "proto": "ipv6"
                               }),
                               content_type='text/json')
        httpretty.register_uri(httpretty.GET,
                               'http://v4.ipv6-test.com/api/myip.php?json',
                               body=json.dumps({
                                   "address": "49.20.57.31",
                                   "proto": "ipv4"
                               }),
                               content_type='text/json')

        records = self.config.records
        self.assertEqual(8, len(records))

        domain_1 = Domain("test.tk")
        record_1 = Record(target=str(ipaddress.ip_address(u"49.20.57.31")),
                          type=RecordType.A,
                          domain=domain_1)

        record_2 = Record(target=str(ipaddress.ip_address(u"49.20.57.31")),
                          type=RecordType.A,
                          name='mysubdomain',
                          domain=domain_1)

        record_3 = Record(target=str(
            ipaddress.ip_address(u"fd2b:1c1b:3641:1cd8::")),
                          type=RecordType.AAAA,
                          name='mysubdomain',
                          domain=domain_1)

        record_4 = Record(target=str(
            ipaddress.ip_address(u"fd2b:1c1b:3641:1cd8::")),
                          type=RecordType.AAAA,
                          domain=domain_1)

        domain_2 = Domain("test2.tk")
        record_5 = Record(target=str(
            ipaddress.ip_address(u"fd2b:1c1b:3641:1cd8::")),
                          type=RecordType.AAAA,
                          domain=domain_2,
                          ttl=24440)

        record_6 = Record(
            name='mysubdomain',
            target=str(ipaddress.ip_address(u"49.20.57.31")),
            type=RecordType.A,
            domain=domain_2,
        )

        record_7 = Record(
            name='ipv6sub',
            target=str(ipaddress.ip_address(u"fd2b:1c1b:3641:1cd8::")),
            type=RecordType.AAAA,
            domain=domain_2,
        )

        record_8 = Record(
            name='ipv4sub',
            target=str(ipaddress.ip_address(u"64.64.64.64")),
            type=RecordType.A,
            domain=domain_2,
        )

        self.assertIn(record_1, records)
        self.assertIn(record_2, records)
        self.assertIn(record_3, records)
        self.assertIn(record_4, records)
        self.assertIn(record_5, records)
        self.assertIn(record_6, records)
        self.assertIn(record_7, records)
        self.assertIn(record_8, records)