Skip to content

Commit

Permalink
add auth to ws requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayThorve committed May 31, 2024
1 parent 10d4f91 commit 969902b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion jupyterlab_nvdashboard/apps/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from tornado.websocket import WebSocketHandler
from jupyter_server.base.handlers import JupyterHandler
import tornado
import json


class CustomWebSocketHandler(WebSocketHandler):
class CustomWebSocketHandler(JupyterHandler, WebSocketHandler):
def open(self):
if not self.current_user:
self.write_message(json.dumps({"error": "Unauthorized access"}))
self.close()
return
self.write_message(json.dumps({"status": "connected"}))
self.set_nodelay(True)
# Start a periodic callback to send data every 50ms
Expand Down
6 changes: 5 additions & 1 deletion jupyterlab_nvdashboard/tests/test_cpu_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ def handler_args():
with patch("tornado.web.Application") as mock_application, patch(
"tornado.httputil.HTTPServerRequest"
) as mock_request:
# Mock the settings to return appropriate values
mock_settings = {
"base_url": "/",
}
mock_application.settings = mock_settings
yield mock_application, mock_request


def test_cpu_resource_handler(mock_handler, handler_args):
handler = CPUResourceWebSocketHandler(*handler_args)
handler.send_data()
Expand Down
5 changes: 5 additions & 0 deletions jupyterlab_nvdashboard/tests/test_gpu_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def handler_args():
with patch("tornado.web.Application") as mock_application, patch(
"tornado.httputil.HTTPServerRequest"
) as mock_request:
# Mock the settings to return appropriate values
mock_settings = {
"base_url": "/",
}
mock_application.settings = mock_settings
yield mock_application, mock_request


Expand Down

0 comments on commit 969902b

Please sign in to comment.