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())
);
}