use openidauthzen::Error;
#[test]
fn http_status_error_should_display_status_and_body() {
let err = Error::HttpStatus {
status: 403,
body: "Forbidden".to_owned(),
};
let msg = err.to_string();
assert!(msg.contains("403"));
assert!(msg.contains("Forbidden"));
}
#[test]
fn invalid_pdp_url_error_should_display_reason() {
let err = Error::InvalidPdpUrl("scheme must be https, got http".to_owned());
let msg = err.to_string();
assert!(msg.contains("scheme must be https"));
}
#[test]
fn pdp_mismatch_error_should_display_expected_and_got() {
let err = Error::PdpMismatch {
expected: "https://pdp.example.com".to_owned(),
got: "https://other.example.com".to_owned(),
};
let msg = err.to_string();
assert!(msg.contains("https://pdp.example.com"));
assert!(msg.contains("https://other.example.com"));
}
#[test]
fn not_cached_error_should_display_pdp_id() {
let err = Error::NotCached("https://pdp.example.com".to_owned());
let msg = err.to_string();
assert!(msg.contains("https://pdp.example.com"));
}
#[test]
fn invalid_response_error_should_display_serde_message() {
let serde_err = serde_json::from_str::<serde_json::Value>("invalid json").unwrap_err();
let err = Error::InvalidResponse(serde_err);
let msg = err.to_string();
assert!(msg.contains("invalid"));
}
#[test]
fn serialization_error_should_display_serde_message() {
let serde_err = serde_json::from_str::<serde_json::Value>("{bad}").unwrap_err();
let err = Error::Serialization(serde_err);
let msg = err.to_string();
assert!(msg.contains("serialization"));
}