Skip to content

Commit 96bad01

Browse files
authored
Add authentication to ws requests (#196)
* add auth to ws requests * style check fix
1 parent 10d4f91 commit 96bad01

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

jupyterlab_nvdashboard/apps/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from tornado.websocket import WebSocketHandler
2+
from jupyter_server.base.handlers import JupyterHandler
23
import tornado
34
import json
45

56

6-
class CustomWebSocketHandler(WebSocketHandler):
7+
class CustomWebSocketHandler(JupyterHandler, WebSocketHandler):
78
def open(self):
9+
if not self.current_user:
10+
self.write_message(json.dumps({"error": "Unauthorized access"}))
11+
self.close()
12+
return
813
self.write_message(json.dumps({"status": "connected"}))
914
self.set_nodelay(True)
1015
# Start a periodic callback to send data every 50ms

jupyterlab_nvdashboard/tests/test_cpu_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def handler_args():
2020
with patch("tornado.web.Application") as mock_application, patch(
2121
"tornado.httputil.HTTPServerRequest"
2222
) as mock_request:
23+
# Mock the settings to return appropriate values
24+
mock_settings = {
25+
"base_url": "/",
26+
}
27+
mock_application.settings = mock_settings
2328
yield mock_application, mock_request
2429

2530

jupyterlab_nvdashboard/tests/test_gpu_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def handler_args():
2626
with patch("tornado.web.Application") as mock_application, patch(
2727
"tornado.httputil.HTTPServerRequest"
2828
) as mock_request:
29+
# Mock the settings to return appropriate values
30+
mock_settings = {
31+
"base_url": "/",
32+
}
33+
mock_application.settings = mock_settings
2934
yield mock_application, mock_request
3035

3136

0 commit comments

Comments
 (0)