From f7349f40050dfb5dc4f4f49df5732686c8d846ba Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 12 Jan 2022 11:41:20 +0100 Subject: Add quotes in returned etags --- src/api/s3_copy.rs | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/api/s3_copy.rs') diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs index 7e91ecd8..f8b3550e 100644 --- a/src/api/s3_copy.rs +++ b/src/api/s3_copy.rs @@ -148,9 +148,9 @@ pub async fn handle_copy( } let last_modified = msec_to_rfc3339(new_timestamp); - let result = s3_xml::CopyObjectResult { + let result = CopyObjectResult { last_modified: s3_xml::Value(last_modified), - etag: s3_xml::Value(etag), + etag: s3_xml::Value(format!("\"{}\"", etag)), }; let xml = s3_xml::to_xml_with_header(&result)?; @@ -394,7 +394,7 @@ pub async fn handle_upload_part_copy( // LGTM let resp_xml = s3_xml::to_xml_with_header(&CopyPartResult { xmlns: (), - etag: s3_xml::Value(etag), + etag: s3_xml::Value(format!("\"{}\"", etag)), last_modified: s3_xml::Value(msec_to_rfc3339(source_object_version.timestamp)), })?; @@ -553,6 +553,14 @@ impl CopyPreconditionHeaders { } } +#[derive(Debug, Serialize, PartialEq)] +pub struct CopyObjectResult { + #[serde(rename = "LastModified")] + pub last_modified: s3_xml::Value, + #[serde(rename = "ETag")] + pub etag: s3_xml::Value, +} + #[derive(Debug, Serialize, PartialEq)] pub struct CopyPartResult { #[serde(serialize_with = "xmlns_tag")] @@ -568,15 +576,35 @@ mod tests { use super::*; use crate::s3_xml::to_xml_with_header; + #[test] + fn copy_object_result() -> Result<(), Error> { + let copy_result = CopyObjectResult { + last_modified: s3_xml::Value(msec_to_rfc3339(0)), + etag: s3_xml::Value("\"9b2cf535f27731c974343645a3985328\"".to_string()), + }; + assert_eq!( + to_xml_with_header(©_result)?, + "\ +\ + 1970-01-01T00:00:00.000Z\ + "9b2cf535f27731c974343645a3985328"\ +\ + " + ); + Ok(()) + } + #[test] fn serialize_copy_part_result() -> Result<(), Error> { - // @FIXME: ETag should be quoted, but we can't add quotes - // because XML serializer replaces them by `"` - let expected_retval = r#"2011-04-11T20:34:56.000Z9b2cf535f27731c974343645a3985328"#; + let expected_retval = "\ +\ + 2011-04-11T20:34:56.000Z\ + "9b2cf535f27731c974343645a3985328"\ +"; let v = CopyPartResult { xmlns: (), last_modified: s3_xml::Value("2011-04-11T20:34:56.000Z".into()), - etag: s3_xml::Value("9b2cf535f27731c974343645a3985328".into()), + etag: s3_xml::Value("\"9b2cf535f27731c974343645a3985328\"".into()), }; println!("{}", to_xml_with_header(&v)?); -- cgit v1.2.3