From 1aafd752ca00ddda5340aacfb0ed291b803845da Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 5 Mar 2024 18:15:03 +0100 Subject: Re-enable cal encoder tests --- src/dav/caldecoder.rs | 33 +++++++++++++++++++++++++++++++++ src/dav/calencoder.rs | 24 +++++++++++++----------- src/dav/caltypes.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- src/dav/mod.rs | 17 ++++++++++++++--- src/dav/realization.rs | 7 +++---- 5 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 src/dav/caldecoder.rs diff --git a/src/dav/caldecoder.rs b/src/dav/caldecoder.rs new file mode 100644 index 0000000..75af4b7 --- /dev/null +++ b/src/dav/caldecoder.rs @@ -0,0 +1,33 @@ +use super::types as dav; +use super::caltypes::*; +use super::xml; +use super::error; + +// ---- ROOT ELEMENTS --- + +// ---- EXTENSIONS --- +impl xml::QRead for Violation { + async fn qread(&self, xml: &mut xml::Reader) -> Result, error::ParsingError> { + unreachable!(); + } +} + +impl xml::QRead for Property { + async fn qread(&self, xml: &mut xml::Reader) -> Result, error::ParsingError> { + unreachable!(); + } +} + +impl xml::QRead for PropertyRequest { + async fn qread(&self, xml: &mut xml::Reader) -> Result, error::ParsingError> { + unreachable!(); + } +} + +impl xml::QRead for ResourceType { + async fn qread(&self, xml: &mut xml::Reader) -> Result, error::ParsingError> { + unreachable!(); + } +} + +// ---- INNER XML ---- diff --git a/src/dav/calencoder.rs b/src/dav/calencoder.rs index 01cecc3..d030aa1 100644 --- a/src/dav/calencoder.rs +++ b/src/dav/calencoder.rs @@ -662,19 +662,25 @@ impl QWrite for TimeRange { } } -/* #[cfg(test)] mod tests { use super::*; use crate::dav::types as dav; + use crate::dav::realization::Calendar; use tokio::io::AsyncWriteExt; use chrono::{Utc,TimeZone,DateTime}; - async fn serialize>(ctx: C, elem: &Q) -> String { + async fn serialize(elem: &impl QWrite) -> String { let mut buffer = Vec::new(); let mut tokio_buffer = tokio::io::BufWriter::new(&mut buffer); - let mut writer = Writer::new_with_indent(&mut tokio_buffer, b' ', 4); - elem.write(&mut writer, ctx).await.expect("xml serialization"); + let q = quick_xml::writer::Writer::new_with_indent(&mut tokio_buffer, b' ', 4); + let ns_to_apply = vec![ + ("xmlns:D".into(), "DAV:".into()), + ("xmlns:C".into(), "urn:ietf:params:xml:ns:caldav".into()), + ]; + let mut writer = Writer { q, ns_to_apply }; + + elem.qwrite(&mut writer).await.expect("xml serialization"); tokio_buffer.flush().await.expect("tokio buffer flush"); let got = std::str::from_utf8(buffer.as_slice()).unwrap(); @@ -684,8 +690,7 @@ mod tests { #[tokio::test] async fn basic_violation() { let got = serialize( - CalExtension { root: true }, - &dav::Error(vec![ + &dav::Error::(vec![ dav::Violation::Extension(Violation::ResourceMustBeNull), ]) ).await; @@ -700,8 +705,7 @@ mod tests { #[tokio::test] async fn rfc_calendar_query1_req() { let got = serialize( - CalExtension { root: true }, - &CalendarQuery { + &CalendarQuery:: { selector: Some(CalendarSelector::Prop(dav::PropName(vec![ dav::PropertyRequest::GetEtag, dav::PropertyRequest::Extension(PropertyRequest::CalendarData(CalendarDataRequest { @@ -806,8 +810,7 @@ mod tests { #[tokio::test] async fn rfc_calendar_query1_res() { let got = serialize( - CalExtension { root: true }, - &dav::Multistatus { + &dav::Multistatus:: { responses: vec![ dav::Response { href: dav::Href("http://cal.example.com/bernard/work/abcd2.ics".into()), @@ -877,4 +880,3 @@ mod tests { assert_eq!(&got, expected, "\n---GOT---\n{got}\n---EXP---\n{expected}\n"); } } -*/ diff --git a/src/dav/caltypes.rs b/src/dav/caltypes.rs index 585afe2..68e7baf 100644 --- a/src/dav/caltypes.rs +++ b/src/dav/caltypes.rs @@ -26,6 +26,7 @@ use super::types as dav; /// instruction in Section 12.13.2 of [RFC2518]. /// /// +#[derive(Debug, PartialEq)] pub struct MkCalendar(pub dav::Set); @@ -42,6 +43,7 @@ pub struct MkCalendar(pub dav::Set); /// Definition: /// /// +#[derive(Debug, PartialEq)] pub struct MkCalendarResponse(pub Vec>); // --- (REPORT PART) --- @@ -59,6 +61,7 @@ pub struct MkCalendarResponse(pub Vec>); /// +#[derive(Debug, PartialEq)] pub struct CalendarQuery { pub selector: Option>, pub filter: Filter, @@ -79,6 +82,7 @@ pub struct CalendarQuery { /// +#[derive(Debug, PartialEq)] pub struct CalendarMultiget { pub selector: Option>, pub href: Vec, @@ -95,14 +99,17 @@ pub struct CalendarMultiget { /// /// Definition: /// +#[derive(Debug, PartialEq)] pub struct FreeBusyQuery(pub TimeRange); // ----- Hooks ----- +#[derive(Debug, PartialEq)] pub enum ResourceType { Calendar, } /// Check the matching Property object for documentation +#[derive(Debug, PartialEq)] pub enum PropertyRequest { CalendarDescription, CalendarTimezone, @@ -116,6 +123,8 @@ pub enum PropertyRequest { SupportedCollationSet, CalendarData(CalendarDataRequest), } + +#[derive(Debug, PartialEq)] pub enum Property { /// Name: calendar-description /// @@ -591,6 +600,7 @@ pub enum Property { CalendarData(CalendarDataPayload), } +#[derive(Debug, PartialEq)] pub enum Violation { /// (DAV:resource-must-be-null): A resource MUST NOT exist at the /// Request-URI; @@ -761,6 +771,7 @@ pub enum Violation { /// If the client chooses a collation not supported by the server, the /// server MUST respond with a CALDAV:supported-collation precondition /// error response. +#[derive(Debug, PartialEq)] pub struct SupportedCollation(pub Collation); /// @@ -769,6 +780,7 @@ pub struct SupportedCollation(pub Collation); /// when nested in the DAV:prop XML element in a calendaring /// REPORT response to specify the content of a returned /// calendar object resource. +#[derive(Debug, PartialEq)] pub struct CalendarDataPayload { pub mime: Option, pub payload: String, @@ -781,6 +793,7 @@ pub struct CalendarDataPayload { /// when nested in the DAV:prop XML element in a calendaring /// REPORT request to specify which parts of calendar object /// resources should be returned in the response; +#[derive(Debug, PartialEq)] pub struct CalendarDataRequest { pub mime: Option, pub comp: Option, @@ -795,6 +808,7 @@ pub struct CalendarDataRequest { /// when nested in the CALDAV:supported-calendar-data property /// to specify a supported media type for calendar object /// resources; +#[derive(Debug, PartialEq)] pub struct CalendarDataEmpty(pub Option); /// ); /// version value: a version string /// attributes can be used on all three variants of the /// CALDAV:calendar-data XML element. +#[derive(Debug, PartialEq)] pub struct CalendarDataSupport { pub content_type: String, pub version: String, @@ -828,10 +843,13 @@ pub struct CalendarDataSupport { /// However, the CALDAV:prop and CALDAV:allprop elements are defined /// in the "urn:ietf:params:xml:ns:caldav" namespace instead of the /// "DAV:" namespace. +#[derive(Debug, PartialEq)] pub struct Comp { pub name: Component, pub additional_rules: Option, } + +#[derive(Debug, PartialEq)] pub struct CompInner { pub prop_kind: PropKind, pub comp_kind: CompKind, @@ -850,6 +868,7 @@ pub struct CompInner { /// /// /// +#[derive(Debug, PartialEq)] pub struct CompSupport(pub Component); /// Name: allcomp @@ -865,6 +884,7 @@ pub struct CompSupport(pub Component); /// Definition: /// /// +#[derive(Debug, PartialEq)] pub enum CompKind { AllComp, Comp(Vec), @@ -888,6 +908,7 @@ pub enum CompKind { /// allprop element defined in [RFC2518]. However, the CALDAV:allprop /// element is defined in the "urn:ietf:params:xml:ns:caldav" /// namespace instead of the "DAV:" namespace. +#[derive(Debug, PartialEq)] pub enum PropKind { AllProp, Prop(Vec), @@ -917,11 +938,13 @@ pub enum PropKind { /// element defined in [RFC2518]. However, the CALDAV:prop element is /// defined in the "urn:ietf:params:xml:ns:caldav" namespace instead /// of the "DAV:" namespace. +#[derive(Debug, PartialEq)] pub struct CalProp { pub name: ComponentProperty, pub novalue: Option, } +#[derive(Debug, PartialEq)] pub enum RecurrenceModifier { Expand(Expand), LimitRecurrenceSet(LimitRecurrenceSet), @@ -967,6 +990,7 @@ pub enum RecurrenceModifier { /// end CDATA #REQUIRED> /// start value: an iCalendar "date with UTC time" /// end value: an iCalendar "date with UTC time" +#[derive(Debug, PartialEq)] pub struct Expand(pub DateTime, pub DateTime); /// CALDAV:limit-recurrence-set XML Element @@ -1014,6 +1038,7 @@ pub struct Expand(pub DateTime, pub DateTime); /// end CDATA #REQUIRED> /// start value: an iCalendar "date with UTC time" /// end value: an iCalendar "date with UTC time" +#[derive(Debug, PartialEq)] pub struct LimitRecurrenceSet(pub DateTime, pub DateTime); /// Name: limit-freebusy-set @@ -1044,9 +1069,11 @@ pub struct LimitRecurrenceSet(pub DateTime, pub DateTime); /// end CDATA #REQUIRED> /// start value: an iCalendar "date with UTC time" /// end value: an iCalendar "date with UTC time" +#[derive(Debug, PartialEq)] pub struct LimitFreebusySet(pub DateTime, pub DateTime); /// Used by CalendarQuery & CalendarMultiget +#[derive(Debug, PartialEq)] pub enum CalendarSelector { AllProp, PropName, @@ -1101,17 +1128,20 @@ pub enum CalendarSelector { /// /// name value: a calendar object or calendar component /// type (e.g., VEVENT) +#[derive(Debug, PartialEq)] pub struct CompFilter { pub name: Component, // Option 1 = None, Option 2, 3, 4 = Some pub additional_rules: Option, } +#[derive(Debug, PartialEq)] pub enum CompFilterRules { // Option 2 IsNotDefined, // Options 3 & 4 Matches(CompFilterMatch), } +#[derive(Debug, PartialEq)] pub struct CompFilterMatch { pub time_range: Option, pub prop_filter: Vec, @@ -1162,22 +1192,26 @@ pub struct CompFilterMatch { /// /// /// name value: a calendar property name (e.g., ATTENDEE) +#[derive(Debug, PartialEq)] pub struct PropFilter { pub name: Component, // None = Option 1, Some() = Option 2, 3 & 4 pub additional_rules: Option, } +#[derive(Debug, PartialEq)] pub enum PropFilterRules { // Option 2 IsNotDefined, // Options 3 & 4 Match(PropFilterMatch), } +#[derive(Debug, PartialEq)] pub struct PropFilterMatch { pub time_range: Option, pub time_or_text: Option, pub param_filter: Vec, } +#[derive(Debug, PartialEq)] pub enum TimeOrText { Time(TimeRange), Text(TextMatch), @@ -1211,6 +1245,7 @@ pub enum TimeOrText { /// PCDATA value: string /// +#[derive(Debug, PartialEq)] pub struct TextMatch { pub collation: Option, pub negate_condition: Option, @@ -1246,10 +1281,12 @@ pub struct TextMatch { /// /// /// name value: a property parameter name (e.g., PARTSTAT) +#[derive(Debug, PartialEq)] pub struct ParamFilter { pub name: PropertyParameter, pub additional_rules: Option, } +#[derive(Debug, PartialEq)] pub enum ParamFilterMatch { IsNotDefined, Match(TextMatch), @@ -1305,6 +1342,7 @@ pub enum ParamFilterMatch { /// /// /// PCDATA value: an iCalendar object with exactly one VTIMEZONE +#[derive(Debug, PartialEq)] pub struct TimeZone(pub String); /// Name: filter @@ -1320,6 +1358,7 @@ pub struct TimeZone(pub String); /// /// Definition: /// +#[derive(Debug, PartialEq)] pub struct Filter(pub CompFilter); /// Name: time-range @@ -1331,6 +1370,7 @@ pub struct Filter(pub CompFilter); /// end CDATA #IMPLIED> /// start value: an iCalendar "date with UTC time" /// end value: an iCalendar "date with UTC time" +#[derive(Debug, PartialEq)] pub enum TimeRange { OnlyStart(DateTime), OnlyEnd(DateTime), @@ -1340,6 +1380,7 @@ pub enum TimeRange { // ----------------------- ENUM ATTRIBUTES --------------------- /// Known components +#[derive(Debug, PartialEq)] pub enum Component { VCalendar, VJournal, @@ -1368,9 +1409,11 @@ impl Component { /// name="VERSION", name="SUMMARY", etc. /// Can be set on different objects: VCalendar, VEvent, etc. /// Might be replaced by an enum later +#[derive(Debug, PartialEq)] pub struct ComponentProperty(pub String); /// like PARSTAT +#[derive(Debug, PartialEq)] pub struct PropertyParameter(pub String); impl PropertyParameter { pub fn as_str<'a>(&'a self) -> &'a str { @@ -1378,7 +1421,7 @@ impl PropertyParameter { } } -#[derive(Default)] +#[derive(Default,Debug,PartialEq)] pub enum Collation { #[default] AsciiCaseMap, diff --git a/src/dav/mod.rs b/src/dav/mod.rs index abc46e7..bff95e7 100644 --- a/src/dav/mod.rs +++ b/src/dav/mod.rs @@ -1,14 +1,25 @@ +// utils mod error; mod xml; + +// webdav mod types; +mod encoder; +mod decoder; + +// calendar mod caltypes; +mod calencoder; +mod caldecoder; + +// wip mod acltypes; mod versioningtypes; -mod encoder; -mod calencoder; -mod decoder; + +// final type mod realization; + use std::net::SocketAddr; use anyhow::{anyhow, Result}; diff --git a/src/dav/realization.rs b/src/dav/realization.rs index 22c9cfc..a02de94 100644 --- a/src/dav/realization.rs +++ b/src/dav/realization.rs @@ -28,14 +28,13 @@ impl dav::Extension for Core { type ResourceType = Disabled; } -/* // WebDAV with the base Calendar implementation (RFC4791) -pub struct CalendarMin {} -impl dav::Extension for CalendarMin +pub struct Calendar {} +impl dav::Extension for Calendar { type Error = cal::Violation; type Property = cal::Property; type PropertyRequest = cal::PropertyRequest; type ResourceType = cal::ResourceType; } -*/ + -- cgit v1.2.3