Lines
100 %
Functions
Branches
use super::parse_json_error;
#[test]
fn status_and_message_are_escaped() {
let html = parse_json_error(
r#"{"status":"<b>fail</b>","message":"<img src=x onerror='alert(1)'> & \"q\""}"#,
);
assert_eq!(
html,
concat!(
r#"<div class="error-alert"><b>fail</b>: "#,
"<img src=x onerror='alert(1)'> & "q"</div>"
)
}
fn missing_fields_use_defaults() {
parse_json_error("{}"),
r#"<div class="error-alert">An error occurred: </div>"#
fn invalid_json_is_reported_as_unparseable() {
assert_eq!(parse_json_error("<html>"), "Unparseable response received");
fn json_error_is_parsed() {
super::safe_error_body("application/json", "{}"),
Some(r#"<div class="error-alert">An error occurred: </div>"#.to_string())
fn html_error_is_left_as_is() {
super::safe_error_body("text/html; charset=utf-8", "<div>x</div>"),
None
fn plain_text_error_is_escaped() {
super::safe_error_body("text/plain", "<img src=x onerror=alert(1)>"),
Some(r#"<div class="error-alert"><img src=x onerror=alert(1)></div>"#.to_string())
fn missing_content_type_is_escaped() {
super::safe_error_body("", "<b>"),
Some(r#"<div class="error-alert"><b></div>"#.to_string())