From b786573e08c78b672880cd212db45fc58ab82c4c Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 8 Mar 2024 11:42:44 +0100 Subject: Fixed 2 more bugs --- aero-dav/src/decoder.rs | 6 ++-- aero-dav/src/encoder.rs | 89 +++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 46 deletions(-) (limited to 'aero-dav') diff --git a/aero-dav/src/decoder.rs b/aero-dav/src/decoder.rs index 28442a6..766d19c 100644 --- a/aero-dav/src/decoder.rs +++ b/aero-dav/src/decoder.rs @@ -473,7 +473,7 @@ impl QRead for Owner { impl QRead for Timeout { async fn qread(xml: &mut Reader) -> Result { - const SEC_PFX: &str = "SEC_PFX"; + const SEC_PFX: &str = "Second-"; xml.open(DAV_URN, "timeout").await?; let timeout = match xml.tag_string().await?.as_str() { @@ -492,7 +492,7 @@ impl QRead for Timeout { impl QRead for LockToken { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "locktoken").await?; - let href = Href::qread(xml).await?; + let href = xml.find::().await?; xml.close().await?; Ok(LockToken(href)) } @@ -501,7 +501,7 @@ impl QRead for LockToken { impl QRead for LockRoot { async fn qread(xml: &mut Reader) -> Result { xml.open(DAV_URN, "lockroot").await?; - let href = Href::qread(xml).await?; + let href = xml.find::().await?; xml.close().await?; Ok(LockRoot(href)) } diff --git a/aero-dav/src/encoder.rs b/aero-dav/src/encoder.rs index 813efe6..3b0bfda 100644 --- a/aero-dav/src/encoder.rs +++ b/aero-dav/src/encoder.rs @@ -996,16 +996,15 @@ mod tests { #[tokio::test] async fn rfc_propertyupdate() { - let got = serialize( - &PropertyUpdate::(vec![ - PropertyUpdateItem::Set(Set(PropValue(vec![ - Property::GetContentLanguage("fr-FR".into()), - ]))), - PropertyUpdateItem::Remove(Remove(PropName(vec![ - PropertyRequest::DisplayName, - ]))), - ]), - ).await; + let orig = PropertyUpdate::(vec![ + PropertyUpdateItem::Set(Set(PropValue(vec![ + Property::GetContentLanguage("fr-FR".into()), + ]))), + PropertyUpdateItem::Remove(Remove(PropName(vec![ + PropertyRequest::DisplayName, + ]))), + ]); + let got = serialize(&orig).await; let expected = r#" @@ -1021,24 +1020,25 @@ mod tests { "#; assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + assert_eq!(deserialize::>(got.as_str()).await, orig) } #[tokio::test] async fn rfc_delete_locked2() { - let got = serialize( - &Multistatus::> { - responses: vec![Response { - status_or_propstat: StatusOrPropstat::Status( - vec![Href("http://www.example.com/container/resource3".into())], - Status(http::status::StatusCode::from_u16(423).unwrap()) - ), - error: Some(Error(vec![Violation::LockTokenSubmitted(vec![])])), - responsedescription: None, - location: None, - }], + let orig = Multistatus::> { + responses: vec![Response { + status_or_propstat: StatusOrPropstat::Status( + vec![Href("http://www.example.com/container/resource3".into())], + Status(http::status::StatusCode::from_u16(423).unwrap()) + ), + error: Some(Error(vec![Violation::LockTokenSubmitted(vec![])])), responsedescription: None, - }, - ).await; + location: None, + }], + responsedescription: None, + }; + + let got = serialize(&orig).await; let expected = r#" @@ -1051,17 +1051,18 @@ mod tests { "#; assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + assert_eq!(deserialize::>>(got.as_str()).await, orig) } #[tokio::test] async fn rfc_simple_lock_request() { - let got = serialize( - &LockInfo { - lockscope: LockScope::Exclusive, - locktype: LockType::Write, - owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), - }, - ).await; + let orig = LockInfo { + lockscope: LockScope::Exclusive, + locktype: LockType::Write, + owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), + }; + + let got = serialize(&orig).await; let expected = r#" @@ -1076,23 +1077,24 @@ mod tests { "#; assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + assert_eq!(deserialize::(got.as_str()).await, orig) } #[tokio::test] async fn rfc_simple_lock_response() { - let got = serialize( - &PropValue::(vec![ - Property::LockDiscovery(vec![ActiveLock { - lockscope: LockScope::Exclusive, - locktype: LockType::Write, - depth: Depth::Infinity, - owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), - timeout: Some(Timeout::Seconds(604800)), - locktoken: Some(LockToken(Href("urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4".into()))), - lockroot: LockRoot(Href("http://example.com/workspace/webdav/proposal.doc".into())), - }]), - ]), - ).await; + let orig = PropValue::(vec![ + Property::LockDiscovery(vec![ActiveLock { + lockscope: LockScope::Exclusive, + locktype: LockType::Write, + depth: Depth::Infinity, + owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), + timeout: Some(Timeout::Seconds(604800)), + locktoken: Some(LockToken(Href("urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4".into()))), + lockroot: LockRoot(Href("http://example.com/workspace/webdav/proposal.doc".into())), + }]), + ]); + + let got = serialize(&orig).await; let expected = r#" @@ -1119,5 +1121,6 @@ mod tests { "#; assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + assert_eq!(deserialize::>(got.as_str()).await, orig) } } -- cgit v1.2.3