-
Notifications
You must be signed in to change notification settings - Fork 34
fix: bump uipath-langchain-client to 1.13.1 for rt_ token support #898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cosminacho
wants to merge
2
commits into
main
Choose a base branch
from
chore/bump-langchain-client-1.13.1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """Reference-token (``rt_``) support in ``PlatformSettings``. | ||
|
|
||
| UiPath issues two kinds of access tokens: JWT bearer tokens, and opaque | ||
| *reference tokens* (prefixed ``rt_``) that carry no client-readable claims. | ||
|
|
||
| Before ``uipath-langchain-client`` 1.13.1 the platform settings validator | ||
| decoded *every* token as a JWT (splitting on ``.`` and base64-decoding the | ||
| payload) to check expiry and pull out the ``client_id``. An opaque ``rt_`` | ||
| token has no dot-separated payload, so that decode raised ``ValueError`` and | ||
| an agent authenticating with a reference token could never construct a chat | ||
| model. 1.13.1 parses JWT claims best-effort and falls back gracefully for | ||
| opaque tokens. These tests pin that behaviour so the dependency cannot | ||
| regress underneath us. | ||
| """ | ||
|
|
||
| import base64 | ||
| import json | ||
| import time | ||
|
|
||
| import httpx | ||
| import pytest | ||
| from pydantic import SecretStr | ||
| from uipath_langchain_client.settings import PlatformSettings | ||
|
|
||
| # An opaque UiPath reference token: no ``.``-separated JWT payload to decode. | ||
| _RT_TOKEN = "rt_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
|
|
||
| _BASE_URL = "https://alpha.uipath.com/TestOrg/TestTenant" | ||
|
|
||
|
|
||
| def _make_jwt(payload: dict) -> str: | ||
| """Build a JWT-shaped token (``header.payload.signature``) for ``payload``.""" | ||
|
|
||
| def _segment(obj: dict) -> str: | ||
| raw = json.dumps(obj).encode() | ||
| return base64.urlsafe_b64encode(raw).rstrip(b"=").decode() | ||
|
|
||
| return f"{_segment({'alg': 'none'})}.{_segment(payload)}.signature" | ||
|
|
||
|
|
||
| def _make_settings(token: str) -> PlatformSettings: | ||
| return PlatformSettings( | ||
| base_url=_BASE_URL, | ||
| organization_id="TestOrg", | ||
| tenant_id="TestTenant", | ||
| access_token=SecretStr(token), | ||
| ) | ||
|
|
||
|
|
||
| class TestReferenceTokenSettings: | ||
| """``PlatformSettings`` must accept opaque ``rt_`` reference tokens.""" | ||
|
|
||
| def test_reference_token_does_not_raise(self) -> None: | ||
| """An opaque ``rt_`` token passes validation (the 1.13.1 fix).""" | ||
| settings = _make_settings(_RT_TOKEN) | ||
|
|
||
| assert settings.access_token.get_secret_value() == _RT_TOKEN | ||
| # Opaque tokens carry no JWT claims, so no client_id is extracted. | ||
| assert settings.client_id is None | ||
|
|
||
| def test_reference_token_used_as_bearer(self) -> None: | ||
| """The reference token is sent verbatim as the Bearer credential.""" | ||
| settings = _make_settings(_RT_TOKEN) | ||
| auth = settings.build_auth_pipeline() | ||
|
|
||
| request = httpx.Request("POST", f"{_BASE_URL}/llm") | ||
| authenticated = next(auth.auth_flow(request)) | ||
|
|
||
| assert authenticated.headers["Authorization"] == f"Bearer {_RT_TOKEN}" | ||
|
|
||
|
|
||
| class TestJwtTokenStillSupported: | ||
| """Regression guard: JWT handling must be unchanged by the ``rt_`` fix.""" | ||
|
|
||
| def test_jwt_claims_extracted(self) -> None: | ||
| """A JWT still has its ``client_id`` claim extracted.""" | ||
| token = _make_jwt({"client_id": "the-client-id", "exp": time.time() + 3600}) | ||
|
|
||
| settings = _make_settings(token) | ||
|
|
||
| assert settings.client_id == "the-client-id" | ||
|
|
||
| def test_expired_jwt_rejected(self) -> None: | ||
| """An expired JWT is still rejected during validation.""" | ||
| token = _make_jwt({"exp": time.time() - 3600}) | ||
|
|
||
| with pytest.raises(ValueError, match="expired"): | ||
| _make_settings(token) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.