def test_auth_url_programming_error_propagates(self): # Ensure that any programming errors from how the proxy is implemented # (i.e. malformed requests) are properly logged. # Ideally, there aren't any programming errors in the current # implementation. Should one exist, it would be better to fix it rather than # use it as a test case here. auth_url = self.get_server_base_url() + '/fake-auth' encoded_query_args = urlparse.urlencode( {'jupyter_http_over_ws_auth_url': auth_url}) ws_request = self.get_ws_connection_request( 'always_throwing_proxied_ws/requires-cookies-from-fake-auth-ws?' + encoded_query_args) with testing.ExpectLog('tornado.application', 'Uncaught error when proxying request', required=True) as expect_log: client = yield websocket.websocket_connect(ws_request) self.assertIsNotNone(client) msg = yield client.read_message() # Message of None indicates that the connection has been closed. self.assertIsNone(msg) self.assertEqual(500, client.close_code) self.assertEqual('Uncaught error when proxying request', client.close_reason) self.assertTrue(expect_log.logged_stack)
def test_newer_protocol_version_requested(self): request = self.get_ws_connection_request() request.url += '?min_version=9.0.0' with testing.ExpectLog('tornado.application', 'Rejecting connection:.*Please upgrade', required=True): client = yield websocket.websocket_connect(request) msg = yield client.read_message() # Message of None indicates that the connection has been closed. self.assertIsNone(msg) self.assertEqual(400, client.close_code) self.assertIn('Please upgrade', client.close_reason)
def _assertCrossDomainRequestFails(self, auth_url): encoded_query_args = urlparse.urlencode( {'jupyter_http_over_ws_auth_url': auth_url}) request = self.get_ws_connection_request( 'http_over_websocket/proxied_ws/requires-cookies-from-fake-auth-ws?' + encoded_query_args) request.headers.add('Origin', ALLOWED_ORIGIN) with testing.ExpectLog('tornado.application', 'Uncaught error when proxying request', required=True) as expect_log: client = yield websocket.websocket_connect(request) self.assertIsNotNone(client) msg = yield client.read_message() # Message of None indicates that the connection has been closed. self.assertIsNone(msg) self.assertEqual(500, client.close_code) self.assertTrue(expect_log.logged_stack)
def test_programming_error_propagates(self): # Ensure that any programming errors from how the proxy is implemented # (i.e. malformed requests) are properly logged. # Ideally, there aren't any programming errors in the current # implementation. Should one exist, it would be better to fix it rather than # use it as a test case here. ws_request = self.get_ws_connection_request('always_throwing_http_over_ws') client = yield websocket.websocket_connect(ws_request) with testing.ExpectLog( 'tornado.application', 'Uncaught error when proxying request', required=True) as expect_log: client.write_message(self.get_request_json('/api/sessions', '1234')) response_body = yield client.read_message() # Message of None indicates that the connection has been closed. self.assertIsNotNone(response_body) response = json.loads(response_body) self.assertEqual(500, response['status']) self.assertTrue(expect_log.logged_stack)
def _assertCrossDomainRequestFails(self, auth_url): encoded_query_args = urlparse.urlencode( {'jupyter_http_over_ws_auth_url': auth_url}) request = self.get_ws_connection_request('http_over_websocket?' + encoded_query_args) with testing.ExpectLog('tornado.application', 'Uncaught error when proxying request', required=True) as expect_log: client = yield websocket.websocket_connect(request) client.write_message( self.get_request_json('/requires-cookies-from-fake-auth-ws', '1234')) response_body = yield client.read_message() response = json.loads(response_body) self.assertEqual('1234', response['message_id']) self.assertEqual(500, response['status']) self.assertEqual( 'Uncaught server-side exception. Check logs for additional details.', response['statusText']) self.assertTrue(response['done']) self.assertTrue(expect_log.logged_stack)