Fixed 2 more bugs

This commit is contained in:
Quentin 2024-03-08 11:42:44 +01:00
parent 4d65366ff3
commit b786573e08
Signed by: quentin
GPG Key ID: E9602264D639FF68
2 changed files with 49 additions and 46 deletions

View File

@ -473,7 +473,7 @@ impl QRead<Owner> for Owner {
impl QRead<Timeout> for Timeout { impl QRead<Timeout> for Timeout {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> { async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
const SEC_PFX: &str = "SEC_PFX"; const SEC_PFX: &str = "Second-";
xml.open(DAV_URN, "timeout").await?; xml.open(DAV_URN, "timeout").await?;
let timeout = match xml.tag_string().await?.as_str() { let timeout = match xml.tag_string().await?.as_str() {
@ -492,7 +492,7 @@ impl QRead<Timeout> for Timeout {
impl QRead<LockToken> for LockToken { impl QRead<LockToken> for LockToken {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> { async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
xml.open(DAV_URN, "locktoken").await?; xml.open(DAV_URN, "locktoken").await?;
let href = Href::qread(xml).await?; let href = xml.find::<Href>().await?;
xml.close().await?; xml.close().await?;
Ok(LockToken(href)) Ok(LockToken(href))
} }
@ -501,7 +501,7 @@ impl QRead<LockToken> for LockToken {
impl QRead<LockRoot> for LockRoot { impl QRead<LockRoot> for LockRoot {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> { async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
xml.open(DAV_URN, "lockroot").await?; xml.open(DAV_URN, "lockroot").await?;
let href = Href::qread(xml).await?; let href = xml.find::<Href>().await?;
xml.close().await?; xml.close().await?;
Ok(LockRoot(href)) Ok(LockRoot(href))
} }

View File

@ -996,16 +996,15 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn rfc_propertyupdate() { async fn rfc_propertyupdate() {
let got = serialize( let orig = PropertyUpdate::<Core>(vec![
&PropertyUpdate::<Core>(vec![ PropertyUpdateItem::Set(Set(PropValue(vec![
PropertyUpdateItem::Set(Set(PropValue(vec![ Property::GetContentLanguage("fr-FR".into()),
Property::GetContentLanguage("fr-FR".into()), ]))),
]))), PropertyUpdateItem::Remove(Remove(PropName(vec![
PropertyUpdateItem::Remove(Remove(PropName(vec![ PropertyRequest::DisplayName,
PropertyRequest::DisplayName, ]))),
]))), ]);
]), let got = serialize(&orig).await;
).await;
let expected = r#"<D:propertyupdate xmlns:D="DAV:"> let expected = r#"<D:propertyupdate xmlns:D="DAV:">
<D:set> <D:set>
@ -1021,24 +1020,25 @@ mod tests {
</D:propertyupdate>"#; </D:propertyupdate>"#;
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
assert_eq!(deserialize::<PropertyUpdate::<Core>>(got.as_str()).await, orig)
} }
#[tokio::test] #[tokio::test]
async fn rfc_delete_locked2() { async fn rfc_delete_locked2() {
let got = serialize( let orig = Multistatus::<Core, PropValue<Core>> {
&Multistatus::<Core, PropValue<Core>> { responses: vec![Response {
responses: vec![Response { status_or_propstat: StatusOrPropstat::Status(
status_or_propstat: StatusOrPropstat::Status( vec![Href("http://www.example.com/container/resource3".into())],
vec![Href("http://www.example.com/container/resource3".into())], Status(http::status::StatusCode::from_u16(423).unwrap())
Status(http::status::StatusCode::from_u16(423).unwrap()) ),
), error: Some(Error(vec![Violation::LockTokenSubmitted(vec![])])),
error: Some(Error(vec![Violation::LockTokenSubmitted(vec![])])),
responsedescription: None,
location: None,
}],
responsedescription: None, responsedescription: None,
}, location: None,
).await; }],
responsedescription: None,
};
let got = serialize(&orig).await;
let expected = r#"<D:multistatus xmlns:D="DAV:"> let expected = r#"<D:multistatus xmlns:D="DAV:">
<D:response> <D:response>
@ -1051,17 +1051,18 @@ mod tests {
</D:multistatus>"#; </D:multistatus>"#;
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
assert_eq!(deserialize::<Multistatus::<Core, PropValue<Core>>>(got.as_str()).await, orig)
} }
#[tokio::test] #[tokio::test]
async fn rfc_simple_lock_request() { async fn rfc_simple_lock_request() {
let got = serialize( let orig = LockInfo {
&LockInfo { lockscope: LockScope::Exclusive,
lockscope: LockScope::Exclusive, locktype: LockType::Write,
locktype: LockType::Write, owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))),
owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), };
},
).await; let got = serialize(&orig).await;
let expected = r#"<D:lockinfo xmlns:D="DAV:"> let expected = r#"<D:lockinfo xmlns:D="DAV:">
<D:lockscope> <D:lockscope>
@ -1076,23 +1077,24 @@ mod tests {
</D:lockinfo>"#; </D:lockinfo>"#;
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
assert_eq!(deserialize::<LockInfo>(got.as_str()).await, orig)
} }
#[tokio::test] #[tokio::test]
async fn rfc_simple_lock_response() { async fn rfc_simple_lock_response() {
let got = serialize( let orig = PropValue::<Core>(vec![
&PropValue::<Core>(vec![ Property::LockDiscovery(vec![ActiveLock {
Property::LockDiscovery(vec![ActiveLock { lockscope: LockScope::Exclusive,
lockscope: LockScope::Exclusive, locktype: LockType::Write,
locktype: LockType::Write, depth: Depth::Infinity,
depth: Depth::Infinity, owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))),
owner: Some(Owner::Href(Href("http://example.org/~ejw/contact.html".into()))), timeout: Some(Timeout::Seconds(604800)),
timeout: Some(Timeout::Seconds(604800)), locktoken: Some(LockToken(Href("urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4".into()))),
locktoken: Some(LockToken(Href("urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4".into()))), lockroot: LockRoot(Href("http://example.com/workspace/webdav/proposal.doc".into())),
lockroot: LockRoot(Href("http://example.com/workspace/webdav/proposal.doc".into())), }]),
}]), ]);
]),
).await; let got = serialize(&orig).await;
let expected = r#"<D:prop xmlns:D="DAV:"> let expected = r#"<D:prop xmlns:D="DAV:">
<D:lockdiscovery> <D:lockdiscovery>
@ -1119,5 +1121,6 @@ mod tests {
</D:prop>"#; </D:prop>"#;
assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n");
assert_eq!(deserialize::<PropValue::<Core>>(got.as_str()).await, orig)
} }
} }