use dynamic_token::*;
#[cfg(test)]
#[test]
pub fn test_dynamic_key() {
use std::{thread, time};
let tolerance_in_millis = 200;
let hundred_millis = time::Duration::from_millis(tolerance_in_millis / 2);
let uuid = "6061f78686f34f52da3ef464";
let api_key = "Opus;Magna-897";
let options = AuthOptions::new(api_key).check_uuid(true).set_tolerance(tolerance_in_millis as u32);
let to_key = to_dynamic_key(&options, Some(uuid));
let valid_auth_token = from_dynamic_key(&to_key, &options);
assert!(valid_auth_token.valid());
assert!(valid_auth_token.age() < 1000);
assert!(valid_auth_token.has_user());
assert_eq!(valid_auth_token.uuid(), uuid.to_string());
thread::sleep(hundred_millis);
let auth_token_2 = from_dynamic_key(&to_key, &options);
assert!(auth_token_2.valid());
thread::sleep(hundred_millis);
let auth_token_3 = from_dynamic_key(&to_key, &options);
assert_eq!(auth_token_3.valid(), false);
assert_eq!(auth_token_3.status(), AuthStatus::TimedOut);
let to_key_2 = to_dynamic_key(&options, Some(uuid));
assert_ne!(to_key_2, to_key);
}
#[test]
pub fn test_control_chars() {
let api_key = "+uNiCode_δࢡබi😉▲⎈";
let control_chars = "㌀兣◐";
let options = AuthOptions::new(api_key).set_tolerance_mins(2).set_rand_char_str(control_chars);
let to_key = to_dynamic_key(&options,None);
use std::{thread, time};
let two_hundred_millis = time::Duration::from_millis(200);
thread::sleep(two_hundred_millis);
let auth_token = from_dynamic_key(&to_key, &options);
assert!(auth_token.valid());
}
#[test]
pub fn test_long_uuid() {
let api_key = "KrYpt0_δࢡබi😎☀︎⎈"; let control_chars = "∑㌀◐"; let options = AuthOptions::new(api_key).check_uuid(true).set_tolerance_mins(2).set_rand_char_str(control_chars);
let long_uuid= "acde070d-8c4c-4f0d-9d8a-162843c10333";
let to_key = to_dynamic_key(&options,Some(long_uuid));
use std::{thread, time};
let two_hundred_millis = time::Duration::from_millis(200);
thread::sleep(two_hundred_millis);
let auth_token = from_dynamic_key(&to_key, &options);
assert!(auth_token.valid());
assert_eq!(auth_token.uuid().len(), 32);
assert_eq!(auth_token.uuid(), long_uuid.replace("-", ""));
}