use super::*;
use serde_json::Value;
#[test]
fn test_get_related_origin_json_with_core_with_additional() {
let rp_id = "core.example.com".to_string();
let origin = "https://core.example.com".to_string();
let additional_origins = vec![
"https://app1.core.com".to_string(),
"https://app2.core.com".to_string(),
];
let result = get_related_origin_json_with_core(rp_id, origin, additional_origins)
.expect("Failed to get related origin JSON with core");
let parsed: Value = serde_json::from_str(&result).expect("Failed to parse JSON");
assert_eq!(parsed["rp_id"], "core.example.com");
assert!(parsed["origins"].is_array());
let origins_array = parsed["origins"].as_array().unwrap();
assert_eq!(origins_array.len(), 3);
assert_eq!(origins_array[0], "https://core.example.com");
assert_eq!(origins_array[1], "https://app1.core.com");
assert_eq!(origins_array[2], "https://app2.core.com");
}
#[test]
fn test_get_related_origin_json_with_core_no_additional() {
let rp_id = "core.example.com".to_string();
let origin = "https://core.example.com".to_string();
let additional_origins: Vec<String> = vec![];
let result = get_related_origin_json_with_core(rp_id, origin, additional_origins)
.expect("Failed to get related origin JSON with core");
let parsed: Value = serde_json::from_str(&result).expect("Failed to parse JSON");
assert_eq!(parsed["rp_id"], "core.example.com");
assert!(parsed["origins"].is_array());
let origins_array = parsed["origins"].as_array().unwrap();
assert_eq!(origins_array.len(), 1);
assert_eq!(origins_array[0], "https://core.example.com");
}
#[test]
fn test_get_related_origin_json_with_core_duplicate_origins() {
let rp_id = "example.com".to_string();
let origin = "https://example.com".to_string();
let additional_origins = vec![
"https://example.com".to_string(), "https://app.example.com".to_string(),
];
let result = get_related_origin_json_with_core(rp_id, origin, additional_origins)
.expect("Failed to get related origin JSON with core");
let parsed: Value = serde_json::from_str(&result).expect("Failed to parse JSON");
assert_eq!(parsed["rp_id"], "example.com");
assert!(parsed["origins"].is_array());
let origins_array = parsed["origins"].as_array().unwrap();
assert_eq!(origins_array.len(), 3); assert_eq!(origins_array[0], "https://example.com");
assert_eq!(origins_array[1], "https://example.com"); assert_eq!(origins_array[2], "https://app.example.com");
}
#[test]
fn test_get_related_origin_json_with_core_empty_strings() {
let rp_id = "".to_string();
let origin = "".to_string();
let additional_origins: Vec<String> = vec![];
let result = get_related_origin_json_with_core(rp_id, origin, additional_origins)
.expect("Failed to get related origin JSON with empty strings");
let parsed: Value = serde_json::from_str(&result).expect("Failed to parse JSON");
assert_eq!(parsed["rp_id"], "");
assert!(parsed["origins"].is_array());
let origins_array = parsed["origins"].as_array().unwrap();
assert_eq!(origins_array.len(), 1);
assert_eq!(origins_array[0], "");
}
#[test]
fn test_get_related_origin_json_with_core_special_characters() {
let rp_id = "test-domain.com".to_string();
let origin = "https://test-domain.com:8080".to_string();
let additional_origins = vec![
"https://app.test-domain.com:3000".to_string(),
"https://api-v2.test-domain.com".to_string(),
];
let result = get_related_origin_json_with_core(rp_id, origin, additional_origins)
.expect("Failed to get related origin JSON with special characters");
let parsed: Value = serde_json::from_str(&result).expect("Failed to parse JSON");
assert_eq!(parsed["rp_id"], "test-domain.com");
assert!(parsed["origins"].is_array());
let origins_array = parsed["origins"].as_array().unwrap();
assert_eq!(origins_array.len(), 3);
assert_eq!(origins_array[0], "https://test-domain.com:8080");
assert_eq!(origins_array[1], "https://app.test-domain.com:3000");
assert_eq!(origins_array[2], "https://api-v2.test-domain.com");
}