diff --git a/poppy/transport/validators/helpers.py b/poppy/transport/validators/helpers.py index 0e91e66c..61dd92a6 100644 --- a/poppy/transport/validators/helpers.py +++ b/poppy/transport/validators/helpers.py @@ -270,6 +270,9 @@ def is_valid_service_configuration(service, schema): if 'rules' in caching: for rule in caching['rules']: request_url = rule['request_url'] + if not request_url.startswith('/'): + request_url = ('/' + request_url) + if request_url in caching_rules: raise exceptions.ValidationFailed( 'The path {0} already exists for another ' @@ -367,6 +370,8 @@ def is_valid_service_configuration(service, schema): pass elif key == 'request_url': request_url = rule['request_url'] + if not request_url.startswith('/'): + request_url = ('/' + request_url) else: entity = key # validate country code is valid @@ -385,6 +390,8 @@ def is_valid_service_configuration(service, schema): pass elif key == 'request_url': request_url = rule['request_url'] + if not request_url.startswith('/'): + request_url = ('/' + request_url) else: entity = key # validate country code is valid @@ -394,8 +401,8 @@ def is_valid_service_configuration(service, schema): entity in blacklist_restriction_entities[ request_url]: raise exceptions.ValidationFailed( - 'Cannot blacklist and whitelist [%s] on %s' - ' at the same time' % (key, request_url)) + 'Cannot blacklist and whitelist {0} on {1}' + ' at the same time'.format(key, request_url)) if request_url not in whitelist_restriction_entities: whitelist_restriction_entities[request_url] = [] whitelist_restriction_entities[request_url].append(entity) @@ -409,8 +416,8 @@ def is_valid_service_configuration(service, schema): ) if len(intersect_entities) > 0: raise exceptions.ValidationFailed( - 'Cannot blacklist and whitelist %s on %s' - ' at the same time' % ( + 'Cannot blacklist and whitelist {0} on {1}' + ' at the same time'.format( str(list(intersect_entities)), request_url )) diff --git a/poppy/transport/validators/schemas/service.py b/poppy/transport/validators/schemas/service.py index 7313cfc8..9392d29f 100644 --- a/poppy/transport/validators/schemas/service.py +++ b/poppy/transport/validators/schemas/service.py @@ -450,8 +450,8 @@ class ServiceSchema(schema_base.SchemaBase): }, 'request_url': { 'type': 'string', - 'minLength': 2, - 'maxLength': 100 + 'minLength': 1, + 'maxLength': 1024 } }, "additionalProperties": False, diff --git a/tests/api/services/data_create_service.json b/tests/api/services/data_create_service.json index 033f95ee..70680c12 100644 --- a/tests/api/services/data_create_service.json +++ b/tests/api/services/data_create_service.json @@ -159,6 +159,28 @@ "rules": [{"name" : "Rule 1", "request_url" : "/*"}]}] }, + "wildcard_caching_no_slash": { + "name": "my_service_name", + "domain_list": [{"domain": "www.mywebsite.com", "protocol": "http"}], + "origin_list": [{ + "origin": "myorigin.com", + "port": 80, + "ssl": false, + "rules":[ + { + "name": "default rule", + "request_url": "/*" + } + ], + "hostheadertype": "custom", + "hostheadervalue": "www.customweb.com" + } + ], + "caching_list": [{"name": "default", + "ttl": 1200, + "rules": [{"name" : "Rule 1", + "request_url" : "*"}]}] + }, "multiple_origin_path_caching": { "name": "my_service_name", "domain_list": [{"domain": "www.mywebsite.com", "protocol": "http"}], @@ -517,7 +539,7 @@ { "name": "only me", "referrer": "www.mywebsite.com", - "request_url" : "restrictions" + "request_url" : "*" } ]} ] diff --git a/tests/api/services/data_create_service_negative.json b/tests/api/services/data_create_service_negative.json index b65caff5..684fc741 100644 --- a/tests/api/services/data_create_service_negative.json +++ b/tests/api/services/data_create_service_negative.json @@ -211,18 +211,13 @@ ], "restrictions_list": [] }, - "duplicate_restriction_matches": { + "duplicate_restriction_matches_blacklist*_whitelist/*": { "service_name": "duplicate_restriction_matches", "domain_list": [{"domain": "www.mywebsite.com"}], "origin_list": [ {"origin": "origin1.com", "rules": [{"name" : "index", "request_url" : "/*"}]} ], - "caching_list": [{"name": "default", "ttl": 3600}, - {"name": "home", - "ttl": 1200, - "rules": [{"name" : "index", - "request_url" : "/*"}]} - ], + "caching_list": [{"name": "default", "ttl": 3600}], "restrictions_list": [ { "name": "restriction one", @@ -238,6 +233,28 @@ }, { "name": "restriction two", + "access": "blacklist", + "rules": + [ + { + "name": "only me", + "referrer": "www.mywebsite.com", + "request_url": "*" + } + ] + } + ] + }, + "duplicate_restriction_matches_blacklist/*_whitelist*": { + "service_name": "duplicate_restriction_matches", + "domain_list": [{"domain": "www.mywebsite.com"}], + "origin_list": [ + {"origin": "origin1.com", "rules": [{"name" : "index", "request_url" : "/*"}]} + ], + "caching_list": [{"name": "default", "ttl": 3600}], + "restrictions_list": [ + { + "name": "restriction one", "access": "whitelist", "rules": [ @@ -247,6 +264,86 @@ "request_url": "*" } ] + }, + { + "name": "restriction two", + "access": "blacklist", + "rules": + [ + { + "name": "only me", + "referrer": "www.mywebsite.com", + "request_url": "/*" + } + ] + } + ] + }, + "duplicate_restriction_matches_blacklist*_whitelist*": { + "service_name": "duplicate_restriction_matches", + "domain_list": [{"domain": "www.mywebsite.com"}], + "origin_list": [ + {"origin": "origin1.com", "rules": [{"name" : "index", "request_url" : "/*"}]} + ], + "caching_list": [{"name": "default", "ttl": 3600}], + "restrictions_list": [ + { + "name": "restriction one", + "access": "whitelist", + "rules": + [ + { + "name": "only me", + "referrer": "www.mywebsite.com", + "request_url": "*" + } + ] + }, + { + "name": "restriction two", + "access": "blacklist", + "rules": + [ + { + "name": "only me", + "referrer": "www.mywebsite.com", + "request_url": "*" + } + ] + } + ] + }, + "duplicate_restriction_matches_blacklist/*_whitelist/*": { + "service_name": "duplicate_restriction_matches", + "domain_list": [{"domain": "www.mywebsite.com"}], + "origin_list": [ + {"origin": "origin1.com", "rules": [{"name" : "index", "request_url" : "/*"}]} + ], + "caching_list": [{"name": "default", "ttl": 3600}], + "restrictions_list": [ + { + "name": "restriction one", + "access": "whitelist", + "rules": + [ + { + "name": "only me", + "referrer": "www.mywebsite.com", + "request_url": "/*" + } + ] + }, + { + "name": "restriction two", + "access": "blacklist", + "rules": + [ + { + "name": "only me", + "referrer": "www.mywebsite.com", + "request_url": "/*" + } + ] } ] },