WebDAV COPY/MOVE tests
This commit is contained in:
@@ -15,4 +15,8 @@ rkyv = { version = "0.8.10", features = ["little_endian"] }
|
||||
calcard = { path = "/Users/me/code/calcard", features = ["serde", "rkyv"] }
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
serde_json = "1.0.138"
|
||||
chrono = { version = "0.4.40", features = ["serde"] }
|
||||
chrono = { version = "0.4.40", features = ["serde"] }
|
||||
|
||||
[features]
|
||||
test_mode = []
|
||||
enterprise = []
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"level_inf": true,
|
||||
"depth": "Infinity",
|
||||
"limit": 9
|
||||
}
|
||||
@@ -17,7 +17,7 @@ impl<'x> RequestHeaders<'x> {
|
||||
pub fn parse(&mut self, key: &str, value: &'x str) -> bool {
|
||||
hashify::fnc_map_ignore_case!(key.as_bytes(),
|
||||
"Depth" => {
|
||||
if let Some(depth) = Depth::parse(value) {
|
||||
if let Some(depth) = Depth::parse(value.as_bytes()) {
|
||||
self.depth = depth;
|
||||
return true;
|
||||
}
|
||||
@@ -292,11 +292,12 @@ pub fn dav_base_uri(uri: &str) -> Option<&str> {
|
||||
}
|
||||
|
||||
impl Depth {
|
||||
pub fn parse(value: &str) -> Option<Self> {
|
||||
hashify::tiny_map!(value.as_bytes(),
|
||||
pub fn parse(value: &[u8]) -> Option<Self> {
|
||||
hashify::tiny_map!(value,
|
||||
"0" => Depth::Zero,
|
||||
"1" => Depth::One,
|
||||
"infinity" => Depth::Infinity,
|
||||
"infinite" => Depth::Infinity,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -595,6 +596,25 @@ mod tests {
|
||||
}],
|
||||
}],
|
||||
),
|
||||
(
|
||||
r#"</test/file.txt> (["1234"]) </specs/rfc2518.doc> (Not ["4217"])"#,
|
||||
vec![
|
||||
If {
|
||||
resource: "/test/file.txt".into(),
|
||||
list: vec![Condition::ETag {
|
||||
is_not: false,
|
||||
tag: "\"1234\"",
|
||||
}],
|
||||
},
|
||||
If {
|
||||
resource: "/specs/rfc2518.doc".into(),
|
||||
list: vec![Condition::ETag {
|
||||
is_not: true,
|
||||
tag: "\"4217\"",
|
||||
}],
|
||||
},
|
||||
],
|
||||
),
|
||||
] {
|
||||
assert!(headers.parse("If", input));
|
||||
assert_eq!(headers.if_, expected, "Failed for input: {}", input);
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
},
|
||||
Attribute, Collation, Element, MatchType, NamedElement, Namespace,
|
||||
},
|
||||
Depth,
|
||||
};
|
||||
|
||||
impl DavParser for Report {
|
||||
@@ -450,7 +451,7 @@ impl DavParser for SyncCollection {
|
||||
properties: PropFind::AllProp(vec![]),
|
||||
limit: None,
|
||||
sync_token: None,
|
||||
level_inf: false,
|
||||
depth: Depth::None,
|
||||
};
|
||||
|
||||
loop {
|
||||
@@ -482,8 +483,8 @@ impl DavParser for SyncCollection {
|
||||
ns: Namespace::Dav,
|
||||
element: Element::SyncLevel,
|
||||
} => {
|
||||
if let Some(Ok(_)) = stream.parse_value::<Infinite>()? {
|
||||
sc.level_inf = true;
|
||||
if let Some(Ok(depth)) = stream.parse_value::<Depth>()? {
|
||||
sc.depth = depth;
|
||||
}
|
||||
}
|
||||
name => return Err(name.into_unexpected()),
|
||||
@@ -626,22 +627,12 @@ impl<A, B, C> Filter<A, B, C> {
|
||||
}
|
||||
}
|
||||
|
||||
struct Infinite;
|
||||
|
||||
impl XmlValueParser for Infinite {
|
||||
impl XmlValueParser for Depth {
|
||||
fn parse_bytes(bytes: &[u8]) -> Option<Self> {
|
||||
if bytes == b"infinite" {
|
||||
Some(Infinite)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Depth::parse(bytes)
|
||||
}
|
||||
|
||||
fn parse_str(text: &str) -> Option<Self> {
|
||||
if text == "infinite" {
|
||||
Some(Infinite)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Depth::parse(text.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ use calcard::{
|
||||
vcard::{VCardParameterName, VCardProperty},
|
||||
};
|
||||
|
||||
use crate::Depth;
|
||||
|
||||
use super::{
|
||||
property::{DavProperty, DavValue, LockScope, LockType, TimeRange},
|
||||
response::Ace,
|
||||
@@ -136,7 +138,7 @@ pub struct MultiGet {
|
||||
pub struct SyncCollection {
|
||||
pub sync_token: Option<String>,
|
||||
pub properties: PropFind,
|
||||
pub level_inf: bool,
|
||||
pub depth: Depth,
|
||||
pub limit: Option<u32>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user