From 35c5d703c2fef4218ec34c8e0c99908012fd04b1 Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Fri, 10 Jul 2026 11:45:35 +0200 Subject: [PATCH] feat: adapt for new token format --- app/proton/proton_client.py | 4 ++-- tests/proton/test_proton_client.py | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/proton/proton_client.py b/app/proton/proton_client.py index a3e304007..d26cc941a 100644 --- a/app/proton/proton_client.py +++ b/app/proton/proton_client.py @@ -49,13 +49,13 @@ def convert_access_token(access_token_response: str) -> AccessCredentials: This method takes the Access token response and extracts the session ID and the access token. """ parts = access_token_response.split("-") - if len(parts) != 3: + if len(parts) < 3: raise Exception("Invalid access token response") if parts[0] != "pt": raise Exception("Invalid access token response format") return AccessCredentials( session_id=parts[1], - access_token=parts[2], + access_token="-".join(parts[2:]), ) diff --git a/tests/proton/test_proton_client.py b/tests/proton/test_proton_client.py index 154cc0af8..6541560ae 100644 --- a/tests/proton/test_proton_client.py +++ b/tests/proton/test_proton_client.py @@ -16,11 +16,25 @@ def test_convert_access_token_not_containing_pt(): proton_client.convert_access_token("pb-abc-123") -def test_convert_access_token_not_containing_invalid_length(): - cases = ["pt-abc-too-long", "pt-short"] - for case in cases: - with pytest.raises(Exception): - proton_client.convert_access_token(case) +def test_convert_access_token_too_short(): + with pytest.raises(Exception): + proton_client.convert_access_token("pt-short") + + +def test_convert_access_token_with_many_hyphens(): + res = proton_client.convert_access_token("pt-abc-part1-part2-part3") + assert res.session_id == "abc" + assert res.access_token == "part1-part2-part3" + + +def test_convert_access_token_real_jwt_example(): + token_response = "pt-gj7m3zauijwvltko4d6xr5rskfq25j34-eyJpdiI6ImdTMjdYU1B.rbVN4d-mx2QnYiLCJ0YWciOi-JlMlAwT0FQVG_tWUW5kUzF-yUEQzZFJBIiwi" + res = proton_client.convert_access_token(token_response) + assert res.session_id == "gj7m3zauijwvltko4d6xr5rskfq25j34" + assert ( + res.access_token + == "eyJpdiI6ImdTMjdYU1B.rbVN4d-mx2QnYiLCJ0YWciOi-JlMlAwT0FQVG_tWUW5kUzF-yUEQzZFJBIiwi" + ) def test_handle_response_not_ok_account_not_verified():