use super::*;
#[test]
fn the_well_known_path_follows_rfc_9728_section_3_1() {
assert_eq!(
well_known_path("https://rs.example"),
"/.well-known/oauth-protected-resource"
);
assert_eq!(
well_known_path("https://rs.example/"),
"/.well-known/oauth-protected-resource"
);
assert_eq!(
well_known_path("https://rs.example/api"),
"/.well-known/oauth-protected-resource/api"
);
assert_eq!(
well_known_path("https://rs.example/api/"),
"/.well-known/oauth-protected-resource/api"
);
assert_eq!(
well_known_path("https://rs.example/api/v2"),
"/.well-known/oauth-protected-resource/api/v2"
);
}
#[test]
fn a_query_component_survives_the_insertion() {
assert_eq!(
well_known_path("https://rs.example/api?tenant=1"),
"/.well-known/oauth-protected-resource/api?tenant=1"
);
assert_eq!(
well_known_path("https://rs.example?tenant=1"),
"/.well-known/oauth-protected-resource?tenant=1"
);
assert_eq!(
well_known_path("https://rs.example/?tenant=1"),
"/.well-known/oauth-protected-resource?tenant=1"
);
}
#[test]
fn the_path_rule_is_the_same_one_the_as_document_uses() {
for identifier in [
"https://x.example",
"https://x.example/",
"https://x.example/tenant1",
"https://x.example/tenant1/",
"https://x.example/a/b/c",
] {
assert_eq!(
resource_path(identifier),
crate::metadata::issuer_path(identifier),
"the two documents must place {identifier} the same way"
);
}
}
#[test]
fn an_empty_list_becomes_an_omitted_member_rather_than_an_empty_array() {
assert_eq!(some_unless_empty(Vec::<String>::new()), None);
assert_eq!(
some_unless_empty(vec!["a".to_string()]),
Some(vec!["a".to_string()])
);
}
#[test]
fn the_well_known_path_is_built_in_one_exactly_sized_allocation() {
for resource in [
"https://rs.example",
"https://rs.example/api",
"https://rs.example/api/v2",
"https://rs.example/?tenant=1",
] {
let path = well_known_path(resource);
let exact = PROTECTED_RESOURCE_WELL_KNOWN_PATH.len() + resource_path(resource).len();
assert_eq!(path.len(), exact, "{resource}");
assert_eq!(
path.capacity(),
exact,
"the hint for {resource} must be exactly the suffix plus the resource path"
);
}
}