コード例 #1
0
ファイル: __init__.py プロジェクト: appliedsec/Powerglove-DNS
def main(args=None, logger=None):

    args = parser.parse_args(args)

    if args.set:
        PowergloveDns.set_config(*args.set)
        return

    assistant = PowergloveDns(pdns_sqla_url=args.pdns_connect_string, logger=logger)

    if args.fqdn_to_test:
        return assistant.fqdn_is_present(args.fqdn_to_test)

    elif args.fqdn_to_assert:
        if not assistant.fqdn_is_present(args.fqdn_to_assert):
            raise PowergloveError('no A or CNAME record named %s is present' % args.fqdn_to_assert)
        return 0

    elif args.remove:
        return assistant.remove_fqdn(args.remove)

    elif args.cname:
        return assistant.add_cname_record(*args.cname)

    elif args.add:
        return assistant.add_a_record(args.add[0], args.add[1:], args.ttl, args.text_record_contents)
    else:
        raise RuntimeError('unknown command specified given args: %r' % args)
コード例 #2
0
    def setUp(self):

        super(PowergloveUtilsTestCase, self).setUp()
        self.powerglove = PowergloveDns(logger=self.log)
コード例 #3
0
class PowergloveUtilsTestCase(PowergloveTestCase):

    def setUp(self):

        super(PowergloveUtilsTestCase, self).setUp()
        self.powerglove = PowergloveDns(logger=self.log)

    def test_get_a_domain(self):
        """
        test that the correct domain can be inferred from a fully-qualified domain name
        """

        self.assertIn('tld', self.powerglove.domains)
        self.assertIn('stable.tld', self.powerglove.domains)
        self.assertIn('super.stable.tld', self.powerglove.domains)

        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.tld').name, "tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.super.tld').name, "tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.super.great.tld').name, "tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.super.stable.great.tld').name, "tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.stable.tld').name, "stable.tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.very.stable.tld').name, "stable.tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.super.stable.tld').name, "super.stable.tld")
        self.assertEqual(self.powerglove.get_a_domain_from_fqdn('host.very.super.stable.tld').name, "super.stable.tld")

        with self.assertRaises(PowergloveError):
            self.powerglove.get_a_domain_from_fqdn('host.unknowntld')

    def test_get_ptr_domain(self):
        """
        test that we can infer the appriate PTR domain (if it even exists)
        """

        self.assertIn('10.10.in-addr.arpa', self.powerglove.domains)
        self.assertIn('10.in-addr.arpa', self.powerglove.domains)
        self.assertIn('132.168.192.in-addr.arpa', self.powerglove.domains)

        self.assertEqual(self.powerglove.get_ptr_domain_from_ptr_record_name('10.10.10.10.in-addr.arpa').name,
                         "10.10.in-addr.arpa")
        self.assertEqual(self.powerglove.get_ptr_domain_from_ptr_record_name('10.10.20.10.in-addr.arpa').name,
                         "10.in-addr.arpa")
        self.assertEqual(self.powerglove.get_ptr_domain_from_ptr_record_name('15.132.168.192.in-addr.arpa').name,
                         "132.168.192.in-addr.arpa")

        with self.assertRaises(PowergloveError):
            self.powerglove.get_ptr_domain_from_ptr_record_name('1.1.168.192.in-addr.arpa')
        with self.assertRaises(PowergloveError):
            self.powerglove.get_ptr_domain_from_ptr_record_name('1.0.0.127.in-addr.arpa')