From 8b948916e7a5aa01e913abe97a8b01a14d39a7a3 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 1 Mar 2024 18:50:06 +0100 Subject: [PATCH] simple lock tests --- src/dav/encoder.rs | 78 +++++++++++++++++++++++++++++++++++++++++++--- src/dav/types.rs | 6 ++-- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index 6bccc78..f842734 100644 --- a/src/dav/encoder.rs +++ b/src/dav/encoder.rs @@ -552,11 +552,9 @@ impl QuickWritable for Owner { let end = start.to_end(); xml.write_event_async(Event::Start(start.clone())).await?; - if let Some(txt) = &self.txt { - xml.write_event_async(Event::Text(BytesText::new(&txt))).await?; - } - if let Some(href) = &self.url { - href.write(xml, ctx.child()).await?; + match self { + Self::Txt(txt) => xml.write_event_async(Event::Text(BytesText::new(&txt))).await?, + Self::Href(href) => href.write(xml, ctx.child()).await?, } xml.write_event_async(Event::End(end)).await } @@ -1094,4 +1092,74 @@ mod tests { assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); } + + #[tokio::test] + async fn rfc_simple_lock_request() { + let got = serialize( + NoExtension { root: true }, + &LockInfo { + lockscope: LockScope::Exclusive, + locktype: LockType::Write, + owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), + }, + ).await; + + let expected = r#" + + + + + + + + http://example.org/~ejw/contact.html + +"#; + + assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + } + + #[tokio::test] + async fn rfc_simple_lock_response() { + let got = serialize( + NoExtension { root: true }, + &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 expected = r#" + + + + + + + + + infinity + + http://example.org/~ejw/contact.html + + Second-604800 + + urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4 + + + http://example.com/workspace/webdav/proposal.doc + + + +"#; + + assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); + } } diff --git a/src/dav/types.rs b/src/dav/types.rs index 4487de7..ffb08d4 100644 --- a/src/dav/types.rs +++ b/src/dav/types.rs @@ -353,9 +353,9 @@ pub struct Multistatus { /// /// //@FIXME might need support for an extension -pub struct Owner { - pub txt: Option, - pub url: Option, +pub enum Owner { + Txt(String), + Href(Href), } /// 14.18. prop XML Element