Beef up sysinv URL validator

The current sysinv URL validator does not handle URLs
containing IPv6 address correctly. This commit fixes that.

Closes-Bug: 1833710
Change-Id: Ic5a450ede0390529e795ca0120200a0f7bbf52ce
Signed-off-by: Tee Ngo <Tee.Ngo@windriver.com>
This commit is contained in:
Tee Ngo 2019-06-24 08:23:11 -04:00
parent c4a50ea11c
commit 04a07648b4
5 changed files with 9 additions and 14 deletions

View File

@ -1,2 +1,2 @@
SRC_DIR="sysinv"
TIS_PATCH_VER=324
TIS_PATCH_VER=325

View File

@ -25,6 +25,7 @@ Requires: python-pbr
Requires: python-webtest
Requires: python-wsme
Requires: python-six
Requires: python2-django
Requires: python2-mox3
Requires: python2-oslo-config
Requires: python2-oslo-concurrency

View File

@ -15,6 +15,7 @@ Package: sysinv
Architecture: all
Depends: ${misc:Depends},
${python:Depends},
python-django,
python-docker,
python-parted,
python-six,

View File

@ -40,3 +40,5 @@ rpm
ruamel.yaml>=0.13.14 # MIT
docker # Apache-2.0
kubernetes # Apache-2.0
Django<2,>=1.11.20 # BSD

View File

@ -51,6 +51,7 @@ import uuid
import wsme
import yaml
from django.core.validators import URLValidator
from eventlet.green import subprocess
from eventlet import greenthread
import netaddr
@ -1769,20 +1770,10 @@ def is_openstack_applied(dbapi):
def is_url(url_str):
# Django URL validation patterns
r = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)' # domain...
r'+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
r'localhost|' # localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
url = r.match(url_str)
if url:
try:
URLValidator()(url_str)
return True
else:
except Exception:
return False