Ejemplo n.º 1
0
 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'}])
Ejemplo n.º 2
0
 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'}])
Ejemplo n.º 3
0
 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': '@'}])
Ejemplo n.º 4
0
 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"'}])
Ejemplo n.º 5
0
 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"'}])
Ejemplo n.º 6
0
 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': '@'}])
Ejemplo n.º 7
0
 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'}])
Ejemplo n.º 8
0
 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"'}])
Ejemplo n.º 9
0
 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"'}])
Ejemplo n.º 10
0
 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'}])
Ejemplo n.º 11
0
 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')
Ejemplo n.º 12
0
 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.'}])
Ejemplo n.º 13
0
 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.'}])
Ejemplo n.º 14
0
 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'}])
Ejemplo n.º 15
0
 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'}])
Ejemplo n.º 16
0
 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')
Ejemplo n.º 17
0
 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': []})
Ejemplo n.º 18
0
 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'}])
Ejemplo n.º 19
0
 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': []})
Ejemplo n.º 20
0
 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'}])
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
 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'}])
Ejemplo n.º 23
0
 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}}")
Ejemplo n.º 24
0
 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'}])
Ejemplo n.º 25
0
 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'}])
Ejemplo n.º 26
0
 def test_dictionary(self):
     z = Zone()
     self.assertTrue(hasattr(z, 'contents'))
Ejemplo n.º 27
0
 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'}])
Ejemplo n.º 28
0
 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}}")