Validates domain names

Change-Id: I4dc30919351b5edd6d05f81cc902b11c7cd346df
This commit is contained in:
Obulpathi 2015-05-04 14:58:14 -04:00
parent 6075b1a3a6
commit bc738b521d
5 changed files with 51 additions and 28 deletions

View File

@ -30,7 +30,7 @@ class Domain(common.DictSerializableModel):
def __init__(self, domain, protocol='http',
certificate=None):
self._domain = domain.lower()
self._domain = domain.lower().strip()
if (protocol in AVAILABLE_PROTOCOLS):
self._protocol = protocol
@ -64,7 +64,7 @@ class Domain(common.DictSerializableModel):
@domain.setter
def domain(self, value):
"""domain setter."""
self._domain = value.lower()
self._domain = value.lower().strip()
@property
def certificate(self):
@ -115,7 +115,7 @@ class Domain(common.DictSerializableModel):
:returns o
"""
o = cls("")
o.domain = dict_obj.get("domain").lower()
o.domain = dict_obj.get("domain").lower().strip()
o.protocol = dict_obj.get("protocol", "http")
if o.protocol == 'https':
o.certificate = dict_obj.get("certificate", None)

View File

@ -41,6 +41,7 @@ class ErrorHook(hooks.PecanHook):
exception_payload = {
'status': 500,
}
exception_str = u'{0}'.format(exception)
message = {
'message': (
'The server encountered an unexpected condition'
@ -54,7 +55,7 @@ class ErrorHook(hooks.PecanHook):
# and send out a a json body
LOG.log(
log_level,
'Exception message: %s' % str(exception),
u'Exception message: {0}'.format(exception_str),
exc_info=True,
extra=exception_payload
)
@ -62,13 +63,13 @@ class ErrorHook(hooks.PecanHook):
if hasattr(exception, 'status'):
exception_payload['status'] = exception.status
msg = str(exception)
exception_json = exception_str
try:
msg = json.loads(str(exception))
exception_json = json.loads(exception_json)
except Exception:
pass
message['message'] = msg
message['message'] = exception_json
return webob.Response(
json.dumps(message),

View File

@ -15,6 +15,7 @@
import functools
import json
import re
import uuid
import jsonschema
@ -216,13 +217,28 @@ def is_valid_service_configuration(service, schema):
'https': 443
}
# origin port must match the domain's protocol
# 6. origin port must match the domain's protocol
if 'origins' in service:
for origin in service['origins']:
origin_port = origin.get('port', 80)
if protocol_port_mapping[cdn_protocol] != origin_port:
raise exceptions.ValidationFailed(
'Domain port does not match origin port')
# 7. domains must be valid
if 'domains' in service:
# only allow ascii
domain_regex = ('^((?=[a-z0-9-]{1,63}\.)[a-z0-9]+'
'(-[a-z0-9]+)*\.)+[a-z]{2,63}$')
# allow Punycode
# domain_regex = ('^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+'
# '(-[a-z0-9]+)*\.)+[a-z]{2,63}$')
domains = []
for domain in service['domains']:
domain_name = domain.get('domain').strip()
if not re.match(domain_regex, domain_name):
raise exceptions.ValidationFailed(
u'Domain {0} is not valid'.format(domain_name))
return

View File

@ -66,26 +66,6 @@
}],
"caching_list": []
},
"non_ASCII": {
"name": "איבערזעצן",
"domain_list": [{"domain": "сайт.com", "protocol": "http"},
{"domain": "ਦੀ ਵੈੱਬਸਾਈਟ.com", "protocol": "http"}],
"origin_list": [{"origin": "www.இணையதளத்தில்.com",
"port": 80,
"ssl": false,
"rules": [
{
"name" : "default",
"request_url" : "/*"
}
]
}],
"caching_list": [{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 1200,
"rules": [{"name" : "index",
"request_url" : "/index.htm"}]}]
},
"multiple_origin_wildcard_caching": {
"name": "my_service_name",
"domain_list": [{"domain": "mywebsite.com", "protocol": "http"}],

View File

@ -551,5 +551,31 @@
"referrer": "www.mywebsite.com",
"request_url" : "/index.htm"}]}
]
},
"non_ASCII": {
"service_name": "איבערזעצן",
"domain_list": [{"domain": "сайт.com", "protocol": "http"},
{"domain": "ਦੀ ਵੈੱਬਸਾਈਟ.com", "protocol": "http"}],
"origin_list": [{"origin": "www.இணையதளத்தில்.com",
"port": 80,
"ssl": false,
"rules": [
{
"name" : "default",
"request_url" : "/*"
}
]
}],
"caching_list": [{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 1200,
"rules": [{"name" : "index",
"request_url" : "/index.htm"}]}],
"restrictions_list": [
{"name": "test",
"rules": [{"name": "only me",
"referrer": "www.mywebsite.com",
"request_url" : "/index.htm"}]}
]
}
}