Esempio n. 1
0
 def setUp(self):
     """Define the test client and other variables."""
     super().setUp()
     self.zone_one = ReverseZone.objects.create(
         name="0.0.10.in-addr.arpa",
         primary_ns="ns1.example.org",
         email="*****@*****.**")
     self.host_one = Host(name='ns1.example.org',
                          contact="*****@*****.**")
     self.host_two = Host(name='ns2.example.org',
                          contact="*****@*****.**")
     self.host_three = Host(name='ns3.example.org',
                            contact="*****@*****.**")
     self.ns_one = NameServer(name='ns1.example.org', ttl=400)
     self.ns_two = NameServer(name='ns2.example.org', ttl=400)
     self.post_data_one = {
         'name': '0.10.in-addr.arpa',
         'primary_ns': ['ns1.example.org', 'ns2.example.org'],
         'email': "*****@*****.**",
         'refresh': 400,
         'retry': 300,
         'expire': 800,
         'soa_ttl': 350,
         'default_ttl': 1000
     }
     self.post_data_two = {
         'name': '0.16.172.in-addr.arpa',
         'primary_ns': ['ns1.example.org', 'ns2.example.org'],
         'email': "*****@*****.**"
     }
     self.patch_data = {'refresh': '500', 'expire': '1000'}
     clean_and_save(self.host_one)
     clean_and_save(self.host_two)
     clean_and_save(self.ns_one)
     clean_and_save(self.ns_two)
Esempio n. 2
0
 def setUp(self):
     """Define the test client and other variables."""
     super().setUp()
     self.zone_one = ForwardZone(name="example.org",
                                 primary_ns="ns1.example.org",
                                 email="*****@*****.**")
     self.host_one = Host(name='ns1.example.org',
                          contact="*****@*****.**")
     self.host_two = Host(name='ns2.example.org',
                          contact="*****@*****.**")
     self.host_three = Host(name='ns3.example.org',
                            contact="*****@*****.**")
     self.ns_one = NameServer(name='ns1.example.org', ttl=400)
     self.ns_two = NameServer(name='ns2.example.org', ttl=400)
     self.post_data_one = {
         'name': 'example.com',
         'primary_ns': ['ns1.example.org', 'ns2.example.org'],
         'email': "*****@*****.**",
         'refresh': 400,
         'retry': 300,
         'expire': 800,
         'soa_ttl': 350
     }
     self.post_data_two = {
         'name': 'example.net',
         'primary_ns': ['ns1.example.org', 'ns2.example.org'],
         'email': "*****@*****.**"
     }
     self.patch_data = {'refresh': '500', 'expire': '1000'}
     clean_and_save(self.host_one)
     clean_and_save(self.host_two)
     clean_and_save(self.ns_one)
     clean_and_save(self.ns_two)
     clean_and_save(self.zone_one)
Esempio n. 3
0
    def setUp(self):
        """Define the test client and other test variables."""
        self.zone_sample = ForwardZone(name='example.org',
                                       primary_ns='some-ns-server.example.org',
                                       email='*****@*****.**')

        clean_and_save(self.zone_sample)

        self.ns_sample = NameServer(name='some-ns-server.example.org',
                                    ttl=300)
Esempio n. 4
0
def _validate_nameservers(names):
    if not names:
        raise ParseError(detail="No nameservers submitted")

    done = set()
    for name in names:
        if name in done:
            raise ParseError(detail=f"Nameserver {name} is used multiple times")
        try:
            NameServer.validate_name(name)
        except django.core.exceptions.ValidationError as error:
            raise ParseError(detail=str(error))
        done.add(name)
Esempio n. 5
0
    def setUp(self):
        """Define the test client and other test variables."""
        self.zone_sample = ForwardZone(name='example.org',
                                       primary_ns='ns.example.org',
                                       email='*****@*****.**')
        clean_and_save(self.zone_sample)

        self.zone_1010 = ReverseZone(name='10.10.in-addr.arpa',
                                     primary_ns='ns.example.org',
                                     email='*****@*****.**')
        clean_and_save(self.zone_1010)

        self.network_sample = Network(range='10.0.0.0/24',
                                      description='some description')
        clean_and_save(self.network_sample)

        self.ns_hostsample = Host(name='ns.example.org',
                                  contact='*****@*****.**')
        clean_and_save(self.ns_hostsample)

        self.ns_hostip = Ipaddress(host=self.ns_hostsample,
                                   ipaddress='10.0.0.111')
        clean_and_save(self.ns_hostip)

        self.ns_sample = NameServer(name='ns.example.org', ttl=300)
        clean_and_save(self.ns_sample)
        self.zone_sample.nameservers.add(self.ns_sample)
        self.zone_sample.save()
Esempio n. 6
0
class ModelNameServerTestCase(TestCase):
    """This class defines the test suite for the NameServer model."""

    def setUp(self):
        """Define the test client and other test variables."""
        self.zone_sample = ForwardZone(name='example.org',
                                       primary_ns='ns.example.org',
                                       email='*****@*****.**')

        clean_and_save(self.zone_sample)

        self.ns_sample = NameServer(name='ns.example.org',
                                    ttl=300)

    def test_model_can_create_ns(self):
        """Test that the model is able to create an Ns."""
        old_count = NameServer.objects.count()
        clean_and_save(self.ns_sample)
        new_count = NameServer.objects.count()
        self.assertNotEqual(old_count, new_count)
        str(self.ns_sample)

    def test_model_can_change_ns(self):
        """Test that the model is able to change an Ns."""
        clean_and_save(self.ns_sample)
        old_name = self.ns_sample.name
        new_name = 'new-ns.example.com'
        ns_sample_id = NameServer.objects.get(name=old_name).id
        self.ns_sample.name = new_name
        clean_and_save(self.ns_sample)
        updated_name = NameServer.objects.get(pk=ns_sample_id).name
        self.assertEqual(new_name, updated_name)

    def test_model_can_delete_ns(self):
        """Test that the model is able to delete an Ns."""
        clean_and_save(self.ns_sample)
        old_count = NameServer.objects.count()
        self.ns_sample.delete()
        new_count = NameServer.objects.count()
        self.assertNotEqual(old_count, new_count)