def test_soa_getset(self): z = Zone() record = {'ttl': '@', 'addr': 'ns1.example.com.', 'owner': 'hostmaster.example.com', 'serial': '2003080800', 'refresh': '12h', 'update-retry': '15m', 'expiry': '3w', 'minimum': '3h'} self.assertEqual(z.soa(), []) self.assertEqual(z.soa(record), [{'ttl': '@', 'addr': 'ns1.example.com.', 'owner': 'hostmaster.example.com', 'serial': '2003080800', 'refresh': '12h', 'update-retry': '15m', 'expiry': '3w', 'minimum': '3h'}]) record = {'ttl': '@', 'addr': 'ns1.example.com.', 'owner': 'hostmaster.example.com', 'serial': '2003080800', 'refresh': '12h', 'update-retry': '15m', 'expiry': '3w', 'minimum': '4h'} self.assertEqual(z.soa(record), [{'ttl': '@', 'addr': 'ns1.example.com.', 'owner': 'hostmaster.example.com', 'serial': '2003080800', 'refresh': '12h', 'update-retry': '15m', 'expiry': '3w', 'minimum': '4h'}])
def test_a_getset(self): z = Zone() record = {'ttl': 300, 'addr': '10.0.0.1', 'alias': '@'} self.assertEqual(z.a(), []) self.assertEqual(z.a(record), [{'ttl': 300, 'addr': '10.0.0.1', 'alias': '@'}]) self.assertEqual(z.a(record), [{'ttl': 300, 'addr': '10.0.0.1', 'alias': '@'}])
def test_txt_getset(self): z = Zone() record = {'alias': 'joe', 'txt': '"Located in a black hole" " somewhere"'} self.assertEqual(z.txt(), []) self.assertEqual(z.txt(record), [{'alias': 'joe', 'txt': '"Located in a black hole" " somewhere"'}])
def test_spf_getset(self): z = Zone() record = {'addr': 'example.com.', 'txt': '"v=spf1 mx include:example.net -all"'} self.assertEqual(z.spf(), []) self.assertEqual(z.spf(record), [{'addr': 'example.com.', 'txt': '"v=spf1 mx include:example.net -all"'}])
def test_cert_getset(self): z = Zone() record = {'ttl': 300, 'type': 1, 'key-tag': '12179', 'algorithm': 3, 'cert-crl': 'AQPSKmynfz'} self.assertEqual(z.cert(), []) self.assertEqual(z.cert(record), [{'ttl': 300, 'type': 1, 'key-tag': '12179', 'algorithm': 3, 'cert-crl': 'AQPSKmynfz'}])
def test_remove(self): z = Zone() z.contents['A'] = [{'addr': '10.0.0.1', 'alias': 'abc', 'ttl': 300}] z.remove('alias', 'A', 'abc') self.assertEqual(z.a(), []) with self.assertRaises(IndexError): z.remove('alias', 'NOPE', 'abc') with self.assertRaises(KeyError): z.remove('alias', 'A', 'abc')
def test_ns_getset(self): z = Zone() record = {'alias': 'example.com.', 'addr': '10.0.0.1'} self.assertEqual(z.ns(), []) self.assertEqual(z.ns(record), [{'addr': '10.0.0.1', 'alias': 'example.com.'}]) record = {'alias': 'example.com.', 'addr': '10.0.0.2'} self.assertEqual(z.ns(record), [{'addr': '10.0.0.2', 'alias': 'example.com.'}])
def test_cname_getset(self): z = Zone() record = {'ttl': 300, 'addr': 'abc.foo.com', 'alias': 'd'} self.assertEqual(z.cname(), []) self.assertEqual(z.cname(record), [{'ttl': 300, 'addr': 'abc.foo.com', 'alias': 'd'}]) # assert that value pops and gets updated record = {'ttl': 300, 'addr': 'def.foo.com', 'alias': 'd'} self.assertEqual(z.cname(record), [{'ttl': 300, 'addr': 'def.foo.com', 'alias': 'd'}])
def test_to_file(self, tm, mopen): mopen.return_value.__enter__ = lambda s: s mopen.return_value.__exit__ = Mock() mopen.return_value.write = Mock() z = Zone() z.read_template = Mock() z.read_template.return_value = "hi {{data}}" z.to_file() z.read_template.assert_called_once() mopen.assert_called_with('/etc/bind/db.example.com', 'w') tm.assert_called_with(data={'SOA': [], 'AAAA': [], 'TXT': [], 'PTR': [], 'SPF': [], 'A': [], 'CERT': [], 'CNAME': [], 'SRV': [], 'CAA': [], 'NS': [], 'NAPTR': []})
def test_srv_getset(self): z = Zone() record = {'addr': '_ldap._tcp.example.com.', 'priority': 0, 'weight': 0, 'port': 389, 'target': 'old-slow-box.example.com'} self.assertEqual(z.srv(), []) self.assertEqual(z.srv(record), [{'addr': '_ldap._tcp.example.com.', 'priority': 0, 'weight': 0, 'port': 389, 'target': 'old-slow-box.example.com'}])
def test_to_file(self, tm, mopen): mopen.return_value.__enter__ = lambda s: s mopen.return_value.__exit__ = Mock() mopen.return_value.write = Mock() z = Zone() z.read_template = Mock() z.read_template.return_value = "hi {{data}}" z.to_file() z.read_template.assert_called_once_with() mopen.assert_called_with('/etc/bind/db.example.com', 'w') tm.assert_called_with(data={'SOA': [], 'AAAA': [], 'TXT': [], 'PTR': [], 'SPF': [], 'A': [], 'CERT': [], 'CNAME': [], 'SRV': [], # noqa 'CAA': [], 'NS': [], 'NAPTR': []})
def on_submit(self, event, params, vars = None): # se for o dialogo if params[0] == 'dlgEditZone': v = vars.getvalue('value', '') if vars.getvalue('action', '') == 'OK': # se a pessoa digitar um nome de arquivo inválido tmp = vars.getvalue('file', '').replace('/','') if tmp == "etcbindlocalzonesdb." or \ tmp == "" or (not tmp.startswith("etcbind")) or \ tmp == "etcbindlocalzones" or \ vars.getvalue('name','') == "": return None # cria a zona z = Zone() # obtendo valores (do xml: 'name=') z.setName( vars.getvalue('name', 'none') ) z.setType( vars.getvalue('type', 'none') ) z.setFile( vars.getvalue('file', 'none') ) # coloca no lugar da antiga: 'edit/' try: self.zones[self._editing] = z # ou adiciona uma nova: 'add' except: self.zones.append(z) # salva alteracoes backend.Config(self.app).save( self.zones ) self.on_init() elif params[0] == 'dlgAddRecord': if vars.getvalue('action', '') == 'OK': if vars.getvalue('typeRecord','').split(':')[0] == 'Directive': r = vars.getvalue('typeRecord','').split(':')[1] v = vars.getvalue('recordValue','') if v <> "": self._zf.setDirective("%s %s" % (r,v)) del r del v elif vars.getvalue('typeRecord','').split(':')[0] == 'Record': r = vars.getvalue('typeRecord','').split(':')[1] s = vars.getvalue('recordValueSource','') p = vars.getvalue('recordValuePr','') t = vars.getvalue('recordValueTarget','') if r <> 'MX': p = '' elif p == '': p = 10 self._zf.insertRecord( "%s IN %s %s %s"%(s,r,p,t) ) elif params[0] == 'dlgEditSOA': if vars.getvalue('action', '') == 'OK' and vars.getvalue('SOAValue','') != '': self._zf.setSOAbyFields( **{self._editSOA[1]:vars.getvalue('SOAValue','')} ) elif params[0] == 'dlgEditDirective': if vars.getvalue('action', '') == 'OK' and vars.getvalue('DirectiveValue','') != '': self._zf.setDirective( "%s %s" % (self._editDirective, vars.getvalue('DirectiveValue','')) ) # fecha janelas de formulario self._editing = None self._restartBind = None self._addDirective = False self._addRecord = False self._editSOA = None self._editDirective = None
def test_ptr_getset(self): z = Zone() record = {'ttl': 2, 'addr': 'joe.example.com'} self.assertEqual(z.ptr(), []) self.assertEqual(z.ptr(record), [{'ttl': 2, 'addr': 'joe.example.com'}])
def test_read_template(self, mopen): mopen.return_value.__enter__ = lambda s: s mopen.return_value.__exit__ = Mock() mopen.return_value.read.return_value = "{{foo}}" z = Zone() self.assertEqual(z.read_template(), "{{foo}}")
def test_caa_getset(self): z = Zone() record = {'ttl': 300, 'priority': 0, 'issue': 'thawte.com'} self.assertEqual(z.caa(), []) self.assertEqual(z.caa(record), [{'ttl': 300, 'priority': 0, 'issue': 'thawte.com'}])
def test_dictionary(self): z = Zone() self.assertTrue(hasattr(z, 'contents'))