def setUp(self): super(TestSOASerialUpdate, self).setUp() self.soa_record = RecordFactory( domain=self.domain, type='SOA', name='example.com', content=('na1.example.com. hostmaster.example.com. ' '0 43200 600 1209600 600'), ) # Less than 1 second will elapse until the test runs, so we update # this manually while circumventing save() Record.objects.filter(pk=self.soa_record.pk).update( change_date=1432720132) self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', )
class TestSOASerialUpdate(RecordTestCase): def setUp(self): super(TestSOASerialUpdate, self).setUp() self.soa_record = RecordFactory( domain=self.domain, type='SOA', name='example.com', content=('na1.example.com. hostmaster.example.com. ' '0 43200 600 1209600 600'), ) # Less than 1 second will elapse until the test runs, so we update # this manually while circumventing save() Record.objects.filter(pk=self.soa_record.pk).update( change_date=1432720132) self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', ) def test_soa_update(self): """Test if SOA change_date is updated when a record is removed""" old_serial = Record.objects.get(pk=self.soa_record.pk).change_date self.a_record.delete() new_serial = Record.objects.get(pk=self.soa_record.pk).change_date self.assertGreater(new_serial, old_serial)
def setUp(self): self.superuser = User.objects.create_superuser( 'superuser', '*****@*****.**', 'password') self.user = User.objects.create_user('user', '*****@*****.**', 'password') self.su_domain = DomainFactory( name='su.example.com', owner=self.superuser, ) self.u_domain = DomainFactory( name='u.example.com', owner=self.user, ) self.su_record = RecordFactory( domain=self.su_domain, name='www.su.example.com', type='A', content='192.168.1.1', owner=self.superuser, auto_ptr=AutoPtrOptions.NEVER, ) self.u_record = RecordFactory( domain=self.u_domain, name='www.u.example.com', type='A', content='192.168.1.2', owner=self.user, auto_ptr=AutoPtrOptions.NEVER, ) self.su_client = user_client(self.superuser) self.u_client = user_client(self.user)
def test_ptr_autoremove(self): """A PTR record is automatically removed with its A record""" a = RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.ALWAYS, ) assert_does_exist(Record, name='1.1.168.192.in-addr.arpa', type='PTR') a.delete() assert_not_exists(Record, name='1.1.168.192.in-addr.arpa', type='PTR')
def setUp(self): super(TestUniquenessConstraints, self).setUp() self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', )
def setUp(self): super(TestSOASerialUpdate, self).setUp() self.soa_record = RecordFactory( domain=self.domain, type='SOA', name='example.com', content=( 'na1.example.com. hostmaster.example.com. ' '0 43200 600 1209600 600' ), ) # Less than 1 second will elapse until the test runs, so we update # this manually while circumventing save() Record.objects.filter(pk=self.soa_record.pk).update( change_date=1432720132 ) self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', )
def setUp(self): super(TestRequestUniquenessConstraints, self).setUp() self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.NEVER, ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', ) self.user = User.objects.create_user('user1', '*****@*****.**', 'password')
def test_auto_ptr_off(self): """PTR is removed when setting auto_ptr to NEVER""" record = RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.ALWAYS, ) domain = Domain.objects.get(name='1.168.192.in-addr.arpa') record.auto_ptr = AutoPtrOptions.NEVER record.save() assert_not_exists( Record, domain=domain, name='1.1.168.192.in-addr.arpa', )
def test_ptr_domain_not_exists(self): """A PTR record with 'only-if-domain' is created if domain exists""" RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.ONLY_IF_DOMAIN, ) assert_not_exists(Record, name='1.1.168.192.in-addr.arpa')
def test_alt_ptr_created(self): """A PTR record is created for an A record with alternative""" self.domain.reverse_template = self.alt_reverse_template RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.ALWAYS, ) domain = Domain.objects.get(name='1.168.192.in-addr.arpa') self.assertTrue(domain.get_soa().content.endswith('1200'))
def test_auto_ptr_edit(self): """PTR changes when A changes""" record = RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.ALWAYS, ) record.content = '192.168.1.9' record.save() domain = Domain.objects.get(name='1.168.192.in-addr.arpa') assert_does_exist( Record, domain=domain, name='9.1.168.192.in-addr.arpa', ) assert_not_exists( Record, domain=domain, name='1.1.168.192.in-addr.arpa', )
def test_default_ptr_never(self): """A PTR record is not created if auto_ptr set to NEVER""" domain = DomainFactory(name='1.168.192.in-addr.arpa') RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.NEVER, ) assert_not_exists(Record, domain=domain, name='1.1.168.192.in-addr.arpa')
class TestSOASerialUpdate(RecordTestCase): def setUp(self): super(TestSOASerialUpdate, self).setUp() self.soa_record = RecordFactory( domain=self.domain, type='SOA', name='example.com', content=( 'na1.example.com. hostmaster.example.com. ' '0 43200 600 1209600 600' ), ) # Less than 1 second will elapse until the test runs, so we update # this manually while circumventing save() Record.objects.filter(pk=self.soa_record.pk).update( change_date=1432720132 ) self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', ) def test_soa_update(self): """Test if SOA change_date is updated when a record is removed""" old_serial = Record.objects.get(pk=self.soa_record.pk).change_date self.a_record.delete() new_serial = Record.objects.get(pk=self.soa_record.pk).change_date self.assertGreater(new_serial, old_serial)
def test_default_ptr_created(self): """A PTR record is created for an A record with default template""" RecordFactory( domain=self.domain, type='A', name='site.example.com', content='192.168.1.1', auto_ptr=AutoPtrOptions.ALWAYS, owner=self.user, ) domain = Domain.objects.get(name='1.168.192.in-addr.arpa') self.assertTrue(domain.get_soa().content.endswith('600')) assert_does_exist( Record, domain=domain, name='1.1.168.192.in-addr.arpa', owner=self.user, )
class TestUniquenessConstraints(RecordTestCase): def setUp(self): super(TestUniquenessConstraints, self).setUp() self.a_record = RecordFactory( domain=self.domain, type='A', name='www.example.com', content='192.168.1.1', ) self.cname_record = RecordFactory( domain=self.domain, type='CNAME', name='blog.example.com', content='www.example.com', ) def test_nonconflicting_a_record(self): """The validation allows an A record when it doesn't conflict with existing CNAME""" self.validate(type='A', name='wiki.example.com', content='192.168.1.2') def test_noconflict_with_itself(self): """A CNAME record can be resaved (it doesn't conflict with itself.)""" self.cname_record.full_clean() def test_conflicting_a_record(self): """The validation doesn't allow an A recrod when it conflicts with existing CNAME""" self.check_invalid( type='A', name='blog.example.com', content='192.168.1.2', ) def test_nonconflicting_cname_record(self): """The validation allows an CNAME record when it doesn't conflict with existing A""" self.validate( type='CNAME', name='wiki.example.com', content='site.example.com' ) def test_conflicting_cname_record(self): """The validation doesn't allow a CNAME record when it conflicts with existing A""" self.check_invalid( type='CNAME', name='www.example.com', content='site.example.com' ) def test_conflicting_second_cname_record(self): """The validation doesn't allow a CNAME record when it conflicts with existing CNAME""" self.check_invalid( type='CNAME', name='blog.example.com', content='site.example.com' )