Skip to content

Commit

Permalink
add list response
Browse files Browse the repository at this point in the history
  • Loading branch information
imWildCat committed Feb 12, 2023
1 parent 5a117e2 commit a3f9b67
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
133 changes: 133 additions & 0 deletions src/services/webdav/list_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
use serde::Deserialize;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Multistatus {
response: Vec<ListOpResponse>,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct ListOpResponse {
href: String,
propstat: Propstat,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Propstat {
prop: Prop,
status: String,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct Prop {
displayname: String,
getlastmodified: String,
resourcetype: ResourceType,
lockdiscovery: (),
supportedlock: SupportedLock,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
#[derive(PartialEq)]
enum ResourceType {
Collection,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct SupportedLock {
lockentry: LockEntry,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct LockEntry {
lockscope: LockScope,
locktype: LockType,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
#[derive(PartialEq)]
enum LockScope {
Exclusive,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
#[derive(PartialEq)]
enum LockType {
Write,
}

#[cfg(test)]
mod tests {
use super::*;
use quick_xml::de::from_str;

#[test]
fn test_lockentry() {
let xml = r#"<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>"#;

let lockentry = from_str::<LockEntry>(xml).unwrap();
assert_eq!(lockentry.lockscope, LockScope::Exclusive);
assert_eq!(lockentry.locktype, LockType::Write);
}

#[test]
fn test_supportedlock() {
let xml = r#"<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>"#;

let supportedlock = from_str::<SupportedLock>(xml).unwrap();
assert_eq!(supportedlock.lockentry.lockscope, LockScope::Exclusive);
assert_eq!(supportedlock.lockentry.locktype, LockType::Write);
}

#[test]
fn test_propstat() {
let xml = r#"<D:propstat>
<D:prop>
<D:displayname>/</D:displayname>
<D:getlastmodified>Tue, 07 Feb 2023 06:39:47 GMT</D:getlastmodified>
<D:resourcetype><D:collection/></D:resourcetype>
<D:lockdiscovery/>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>"#;

let propstat = from_str::<Propstat>(xml).unwrap();
assert_eq!(propstat.prop.displayname, "/");
assert_eq!(
propstat.prop.getlastmodified,
"Tue, 07 Feb 2023 06:39:47 GMT"
);
assert_eq!(propstat.prop.resourcetype, ResourceType::Collection);
assert_eq!(
propstat.prop.supportedlock.lockentry.lockscope,
LockScope::Exclusive
);
assert_eq!(
propstat.prop.supportedlock.lockentry.locktype,
LockType::Write
);
assert_eq!(propstat.status, "HTTP/1.1 200 OK");
}
}
1 change: 1 addition & 0 deletions src/services/webdav/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ mod backend;
pub use backend::WebdavBuilder as Webdav;

mod error;
mod list_response;

0 comments on commit a3f9b67

Please sign in to comment.