Makes sure that origin and domain cannot be same

This patch checks to see if origin and domain are same. If they are
equal, error is returned.

Change-Id: Ib3e6c16d84a62d9211423902a41c7c5e95e73ad2
Closes-Bug: 1452770
This commit is contained in:
Obulpathi 2015-05-07 11:08:38 -04:00
parent ee6add0746
commit a934f261ae
2 changed files with 34 additions and 0 deletions

View File

@ -16,6 +16,10 @@
import functools
import json
import re
try:
set
except NameError: # noqa pragma: no cover
from sets import Set as set # noqa pragma: no cover
import uuid
import jsonschema
@ -248,6 +252,23 @@ def is_valid_service_configuration(service, schema):
if not re.match(domain_regex, domain_name):
raise exceptions.ValidationFailed(
u'Domain {0} is not valid'.format(domain_name))
# 8. origins and domains cannot be the same
if 'origins' in service and 'domains' in service:
origins = set()
for origin in service['origins']:
origin_name = origin.get('origin').lower().strip()
origins.add(origin_name)
domains = set()
for domain in service['domains']:
domain_name = domain.get('domain').lower().strip()
domains.add(domain_name)
if origins.intersection(domains):
raise exceptions.ValidationFailed(
u'Domains and origins cannot be same: {0}'.format(origin))
return

View File

@ -616,5 +616,18 @@
"rules": [{"name" : "index",
"request_url" : "/index.htm"}]}],
"restrictions_list": []
},
"same_domain_and_origin": {
"service_name": "same_domain_and_origin",
"domain_list": [{"domain": "mywebsite.com "}],
"origin_list": [{"origin": "mywebsite.com",
"port": 80,
"ssl": false}],
"caching_list": [{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 1200,
"rules": [{"name" : "index",
"request_url" : "/index.htm"}]}],
"restrictions_list": []
}
}