Repository navigation
[Rust][Python] Add federation end-to-end tests - #1107
Open
anilmenon14 wants to merge 1 commit into
Open
anilmenon14 wants to merge 1 commit into
anilmenon14 wants to merge 1 commit into
Conversation
Collaborator
Author
|
Edit: #1071/#1072 fixed the lockfile on main, so the branch is now rebased and above fix in #1102 isn't needed. |
Add end-to-end tests for external-IdP token federation that go through the public API. The Rust tests build streams with StreamBuilder::federated_auth against the mock token endpoint and mock gRPC server. The Python tests call create_stream(auth=FederatedToken) against a loopback mock token endpoint. They check the exchange request in both modes, caching and isolation, refresh, supplier errors, auth rejection, a hung refresh, and token-endpoint errors. The mock token endpoint now records each request, and the mock gRPC server records each stream's authorization and table-name headers. Fix a bug the tests found: a supplier returning an empty token caused an empty subject_token to be sent. FederatedTokenProvider now rejects an empty or whitespace-only token as a non-retryable InvalidArgument. Give the cold first stream in the OAuth hung-refresh test the default timeout; a loopback mint can take over a second on a loaded machine. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Anil Menon <anil.menon@databricks.com>
anilmenon14
force-pushed
the
feature/federation-e2e-tests
branch
from
November 21, 2026 16:31
7f64292 to
b14a140
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds end-to-end tests for external-IdP token federation (#740 / #760) in the Rust core and the Python SDK, and fixes one bug those tests found. This is the Rust and Python part of #1069. Java (#1105) and Go (#1106) add the same coverage for their bindings.
WHY: the existing federation tests check the core's logic when it's called directly, but not the wiring between layers. No Rust test built a stream with
.federated_auth(), and no Python test reached a working token endpoint: every Python bridge test was a failure path. So a regression in the builder's federation arm, the shared token cache, or the Python bridge would pass CI. I checked this by breaking the code: onmain, nothing fails when the federation arm swapsworkspace_idand the Unity Catalog URL, gets a fresh token cache instead of the SDK's shared one, or drops the refresh timeout.WHAT:
ZerobusError::InvalidArgument(NonRetriableExceptionin Python). Before, the SDK posted an emptysubject_tokento the token endpoint, and the failure looked like a federation-policy problem. Java and Go reject an empty token in their bridges ([Java] Add external-IdP token federation #1105, [Go] Add external-IdP token federation #1106); this check inFederatedTokenProvidercovers Rust and Python, and backs up the other two.rust/tests/src/federated_token_tests.rs(16 tests). Each builds real streams withStreamBuilder::federated_authagainst the mock token endpoint and mock gRPC server.mock_oauth.rsnow records each request's method, path, headers and decoded form.get_auth_headers(), added onmainby [Rust] Add personal access token auth #1071.oauth_token_tests::hung_refresh_falls_back_to_cached_tokengave its first stream, which does a cold mint, a 1-second budget. A loopback mint takes about 600 ms and up to about 2 s on a loaded machine (measured onmain), so the test failed once in a fullmake testrun here. Only the second stream, which never mints, needs the tight budget. The first now uses the default timeout, and the new federated version of the test does the same. What each test checks hasn't changed.python/tests/test_federated_exchange.py(15 tests). Each calls the realcreate_stream(auth=FederatedToken(...))against a loopback mock token endpoint (ThreadingHTTPServer). The gRPC endpoint is a refused port with recovery off; the SDK exchanges the token before it connects, so each create reaches the token endpoint.python/tests/test_federated_auth.py, which said the bridge was already tested end to end.IdpTokenCallbackandFederatedToken.NEXT_CHANGELOG.mdentries for Rust and Python.How is this tested?
federated_token_tests.rs), in both federation modes where it applies:POST /oidc/v1/token, form-encoded, with noAuthorizationheader.subject_tokenis byte-identical to the supplier's token (a realistic ~1.5 KB JWT).grant_typeandsubject_token_typeare the token-exchange values.client_idis sent only for workload identity federation.scope,resourceandauthorization_detailsmatch the OAuth grant for the same table.Bearertoken, with the table-name header.client_id.UNAUTHENTICATEDrejection re-exchanges once and succeeds. Repeated rejection stops after one re-exchange.test_federated_exchange.py):subject_token, grant parameters, andclient_idonly for workload identity).FederatedTokenshares one exchange across streams.FederatedTokens never share a token.client_id.NonRetriableException) and isn't cached.NonRetriableExceptionand is never sent.NonRetriableExceptionwith the server's reason, and HTTP 500 is retryable. No error contains the IdP token.async defsupplier, in both modes, sends the exact token and caches it.Rust core:
workspace_idand the Unity Catalog URL.client_id.subject_tokentruncated by one byte.invalidate()does nothing.The first, second and fourth weren't caught by any existing test.
Python:
client_iddropped on the sync path, or on the async path.FederatedToken.make test(the full feature matrix) passes.make lintandcargo fmt --checkare clean.make lint,blackandisortare clean.