improve caldav integration test

This commit is contained in:
Lennart
2025-12-12 23:43:14 +01:00
parent 50a74e3a25
commit d9cca5a298
5 changed files with 65 additions and 21 deletions

View File

@@ -1,13 +1,23 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use crate::integration_tests::{ResponseExtractString, get_app};
use axum::body::{Body, Bytes}; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};
use http::{HeaderValue, StatusCode}; use http::{HeaderValue, StatusCode};
use rstest::rstest; use rstest::rstest;
use rustical_store::{Calendar, CalendarMetadata}; use rustical_store::{CalendarMetadata, CalendarStore};
use rustical_store_sqlite::{calendar_store::SqliteCalendarStore, tests::get_test_calendar_store};
use tower::ServiceExt; use tower::ServiceExt;
const MKCOL_REQUEST: &str = r#" fn mkcalendar_template(
CalendarMetadata {
displayname,
order: _order,
description,
color,
}: &CalendarMetadata,
) -> String {
format!(
r#"
<?xml version='1.0' encoding='UTF-8' ?> <?xml version='1.0' encoding='UTF-8' ?>
<CAL:mkcalendar xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav"> <CAL:mkcalendar xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
<set> <set>
@@ -16,9 +26,9 @@ const MKCOL_REQUEST: &str = r#"
<collection /> <collection />
<CAL:calendar /> <CAL:calendar />
</resourcetype> </resourcetype>
<displayname>Amazing Calendar</displayname> <displayname>{displayname}</displayname>
<CAL:calendar-description>Description</CAL:calendar-description> <CAL:calendar-description>{description}</CAL:calendar-description>
<n0:calendar-color xmlns:n0="http://apple.com/ns/ical/">#FFF8DCFF</n0:calendar-color> <n0:calendar-color xmlns:n0="http://apple.com/ns/ical/">{color}</n0:calendar-color>
<CAL:calendar-timezone-id>Europe/Berlin</CAL:calendar-timezone-id> <CAL:calendar-timezone-id>Europe/Berlin</CAL:calendar-timezone-id>
<CAL:supported-calendar-component-set> <CAL:supported-calendar-component-set>
<CAL:comp name="VEVENT"/> <CAL:comp name="VEVENT"/>
@@ -28,7 +38,12 @@ const MKCOL_REQUEST: &str = r#"
</prop> </prop>
</set> </set>
</CAL:mkcalendar> </CAL:mkcalendar>
"#; "#,
displayname = displayname.as_deref().unwrap_or_default(),
description = description.as_deref().unwrap_or_default(),
color = color.as_deref().unwrap_or_default(),
)
}
#[rstest] #[rstest]
#[tokio::test] #[tokio::test]
@@ -36,14 +51,27 @@ async fn test_caldav_calendar(
#[from(get_app)] #[from(get_app)]
#[future] #[future]
app: axum::Router, app: axum::Router,
#[from(get_test_calendar_store)]
#[future]
cal_store: SqliteCalendarStore,
) { ) {
let app = app.await; let app = app.await;
let cal_store = cal_store.await;
let calendar_meta = CalendarMetadata {
displayname: Some("Calendar".to_string()),
description: Some("Description".to_string()),
color: Some("#00FF00".to_string()),
order: 0,
};
let (principal, cal_id) = ("user", "calendar");
let url = format!("/caldav/principal/{principal}/{cal_id}");
let request_template = || { let request_template = || {
Request::builder() Request::builder()
.method("MKCALENDAR") .method("MKCALENDAR")
.uri("/caldav/principal/user/calendar") .uri(&url)
.body(Body::from(MKCOL_REQUEST)) .body(Body::from(mkcalendar_template(&calendar_meta)))
.unwrap() .unwrap()
}; };
@@ -66,7 +94,7 @@ async fn test_caldav_calendar(
let mut request = Request::builder() let mut request = Request::builder()
.method("GET") .method("GET")
.uri("/caldav/principal/user/calendar") .uri(&url)
.body(Body::empty()) .body(Body::empty())
.unwrap(); .unwrap();
request request
@@ -77,9 +105,18 @@ async fn test_caldav_calendar(
let body = response.extract_string().await; let body = response.extract_string().await;
insta::assert_snapshot!(body); insta::assert_snapshot!(body);
assert_eq!(
cal_store
.get_calendar(principal, cal_id, false)
.await
.unwrap()
.meta,
calendar_meta
);
let mut request = Request::builder() let mut request = Request::builder()
.method("PROPFIND") .method("PROPFIND")
.uri("/caldav/principal/user/calendar") .uri(&url)
.body(Body::empty()) .body(Body::empty())
.unwrap(); .unwrap();
request request
@@ -90,7 +127,7 @@ async fn test_caldav_calendar(
let body = response.extract_string().await; let body = response.extract_string().await;
insta::with_settings!({ insta::with_settings!({
filters => vec![ filters => vec![
(r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "[PUSH_TOPIC]") (r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>")
] ]
}, { }, {
insta::assert_snapshot!(body); insta::assert_snapshot!(body);
@@ -98,7 +135,8 @@ async fn test_caldav_calendar(
let mut request = Request::builder() let mut request = Request::builder()
.method("DELETE") .method("DELETE")
.uri("/caldav/principal/user/calendar") .uri(&url)
.header("X-No-Trashbin", HeaderValue::from_static("1"))
.body(Body::empty()) .body(Body::empty())
.unwrap(); .unwrap();
request request
@@ -108,4 +146,10 @@ async fn test_caldav_calendar(
assert_eq!(response.status(), StatusCode::OK); assert_eq!(response.status(), StatusCode::OK);
let body = response.extract_string().await; let body = response.extract_string().await;
insta::assert_snapshot!(body); insta::assert_snapshot!(body);
assert!(matches!(
cal_store.get_calendar(principal, cal_id, false).await,
Err(rustical_store::Error::NotFound)
));
} }

View File

@@ -111,7 +111,7 @@ async fn test_caldav_principal(
let body = response.extract_string().await; let body = response.extract_string().await;
insta::with_settings!({ insta::with_settings!({
filters => vec![ filters => vec![
(r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "[PUSH_TOPIC]") (r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>")
] ]
}, { }, {
insta::assert_snapshot!(body); insta::assert_snapshot!(body);

View File

@@ -54,7 +54,7 @@ expression: body
<href>/caldav/principal/user/calendar/</href> <href>/caldav/principal/user/calendar/</href>
<propstat> <propstat>
<prop> <prop>
<calendar-color xmlns="http://apple.com/ns/ical/">#FFF8DCFF</calendar-color> <calendar-color xmlns="http://apple.com/ns/ical/">#00FF00</calendar-color>
<CAL:calendar-description>Description</CAL:calendar-description> <CAL:calendar-description>Description</CAL:calendar-description>
<CAL:calendar-timezone>BEGIN:VCALENDAR <CAL:calendar-timezone>BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
@@ -209,7 +209,7 @@ END:VCALENDAR
<PUSH:transports> <PUSH:transports>
<PUSH:web-push/> <PUSH:web-push/>
</PUSH:transports> </PUSH:transports>
[PUSH_TOPIC] <PUSH:topic>[PUSH_TOPIC]</PUSH:topic>
<PUSH:supported-triggers> <PUSH:supported-triggers>
<PUSH:content-update> <PUSH:content-update>
<depth>1</depth> <depth>1</depth>
@@ -222,7 +222,7 @@ END:VCALENDAR
<collection/> <collection/>
<CAL:calendar/> <CAL:calendar/>
</resourcetype> </resourcetype>
<displayname>Amazing Calendar</displayname> <displayname>Calendar</displayname>
<current-user-principal> <current-user-principal>
<href>/caldav/principal/user/</href> <href>/caldav/principal/user/</href>
</current-user-principal> </current-user-principal>

View File

@@ -6,7 +6,7 @@ BEGIN:VCALENDAR
VERSION:4.0 VERSION:4.0
CALSCALE:GREGORIAN CALSCALE:GREGORIAN
PRODID:RustiCal PRODID:RustiCal
X-WR-CALNAME:Amazing Calendar X-WR-CALNAME:Calendar
X-WR-CALDESC:Description X-WR-CALDESC:Description
X-WR-TIMEZONE:Europe/Berlin X-WR-TIMEZONE:Europe/Berlin
END:VCALENDAR END:VCALENDAR

View File

@@ -8,7 +8,7 @@ expression: body
<href>/caldav/principal/user/calendar/</href> <href>/caldav/principal/user/calendar/</href>
<propstat> <propstat>
<prop> <prop>
<calendar-color xmlns="http://apple.com/ns/ical/">#FFF8DCFF</calendar-color> <calendar-color xmlns="http://apple.com/ns/ical/">#00FF00</calendar-color>
<CAL:calendar-description>Description</CAL:calendar-description> <CAL:calendar-description>Description</CAL:calendar-description>
<CAL:calendar-timezone>BEGIN:VCALENDAR <CAL:calendar-timezone>BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
@@ -163,7 +163,7 @@ END:VCALENDAR
<PUSH:transports> <PUSH:transports>
<PUSH:web-push/> <PUSH:web-push/>
</PUSH:transports> </PUSH:transports>
[PUSH_TOPIC] <PUSH:topic>[PUSH_TOPIC]</PUSH:topic>
<PUSH:supported-triggers> <PUSH:supported-triggers>
<PUSH:content-update> <PUSH:content-update>
<depth>1</depth> <depth>1</depth>
@@ -176,7 +176,7 @@ END:VCALENDAR
<collection/> <collection/>
<CAL:calendar/> <CAL:calendar/>
</resourcetype> </resourcetype>
<displayname>Amazing Calendar</displayname> <displayname>Calendar</displayname>
<current-user-principal> <current-user-principal>
<href>/caldav/principal/user/</href> <href>/caldav/principal/user/</href>
</current-user-principal> </current-user-principal>