Skip to content

Commit 1f1c9c4

Browse files
style: Satisfy clippy map_or and Duration unit lints (#11)
clippy 0.1.97 promotes two lints across the crate: map(f).unwrap_or(a) on Result (use map_or), and constructing a Duration from a smaller unit where a larger one reads better (from_secs(3600) -> from_hours(1)). Mechanical rewrites only — every Duration keeps its exact value and the map_or calls are semantically identical. No behavior change; full suite passes (168 tests, --features testing).
1 parent 1746930 commit 1f1c9c4

8 files changed

Lines changed: 28 additions & 33 deletions

File tree

src/oidc/claims/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl Claims {
192192
/// considered valid.
193193
#[must_use]
194194
pub fn is_expired(&self) -> bool {
195-
SystemTime::now() > self.exp + std::time::Duration::from_secs(60)
195+
SystemTime::now() > self.exp + std::time::Duration::from_mins(1)
196196
}
197197
}
198198

src/oidc/claims/serde.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ impl Serialize for Claims {
2525
let iat_secs = self
2626
.iat
2727
.duration_since(UNIX_EPOCH)
28-
.map(|d| d.as_secs())
29-
.unwrap_or(0);
28+
.map_or(0, |d| d.as_secs());
3029
let exp_secs = self
3130
.exp
3231
.duration_since(UNIX_EPOCH)
33-
.map(|d| d.as_secs())
34-
.unwrap_or(0);
32+
.map_or(0, |d| d.as_secs());
3533
s.serialize_field("iat", &iat_secs)?;
3634
s.serialize_field("exp", &exp_secs)?;
3735
s.end()

src/oidc/token.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ mod tests {
318318
}
319319

320320
fn token_with_nbf_offset(offset_secs: i64) -> Token {
321-
let exp = SystemTime::now() + Duration::from_secs(3600);
321+
let exp = SystemTime::now() + Duration::from_hours(1);
322322
let iat = SystemTime::now() - Duration::from_secs(10);
323323
let nbf = if offset_secs >= 0 {
324324
SystemTime::now() + Duration::from_secs(offset_secs.cast_unsigned())
@@ -385,7 +385,7 @@ mod tests {
385385
}
386386

387387
fn token_with_iat_offset(offset_secs: i64) -> Token {
388-
let exp = SystemTime::now() + Duration::from_secs(3600);
388+
let exp = SystemTime::now() + Duration::from_hours(1);
389389
let iat = if offset_secs >= 0 {
390390
SystemTime::now() + Duration::from_secs(offset_secs.cast_unsigned())
391391
} else {
@@ -429,7 +429,7 @@ mod tests {
429429
}
430430

431431
fn token_with_nonce(nonce: Option<String>) -> Token {
432-
let exp = SystemTime::now() + Duration::from_secs(3600);
432+
let exp = SystemTime::now() + Duration::from_hours(1);
433433
let iat = SystemTime::now() - Duration::from_secs(10);
434434
let iss = url::Url::parse("https://issuer.example.com").expect("valid url");
435435
let claims = Claims::new(

src/pages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ mod tests {
386386
}
387387

388388
fn future_expiry() -> SystemTime {
389-
SystemTime::now() + Duration::from_secs(3600)
389+
SystemTime::now() + Duration::from_hours(1)
390390
}
391391

392392
#[test]

src/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ mod tests {
103103
TokenSet::new(
104104
"access".to_string(),
105105
None,
106-
Some(SystemTime::now() + Duration::from_secs(3600)),
106+
Some(SystemTime::now() + Duration::from_hours(1)),
107107
"Bearer".to_string(),
108108
None,
109109
Vec::new(),

src/token/mod.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ where
2323
{
2424
match time {
2525
Some(t) => {
26-
let secs = t
27-
.duration_since(UNIX_EPOCH)
28-
.map(|d| d.as_secs())
29-
.unwrap_or(0);
26+
let secs = t.duration_since(UNIX_EPOCH).map_or(0, |d| d.as_secs());
3027
serializer.serialize_some(&secs)
3128
}
3229
None => serializer.serialize_none(),
@@ -292,39 +289,39 @@ mod tests {
292289

293290
#[test]
294291
fn token_set_future_expiry_is_not_expired() {
295-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
292+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
296293
assert!(!token.is_expired());
297294
}
298295

299296
#[test]
300297
fn token_set_expiring_soon_is_within_threshold() {
301298
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(30));
302-
assert!(token.expires_within(Duration::from_secs(60)));
299+
assert!(token.expires_within(Duration::from_mins(1)));
303300
}
304301

305302
#[test]
306303
fn token_set_far_future_not_within_threshold() {
307-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
308-
assert!(!token.expires_within(Duration::from_secs(60)));
304+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
305+
assert!(!token.expires_within(Duration::from_mins(1)));
309306
}
310307

311308
#[test]
312309
fn token_set_already_expired_is_within_any_threshold() {
313310
let token = make_token_set_expiring_at(UNIX_EPOCH);
314-
assert!(token.expires_within(Duration::from_secs(60)));
311+
assert!(token.expires_within(Duration::from_mins(1)));
315312
}
316313

317314
#[test]
318315
fn token_set_serde_roundtrip_access_token() {
319-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
316+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
320317
let json = serde_json::to_string(&token).expect("serialize");
321318
let decoded: TokenSet<Unvalidated> = serde_json::from_str(&json).expect("deserialize");
322319
assert_eq!(decoded.access_token().as_str(), "access_token_value");
323320
}
324321

325322
#[test]
326323
fn token_set_expires_at_serializes_as_u64() {
327-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
324+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
328325
let json = serde_json::to_string(&token).expect("serialize");
329326
let value: serde_json::Value = serde_json::from_str(&json).expect("parse");
330327
assert!(
@@ -356,14 +353,14 @@ mod tests {
356353

357354
#[test]
358355
fn access_token_getter_returns_access_token_newtype() {
359-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
356+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
360357
let at: &AccessToken = token.access_token();
361358
assert_eq!(at.as_str(), "access_token_value");
362359
}
363360

364361
#[test]
365362
fn refresh_token_getter_returns_refresh_token_newtype() {
366-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
363+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
367364
let rt: Option<&RefreshToken> = token.refresh_token();
368365
assert!(rt.is_some());
369366
assert_eq!(rt.unwrap().as_str(), "refresh_token_value");
@@ -374,7 +371,7 @@ mod tests {
374371
let token = TokenSet::new(
375372
"access".to_string(),
376373
None,
377-
Some(SystemTime::now() + Duration::from_secs(3600)),
374+
Some(SystemTime::now() + Duration::from_hours(1)),
378375
"Bearer".to_string(),
379376
None,
380377
Vec::new(),
@@ -385,7 +382,7 @@ mod tests {
385382

386383
#[test]
387384
fn id_token_raw_absent_returns_none() {
388-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
385+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
389386
assert!(token.id_token_raw().is_none());
390387
}
391388

@@ -406,7 +403,7 @@ mod tests {
406403
let token = TokenSet::new(
407404
"access".to_string(),
408405
None,
409-
Some(SystemTime::now() + Duration::from_secs(3600)),
406+
Some(SystemTime::now() + Duration::from_hours(1)),
410407
"Bearer".to_string(),
411408
Some(oidc),
412409
Vec::new(),
@@ -417,15 +414,15 @@ mod tests {
417414

418415
#[test]
419416
fn expires_at_is_publicly_callable() {
420-
let expiry = SystemTime::now() + Duration::from_secs(3600);
417+
let expiry = SystemTime::now() + Duration::from_hours(1);
421418
let token = make_token_set_expiring_at(expiry);
422419
// expires_at() must be pub - compile-time check
423420
let _ = token.expires_at();
424421
}
425422

426423
#[test]
427424
fn scopes_returns_empty_slice_when_empty() {
428-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
425+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
429426
assert_eq!(token.scopes(), &[] as &[OAuth2Scope]);
430427
}
431428

@@ -434,7 +431,7 @@ mod tests {
434431
let token = TokenSet::new(
435432
"access".to_string(),
436433
None,
437-
Some(SystemTime::now() + Duration::from_secs(3600)),
434+
Some(SystemTime::now() + Duration::from_hours(1)),
438435
"Bearer".to_string(),
439436
None,
440437
vec![OAuth2Scope::OpenId, OAuth2Scope::Email],
@@ -455,7 +452,7 @@ mod tests {
455452

456453
#[test]
457454
fn token_set_token_type_returns_bearer() {
458-
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_secs(3600));
455+
let token = make_token_set_expiring_at(SystemTime::now() + Duration::from_hours(1));
459456
assert_eq!(token.token_type(), "Bearer");
460457
}
461458
}

tests/refresh_flow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async fn refresh_if_expiring_not_needed() {
6969

7070
// Token has ~3600s expiry; 60s threshold means it is NOT expiring soon
7171
let result = auth
72-
.refresh_if_expiring(&token_set, Duration::from_secs(60))
72+
.refresh_if_expiring(&token_set, Duration::from_mins(1))
7373
.await;
7474

7575
match result {
@@ -91,7 +91,7 @@ async fn refresh_if_expiring_refreshed() {
9191

9292
// Token has ~3600s expiry; 7200s threshold means it IS expiring soon
9393
let result = auth
94-
.refresh_if_expiring(&token_set, Duration::from_secs(7200))
94+
.refresh_if_expiring(&token_set, Duration::from_hours(2))
9595
.await;
9696

9797
match result {

tests/refresh_token_preservation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async fn refresh_if_expiring_preserves_token_when_provider_omits_it() {
7979
let expired_tokens = expired_tokens.into_validated();
8080

8181
let outcome = client
82-
.refresh_if_expiring(&expired_tokens, Duration::from_secs(300))
82+
.refresh_if_expiring(&expired_tokens, Duration::from_mins(5))
8383
.await;
8484

8585
match outcome {

0 commit comments

Comments
 (0)