Skip to content

Commit

Permalink
Handle / in zone names for arpa domains. fixes #61.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barnaby Gray committed Mar 13, 2013
1 parent e048bfa commit 02b1da1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions scripts/cli53
Expand Up @@ -425,13 +425,15 @@ class R53ToBindFormatter(object):
def convert(self, info, rrsets, z=None):
if not z:
origin = info.HostedZone.Name
origin = origin.replace('\\057', '/')
z = dns.zone.Zone(dns.name.from_text(origin))

for rrset in rrsets:
name = rrset.name
if '\\052' in name:
# * char seems to confuse Amazon and is returned as \\052
name = name.replace('\\052', '*')
name = name.replace('\\057', '/')
rtype = rrset.type
ttl = int(rrset.ttl)
values = rrset.resource_records
Expand Down Expand Up @@ -603,6 +605,7 @@ def Zone(zone):
return zone
ret = r53.get_all_hosted_zones()

zone = zone.replace('/', '\\057')
hzs = [ hz.Id.replace('/hostedzone/', '') for hz in ret.ListHostedZonesResponse.HostedZones if hz.Name == zone or hz.Name == zone+'.' ]
if len(hzs) == 1:
return hzs[0]
Expand Down
30 changes: 27 additions & 3 deletions tests/test_bind.py
Expand Up @@ -20,8 +20,6 @@ def __eq__(self, x):

class BindTest(unittest.TestCase):
def setUp(self):
# re-use if already created
self.zone = '%d.example.com' % random.randint(0, sys.maxint)
self._cmd('create', self.zone)

def tearDown(self):
Expand All @@ -38,6 +36,9 @@ def _cmd(self, cmd, *args):
raise NonZeroExit
return p.stdout.read()

class ZoneTest(BindTest):
zone = '%d.example.com' % random.randint(0, sys.maxint)

def _zonefile(self, fname):
with file('temp.txt', 'w') as fout:
print >>fout, "$ORIGIN %s." % self.zone
Expand Down Expand Up @@ -102,7 +103,7 @@ def test_import2(self):
],
output
)

def test_aws_extensions(self):
fname = self._zonefile('zoneaws.txt')
self._cmd('import', '--file', fname, self.zone)
Expand Down Expand Up @@ -133,3 +134,26 @@ def test_invalid1(self):
fname = self._zonefile('invalid1.txt')
self.assertRaises(NonZeroExit,
self._cmd, 'import', '--file', fname, self.zone)

class ArpaTest(BindTest):
zone = '0/25.0.1.10.in-addr.arpa'

def test_import_arpa(self):
self._cmd('import', '--file', _f('zone3.txt'), self.zone)

output = self._cmd('export', self.zone)
output = [ x for x in output.split('\n') if x ]
output.sort()

self.assertEqual(
[
"$ORIGIN %s." % self.zone,
"98 0 IN PTR blah.foo.com.",
RegexEqual('^@ 172800 IN NS'),
RegexEqual('^@ 172800 IN NS'),
RegexEqual('^@ 172800 IN NS'),
RegexEqual('^@ 172800 IN NS'),
RegexEqual('^@ 900 IN SOA'),
],
output
)
10 changes: 5 additions & 5 deletions tests/test_commands.py
Expand Up @@ -38,13 +38,13 @@ def test_rrcreate(self):
self._cmd('rrcreate', self.zone, '', 'A', '10.0.0.1')
self._cmd('rrcreate', self.zone, 'www', 'CNAME', self.zone+'.', '-x 3600')
self._cmd('rrcreate', self.zone, 'info', 'TXT', 'this is a "test"')
self._cmd('rrcreate', self.zone, 'weighttest1', 'CNAME', self.zone+'.', '-x 60', '-w 0', '-i awsweightzero')
self._cmd('rrcreate', self.zone, 'weighttest2', 'CNAME', self.zone+'.', '-x 60', '-w 1', '-i awsweightone')
self._cmd('rrcreate', self.zone, 'weighttest3', 'CNAME', self.zone+'.', '-x 60', '-w 50', '-i awsweightfifty')
self._cmd('rrcreate', self.zone, 'weighttest1', 'CNAME', self.zone+'.', '-x 60', '-w 0', '-i awsweightzero')
self._cmd('rrcreate', self.zone, 'weighttest2', 'CNAME', self.zone+'.', '-x 60', '-w 1', '-i awsweightone')
self._cmd('rrcreate', self.zone, 'weighttest3', 'CNAME', self.zone+'.', '-x 60', '-w 50', '-i awsweightfifty')

output = self._cmd('export', self.zone)
output = [ x for x in output.split('\n') if '10.0.0.1' in x or 'CNAME' in x or 'TXT' in x ]

self.assertEqual(
[
"@ 86400 IN A 10.0.0.1",
Expand All @@ -56,7 +56,7 @@ def test_rrcreate(self):
],
output
)

def test_rrdelete(self):
self._cmd('rrcreate', self.zone, '', 'A', '10.0.0.1')
self._cmd('rrdelete', self.zone, '', 'A')
Expand Down
2 changes: 2 additions & 0 deletions tests/zone3.txt
@@ -0,0 +1,2 @@
$ORIGIN 0/25.0.1.10.in-addr.arpa.
98 PTR blah.foo.com.

0 comments on commit 02b1da1

Please sign in to comment.