bug 73: Add url validator in http_post_images
Signed-off-by: Leonardo <leonardo.mirabal@altran.com>
diff --git a/httpserver.py b/httpserver.py
index 88b1f0a..870d680 100644
--- a/httpserver.py
+++ b/httpserver.py
@@ -30,6 +30,7 @@
__date__ ="$10-jul-2014 12:07:15$"
import bottle
+import urlparse
import yaml
import json
import threading
@@ -451,6 +452,18 @@
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 @@
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"