fix(rust): Test suite fixes from final validation#324
fix(rust): Test suite fixes from final validation#324vikrantpuppala wants to merge 10 commits intoadbc-drivers:mainfrom
Conversation
727b177 to
0e69f4a
Compare
rust/src/auth/oauth/cache.rs
Outdated
| scopes: Vec<String>, | ||
| } | ||
|
|
||
| #[allow(dead_code)] // Used in Phase 3 (U2M) |
There was a problem hiding this comment.
why this? i think this is used now? we should fix all such instances across
| <p>You can close this tab and return to your application.</p> | ||
| </div> | ||
| </body> | ||
| </html>"#; |
There was a problem hiding this comment.
let's make this page simpler, no need for fancy fonts colours, check marks, etc.
| <p>An error occurred during authentication. You can close this tab and try again.</p> | ||
| </div> | ||
| </body> | ||
| </html>"#; |
There was a problem hiding this comment.
use simple pages
| // Use block_in_place to avoid blocking the runtime if we're in one, | ||
| // and get the handle to block_on the async operation | ||
| tokio::task::block_in_place(|| { | ||
| tokio::runtime::Handle::current().block_on(async { |
There was a problem hiding this comment.
shouldn't this happen async? check all instances and see if we're handling this correctly
rust/src/auth/oauth.rs.old
Outdated
There was a problem hiding this comment.
should we just remove this?
rust/src/database.rs
Outdated
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| #[repr(u8)] | ||
| pub enum AuthMechanism { | ||
| /// Personal access token (no OAuth). Config value: 0 | ||
| Pat = 0, | ||
| /// OAuth 2.0 -- requires AuthFlow to select the specific flow. Config value: 11 | ||
| OAuth = 11, | ||
| } | ||
|
|
||
| impl TryFrom<i64> for AuthMechanism { | ||
| type Error = crate::error::Error; | ||
|
|
||
| fn try_from(value: i64) -> std::result::Result<Self, Self::Error> { | ||
| match value { | ||
| 0 => Ok(AuthMechanism::Pat), | ||
| 11 => Ok(AuthMechanism::OAuth), | ||
| _ => Err(DatabricksErrorHelper::invalid_argument().message(format!( | ||
| "Invalid auth mechanism value: {}. Valid values are 0 (PAT) or 11 (OAuth)", | ||
| value | ||
| ))), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// OAuth authentication flow -- selects the specific OAuth grant type. | ||
| /// Config values match the ODBC driver's Auth_Flow numeric codes. | ||
| /// Only applicable when AuthMechanism is OAuth. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| #[repr(u8)] | ||
| pub enum AuthFlow { | ||
| /// Use a pre-obtained OAuth access token directly. Config value: 0 | ||
| TokenPassthrough = 0, | ||
| /// M2M: client credentials grant for service principals. Config value: 1 | ||
| ClientCredentials = 1, | ||
| /// U2M: browser-based authorization code + PKCE. Config value: 2 | ||
| Browser = 2, | ||
| } | ||
|
|
||
| impl TryFrom<i64> for AuthFlow { | ||
| type Error = crate::error::Error; | ||
|
|
||
| fn try_from(value: i64) -> std::result::Result<Self, Self::Error> { | ||
| match value { | ||
| 0 => Ok(AuthFlow::TokenPassthrough), | ||
| 1 => Ok(AuthFlow::ClientCredentials), | ||
| 2 => Ok(AuthFlow::Browser), | ||
| _ => Err(DatabricksErrorHelper::invalid_argument().message(format!( | ||
| "Invalid auth flow value: {}. Valid values are 0 (token passthrough), 1 (client credentials), or 2 (browser)", | ||
| value | ||
| ))), | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
is this the right place to define this? seems like database is becoming bloated?
There was a problem hiding this comment.
overall would be great if we can abstract out the auth related stuff in this file so that it is less bloated
rust/CLAUDE.md
Outdated
| - Test names: `test_<function>_<scenario>` | ||
| - E2E tests that require real Databricks connection should be marked with `#[ignore]` | ||
|
|
||
| #### Running E2E OAuth Tests |
There was a problem hiding this comment.
don't think we need this section
0e69f4a to
13f8c28
Compare
f87df69 to
b8141fb
Compare
Range-diff: stack/pr-integration-tests (f87df69 -> b8141fb)
Reproduce locally: |
7dfee16 to
e2cd82b
Compare
## 🥞 Stacked PR Use this [link](https://github.com/adbc-drivers/databricks/pull/319/files) to review incremental changes. - [**stack/oauth-u2m-m2m-design**](#319) [[Files changed](https://github.com/adbc-drivers/databricks/pull/319/files)] - [stack/pr-oauth-foundation](#320) [[Files changed](https://github.com/adbc-drivers/databricks/pull/320/files/250ff3d91c3001f671f08084f68e949e556bc5d2..bd474c189621aa70c1f14e97c32d64605275e07d)] - [stack/pr-database-config](#321) [[Files changed](https://github.com/adbc-drivers/databricks/pull/321/files/bd474c189621aa70c1f14e97c32d64605275e07d..296931cd396d82dccb1b548a51f6b9d31be3683e)] - [stack/pr-u2m-provider](#322) [[Files changed](https://github.com/adbc-drivers/databricks/pull/322/files/296931cd396d82dccb1b548a51f6b9d31be3683e..c96689981e79c04f43e8251f2cbd5690371dfca5)] - [stack/pr-integration-tests](#323) [[Files changed](https://github.com/adbc-drivers/databricks/pull/323/files/c96689981e79c04f43e8251f2cbd5690371dfca5..83d639337ca30688abb7bdba85aa16426d76eb31)] - [stack/pr-final-validation](#324) [[Files changed](https://github.com/adbc-drivers/databricks/pull/324/files/83d639337ca30688abb7bdba85aa16426d76eb31..e2cd82bf1e9510169735774784591074f30351d3)] --------- ## Summary - Design document for adding OAuth 2.0 authentication to the Rust ADBC driver covering both U2M (Authorization Code + PKCE) and M2M (Client Credentials) flows - Sprint plan breaking the implementation into 3 tasks: foundation + HTTP client changes, M2M provider, U2M provider - Uses the `oauth2` crate for protocol-level operations, unified `DatabricksHttpClient` with two-phase `OnceLock` init, and ODBC-aligned numeric config values (`AuthMech`/`Auth_Flow`) ## Key decisions and alternatives considered - **`oauth2` crate adoption** over hand-rolling OAuth protocol (eliminates ~200 lines of boilerplate, handles PKCE/token exchange/refresh) - **Unified HTTP client** (`DatabricksHttpClient` with `OnceLock`) over separate `reqwest::Client` for token calls (shared retry logic, connection pooling) - **ODBC-aligned numeric config** (`mechanism=0/11`, `flow=0/1/2`) over string-based or auto-detection (explicit, predictable, matches ODBC driver) - **Separate U2M/M2M providers** over single OAuthProvider (different flows, refresh strategies, caching needs) - **Separate token cache** (`~/.config/databricks-adbc/oauth/`) over sharing Python SDK cache (fragile cross-SDK compatibility) ## Areas needing specific review focus - Two-phase HTTP client initialization pattern (OnceLock for auth provider) — is this the right approach for breaking the circular dependency? - Token refresh state machine (FRESH/STALE/EXPIRED) — are the thresholds (40s expiry buffer, min(TTL*0.5, 20min) stale) appropriate? - Config option naming (`databricks.auth.mechanism`, `databricks.auth.flow`) — alignment with ODBC driver - Sprint plan task breakdown — is the scope realistic for 2 weeks? --- *Replaces #318 (closed — converted to stacked branch)* 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
23d69f3 to
01cfd62
Compare
85d9339 to
2d6ccb0
Compare
…tore (#320) ## 🥞 Stacked PR Use this [link](https://github.com/adbc-drivers/databricks/pull/320/files) to review incremental changes. - [**stack/pr-oauth-foundation**](#320) [[Files changed](https://github.com/adbc-drivers/databricks/pull/320/files)] - [stack/pr-database-config](#321) [[Files changed](https://github.com/adbc-drivers/databricks/pull/321/files/78b9ec88459f895c76bd1aea99fcb47e5eb94893..164ada04d14660306c7e44dd3d52a7943050aa27)] - [stack/pr-u2m-provider](#322) [[Files changed](https://github.com/adbc-drivers/databricks/pull/322/files/164ada04d14660306c7e44dd3d52a7943050aa27..abc00ced51d89f1a652f78209f692775eba05e73)] - [stack/pr-integration-tests](#323) [[Files changed](https://github.com/adbc-drivers/databricks/pull/323/files/abc00ced51d89f1a652f78209f692775eba05e73..75b18d6c594eeba89a30450152d6d6f672239614)] - [stack/pr-final-validation](#324) [[Files changed](https://github.com/adbc-drivers/databricks/pull/324/files/75b18d6c594eeba89a30450152d6d6f672239614..2d6ccb09e121015aa6a0da6e992529a686bb0f04)] --------- ## Summary Adds the core OAuth token infrastructure used by both U2M and M2M flows: - **`OAuthToken`** — token struct with expiry tracking, stale detection (40s buffer / 50% TTL), and serde support - **OIDC discovery** — fetches `authorization_endpoint` and `token_endpoint` from `/.well-known/oauth-authorization-server` - **`TokenCache`** — file-based persistence at `~/.config/databricks-adbc/oauth/` with SHA-256 hashed filenames and `0o600` permissions - **`TokenStore`** — thread-safe token lifecycle (Empty → Fresh → Stale → Expired) with coordinated refresh via `RwLock` + `AtomicBool` - **Cargo dependencies** — `oauth2`, `sha2`, `dirs`, `serde`, `open` crates - **`DatabricksHttpClient`** — extended with `OnceLock`-based auth provider and `inner()` accessor for the `oauth2` crate ### Key files - `src/auth/oauth/token.rs` — `OAuthToken` struct - `src/auth/oauth/oidc.rs` — OIDC endpoint discovery - `src/auth/oauth/cache.rs` — file-based token cache - `src/auth/oauth/token_store.rs` — token lifecycle state machine - `src/client/http.rs` — HTTP client auth provider integration
…: task-2.2-database-config-fields
2d6ccb0 to
04d7b09
Compare
…2.3-database-validation
…1-callback-server
…sk-3.2-u2m-provider
…3-database-integration
…task-4.1-wiremock-u2m-refresh
…sk ID: task-4.2-m2m-database-integration
04d7b09 to
720434f
Compare
|
Folded into PR #323 to reduce stack size. |
🥞 Stacked PR
Use this link to review incremental changes.
Summary
Minor fixes discovered while running the full test suite:
Key files
src/auth/oauth/callback.rs— HTML response fixThis pull request was AI-assisted by Isaac.