Merge "Check for multi level tlds"

This commit is contained in:
Zuul 2017-11-04 23:51:26 +00:00 committed by Gerrit Code Review
commit 434a625a29
6 changed files with 7241 additions and 7 deletions

File diff suppressed because it is too large Load Diff

View File

@ -275,12 +275,17 @@ class Service(service.RPCService, service.Service):
raise exceptions.InvalidZoneName('More than one label is '
'required')
# Check the TLD for validity if there are entries in the database
if self.storage.find_tlds({}):
LOG.info(_LI("Checking for TLDs"))
try:
self.storage.find_tld(context, {'name': zone_labels[-1]})
except exceptions.TldNotFound:
tlds = self.storage.find_tlds(context)
if tlds:
LOG.debug("Checking if %s has a valid TLD", zone_name)
allowed = False
for i in range(-len(zone_labels), 0):
last_i_labels = zone_labels[i:]
LOG.debug("Checking %s against the TLD list", last_i_labels)
if ".".join(last_i_labels) in tlds:
allowed = True
break
if not allowed:
raise exceptions.InvalidZoneName('Invalid TLD')
# Now check that the zone name is not the same as a TLD
@ -290,7 +295,7 @@ class Service(service.RPCService, service.Service):
context,
{'name': stripped_zone_name})
except exceptions.TldNotFound:
pass
LOG.debug("%s has a valid TLD", zone_name)
else:
raise exceptions.InvalidZoneName(
'Zone name cannot be the same as a TLD')

View File

@ -59,6 +59,8 @@ class TLDCommands(base.Commands):
def __init__(self):
super(TLDCommands, self).__init__()
def _startup(self):
rpc.init(cfg.CONF)
self.central_api = central_rpcapi.CentralAPI()
@ -108,6 +110,7 @@ class TLDCommands(base.Commands):
help="delimiter between fields in the input file",
default=',', type=str)
def from_file(self, input_file=None, delimiter=None):
self._startup()
input_file = str(input_file) if input_file is not None else None
if not os.path.exists(input_file):

View File

@ -42,3 +42,6 @@ class Tld(base.DictObjectMixin, base.PersistentObjectMixin,
class TldList(base.ListObjectMixin, base.DesignateObject):
LIST_ITEM_TYPE = Tld
def __contains__(self, key):
return bool(list(filter(lambda tld: tld.name == key, self.objects)))

View File

@ -515,6 +515,12 @@ class CentralZoneTestCase(CentralBasic):
if d['name'] not in ('org',):
raise exceptions.TldNotFound
def storage_find_tlds(c):
return objects.TldList.from_list(
[objects.Tld.from_dict({'name': 'org'})]
)
self.service.storage.find_tlds = storage_find_tlds
self.service.storage.find_tld = storage_find_tld
def test__is_valid_zone_name_valid(self):

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Check for multi level tlds
Previously we only checked for the last label of a TLD
which does not work for `co.uk` or custom internal
TLDs that deployers may use