@ -18,6 +18,7 @@ import copy
import socket
import mock
import six . moves . urllib . parse as urlparse
import nova . conf
from nova . console . securityproxy import base
@ -47,6 +48,7 @@ class NovaProxyRequestHandlerDBTestCase(test.TestCase):
self . wh . msg = mock . MagicMock ( )
self . wh . do_proxy = mock . MagicMock ( )
self . wh . headers = mock . MagicMock ( )
self . path = urlparse . urlencode ( { ' path ' : ' ?token=123-456-789 ' } )
def _fake_console_db ( self , * * updates ) :
console_db = copy . deepcopy ( fake_ca . fake_token_dict )
@ -96,7 +98,7 @@ class NovaProxyRequestHandlerDBTestCase(test.TestCase):
tsock . recv . return_value = " HTTP/1.1 200 OK \r \n \r \n "
self . wh . socket . return_value = tsock
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
if instance_not_found :
@ -143,6 +145,8 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
self . wh . msg = mock . MagicMock ( )
self . wh . do_proxy = mock . MagicMock ( )
self . wh . headers = mock . MagicMock ( )
self . path = urlparse . urlencode ( { ' path ' : ' ?token=123-456-789 ' } )
self . path_invalid = urlparse . urlencode ( { ' path ' : ' ?token=XXX ' } )
fake_header = {
' cookie ' : ' token= " 123-456-789 " ' ,
@ -228,7 +232,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
' access_url ' : ' https://example.net:6080 '
}
self . wh . socket . return_value = ' <socket> '
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . wh . new_websocket_client ( )
@ -261,7 +265,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
validate . return_value = objects . ConsoleAuthToken ( * * params )
self . wh . socket . return_value = ' <socket> '
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . wh . new_websocket_client ( )
@ -287,7 +291,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
validate . return_value = objects . ConsoleAuthToken ( * * params )
self . wh . socket . return_value = ' <socket> '
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . wh . new_websocket_client ( )
@ -312,7 +316,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
validate . return_value = objects . ConsoleAuthToken ( * * params )
self . wh . socket . return_value = ' <socket> '
self . wh . path = " http://[2001:db8::1]/?token=123-456-789 "
self . wh . path = " http://[2001:db8::1]/? %s " % self . path
self . wh . headers = self . fake_header_ipv6
self . wh . new_websocket_client ( )
@ -325,7 +329,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
def test_new_websocket_client_token_invalid ( self , validate ) :
validate . side_effect = exception . InvalidToken ( token = ' XXX ' )
self . wh . path = " http://127.0.0.1/?token=XXX "
self . wh . path = " http://127.0.0.1/? %s " % self . path_invalid
self . wh . headers = self . fake_header_bad_token
self . assertRaises ( exception . InvalidToken ,
@ -353,7 +357,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
tsock . recv . return_value = " HTTP/1.1 200 OK \r \n \r \n "
self . wh . socket . return_value = tsock
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . wh . new_websocket_client ( )
@ -386,7 +390,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
tsock . recv . return_value = " HTTP/1.1 500 Internal Server Error \r \n \r \n "
self . wh . socket . return_value = tsock
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . assertRaises ( exception . InvalidConnectionInfo ,
@ -418,7 +422,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
HTTP_RESP ]
self . wh . socket . return_value = tsock
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . wh . new_websocket_client ( )
@ -448,7 +452,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
validate . return_value = objects . ConsoleAuthToken ( * * params )
self . wh . socket . return_value = ' <socket> '
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
self . wh . path = " http://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . wh . new_websocket_client ( )
@ -468,7 +472,7 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
' console_type ' : ' novnc '
}
self . wh . socket . return_value = ' <socket> '
self . wh . path = " ws://127.0.0.1/?token=123-456-789 "
self . wh . path = " ws://127.0.0.1/? %s " % self . path
self . wh . headers = self . fake_header
self . assertRaises ( exception . NovaException ,
@ -477,10 +481,9 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
@mock . patch ( ' socket.getfqdn ' )
def test_address_string_doesnt_do_reverse_dns_lookup ( self , getfqdn ) :
request_mock = mock . MagicMock ( )
request_mock . makefile ( ) . readline . side_effect = [
b ' GET /vnc.html?token=123-456-789 HTTP/1.1 \r \n ' ,
b ' '
]
msg = ' GET /vnc.html? %s HTTP/1.1 \r \n ' % self . path
request_mock . makefile ( ) . readline . side_effect = [ msg . encode ( ' utf-8 ' ) ,
b ' ' ]
server_mock = mock . MagicMock ( )
client_address = ( ' 8.8.8.8 ' , 54321 )
@ -734,7 +737,8 @@ class NovaWebsocketSecurityProxyTestCase(test.NoDBTestCase):
with mock . patch ( ' websockify.ProxyRequestHandler ' ) :
self . wh = websocketproxy . NovaProxyRequestHandler ( )
self . wh . server = self . server
self . wh . path = " http://127.0.0.1/?token=123-456-789 "
path = urlparse . urlencode ( { ' path ' : ' ?token=123-456-789 ' } )
self . wh . path = " http://127.0.0.1/? %s " % path
self . wh . socket = mock . MagicMock ( )
self . wh . msg = mock . MagicMock ( )
self . wh . do_proxy = mock . MagicMock ( )