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}
0 commit comments