Skip to content

Commit 7c58157

Browse files
authored
Unescape passcode (#26)
1 parent db05208 commit 7c58157

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
image: apache/activemq-artemis:2.34.0-alpine
1515
environment:
1616
ARTEMIS_USER: admin
17-
ARTEMIS_PASSWORD: admin
17+
ARTEMIS_PASSWORD: =123
1818
ports:
1919
- 8161:8161
2020
- 61616:61616

stompman/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dataclasses import dataclass, field
55
from types import TracebackType
66
from typing import Any, ClassVar, NamedTuple, Self, TypedDict
7+
from urllib.parse import unquote
78
from uuid import uuid4
89

910
from stompman.connection import AbstractConnection, Connection
@@ -59,6 +60,10 @@ class ConnectionParameters:
5960
login: str
6061
passcode: str = field(repr=False)
6162

63+
@property
64+
def unescaped_passcode(self) -> str:
65+
return unquote(self.passcode)
66+
6267
@classmethod
6368
def from_pydantic_multihost_hosts(cls, hosts: list[MultiHostHostLike]) -> list[Self]:
6469
"""Create connection parameters from a list of `MultiHostUrl` objects.
@@ -168,7 +173,7 @@ async def _connection_lifespan(self) -> AsyncGenerator[None, None]:
168173
"heart-beat": self.heartbeat.to_header(),
169174
"host": self._connection_parameters.host,
170175
"login": self._connection_parameters.login,
171-
"passcode": self._connection_parameters.passcode,
176+
"passcode": self._connection_parameters.unescaped_passcode,
172177
},
173178
)
174179
)

tests/integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@pytest.fixture()
1414
def server() -> stompman.ConnectionParameters:
15-
return stompman.ConnectionParameters(host=os.environ["ARTEMIS_HOST"], port=61616, login="admin", passcode="admin")
15+
return stompman.ConnectionParameters(host=os.environ["ARTEMIS_HOST"], port=61616, login="admin", passcode="%3D123")
1616

1717

1818
async def test_ok(server: stompman.ConnectionParameters) -> None:

tests/test_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ class MockConnection(connection_class): # type: ignore[valid-type, misc]
218218
monkeypatch.setattr(stompman.client, "uuid4", lambda: receipt_id)
219219

220220
login = "login"
221-
passcode = "passcode"
222221
async with EnrichedClient(
223-
[ConnectionParameters("localhost", 10, login, passcode)], connection_class=MockConnection
222+
[ConnectionParameters("localhost", 10, login, "%3Dpasscode")], connection_class=MockConnection
224223
) as client:
225224
await asyncio.sleep(0)
226225

@@ -231,7 +230,7 @@ class MockConnection(connection_class): # type: ignore[valid-type, misc]
231230
"accept-version": client.PROTOCOL_VERSION,
232231
"heart-beat": client.heartbeat.to_header(),
233232
"login": login,
234-
"passcode": passcode,
233+
"passcode": "=passcode",
235234
}
236235
),
237236
connected_frame,

0 commit comments

Comments
 (0)