use super::*;
#[test]
fn issuer_join_never_doubles_the_slash() {
assert_eq!(
under_issuer("https://as.example.com/", "/token"),
"https://as.example.com/token"
);
assert_eq!(
under_issuer("https://as.example.com", "/token"),
"https://as.example.com/token"
);
}
#[test]
fn the_well_known_path_follows_rfc_8414_section_3_1() {
assert_eq!(
well_known_path("https://as.example"),
"/.well-known/oauth-authorization-server"
);
assert_eq!(
well_known_path("https://as.example/"),
"/.well-known/oauth-authorization-server"
);
assert_eq!(
well_known_path("https://as.example/tenant1"),
"/.well-known/oauth-authorization-server/tenant1"
);
assert_eq!(
well_known_path("https://as.example/tenant1/"),
"/.well-known/oauth-authorization-server/tenant1"
);
assert_eq!(
well_known_path("https://as.example:8443/a/b"),
"/.well-known/oauth-authorization-server/a/b"
);
}
#[test]
fn the_issuer_path_is_only_what_follows_the_authority() {
assert_eq!(issuer_path("https://as.example"), "");
assert_eq!(issuer_path("https://as.example:8443"), "");
assert_eq!(issuer_path("https://as.example:8443/tenant1"), "/tenant1");
assert_eq!(issuer_path("as.example/tenant1"), "/tenant1");
assert_eq!(issuer_path("https://a.io/tenant"), "/tenant");
assert_eq!(issuer_path("http://a.io/t"), "/t");
assert_eq!(issuer_path("https://a.io"), "");
}
#[cfg(feature = "jwt-p256")]
#[test]
fn jwks_uri_is_advertised_exactly_when_the_server_signs() {
use crate::jwt::{AccessTokenFormat, EcdsaP256Key, JwtConfig};
let mut config = ServerConfig::new("https://as.example", "https://as.example/device");
config.jwks_uri = Some("https://as.example/jwks".to_string());
assert_eq!(
AuthorizationServerMetadata::from_config(&config).jwks_uri,
None
);
config.jwks_uri = None;
config.access_token_format = AccessTokenFormat::Jwt(Box::new(
JwtConfig::new(EcdsaP256Key::generate("k1"), "https://rs.example")
.with_jwks_uri("https://as.example/jwks"),
));
assert_eq!(
AuthorizationServerMetadata::from_config(&config).jwks_uri,
Some("https://as.example/jwks".to_string())
);
config.access_token_format = AccessTokenFormat::Jwt(Box::new(JwtConfig::new(
EcdsaP256Key::generate("k1"),
"https://rs.example",
)));
assert_eq!(
AuthorizationServerMetadata::from_config(&config).jwks_uri,
None
);
}
#[cfg(not(feature = "jwt"))]
#[test]
fn without_the_jwt_feature_jwks_uri_is_whatever_the_host_declared() {
let mut config = ServerConfig::new("https://as.example", "https://as.example/device");
assert_eq!(
AuthorizationServerMetadata::from_config(&config).jwks_uri,
None
);
config.jwks_uri = Some("https://keys.example/jwks".to_string());
assert_eq!(
AuthorizationServerMetadata::from_config(&config).jwks_uri,
Some("https://keys.example/jwks".to_string())
);
}
#[cfg(feature = "client-assertion")]
#[test]
fn announcing_es256_verification_adds_what_the_document_was_missing() {
let cfg = ServerConfig::new("https://as.example", "https://as.example/device");
let mut doc = AuthorizationServerMetadata::from_config(&cfg);
doc.token_endpoint_auth_methods_supported
.retain(|m| m != "private_key_jwt");
doc.token_endpoint_auth_signing_alg_values_supported = None;
doc.es256_verification_is_available();
assert!(
doc.token_endpoint_auth_methods_supported
.iter()
.any(|m| m == "private_key_jwt"),
"a deployment whose host installed an ES256 verifier must advertise private_key_jwt, or an \
RFC 7523 client reading the document concludes it cannot authenticate that way: {:?}",
doc.token_endpoint_auth_methods_supported
);
assert!(
doc.token_endpoint_auth_signing_alg_values_supported
.as_ref()
.is_some_and(|algs| algs.iter().any(|a| a == "ES256")),
"and it must name ES256 among the algorithms it accepts"
);
doc.es256_verification_is_available();
assert_eq!(
doc.token_endpoint_auth_methods_supported
.iter()
.filter(|m| *m == "private_key_jwt")
.count(),
1,
"calling it twice must not duplicate the entry"
);
}