use chrono::{Duration, Utc};
use force::auth::{AccessToken, TokenResponse};
#[test]
fn test_expires_in_inconsistency_repro() {
let response_overflow = TokenResponse {
access_token: "overflow_token".to_string(),
instance_url: "https://test.salesforce.com".to_string(),
token_type: "Bearer".to_string(),
issued_at: Utc::now().timestamp_millis().to_string(),
signature: "sig".to_string(),
expires_in: Some(u64::MAX), refresh_token: None,
};
let token_overflow = AccessToken::from_response(response_overflow);
assert!(
token_overflow.expires_at().is_none(),
"u64::MAX should result in infinite validity"
);
let response_large = TokenResponse {
access_token: "large_token".to_string(),
instance_url: "https://test.salesforce.com".to_string(),
token_type: "Bearer".to_string(),
issued_at: Utc::now().timestamp_millis().to_string(),
signature: "sig".to_string(),
expires_in: Some(4_000_000_000), refresh_token: None,
};
let token_large = AccessToken::from_response(response_large);
assert!(
token_large.expires_at().is_none(),
"4B should result in infinite validity"
);
}
#[test]
fn test_invalid_issued_at_extends_validity_repro() {
let past = Utc::now() - Duration::hours(1);
let _ = past.timestamp_millis().to_string();
let response_garbage = TokenResponse {
access_token: "garbage_token".to_string(),
instance_url: "https://test.salesforce.com".to_string(),
token_type: "Bearer".to_string(),
issued_at: "not_a_timestamp".to_string(), signature: "sig".to_string(),
expires_in: Some(3600), refresh_token: None,
};
let token = AccessToken::from_response(response_garbage);
let issued_at = token.issued_at();
let now = Utc::now();
let diff = (now - issued_at).num_seconds().abs();
assert!(diff < 5, "Invalid issued_at defaults to Utc::now()");
}