From 2a5a0c5f6604a8dea29bcae20d9a1b2d00bdb8ff Mon Sep 17 00:00:00 2001 From: Leonardo Date: Mon, 7 Nov 2016 14:28:35 +0100 Subject: [PATCH] bug 73: Add url validator in http_post_images Signed-off-by: Leonardo --- httpserver.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/httpserver.py b/httpserver.py index 88b1f0a..870d680 100644 --- a/httpserver.py +++ b/httpserver.py @@ -30,6 +30,7 @@ __author__="Alfonso Tierno" __date__ ="$10-jul-2014 12:07:15$" import bottle +import urlparse import yaml import json import threading @@ -451,6 +452,18 @@ def check_valid_uuid(uuid): except js_e.ValidationError: return False + +def is_url(url): + ''' + Check if string value is a well-wormed url + :param url: string url + :return: True if is a valid url, False if is not well-formed + ''' + + parsed_url = urlparse.urlparse(url) + return parsed_url + + @bottle.error(400) @bottle.error(401) @bottle.error(404) @@ -1091,6 +1104,8 @@ def http_post_images(tenant_id): image_file = http_content['image'].get('path',None) if os.path.exists(image_file): http_content['image']['checksum'] = md5(image_file) + elif is_url(image_file): + pass else: if not host_test_mode: content = "Image file not found" -- 2.25.1