Skip to content

Commit 4fa4768

Browse files
Implement TokenStore with FRESH/STALE/EXPIRED state machine\n\nTask ID: task-1.4-token-store
1 parent 06636dd commit 4fa4768

File tree

4 files changed

+525
-18
lines changed

4 files changed

+525
-18
lines changed

rust/src/auth/oauth/cache.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ use std::path::PathBuf;
2727

2828
/// Cache key used for generating the cache filename.
2929
/// This struct is serialized to JSON and then hashed with SHA-256 to produce a unique filename.
30+
#[allow(dead_code)] // Used in Phase 3 (U2M)
3031
#[derive(Debug, Serialize, Deserialize)]
3132
struct CacheKey {
3233
host: String,
3334
client_id: String,
3435
scopes: Vec<String>,
3536
}
3637

38+
#[allow(dead_code)] // Used in Phase 3 (U2M)
3739
impl CacheKey {
3840
/// Creates a new cache key from the given parameters.
3941
fn new(host: &str, client_id: &str, scopes: &[String]) -> Self {
@@ -67,8 +69,10 @@ impl CacheKey {
6769
/// set to `0o600` (owner read/write only) for security.
6870
///
6971
/// Cache I/O errors are logged as warnings and never block authentication.
72+
#[allow(dead_code)] // Used in Phase 3 (U2M)
7073
pub(crate) struct TokenCache;
7174

75+
#[allow(dead_code)] // Used in Phase 3 (U2M)
7276
impl TokenCache {
7377
/// Returns the cache directory path.
7478
/// Location: `~/.config/databricks-adbc/oauth/`
@@ -127,11 +131,7 @@ impl TokenCache {
127131
Some(token)
128132
}
129133
Err(e) => {
130-
tracing::warn!(
131-
"Token cache corrupted at {:?}, ignoring: {}",
132-
cache_path,
133-
e
134-
);
134+
tracing::warn!("Token cache corrupted at {:?}, ignoring: {}", cache_path, e);
135135
None
136136
}
137137
},
@@ -342,7 +342,10 @@ mod tests {
342342
&["all-apis".to_string()],
343343
);
344344

345-
assert!(result.is_none(), "Load should return None for missing cache");
345+
assert!(
346+
result.is_none(),
347+
"Load should return None for missing cache"
348+
);
346349
}
347350

348351
#[test]

rust/src/auth/oauth/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
pub mod cache;
2525
pub mod oidc;
2626
pub mod token;
27+
pub(crate) mod token_store;
2728

2829
// Re-export the main types
2930
pub use oidc::OidcEndpoints;

rust/src/auth/oauth/oidc.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ mod tests {
181181
endpoints.authorization_endpoint,
182182
"https://example.com/oidc/v1/authorize"
183183
);
184-
assert_eq!(endpoints.token_endpoint, "https://example.com/oidc/v1/token");
184+
assert_eq!(
185+
endpoints.token_endpoint,
186+
"https://example.com/oidc/v1/token"
187+
);
185188
}
186189

187190
#[tokio::test]
@@ -241,10 +244,7 @@ mod tests {
241244
// Discovery should fail with deserialization error
242245
let result = OidcEndpoints::discover(&mock_server.uri(), &http_client).await;
243246

244-
assert!(
245-
result.is_err(),
246-
"Discovery should fail with missing fields"
247-
);
247+
assert!(result.is_err(), "Discovery should fail with missing fields");
248248
let error_msg = format!("{:?}", result.unwrap_err());
249249
assert!(
250250
error_msg.contains("Failed to parse OIDC discovery response"),
@@ -261,9 +261,7 @@ mod tests {
261261
// Mock with 404 response
262262
Mock::given(method("GET"))
263263
.and(path("/oidc/.well-known/oauth-authorization-server"))
264-
.respond_with(
265-
ResponseTemplate::new(404).set_body_string("Endpoint not found"),
266-
)
264+
.respond_with(ResponseTemplate::new(404).set_body_string("Endpoint not found"))
267265
.mount(&mock_server)
268266
.await;
269267

@@ -293,9 +291,7 @@ mod tests {
293291
// Mock with 500 response
294292
Mock::given(method("GET"))
295293
.and(path("/oidc/.well-known/oauth-authorization-server"))
296-
.respond_with(
297-
ResponseTemplate::new(500).set_body_string("Internal server error"),
298-
)
294+
.respond_with(ResponseTemplate::new(500).set_body_string("Internal server error"))
299295
.mount(&mock_server)
300296
.await;
301297

@@ -356,6 +352,9 @@ mod tests {
356352
endpoints.authorization_endpoint,
357353
"https://example.com/oidc/v1/authorize"
358354
);
359-
assert_eq!(endpoints.token_endpoint, "https://example.com/oidc/v1/token");
355+
assert_eq!(
356+
endpoints.token_endpoint,
357+
"https://example.com/oidc/v1/token"
358+
);
360359
}
361360
}

0 commit comments

Comments
 (0)