Skip to content

Commit

Permalink
[NHUB-231] fix(ws): Filter consumers on push not working when proxy i…
Browse files Browse the repository at this point in the history
…s used (#2430)

* [NHUB-231] fix(ws): Filter consumers on push not working when proxy is used

* fix(mypy)
  • Loading branch information
MarkLark86 authored Feb 15, 2023
1 parent f78eee7 commit 42ac2dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions superdesk/io/feeding_services/http_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from typing import List, Dict, Optional
from typing import List, Dict, Optional, Union
import traceback
import requests
from superdesk.errors import IngestApiError, SuperdeskIngestError
Expand Down Expand Up @@ -73,7 +73,7 @@ class HTTPFeedingServiceBase(FeedingService):
# Set to True if authentication is mandatory, False if there is no authentication
# and None to add authentication if user and password are defined.
# If auth_required is defined in config fields, it will override this value.
HTTP_AUTH = True
HTTP_AUTH: Union[bool, None] = True

# use this when auth is always required
AUTH_FIELDS: List[Dict] = [
Expand Down
10 changes: 5 additions & 5 deletions superdesk/websockets_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import websockets
from websockets.server import WebSocketServerProtocol
import signal
from urllib.parse import parse_qs
from urllib.parse import urlparse, parse_qs
from uuid import UUID

from datetime import timedelta, datetime
Expand Down Expand Up @@ -191,12 +191,12 @@ def _add_client(self, websocket: WebSocketServerProtocol):
self.clients.add(websocket)

# Store client URL args for use with message filters
if not websocket.path.startswith(self.subscribe_prefix):
if self.subscribe_prefix not in websocket.path:
self.client_url_args[websocket.id] = {}
else:
self.client_url_args[websocket.id] = {
key: val[0] for key, val in parse_qs(websocket.path.replace(self.subscribe_prefix, "")).items()
}
parsed_url = urlparse(websocket.path)
url_params = parse_qs(parsed_url.query)
self.client_url_args[websocket.id] = {key: val[0] for key, val in url_params.items()}

def _remove_client(self, websocket: WebSocketServerProtocol):
self.clients.remove(websocket)
Expand Down
6 changes: 3 additions & 3 deletions tests/websockets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def test_broadcast_specific_recipients(self):
com = SocketCommunication("host", "port", "url")

client_no_user = TestClient("")
client_user_abc123_sess_12345 = TestClient("/subscribe?user=abc123&session=12345")
client_user_abc123_sess_67890 = TestClient("/subscribe?user=abc123&session=67890")
client_user_def456 = TestClient("/subscribe?user=def456")
client_user_abc123_sess_12345 = TestClient("/ws/subscribe?user=abc123&session=12345")
client_user_abc123_sess_67890 = TestClient("/ws/subscribe?user=abc123&session=67890")
client_user_def456 = TestClient("/ws/subscribe?user=def456")
com._add_client(client_no_user)
com._add_client(client_user_abc123_sess_12345)
com._add_client(client_user_abc123_sess_67890)
Expand Down

0 comments on commit 42ac2dd

Please sign in to comment.