From a934f261ae3ed98de862d85ea6091653d2c9dae5 Mon Sep 17 00:00:00 2001 From: Obulpathi Date: Thu, 7 May 2015 11:08:38 -0400 Subject: [PATCH] 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 --- poppy/transport/validators/helpers.py | 21 +++++++++++++++++++ .../data_create_service_negative.json | 13 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/poppy/transport/validators/helpers.py b/poppy/transport/validators/helpers.py index 9858a25a..da5fe96d 100644 --- a/poppy/transport/validators/helpers.py +++ b/poppy/transport/validators/helpers.py @@ -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 diff --git a/tests/api/services/data_create_service_negative.json b/tests/api/services/data_create_service_negative.json index 36a945bf..bf5e402a 100644 --- a/tests/api/services/data_create_service_negative.json +++ b/tests/api/services/data_create_service_negative.json @@ -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": [] } }