mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-07-26 07:58:14 +00:00
Fix: correctly parse CORS website configuration with no rules (#1392)
This is a port of #1320 on top of the main-v2 branch. Co-authored-by: Armaël Guéneau <armael.gueneau@ens-lyon.org> Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1392 Co-authored-by: Armael <armael@noreply.localhost> Co-committed-by: Armael <armael@noreply.localhost>
This commit is contained in:
@@ -13,7 +13,9 @@ use crate::common_error::{CommonError as Error, OkOrBadRequest};
|
||||
pub struct CorsConfiguration {
|
||||
#[serde(rename = "@xmlns", serialize_with = "xmlns_tag", skip_deserializing)]
|
||||
pub xmlns: (),
|
||||
#[serde(rename = "CORSRule")]
|
||||
// "default" is required to be able to parse an empty list of rules,
|
||||
// cf https://docs.rs/quick-xml/latest/quick_xml/de/#sequences-xsall-and-xssequence-xml-schema-types
|
||||
#[serde(rename = "CORSRule", default)]
|
||||
pub cors_rules: Vec<CorsRule>,
|
||||
}
|
||||
|
||||
@@ -199,4 +201,22 @@ mod tests {
|
||||
|
||||
assert_eq!(unprettify_xml(message), unprettify_xml(&message2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_norules() {
|
||||
let message = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></CORSConfiguration>"#;
|
||||
let conf: CorsConfiguration = from_str(message).unwrap();
|
||||
let ref_value = CorsConfiguration {
|
||||
xmlns: (),
|
||||
cors_rules: vec![],
|
||||
};
|
||||
assert_eq! {
|
||||
ref_value,
|
||||
conf
|
||||
};
|
||||
|
||||
let message2 = to_xml_with_header(&ref_value).expect("xml serialization");
|
||||
assert_eq!(unprettify_xml(&message), unprettify_xml(&message2));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user