Add quotes in returned etags
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex 2022-01-12 11:41:20 +01:00
parent 1ee8f596ee
commit f7349f4005
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1
4 changed files with 45 additions and 53 deletions

View file

@ -148,9 +148,9 @@ pub async fn handle_copy(
} }
let last_modified = msec_to_rfc3339(new_timestamp); let last_modified = msec_to_rfc3339(new_timestamp);
let result = s3_xml::CopyObjectResult { let result = CopyObjectResult {
last_modified: s3_xml::Value(last_modified), 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)?; let xml = s3_xml::to_xml_with_header(&result)?;
@ -394,7 +394,7 @@ pub async fn handle_upload_part_copy(
// LGTM // LGTM
let resp_xml = s3_xml::to_xml_with_header(&CopyPartResult { let resp_xml = s3_xml::to_xml_with_header(&CopyPartResult {
xmlns: (), xmlns: (),
etag: s3_xml::Value(etag), etag: s3_xml::Value(format!("\"{}\"", etag)),
last_modified: s3_xml::Value(msec_to_rfc3339(source_object_version.timestamp)), 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)] #[derive(Debug, Serialize, PartialEq)]
pub struct CopyPartResult { pub struct CopyPartResult {
#[serde(serialize_with = "xmlns_tag")] #[serde(serialize_with = "xmlns_tag")]
@ -568,15 +576,35 @@ mod tests {
use super::*; use super::*;
use crate::s3_xml::to_xml_with_header; 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(&copy_result)?,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<CopyObjectResult>\
<LastModified>1970-01-01T00:00:00.000Z</LastModified>\
<ETag>&quot;9b2cf535f27731c974343645a3985328&quot;</ETag>\
</CopyObjectResult>\
"
);
Ok(())
}
#[test] #[test]
fn serialize_copy_part_result() -> Result<(), Error> { fn serialize_copy_part_result() -> Result<(), Error> {
// @FIXME: ETag should be quoted, but we can't add quotes let expected_retval = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
// because XML serializer replaces them by `&quot;` <CopyPartResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\
let expected_retval = r#"<?xml version="1.0" encoding="UTF-8"?><CopyPartResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LastModified>2011-04-11T20:34:56.000Z</LastModified><ETag>9b2cf535f27731c974343645a3985328</ETag></CopyPartResult>"#; <LastModified>2011-04-11T20:34:56.000Z</LastModified>\
<ETag>&quot;9b2cf535f27731c974343645a3985328&quot;</ETag>\
</CopyPartResult>";
let v = CopyPartResult { let v = CopyPartResult {
xmlns: (), xmlns: (),
last_modified: s3_xml::Value("2011-04-11T20:34:56.000Z".into()), 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)?); println!("{}", to_xml_with_header(&v)?);

View file

@ -121,7 +121,7 @@ pub async fn handle_list(
key: uriencode_maybe(key, query.common.urlencode_resp), key: uriencode_maybe(key, query.common.urlencode_resp),
last_modified: s3_xml::Value(msec_to_rfc3339(info.last_modified)), last_modified: s3_xml::Value(msec_to_rfc3339(info.last_modified)),
size: s3_xml::IntValue(info.size as i64), size: s3_xml::IntValue(info.size as i64),
etag: s3_xml::Value(info.etag.to_string()), etag: s3_xml::Value(format!("\"{}\"", info.etag.to_string())),
storage_class: s3_xml::Value("STANDARD".to_string()), storage_class: s3_xml::Value("STANDARD".to_string()),
}) })
.collect(), .collect(),

View file

@ -532,7 +532,7 @@ pub async fn handle_complete_multipart_upload(
location: None, location: None,
bucket: s3_xml::Value(bucket_name.to_string()), bucket: s3_xml::Value(bucket_name.to_string()),
key: s3_xml::Value(key), key: s3_xml::Value(key),
etag: s3_xml::Value(etag), etag: s3_xml::Value(format!("\"{}\"", etag)),
}; };
let xml = s3_xml::to_xml_with_header(&result)?; let xml = s3_xml::to_xml_with_header(&result)?;

View file

@ -107,14 +107,6 @@ pub struct DeleteResult {
pub errors: Vec<DeleteError>, pub errors: Vec<DeleteError>,
} }
#[derive(Debug, Serialize, PartialEq)]
pub struct CopyObjectResult {
#[serde(rename = "LastModified")]
pub last_modified: Value,
#[serde(rename = "ETag")]
pub etag: Value,
}
#[derive(Debug, Serialize, PartialEq)] #[derive(Debug, Serialize, PartialEq)]
pub struct InitiateMultipartUploadResult { pub struct InitiateMultipartUploadResult {
#[serde(serialize_with = "xmlns_tag")] #[serde(serialize_with = "xmlns_tag")]
@ -426,26 +418,6 @@ mod tests {
Ok(()) Ok(())
} }
#[test]
fn copy_object_result() -> Result<(), ApiError> {
// @FIXME: ETag should be quoted, but we can't add quotes
// because XML serializer replaces them by `&quot;`
let copy_result = CopyObjectResult {
last_modified: Value(msec_to_rfc3339(0)),
etag: Value("9b2cf535f27731c974343645a3985328".to_string()),
};
assert_eq!(
to_xml_with_header(&copy_result)?,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<CopyObjectResult>\
<LastModified>1970-01-01T00:00:00.000Z</LastModified>\
<ETag>9b2cf535f27731c974343645a3985328</ETag>\
</CopyObjectResult>\
"
);
Ok(())
}
#[test] #[test]
fn initiate_multipart_upload_result() -> Result<(), ApiError> { fn initiate_multipart_upload_result() -> Result<(), ApiError> {
let result = InitiateMultipartUploadResult { let result = InitiateMultipartUploadResult {
@ -468,14 +440,12 @@ mod tests {
#[test] #[test]
fn complete_multipart_upload_result() -> Result<(), ApiError> { fn complete_multipart_upload_result() -> Result<(), ApiError> {
// @FIXME: ETag should be quoted, but we can't add quotes
// because XML serializer replaces them by `&quot;`
let result = CompleteMultipartUploadResult { let result = CompleteMultipartUploadResult {
xmlns: (), xmlns: (),
location: Some(Value("https://garage.tld/mybucket/a/plop".to_string())), location: Some(Value("https://garage.tld/mybucket/a/plop".to_string())),
bucket: Value("mybucket".to_string()), bucket: Value("mybucket".to_string()),
key: Value("a/plop".to_string()), key: Value("a/plop".to_string()),
etag: Value("3858f62230ac3c915f300c664312c11f-9".to_string()), etag: Value("\"3858f62230ac3c915f300c664312c11f-9\"".to_string()),
}; };
assert_eq!( assert_eq!(
to_xml_with_header(&result)?, to_xml_with_header(&result)?,
@ -484,7 +454,7 @@ mod tests {
<Location>https://garage.tld/mybucket/a/plop</Location>\ <Location>https://garage.tld/mybucket/a/plop</Location>\
<Bucket>mybucket</Bucket>\ <Bucket>mybucket</Bucket>\
<Key>a/plop</Key>\ <Key>a/plop</Key>\
<ETag>3858f62230ac3c915f300c664312c11f-9</ETag>\ <ETag>&quot;3858f62230ac3c915f300c664312c11f-9&quot;</ETag>\
</CompleteMultipartUploadResult>" </CompleteMultipartUploadResult>"
); );
Ok(()) Ok(())
@ -544,8 +514,6 @@ mod tests {
#[test] #[test]
fn list_objects_v1_1() -> Result<(), ApiError> { fn list_objects_v1_1() -> Result<(), ApiError> {
// @FIXME: ETag should be quoted, but we can't add quotes
// because XML serializer replaces them by `&quot;`
let result = ListBucketResult { let result = ListBucketResult {
xmlns: (), xmlns: (),
name: Value("example-bucket".to_string()), name: Value("example-bucket".to_string()),
@ -563,7 +531,7 @@ mod tests {
contents: vec![ListBucketItem { contents: vec![ListBucketItem {
key: Value("sample.jpg".to_string()), key: Value("sample.jpg".to_string()),
last_modified: Value(msec_to_rfc3339(0)), last_modified: Value(msec_to_rfc3339(0)),
etag: Value("bf1d737a4d46a19f3bced6905cc8b902".to_string()), etag: Value("\"bf1d737a4d46a19f3bced6905cc8b902\"".to_string()),
size: IntValue(142863), size: IntValue(142863),
storage_class: Value("STANDARD".to_string()), storage_class: Value("STANDARD".to_string()),
}], }],
@ -584,7 +552,7 @@ mod tests {
<Contents>\ <Contents>\
<Key>sample.jpg</Key>\ <Key>sample.jpg</Key>\
<LastModified>1970-01-01T00:00:00.000Z</LastModified>\ <LastModified>1970-01-01T00:00:00.000Z</LastModified>\
<ETag>bf1d737a4d46a19f3bced6905cc8b902</ETag>\ <ETag>&quot;bf1d737a4d46a19f3bced6905cc8b902&quot;</ETag>\
<Size>142863</Size>\ <Size>142863</Size>\
<StorageClass>STANDARD</StorageClass>\ <StorageClass>STANDARD</StorageClass>\
</Contents>\ </Contents>\
@ -645,8 +613,6 @@ mod tests {
#[test] #[test]
fn list_objects_v2_1() -> Result<(), ApiError> { fn list_objects_v2_1() -> Result<(), ApiError> {
// @FIXME: ETag should be quoted, but we can't add quotes
// because XML serializer replaces them by `&quot;`
let result = ListBucketResult { let result = ListBucketResult {
xmlns: (), xmlns: (),
name: Value("quotes".to_string()), name: Value("quotes".to_string()),
@ -664,7 +630,7 @@ mod tests {
contents: vec![ListBucketItem { contents: vec![ListBucketItem {
key: Value("ExampleObject.txt".to_string()), key: Value("ExampleObject.txt".to_string()),
last_modified: Value(msec_to_rfc3339(0)), last_modified: Value(msec_to_rfc3339(0)),
etag: Value("599bab3ed2c697f1d26842727561fd94".to_string()), etag: Value("\"599bab3ed2c697f1d26842727561fd94\"".to_string()),
size: IntValue(857), size: IntValue(857),
storage_class: Value("REDUCED_REDUNDANCY".to_string()), storage_class: Value("REDUCED_REDUNDANCY".to_string()),
}], }],
@ -682,7 +648,7 @@ mod tests {
<Contents>\ <Contents>\
<Key>ExampleObject.txt</Key>\ <Key>ExampleObject.txt</Key>\
<LastModified>1970-01-01T00:00:00.000Z</LastModified>\ <LastModified>1970-01-01T00:00:00.000Z</LastModified>\
<ETag>599bab3ed2c697f1d26842727561fd94</ETag>\ <ETag>&quot;599bab3ed2c697f1d26842727561fd94&quot;</ETag>\
<Size>857</Size>\ <Size>857</Size>\
<StorageClass>REDUCED_REDUNDANCY</StorageClass>\ <StorageClass>REDUCED_REDUNDANCY</StorageClass>\
</Contents>\ </Contents>\
@ -693,8 +659,6 @@ mod tests {
#[test] #[test]
fn list_objects_v2_2() -> Result<(), ApiError> { fn list_objects_v2_2() -> Result<(), ApiError> {
// @FIXME: ETag should be quoted, but we can't add quotes
// because XML serializer replaces them by `&quot;`
let result = ListBucketResult { let result = ListBucketResult {
xmlns: (), xmlns: (),
name: Value("bucket".to_string()), name: Value("bucket".to_string()),
@ -714,7 +678,7 @@ mod tests {
contents: vec![ListBucketItem { contents: vec![ListBucketItem {
key: Value("happyfacex.jpg".to_string()), key: Value("happyfacex.jpg".to_string()),
last_modified: Value(msec_to_rfc3339(0)), last_modified: Value(msec_to_rfc3339(0)),
etag: Value("70ee1738b6b21e2c8a43f3a5ab0eee71".to_string()), etag: Value("\"70ee1738b6b21e2c8a43f3a5ab0eee71\"".to_string()),
size: IntValue(1111), size: IntValue(1111),
storage_class: Value("STANDARD".to_string()), storage_class: Value("STANDARD".to_string()),
}], }],
@ -734,7 +698,7 @@ mod tests {
<Contents>\ <Contents>\
<Key>happyfacex.jpg</Key>\ <Key>happyfacex.jpg</Key>\
<LastModified>1970-01-01T00:00:00.000Z</LastModified>\ <LastModified>1970-01-01T00:00:00.000Z</LastModified>\
<ETag>70ee1738b6b21e2c8a43f3a5ab0eee71</ETag>\ <ETag>&quot;70ee1738b6b21e2c8a43f3a5ab0eee71&quot;</ETag>\
<Size>1111</Size>\ <Size>1111</Size>\
<StorageClass>STANDARD</StorageClass>\ <StorageClass>STANDARD</StorageClass>\
</Contents>\ </Contents>\