Merge "Fix noVNC console access for an IPv6 setup"

This commit is contained in:
Jenkins 2015-06-15 15:59:31 +00:00 committed by Gerrit Code Review
commit c4ae4c62e7
2 changed files with 32 additions and 1 deletions

View File

@ -100,7 +100,10 @@ class NovaProxyRequestHandlerBase(object):
expected_origin_hostname = self.headers.getheader('Host')
if ':' in expected_origin_hostname:
e = expected_origin_hostname
expected_origin_hostname = e.split(':')[0]
if '[' in e and ']' in e:
expected_origin_hostname = e.split(']')[0][1:]
else:
expected_origin_hostname = e.split(':')[0]
origin_url = self.headers.getheader('Origin')
# missing origin header indicates non-browser client which is OK
if origin_url is not None:

View File

@ -46,6 +46,16 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
else:
return
def _fake_getheader_ipv6(self, header):
if header == 'cookie':
return 'token="123-456-789"'
elif header == 'Origin':
return 'https://[2001:db8::1]:6080'
elif header == 'Host':
return '[2001:db8::1]:6080'
else:
return
def _fake_getheader_bad_token(self, header):
if header == 'cookie':
return 'token="XXX"'
@ -114,6 +124,24 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with('<socket>')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_ipv6_url(self, check_token):
check_token.return_value = {
'host': 'node1',
'port': '10000',
'console_type': 'novnc',
'access_url': 'https://[2001:db8::1]:6080'
}
self.wh.socket.return_value = '<socket>'
self.wh.path = "http://[2001:db8::1]/?token=123-456-789"
self.wh.headers.getheader = self._fake_getheader_ipv6
self.wh.new_websocket_client()
check_token.assert_called_with(mock.ANY, token="123-456-789")
self.wh.socket.assert_called_with('node1', 10000, connect=True)
self.wh.do_proxy.assert_called_with('<socket>')
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
def test_new_websocket_client_token_invalid(self, check_token):
check_token.return_value = False