use super::*; const ROTATED: &str = "2026-09-29T04:10:00.000Z"; const BEFORE: &str = "2026-09-20T10:00:00.000Z"; const AFTER: &str = "2026-09-29T05:00:00.000Z"; fn signed_in_before_the_rotation() -> ConnectorFacts<'static> { ConnectorFacts { vmk_version: Some(2), rotated_at: Some(ROTATED), grant_created_at: Some(BEFORE), grant_refreshed_at: Some(BEFORE), token_revoked: false, token_last_used_at: Some(BEFORE), grant_outlives_rotation: false, } } #[test] fn a_connector_last_seen_before_the_rotation_needs_sign_in_since_that_day() { assert_eq!( needs_sign_in_since(&signed_in_before_the_rotation()), NaiveDate::from_ymd_opt(2026, 9, 29) ); } #[test] fn any_sign_of_life_after_the_rotation_clears_it() { for facts in [ ConnectorFacts { grant_created_at: Some(AFTER), ..signed_in_before_the_rotation() }, ConnectorFacts { grant_refreshed_at: Some(AFTER), ..signed_in_before_the_rotation() }, ConnectorFacts { token_last_used_at: Some(AFTER), ..signed_in_before_the_rotation() }, ] { assert_eq!(needs_sign_in_since(&facts), None, "{facts:?}"); } } #[test] fn a_workspace_on_its_first_key_has_never_rotated() { let facts = ConnectorFacts { vmk_version: Some(1), ..signed_in_before_the_rotation() }; assert_eq!(needs_sign_in_since(&facts), None); } #[test] fn a_pasted_token_or_a_disconnected_one_is_not_asked_to_sign_in() { let pasted = ConnectorFacts { grant_created_at: None, ..signed_in_before_the_rotation() }; let revoked = ConnectorFacts { token_revoked: true, ..signed_in_before_the_rotation() }; assert_eq!(needs_sign_in_since(&pasted), None); assert_eq!(needs_sign_in_since(&revoked), None); } #[test] fn a_never_refreshed_never_used_connector_is_judged_by_its_creation() { let facts = ConnectorFacts { grant_refreshed_at: None, token_last_used_at: None, ..signed_in_before_the_rotation() }; assert_eq!(needs_sign_in_since(&facts), NaiveDate::from_ymd_opt(2026, 9, 29)); } #[test] fn an_unreadable_timestamp_is_no_answer_rather_than_a_guess() { let facts = ConnectorFacts { rotated_at: Some("yesterday"), ..signed_in_before_the_rotation() }; assert_eq!(needs_sign_in_since(&facts), None); } /// RULE: A connector whose live grant carries a refresh digest and names its minter is never listed as needing sign-in after a key rotation, because its current refresh token is still admitted. #[test] fn a_grant_that_outlives_the_rotation_is_not_signed_out() { let facts = ConnectorFacts { grant_outlives_rotation: true, ..signed_in_before_the_rotation() }; assert_eq!(needs_sign_in_since(&facts), None); // Without the fact, the same connector is signed out since that day. assert_eq!( needs_sign_in_since(&signed_in_before_the_rotation()), NaiveDate::from_ymd_opt(2026, 9, 29) ); }