tests: Use consistent URL regex substitution

For some reason, we were using a really convoluted regex that allowed
URLs of formats like 'https:\\foo' (i.e. backslashes instead of forward
slashes). I'm not really sure if this is even valid but it's certainly
not necessary. Use a far simpler substitution and DRY the test cases up
a little.

Change-Id: I634a6de795893d995c4e7c3707f73061c7aa5401
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2019-06-18 11:40:25 +01:00 committed by Eric Fried
parent dc6fc82c14
commit 4cd45c8e45
1 changed files with 11 additions and 21 deletions

View File

@ -15,6 +15,8 @@
from nova.tests.functional.api_sample_tests import test_servers
HTTP_RE = r'(https?://)([\w\d:#@%/;$()~_?\+-=\\.&](#!)?)*'
class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
microversion = None
@ -33,18 +35,15 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
response = self._do_post('servers/%s/action' % uuid,
'get-vnc-console-post-req',
{'action': 'os-getVNCConsole'})
subs = {"url":
"((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"}
self._verify_response('get-vnc-console-post-resp', subs, response, 200)
self._verify_response('get-vnc-console-post-resp', {'url': HTTP_RE},
response, 200)
def test_get_spice_console(self):
uuid = self._post_server()
response = self._do_post('servers/%s/action' % uuid,
'get-spice-console-post-req',
{'action': 'os-getSPICEConsole'})
subs = {"url":
"((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"}
self._verify_response('get-spice-console-post-resp', subs,
self._verify_response('get-spice-console-post-resp', {'url': HTTP_RE},
response, 200)
def test_get_rdp_console(self):
@ -52,9 +51,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
response = self._do_post('servers/%s/action' % uuid,
'get-rdp-console-post-req',
{'action': 'os-getRDPConsole'})
subs = {"url":
"((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"}
self._verify_response('get-rdp-console-post-resp', subs,
self._verify_response('get-rdp-console-post-resp', {'url': HTTP_RE},
response, 200)
def test_get_serial_console(self):
@ -62,9 +59,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
response = self._do_post('servers/%s/action' % uuid,
'get-serial-console-post-req',
{'action': 'os-getSerialConsole'})
subs = {"url":
"((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"}
self._verify_response('get-serial-console-post-resp', subs,
self._verify_response('get-serial-console-post-resp', {'url': HTTP_RE},
response, 200)
@ -76,18 +71,14 @@ class ConsolesV26SampleJsonTests(test_servers.ServersSampleBase):
# by appending '(v2_6)' in test_id.
scenarios = [('v2_6', {'api_major_version': 'v2.1'})]
def setUp(self):
super(ConsolesV26SampleJsonTests, self).setUp()
self.http_regex = '(https?://)([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*'
def test_create_console(self):
uuid = self._post_server()
body = {'protocol': 'vnc', 'type': 'novnc'}
response = self._do_post('servers/%s/remote-consoles' % uuid,
'create-vnc-console-req', body)
subs = {"url": self.http_regex}
self._verify_response('create-vnc-console-resp', subs, response, 200)
self._verify_response('create-vnc-console-resp', {'url': HTTP_RE},
response, 200)
class ConsolesV28SampleJsonTests(test_servers.ServersSampleBase):
@ -97,7 +88,6 @@ class ConsolesV28SampleJsonTests(test_servers.ServersSampleBase):
def setUp(self):
super(ConsolesV28SampleJsonTests, self).setUp()
self.http_regex = '(https?://)([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*'
self.flags(enabled=True, group='mks')
def test_create_mks_console(self):
@ -106,5 +96,5 @@ class ConsolesV28SampleJsonTests(test_servers.ServersSampleBase):
body = {'protocol': 'mks', 'type': 'webmks'}
response = self._do_post('servers/%s/remote-consoles' % uuid,
'create-mks-console-req', body)
subs = {"url": self.http_regex}
self._verify_response('create-mks-console-resp', subs, response, 200)
self._verify_response('create-mks-console-resp', {'url': HTTP_RE},
response, 200)