@@ -89,3 +89,35 @@ async def test_subscribe_to_repository_activity(self, api_key):
8989 response_action = "repository/create" ,
9090 serializer = RepositorySerializer ,
9191 )
92+
93+ async def test_invalid_api_key (self ):
94+ communicator = WebsocketCommunicator (
95+ LiveStatusConsumer .as_asgi (), "/ws/test-live-status/"
96+ )
97+ try :
98+ connected , _ = await communicator .connect ()
99+ assert connected
100+ await communicator .send_json_to (
101+ {"api_key" : "invalid_key" , "action" : "subscribe_to_repository_activity" , "request_id" : 1 }
102+ )
103+ response = await communicator .receive_json_from ()
104+ assert response ["response_status" ] == 403
105+ assert await communicator .receive_nothing (), await communicator .show_queue ()
106+ finally :
107+ await communicator .disconnect ()
108+
109+ async def test_unknown_action (self , api_key ):
110+ communicator = WebsocketCommunicator (
111+ LiveStatusConsumer .as_asgi (), "/ws/test-live-status/"
112+ )
113+ try :
114+ connected , _ = await communicator .connect ()
115+ assert connected
116+ await communicator .send_json_to (
117+ {"api_key" : api_key , "action" : "non_existing_action" , "request_id" : 1 }
118+ )
119+ response = await communicator .receive_json_from ()
120+ assert response ["response_status" ] == 405
121+ assert await communicator .receive_nothing (), await communicator .show_queue ()
122+ finally :
123+ await communicator .disconnect ()
0 commit comments