Compare commits

..

53 Commits

Author SHA1 Message Date
Lennart
4fabf74333 version 0.11.9 2025-12-31 15:58:49 +01:00
Lennart
7b154adec3 remove stray dbg! 2025-12-31 15:57:56 +01:00
Lennart
951a1e4bdc update mkdocs.yml 2025-12-31 15:57:23 +01:00
Lennart
8c44733d0a carddav: Fix namespace for max-resource-size 2025-12-31 15:57:13 +01:00
Lennart
829f7b727f carddav calendar-query: Add parsing support for limit 2025-12-31 15:15:07 +01:00
Lennart
037e6f5c92 version 0.11.8 2025-12-31 14:57:54 +01:00
Lennart
311ceb6bc5 Update README.md 2025-12-31 14:56:39 +01:00
Lennart
1174af3a4b carddav: Add some tests to make sure the filters work 2025-12-31 14:47:23 +01:00
Lennart
845b3e61e3 carddav: Fix filter test="allof"|"anyof" 2025-12-31 14:46:49 +01:00
Lennart
e5d6541ffb fix prop-filter when multiple properties of a name exist 2025-12-31 13:46:43 +01:00
Lennart
b632ff6fe8 update dependencies 2025-12-31 13:31:17 +01:00
Lennart
1ee873ac93 caldav: Add basic filtering test 2025-12-31 13:31:07 +01:00
Lennart
bf5bdb96bc implement param-filter for caldav 2025-12-31 13:07:43 +01:00
Lennart
47c2a55941 implement text-match and prop-filter for carddav 2025-12-31 13:02:53 +01:00
Lennart
bfcd94f096 update test snapshot 2025-12-31 12:35:57 +01:00
Lennart
8cbb72719d fix text-match test 2025-12-31 12:31:09 +01:00
Lennart
ff0246c4fc clippy appeasement 2025-12-31 12:29:19 +01:00
Lennart
15124a2fd5 clippy appeasement 2025-12-31 12:25:59 +01:00
Lennart
5c6f63a5f3 carddav addressbook: Add supported-collation-set 2025-12-31 12:25:35 +01:00
Lennart
17ba8faef2 text-match: Support match types and unicode-casemap collation 2025-12-31 12:25:04 +01:00
Lennart
578ddde36d ResourceName trait: Use Cow instead of String 2025-12-31 10:57:28 +01:00
Lennart
9c3972e21c fix addressbook import test 2025-12-31 01:59:19 +01:00
Lennart
816c26565a clippy appeasement 2025-12-31 01:56:16 +01:00
Lennart
4de0f9f665 add basic addressbook import test 2025-12-31 01:55:49 +01:00
Lennart
cf31a51965 small changes to regression tests and xml namespaces 2025-12-31 01:43:03 +01:00
Lennart
9fc099f6f4 fix carddav integration tests 2025-12-31 01:30:35 +01:00
Lennart
498be172c9 clippy appeasement 2025-12-31 01:23:48 +01:00
Lennart
b8c395e746 add basic integration test for carddav addressbook 2025-12-31 01:23:21 +01:00
Lennart
4b8a8c61f2 Tests: Fix scope of store 2025-12-31 01:05:56 +01:00
Lennart
f778c470d0 update GitHub workflows 2025-12-30 19:16:59 +01:00
Lennart
d44a172261 bump Rust version to 1.92 2025-12-30 19:10:05 +01:00
Lennart
e0ba34baea clippy appeasement 2025-12-30 19:08:58 +01:00
Lennart
a7893ddbda Replace deprecated axum Host extractor with Host header 2025-12-30 13:53:42 +01:00
Lennart
ed7becffc2 update askama to 0.15 2025-12-28 21:02:44 +01:00
Lennart
c29400a799 version 0.11.7 2025-12-28 19:27:27 +01:00
Lennart
047552a726 update dependencies 2025-12-28 19:24:00 +01:00
Lennart K
1cfc8e7c23 frontend: Update dependencies 2025-12-27 15:07:06 +01:00
Lennart
b0fdca1b64 clippy appeasement 2025-12-27 14:30:36 +01:00
Lennart
b65cca9d17 version 0.11.6 2025-12-27 14:23:56 +01:00
Lennart
55ecbdcd41 carddav: Implement addressbook-query 2025-12-27 14:22:23 +01:00
Lennart
89d3d3b7a4 caldav: Outsource text-match to rustical_dav 2025-12-27 13:45:26 +01:00
Lennart K
a74b74369c version 0.11.5 2025-12-21 16:16:48 +01:00
Lennart K
85c49a0bdf update ical-rs 2025-12-20 14:30:26 +01:00
Lennart K
f2e4e2c1a7 add a database benchmark 2025-12-20 11:48:30 +01:00
Lennart K
28c925301e calendar store: Add method for bulk insert 2025-12-20 11:48:05 +01:00
Lennart K
b50ea478db Content-Type: Add charset=utf-8 2025-12-18 21:43:27 +01:00
Lennart K
2c7748255c update test snapshot 2025-12-18 21:40:39 +01:00
Lennart K
f40a23a1f1 update Cargo.toml and fix calendar export ical version 2025-12-18 21:39:36 +01:00
Lennart K
2a4ba33e45 refactor recurrence expansion 2025-12-18 21:27:40 +01:00
Lennart K
6bc4bd3fa3 Update ical-rs dependency 2025-12-18 14:14:26 +01:00
Lennart
7b32d478b8 version 0.11.4 2025-12-17 17:35:11 +01:00
Lennart
fb0bd67176 Update ical-rs version to fix bug with unicode characters in params
addresses #157
2025-12-17 17:33:46 +01:00
Lennart
ecad0d4490 frontend: update vite 2025-12-15 20:44:50 +01:00
92 changed files with 2496 additions and 1242 deletions

View File

@@ -5,6 +5,7 @@ permissions:
pull-requests: write
env:
RUST_VERSION: "1.92"
CARGO_TERM_COLOR: always
jobs:
@@ -12,7 +13,9 @@ jobs:
name: Check
runs-on: ubuntu-latest
steps:
- run: rustup update
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Checkout sources
uses: actions/checkout@v4
- run: cargo check
@@ -21,7 +24,9 @@ jobs:
name: Test Suite
runs-on: ubuntu-latest
steps:
- run: rustup update
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Checkout sources
uses: actions/checkout@v4
- run: cargo test --all-features --verbose --workspace
@@ -30,7 +35,9 @@ jobs:
name: Test Coverage
runs-on: ubuntu-latest
steps:
- run: rustup update
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
@@ -44,8 +51,10 @@ jobs:
name: Lints
runs-on: ubuntu-latest
steps:
- run: rustup update
- run: rustup component add rustfmt clippy
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt, clippy
- name: Checkout sources
uses: actions/checkout@v4

View File

@@ -26,12 +26,12 @@ jobs:
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
uses: docker/setup-buildx-action@v3
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
@@ -54,7 +54,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64,linux/amd64

547
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
members = ["crates/*"]
[workspace.package]
version = "0.11.3"
rust-version = "1.91"
version = "0.11.9"
rust-version = "1.92"
edition = "2024"
description = "A CalDAV server"
documentation = "https://lennart-k.github.io/rustical/"
@@ -32,12 +32,11 @@ opentelemetry = [
"dep:tracing-opentelemetry",
]
[profile.dev]
debug = 0
[workspace.dependencies]
rustical_dav = { path = "./crates/dav/" }
rustical_dav = { path = "./crates/dav/", features = ["ical"] }
rustical_dav_push = { path = "./crates/dav_push/" }
rustical_store = { path = "./crates/store/" }
rustical_store_sqlite = { path = "./crates/store_sqlite/" }
@@ -90,8 +89,8 @@ derive_more = { version = "2.1", features = [
"constructor",
"display",
] }
askama = { version = "0.14", features = ["serde_json"] }
askama_web = { version = "0.14", features = ["axum-0.8"] }
askama = { version = "0.15", features = ["serde_json"] }
askama_web = { version = "0.15", features = ["axum-0.8"] }
sqlx = { version = "0.8", default-features = false, features = [
"sqlx-sqlite",
"uuid",
@@ -109,8 +108,6 @@ strum_macros = "0.27"
serde_json = { version = "1.0", features = ["raw_value"] }
sqlx-sqlite = { version = "0.8", features = ["bundled"] }
ical = { git = "https://github.com/lennart-k/ical-rs", features = [
"generator",
"serde",
"chrono-tz",
] }
toml = "0.9"
@@ -150,6 +147,7 @@ openssl = { version = "0.10", features = ["vendored"] }
async-std = { version = "1.13", features = ["attributes"] }
similar-asserts = "1.7"
insta = { version = "1.44", features = ["filters"] }
criterion = { version = "0.8", features = ["async_tokio"] }
[dev-dependencies]
rstest.workspace = true

View File

@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM rust:1.91-alpine AS chef
FROM --platform=$BUILDPLATFORM rust:1.92-alpine AS chef
ARG TARGETPLATFORM
ARG BUILDPLATFORM

View File

@@ -1,3 +1,6 @@
[![license](https://img.shields.io/github/license/lennart-k/rustical)](https://raw.githubusercontent.com/lennart-k/rustical/main/LICENSE)
[![Coverage Status](https://coveralls.io/repos/github/lennart-k/rustical/badge.svg?branch=main)](https://coveralls.io/github/lennart-k/rustical?branch=main)
# RustiCal
a CalDAV/CardDAV server

View File

@@ -29,7 +29,7 @@ base64.workspace = true
serde.workspace = true
tokio.workspace = true
url.workspace = true
rustical_dav.workspace = true
rustical_dav = { workspace = true, features = ["ical"] }
rustical_store.workspace = true
chrono.workspace = true
chrono-tz.workspace = true

View File

@@ -5,7 +5,8 @@ use axum::extract::State;
use axum::{extract::Path, response::Response};
use headers::{ContentType, HeaderMapExt};
use http::{HeaderValue, Method, StatusCode, header};
use ical::generator::{Emitter, IcalCalendarBuilder};
use ical::builder::calendar::IcalCalendarBuilder;
use ical::generator::Emitter;
use ical::property::Property;
use percent_encoding::{CONTROLS, utf8_percent_encode};
use rustical_ical::{CalendarObjectComponent, EventObject};
@@ -35,28 +36,28 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
let mut vtimezones = HashMap::new();
let objects = cal_store.get_objects(&principal, &calendar_id).await?;
let mut ical_calendar_builder = IcalCalendarBuilder::version("4.0")
let mut ical_calendar_builder = IcalCalendarBuilder::version("2.0")
.gregorian()
.prodid("RustiCal");
if let Some(displayname) = calendar.meta.displayname {
ical_calendar_builder = ical_calendar_builder.set(Property {
name: "X-WR-CALNAME".to_owned(),
value: Some(displayname),
params: None,
params: vec![],
});
}
if let Some(description) = calendar.meta.description {
ical_calendar_builder = ical_calendar_builder.set(Property {
name: "X-WR-CALDESC".to_owned(),
value: Some(description),
params: None,
params: vec![],
});
}
if let Some(timezone_id) = calendar.timezone_id {
ical_calendar_builder = ical_calendar_builder.set(Property {
name: "X-WR-TIMEZONE".to_owned(),
value: Some(timezone_id),
params: None,
params: vec![],
});
}
@@ -64,30 +65,24 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
vtimezones.extend(object.get_vtimezones());
match object.get_data() {
CalendarObjectComponent::Event(EventObject { event, .. }, overrides) => {
ical_calendar_builder = ical_calendar_builder.add_event(event.clone());
for ev_override in overrides {
ical_calendar_builder =
ical_calendar_builder.add_event(ev_override.event.clone());
}
ical_calendar_builder = ical_calendar_builder
.add_event(event.clone())
.add_events(overrides.iter().map(|ev| ev.event.clone()));
}
CalendarObjectComponent::Todo(todo, overrides) => {
ical_calendar_builder = ical_calendar_builder.add_todo(todo.clone());
for ev_override in overrides {
ical_calendar_builder = ical_calendar_builder.add_todo(ev_override.clone());
}
ical_calendar_builder = ical_calendar_builder
.add_todo(todo.clone())
.add_todos(overrides.iter().cloned());
}
CalendarObjectComponent::Journal(journal, overrides) => {
ical_calendar_builder = ical_calendar_builder.add_journal(journal.clone());
for ev_override in overrides {
ical_calendar_builder = ical_calendar_builder.add_journal(ev_override.clone());
}
ical_calendar_builder = ical_calendar_builder
.add_journal(journal.clone())
.add_journals(overrides.iter().cloned());
}
}
}
for vtimezone in vtimezones.into_values() {
ical_calendar_builder = ical_calendar_builder.add_tz(vtimezone.to_owned());
}
ical_calendar_builder = ical_calendar_builder.add_timezones(vtimezones.into_values().cloned());
let ical_calendar = ical_calendar_builder
.build()
@@ -95,7 +90,7 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
let mut resp = Response::builder().status(StatusCode::OK);
let hdrs = resp.headers_mut().unwrap();
hdrs.typed_insert(ContentType::from_str("text/calendar").unwrap());
hdrs.typed_insert(ContentType::from_str("text/calendar; charset=utf-8").unwrap());
let filename = format!("{}_{}.ics", calendar.principal, calendar.id);
let filename = utf8_percent_encode(&filename, CONTROLS);

View File

@@ -137,13 +137,11 @@ impl CompFilterable for CalendarObjectComponent {
#[cfg(test)]
mod tests {
use chrono::{TimeZone, Utc};
use rustical_dav::xml::{MatchType, NegateCondition, TextCollation, TextMatchElement};
use rustical_ical::{CalendarObject, UtcDateTime};
use crate::calendar::methods::report::calendar_query::{
CompFilterable, TextMatchElement, TimeRangeElement,
comp_filter::CompFilterElement,
prop_filter::PropFilterElement,
text_match::{NegateCondition, TextCollation},
CompFilterElement, CompFilterable, PropFilterElement, TimeRangeElement,
};
const ICS: &str = r"BEGIN:VCALENDAR
@@ -219,6 +217,7 @@ END:VCALENDAR";
name: "VERSION".to_string(),
time_range: None,
text_match: Some(TextMatchElement {
match_type: MatchType::Contains,
needle: "2.0".to_string(),
collation: TextCollation::default(),
negate_condition: NegateCondition::default(),
@@ -242,6 +241,7 @@ END:VCALENDAR";
name: "SUMMARY".to_string(),
time_range: None,
text_match: Some(TextMatchElement {
match_type: MatchType::Contains,
collation: TextCollation::default(),
negate_condition: NegateCondition(false),
needle: "weekly".to_string(),
@@ -329,6 +329,7 @@ END:VCALENDAR";
name: "TZID".to_string(),
time_range: None,
text_match: Some(TextMatchElement {
match_type: MatchType::Contains,
collation: TextCollation::AsciiCasemap,
negate_condition: NegateCondition::default(),
needle: "Europe/Berlin".to_string(),

View File

@@ -1,14 +1,10 @@
use crate::{
calendar::methods::report::calendar_query::{
TextMatchElement,
comp_filter::{CompFilterElement, CompFilterable},
},
calendar_object::CalendarObjectPropWrapperName,
};
use rustical_dav::xml::PropfindType;
use super::comp_filter::{CompFilterElement, CompFilterable};
use crate::calendar_object::CalendarObjectPropWrapperName;
use ical::property::Property;
use rustical_dav::xml::{PropfindType, TextMatchElement};
use rustical_ical::{CalendarObject, UtcDateTime};
use rustical_store::calendar_store::CalendarQuery;
use rustical_xml::XmlDeserialize;
use rustical_xml::{XmlDeserialize, XmlRootTag};
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
@@ -32,7 +28,25 @@ pub struct ParamFilterElement {
pub(crate) name: String,
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
impl ParamFilterElement {
#[must_use]
pub fn match_property(&self, prop: &Property) -> bool {
let Some(param) = prop.get_param(&self.name) else {
return self.is_not_defined.is_some();
};
if self.is_not_defined.is_some() {
return false;
}
let Some(text_match) = self.text_match.as_ref() else {
return true;
};
text_match.match_text(param)
}
}
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq)]
#[xml(root = "filter", ns = "rustical_dav::namespace::NS_CALDAV")]
#[allow(dead_code)]
// https://datatracker.ietf.org/doc/html/rfc4791#section-9.7
pub struct FilterElement {

View File

@@ -5,14 +5,13 @@ use rustical_store::CalendarStore;
mod comp_filter;
mod elements;
mod prop_filter;
pub mod text_match;
#[cfg(test)]
mod tests;
#[allow(unused_imports)]
pub use comp_filter::{CompFilterElement, CompFilterable};
pub use elements::*;
#[allow(unused_imports)]
pub use prop_filter::{PropFilterElement, PropFilterable};
#[allow(unused_imports)]
pub use text_match::TextMatchElement;
pub async fn get_objects_calendar_query<C: CalendarStore>(
cal_query: &CalendarQueryRequest,
@@ -30,22 +29,19 @@ pub async fn get_objects_calendar_query<C: CalendarStore>(
}
#[cfg(test)]
mod tests {
use rustical_dav::xml::PropElement;
use rustical_xml::XmlDocument;
mod xml_tests {
use super::{
CalendarQueryRequest, FilterElement, ParamFilterElement, comp_filter::CompFilterElement,
prop_filter::PropFilterElement,
};
use crate::{
calendar::methods::report::{
ReportRequest,
calendar_query::{
CalendarQueryRequest, FilterElement, ParamFilterElement, TextMatchElement,
comp_filter::CompFilterElement,
prop_filter::PropFilterElement,
text_match::{NegateCondition, TextCollation},
},
},
calendar::methods::report::ReportRequest,
calendar_object::{CalendarData, CalendarObjectPropName, CalendarObjectPropWrapperName},
};
use rustical_dav::xml::{
MatchType, NegateCondition, PropElement, TextCollation, TextMatchElement,
};
use rustical_xml::XmlDocument;
#[test]
fn calendar_query_7_8_7() {
@@ -57,16 +53,16 @@ mod tests {
<C:calendar-data/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="ATTENDEE">
<C:text-match collation="i;ascii-casemap">mailto:lisa@example.com</C:text-match>
<C:param-filter name="PARTSTAT">
<C:text-match collation="i;ascii-casemap">NEEDS-ACTION</C:text-match>
</C:param-filter>
</C:prop-filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="ATTENDEE">
<C:text-match collation="i;ascii-casemap">mailto:lisa@example.com</C:text-match>
<C:param-filter name="PARTSTAT">
<C:text-match collation="i;ascii-casemap">NEEDS-ACTION</C:text-match>
</C:param-filter>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
"#;
@@ -101,6 +97,7 @@ mod tests {
prop_filter: vec![PropFilterElement {
name: "ATTENDEE".to_owned(),
text_match: Some(TextMatchElement {
match_type: MatchType::Contains,
collation: TextCollation::AsciiCasemap,
negate_condition: NegateCondition(false),
needle: "mailto:lisa@example.com".to_string()
@@ -110,6 +107,7 @@ mod tests {
is_not_defined: None,
name: "PARTSTAT".to_owned(),
text_match: Some(TextMatchElement {
match_type: MatchType::Contains,
collation: TextCollation::AsciiCasemap,
negate_condition: NegateCondition(false),
needle: "NEEDS-ACTION".to_string()

View File

@@ -1,5 +1,4 @@
use std::collections::HashMap;
use super::{ParamFilterElement, TimeRangeElement};
use ical::{
generator::{IcalCalendar, IcalEvent},
parser::{
@@ -8,12 +7,10 @@ use ical::{
},
property::Property,
};
use rustical_dav::xml::TextMatchElement;
use rustical_ical::{CalDateTime, CalendarObject, CalendarObjectComponent, UtcDateTime};
use rustical_xml::XmlDeserialize;
use crate::calendar::methods::report::calendar_query::{
ParamFilterElement, TextMatchElement, TimeRangeElement,
};
use std::collections::HashMap;
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
@@ -33,18 +30,8 @@ pub struct PropFilterElement {
}
impl PropFilterElement {
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
let property = comp.get_property(&self.name);
let property = match (self.is_not_defined.is_some(), property) {
// We are the component that's not supposed to be defined
(true, Some(_))
// We don't match
| (false, None) => return false,
// We shall not be and indeed we aren't
(true, None) => return true,
(false, Some(property)) => property
};
#[must_use]
pub fn match_property(&self, property: &Property) -> bool {
if let Some(TimeRangeElement { start, end }) = &self.time_range {
// TODO: Respect timezones
let Ok(timestamp) = CalDateTime::parse_prop(property, &HashMap::default()) else {
@@ -70,58 +57,75 @@ impl PropFilterElement {
return false;
}
// TODO: param-filter
if !self
.param_filter
.iter()
.all(|param_filter| param_filter.match_property(property))
{
return false;
}
true
}
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
let properties = comp.get_named_properties(&self.name);
if self.is_not_defined.is_some() {
return properties.is_empty();
}
// The filter matches when one property instance matches
// Example where this matters: We have multiple attendees and want to match one
properties.iter().any(|prop| self.match_property(prop))
}
}
pub trait PropFilterable {
fn get_property(&self, name: &str) -> Option<&Property>;
fn get_named_properties(&self, name: &str) -> Vec<&Property>;
}
impl PropFilterable for CalendarObject {
fn get_property(&self, name: &str) -> Option<&Property> {
Self::get_property(self, name)
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
Self::get_named_properties(self, name)
}
}
impl PropFilterable for IcalEvent {
fn get_property(&self, name: &str) -> Option<&Property> {
Component::get_property(self, name)
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
Component::get_named_properties(self, name)
}
}
impl PropFilterable for IcalTodo {
fn get_property(&self, name: &str) -> Option<&Property> {
Component::get_property(self, name)
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
Component::get_named_properties(self, name)
}
}
impl PropFilterable for IcalJournal {
fn get_property(&self, name: &str) -> Option<&Property> {
Component::get_property(self, name)
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
Component::get_named_properties(self, name)
}
}
impl PropFilterable for IcalCalendar {
fn get_property(&self, name: &str) -> Option<&Property> {
Component::get_property(self, name)
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
Component::get_named_properties(self, name)
}
}
impl PropFilterable for IcalTimeZone {
fn get_property(&self, name: &str) -> Option<&Property> {
Component::get_property(self, name)
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
Component::get_named_properties(self, name)
}
}
impl PropFilterable for CalendarObjectComponent {
fn get_property(&self, name: &str) -> Option<&Property> {
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
match self {
Self::Event(event, _) => PropFilterable::get_property(&event.event, name),
Self::Todo(todo, _) => PropFilterable::get_property(todo, name),
Self::Journal(journal, _) => PropFilterable::get_property(journal, name),
Self::Event(event, _) => PropFilterable::get_named_properties(&event.event, name),
Self::Todo(todo, _) => PropFilterable::get_named_properties(todo, name),
Self::Journal(journal, _) => PropFilterable::get_named_properties(journal, name),
}
}
}

View File

@@ -0,0 +1,83 @@
use super::FilterElement;
use rstest::rstest;
use rustical_ical::CalendarObject;
use rustical_xml::XmlDocument;
const ICS_1: &str = r"BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example Corp.//CalDAV Client//EN
BEGIN:VTIMEZONE
LAST-MODIFIED:20040110T032845Z
TZID:US/Eastern
BEGIN:DAYLIGHT
DTSTART:20000404T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
TZNAME:EDT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
BEGIN:STANDARD
DTSTART:20001026T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:EST
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
DTSTAMP:20060206T001220Z
DTSTART;TZID=US/Eastern:20060104T100000
DURATION:PT1H
LAST-MODIFIED:20060206T001330Z
ORGANIZER:mailto:cyrus@example.com
SEQUENCE:1
STATUS:TENTATIVE
SUMMARY:Event #3
UID:DC6C50A017428C5216A2F1CD@example.com
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
END:VEVENT
END:VCALENDAR
";
const FILTER_1: &str = r#"
<?xml version="1.0" encoding="utf-8" ?>
<C:filter xmlns:C="urn:ietf:params:xml:ns:caldav">
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="ATTENDEE">
<C:text-match collation="i;ascii-casemap">mailto:lisa@example.com</C:text-match>
<C:param-filter name="PARTSTAT">
<C:text-match collation="i;ascii-casemap">NEEDS-ACTION</C:text-match>
</C:param-filter>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
"#;
const FILTER_2: &str = r#"
<?xml version="1.0" encoding="utf-8" ?>
<C:filter xmlns:C="urn:ietf:params:xml:ns:caldav">
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="ATTENDEE">
<C:text-match collation="i;ascii-casemap">mailto:lisa@example.com</C:text-match>
<C:param-filter name="PARTSTAT">
<C:text-match collation="i;ascii-casemap">ACCEPTED</C:text-match>
</C:param-filter>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
"#;
#[rstest]
#[case(ICS_1, FILTER_1, true)]
#[case(ICS_1, FILTER_2, false)]
fn yeet(#[case] ics: &str, #[case] filter: &str, #[case] matches: bool) {
let obj = CalendarObject::from_ics(ics.to_owned(), None).unwrap();
let filter = FilterElement::parse_str(filter).unwrap();
assert_eq!(matches, filter.matches(&obj));
}

View File

@@ -1,103 +0,0 @@
use ical::property::Property;
use rustical_xml::{ValueDeserialize, XmlDeserialize};
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub enum TextCollation {
#[default]
AsciiCasemap,
Octet,
}
impl TextCollation {
// Check whether a haystack contains a needle respecting the collation
#[must_use]
pub fn match_text(&self, needle: &str, haystack: &str) -> bool {
match self {
// https://datatracker.ietf.org/doc/html/rfc4790#section-9.2
Self::AsciiCasemap => haystack
.to_ascii_uppercase()
.contains(&needle.to_ascii_uppercase()),
Self::Octet => haystack.contains(needle),
}
}
}
impl AsRef<str> for TextCollation {
fn as_ref(&self) -> &str {
match self {
Self::AsciiCasemap => "i;ascii-casemap",
Self::Octet => "i;octet",
}
}
}
impl ValueDeserialize for TextCollation {
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
match val {
"i;ascii-casemap" => Ok(Self::AsciiCasemap),
"i;octet" => Ok(Self::Octet),
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
"Invalid collation: {val}"
))),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct NegateCondition(pub bool);
impl ValueDeserialize for NegateCondition {
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
match val {
"yes" => Ok(Self(true)),
"no" => Ok(Self(false)),
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
"Invalid negate-condition parameter: {val}"
))),
}
}
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
pub struct TextMatchElement {
#[xml(ty = "attr", default = "Default::default")]
pub collation: TextCollation,
#[xml(ty = "attr", default = "Default::default")]
pub(crate) negate_condition: NegateCondition,
#[xml(ty = "text")]
pub(crate) needle: String,
}
impl TextMatchElement {
#[must_use]
pub fn match_property(&self, property: &Property) -> bool {
let Self {
collation,
negate_condition,
needle,
} = self;
let matches = property
.value
.as_ref()
.is_some_and(|haystack| collation.match_text(needle, haystack));
// XOR
negate_condition.0 ^ matches
}
}
#[cfg(test)]
mod tests {
use crate::calendar::methods::report::calendar_query::text_match::TextCollation;
#[test]
fn test_collation() {
assert!(TextCollation::AsciiCasemap.match_text("GrüN", "grün"));
assert!(!TextCollation::AsciiCasemap.match_text("GrÜN", "grün"));
assert!(!TextCollation::Octet.match_text("GrÜN", "grün"));
assert!(TextCollation::Octet.match_text("hallo", "hallo"));
assert!(TextCollation::AsciiCasemap.match_text("HaLlo", "hAllo"));
}
}

View File

@@ -1,10 +1,9 @@
use derive_more::derive::{From, Into};
use rustical_dav::xml::TextCollation;
use rustical_ical::CalendarObjectType;
use rustical_xml::{XmlDeserialize, XmlSerialize};
use strum_macros::VariantArray;
use crate::calendar::methods::report::calendar_query::text_match::TextCollation;
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq, From, Into)]
pub struct SupportedCalendarComponent {
#[xml(ty = "attr")]
@@ -55,6 +54,7 @@ impl Default for SupportedCollationSet {
fn default() -> Self {
Self(vec![
SupportedCollation(TextCollation::AsciiCasemap),
SupportedCollation(TextCollation::UnicodeCasemap),
SupportedCollation(TextCollation::Octet),
])
}

View File

@@ -17,6 +17,7 @@ use rustical_store::auth::Principal;
use rustical_xml::{EnumVariants, PropName};
use rustical_xml::{XmlDeserialize, XmlSerialize};
use serde::Deserialize;
use std::borrow::Cow;
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Eq, Clone, EnumVariants, PropName)]
#[xml(unit_variants_ident = "CalendarPropName")]
@@ -72,8 +73,8 @@ pub struct CalendarResource {
}
impl ResourceName for CalendarResource {
fn get_name(&self) -> String {
self.cal.id.clone()
fn get_name(&self) -> Cow<'_, str> {
Cow::from(&self.cal.id)
}
}

View File

@@ -0,0 +1,200 @@
---
source: crates/caldav/src/calendar/tests.rs
expression: output
---
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:">
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop xmlns="DAV:">
<calendar-timezone xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
LAST-MODIFIED:20250723T190331Z
X-LIC-LOCATION:Europe/Berlin
X-PROLEPTIC-TZNAME:LMT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+005328
TZOFFSETTO:+0100
DTSTART:18930401T000000
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19160430T230000
RDATE:19400401T020000
RDATE:19430329T020000
RDATE:19460414T020000
RDATE:19470406T030000
RDATE:19480418T020000
RDATE:19490410T020000
RDATE:19800406T020000
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19161001T010000
RDATE:19421102T030000
RDATE:19431004T030000
RDATE:19441002T030000
RDATE:19451118T030000
RDATE:19461007T030000
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19170416T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=3MO;UNTIL=19180415T010000Z
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19170917T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=3MO;UNTIL=19180916T010000Z
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19440403T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1MO;UNTIL=19450402T010000Z
END:DAYLIGHT
BEGIN:DAYLIGHT
TZNAME:CEMT
TZOFFSETFROM:+0200
TZOFFSETTO:+0300
DTSTART:19450524T020000
RDATE:19470511T030000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0300
TZOFFSETTO:+0200
DTSTART:19450924T030000
RDATE:19470629T030000
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0100
TZOFFSETTO:+0100
DTSTART:19460101T000000
RDATE:19800101T000000
END:STANDARD
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19471005T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU;UNTIL=19491002T010000Z
END:STANDARD
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU;UNTIL=19950924T010000Z
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
</calendar-timezone>
<timezone-service-set xmlns="urn:ietf:params:xml:ns:caldav">
<href xmlns="DAV:">https://www.iana.org/time-zones</href>
</timezone-service-set>
<calendar-timezone-id xmlns="urn:ietf:params:xml:ns:caldav">Europe/Berlin</calendar-timezone-id>
<calendar-order xmlns="http://apple.com/ns/ical/">0</calendar-order>
<supported-calendar-component-set xmlns="urn:ietf:params:xml:ns:caldav">
<comp xmlns="urn:ietf:params:xml:ns:caldav" name="VEVENT"/>
<comp xmlns="urn:ietf:params:xml:ns:caldav" name="VTODO"/>
</supported-calendar-component-set>
<supported-calendar-data xmlns="urn:ietf:params:xml:ns:caldav">
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav" content-type="text/calendar" version="2.0"/>
</supported-calendar-data>
<supported-collation-set xmlns="urn:ietf:params:xml:ns:caldav">
<supported-collation xmlns="urn:ietf:params:xml:ns:caldav">i;ascii-casemap</supported-collation>
<supported-collation xmlns="urn:ietf:params:xml:ns:caldav">i;unicode-casemap</supported-collation>
<supported-collation xmlns="urn:ietf:params:xml:ns:caldav">i;octet</supported-collation>
</supported-collation-set>
<max-resource-size xmlns="DAV:">10000000</max-resource-size>
<supported-report-set xmlns="DAV:">
<supported-report xmlns="DAV:">
<report xmlns="DAV:">
<calendar-query xmlns="urn:ietf:params:xml:ns:caldav"/>
</report>
</supported-report>
<supported-report xmlns="DAV:">
<report xmlns="DAV:">
<calendar-multiget xmlns="urn:ietf:params:xml:ns:caldav"/>
</report>
</supported-report>
<supported-report xmlns="DAV:">
<report xmlns="DAV:">
<sync-collection xmlns="DAV:"/>
</report>
</supported-report>
</supported-report-set>
<min-date-time xmlns="urn:ietf:params:xml:ns:caldav">-2621430101T000000Z</min-date-time>
<max-date-time xmlns="urn:ietf:params:xml:ns:caldav">+2621421231T235959Z</max-date-time>
<sync-token xmlns="DAV:">github.com/lennart-k/rustical/ns/12</sync-token>
<getctag xmlns="http://calendarserver.org/ns/">github.com/lennart-k/rustical/ns/12</getctag>
<transports xmlns="https://bitfire.at/webdav-push">
<web-push xmlns="https://bitfire.at/webdav-push"/>
</transports>
<topic xmlns="https://bitfire.at/webdav-push">b28b41e9-8801-4fc5-ae29-8efb5fadeb36</topic>
<supported-triggers xmlns="https://bitfire.at/webdav-push">
<content-update xmlns="https://bitfire.at/webdav-push">
<depth xmlns="DAV:">1</depth>
</content-update>
<property-update xmlns="https://bitfire.at/webdav-push">
<depth xmlns="DAV:">1</depth>
</property-update>
</supported-triggers>
<resourcetype xmlns="DAV:">
<collection xmlns="DAV:"/>
<calendar xmlns="urn:ietf:params:xml:ns:caldav"/>
</resourcetype>
<displayname xmlns="DAV:">Calendar</displayname>
<current-user-principal xmlns="DAV:">
<href xmlns="DAV:">/caldav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set xmlns="DAV:">
<privilege>
<read/>
</privilege>
<privilege>
<write-properties/>
</privilege>
<privilege>
<read-acl/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
</current-user-privilege-set>
<owner xmlns="DAV:">
<href xmlns="DAV:">/caldav/principal/user/</href>
</owner>
</prop>
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
</propstat>
</response>

View File

@@ -0,0 +1,37 @@
---
source: crates/caldav/src/calendar/tests.rs
expression: output
---
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:">
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop xmlns="DAV:">
<calendar-color xmlns="http://apple.com/ns/ical/"/>
<calendar-description xmlns="urn:ietf:params:xml:ns:caldav"/>
<calendar-timezone xmlns="urn:ietf:params:xml:ns:caldav"/>
<timezone-service-set xmlns="urn:ietf:params:xml:ns:caldav"/>
<calendar-timezone-id xmlns="urn:ietf:params:xml:ns:caldav"/>
<calendar-order xmlns="http://apple.com/ns/ical/"/>
<supported-calendar-component-set xmlns="urn:ietf:params:xml:ns:caldav"/>
<supported-calendar-data xmlns="urn:ietf:params:xml:ns:caldav"/>
<supported-collation-set xmlns="urn:ietf:params:xml:ns:caldav"/>
<max-resource-size xmlns="DAV:"/>
<supported-report-set xmlns="DAV:"/>
<source xmlns="http://calendarserver.org/ns/"/>
<min-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
<max-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
<sync-token xmlns="DAV:"/>
<getctag xmlns="http://calendarserver.org/ns/"/>
<transports xmlns="https://bitfire.at/webdav-push"/>
<topic xmlns="https://bitfire.at/webdav-push"/>
<supported-triggers xmlns="https://bitfire.at/webdav-push"/>
<resourcetype xmlns="DAV:"/>
<displayname xmlns="DAV:"/>
<current-user-principal xmlns="DAV:"/>
<current-user-privilege-set xmlns="DAV:"/>
<owner xmlns="DAV:"/>
</prop>
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
</propstat>
</response>

View File

@@ -1,230 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop>
<calendar-color xmlns="http://apple.com/ns/ical/"/>
<calendar-description xmlns="urn:ietf:params:xml:ns:caldav"/>
<calendar-timezone xmlns="urn:ietf:params:xml:ns:caldav"/>
<timezone-service-set xmlns="urn:ietf:params:xml:ns:caldav"/>
<calendar-timezone-id xmlns="urn:ietf:params:xml:ns:caldav"/>
<calendar-order xmlns="http://apple.com/ns/ical/"/>
<supported-calendar-component-set xmlns="urn:ietf:params:xml:ns:caldav"/>
<supported-calendar-data xmlns="urn:ietf:params:xml:ns:caldav"/>
<supported-collation-set xmlns="urn:ietf:params:xml:ns:caldav"/>
<max-resource-size xmlns="DAV:"/>
<supported-report-set xmlns="DAV:"/>
<source xmlns="http://calendarserver.org/ns/"/>
<min-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
<max-date-time xmlns="urn:ietf:params:xml:ns:caldav"/>
<sync-token xmlns="DAV:"/>
<getctag xmlns="http://calendarserver.org/ns/"/>
<transports xmlns="https://bitfire.at/webdav-push"/>
<topic xmlns="https://bitfire.at/webdav-push"/>
<supported-triggers xmlns="https://bitfire.at/webdav-push"/>
<resourcetype xmlns="DAV:"/>
<displayname xmlns="DAV:"/>
<current-user-principal xmlns="DAV:"/>
<current-user-privilege-set xmlns="DAV:"/>
<owner xmlns="DAV:"/>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop>
<CAL:calendar-timezone>BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
LAST-MODIFIED:20250723T190331Z
X-LIC-LOCATION:Europe/Berlin
X-PROLEPTIC-TZNAME:LMT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+005328
TZOFFSETTO:+0100
DTSTART:18930401T000000
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19160430T230000
RDATE:19400401T020000
RDATE:19430329T020000
RDATE:19460414T020000
RDATE:19470406T030000
RDATE:19480418T020000
RDATE:19490410T020000
RDATE:19800406T020000
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19161001T010000
RDATE:19421102T030000
RDATE:19431004T030000
RDATE:19441002T030000
RDATE:19451118T030000
RDATE:19461007T030000
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19170416T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=3MO;UNTIL=19180415T010000Z
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19170917T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=3MO;UNTIL=19180916T010000Z
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19440403T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1MO;UNTIL=19450402T010000Z
END:DAYLIGHT
BEGIN:DAYLIGHT
TZNAME:CEMT
TZOFFSETFROM:+0200
TZOFFSETTO:+0300
DTSTART:19450524T020000
RDATE:19470511T030000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0300
TZOFFSETTO:+0200
DTSTART:19450924T030000
RDATE:19470629T030000
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0100
TZOFFSETTO:+0100
DTSTART:19460101T000000
RDATE:19800101T000000
END:STANDARD
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19471005T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU;UNTIL=19491002T010000Z
END:STANDARD
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU;UNTIL=19950924T010000Z
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
</CAL:calendar-timezone>
<CAL:timezone-service-set>
<href>https://www.iana.org/time-zones</href>
</CAL:timezone-service-set>
<CAL:calendar-timezone-id>Europe/Berlin</CAL:calendar-timezone-id>
<calendar-order xmlns="http://apple.com/ns/ical/">0</calendar-order>
<CAL:supported-calendar-component-set>
<CAL:comp name="VEVENT"/>
<CAL:comp name="VTODO"/>
</CAL:supported-calendar-component-set>
<CAL:supported-calendar-data>
<CAL:calendar-data content-type="text/calendar" version="2.0"/>
</CAL:supported-calendar-data>
<CAL:supported-collation-set>
<CAL:supported-collation>i;ascii-casemap</CAL:supported-collation>
<CAL:supported-collation>i;octet</CAL:supported-collation>
</CAL:supported-collation-set>
<max-resource-size>10000000</max-resource-size>
<supported-report-set>
<supported-report>
<report>
<CAL:calendar-query/>
</report>
</supported-report>
<supported-report>
<report>
<CAL:calendar-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
</supported-report-set>
<CAL:min-date-time>-2621430101T000000Z</CAL:min-date-time>
<CAL:max-date-time>+2621421231T235959Z</CAL:max-date-time>
<sync-token>github.com/lennart-k/rustical/ns/12</sync-token>
<CS:getctag>github.com/lennart-k/rustical/ns/12</CS:getctag>
<PUSH:transports>
<PUSH:web-push/>
</PUSH:transports>
<PUSH:topic>b28b41e9-8801-4fc5-ae29-8efb5fadeb36</PUSH:topic>
<PUSH:supported-triggers>
<PUSH:content-update>
<depth>1</depth>
</PUSH:content-update>
<PUSH:property-update>
<depth>1</depth>
</PUSH:property-update>
</PUSH:supported-triggers>
<resourcetype>
<collection/>
<CAL:calendar/>
</resourcetype>
<displayname>Calendar</displayname>
<current-user-principal>
<href>/caldav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<write-properties/>
</privilege>
<privilege>
<read-acl/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
</current-user-privilege-set>
<owner>
<href>/caldav/principal/user/</href>
</owner>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>

View File

@@ -14,14 +14,9 @@ async fn test_propfind() {
from_str(include_str!("./test_files/propfind.principals.json")).unwrap();
let resources: Vec<CalendarResource> =
from_str(include_str!("./test_files/propfind.resources.json")).unwrap();
let outputs: Vec<_> = include_str!("./test_files/propfind.outputs")
.trim()
.split("\n\n")
.collect();
for principal in principals {
for ((request, resource), &expected_output) in requests.iter().zip(&resources).zip(&outputs)
{
for (request, resource) in requests.iter().zip(&resources) {
let propfind = CalendarResource::parse_propfind(request).unwrap();
let response = resource
@@ -33,13 +28,12 @@ async fn test_propfind() {
&principal,
)
.unwrap();
let expected_output = expected_output.trim();
let output = response
.serialize_to_string()
.unwrap()
.trim()
.replace("\r\n", "\n");
similar_asserts::assert_eq!(expected_output, output);
insta::assert_snapshot!(output);
}
}
}

View File

@@ -42,7 +42,7 @@ pub async fn get_event<C: CalendarStore>(
let mut resp = Response::builder().status(StatusCode::OK);
let hdrs = resp.headers_mut().unwrap();
hdrs.typed_insert(ETag::from_str(&event.get_etag()).unwrap());
hdrs.typed_insert(ContentType::from_str("text/calendar").unwrap());
hdrs.typed_insert(ContentType::from_str("text/calendar; charset=utf-8").unwrap());
if matches!(method, Method::HEAD) {
Ok(resp.body(Body::empty()).unwrap())
} else {

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use super::prop::{
CalendarData, CalendarObjectProp, CalendarObjectPropName, CalendarObjectPropWrapper,
CalendarObjectPropWrapperName,
@@ -20,8 +22,8 @@ pub struct CalendarObjectResource {
}
impl ResourceName for CalendarObjectResource {
fn get_name(&self) -> String {
format!("{}.ics", self.object.get_id())
fn get_name(&self) -> Cow<'_, str> {
Cow::from(format!("{}.ics", self.object.get_id()))
}
}

View File

@@ -6,6 +6,7 @@ use rustical_dav::xml::{
GroupMemberSet, GroupMembership, Resourcetype, ResourcetypeInner, SupportedReportSet,
};
use rustical_store::auth::Principal;
use std::borrow::Cow;
mod service;
pub use service::*;
@@ -23,8 +24,8 @@ pub struct PrincipalResource {
}
impl ResourceName for PrincipalResource {
fn get_name(&self) -> String {
self.principal.id.clone()
fn get_name(&self) -> Cow<'_, str> {
Cow::from(&self.principal.id)
}
}

View File

@@ -3,51 +3,51 @@ source: crates/caldav/src/principal/tests.rs
expression: response.serialize_to_string().unwrap()
---
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:">
<href>/caldav/principal/user/</href>
<propstat>
<prop>
<CAL:calendar-user-type>INDIVIDUAL</CAL:calendar-user-type>
<CAL:calendar-user-address-set>
<href>/caldav/principal/user/</href>
</CAL:calendar-user-address-set>
<principal-URL>
<href>/caldav/principal/user/</href>
<prop xmlns="DAV:">
<calendar-user-type xmlns="urn:ietf:params:xml:ns:caldav">INDIVIDUAL</calendar-user-type>
<calendar-user-address-set xmlns="urn:ietf:params:xml:ns:caldav">
<href xmlns="DAV:">/caldav/principal/user/</href>
</calendar-user-address-set>
<principal-URL xmlns="DAV:">
<href xmlns="DAV:">/caldav/principal/user/</href>
</principal-URL>
<group-membership>
<href>/caldav/principal/group/</href>
<group-membership xmlns="DAV:">
<href xmlns="DAV:">/caldav/principal/group/</href>
</group-membership>
<group-member-set>
<group-member-set xmlns="DAV:">
</group-member-set>
<alternate-URI-set/>
<supported-report-set>
<supported-report>
<report>
<principal-match/>
<alternate-URI-set xmlns="DAV:"/>
<supported-report-set xmlns="DAV:">
<supported-report xmlns="DAV:">
<report xmlns="DAV:">
<principal-match xmlns="DAV:"/>
</report>
</supported-report>
</supported-report-set>
<CAL:calendar-home-set>
<href>/caldav/principal/group/</href>
<href>/caldav/principal/user/</href>
</CAL:calendar-home-set>
<resourcetype>
<collection/>
<principal/>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">
<href xmlns="DAV:">/caldav/principal/group/</href>
<href xmlns="DAV:">/caldav/principal/user/</href>
</calendar-home-set>
<resourcetype xmlns="DAV:">
<collection xmlns="DAV:"/>
<principal xmlns="DAV:"/>
</resourcetype>
<displayname>user</displayname>
<current-user-principal>
<href>/caldav/principal/user/</href>
<displayname xmlns="DAV:">user</displayname>
<current-user-principal xmlns="DAV:">
<href xmlns="DAV:">/caldav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<current-user-privilege-set xmlns="DAV:">
<privilege>
<all/>
</privilege>
</current-user-privilege-set>
<owner>
<href>/caldav/principal/user/</href>
<owner xmlns="DAV:">
<href xmlns="DAV:">/caldav/principal/user/</href>
</owner>
</prop>
<status>HTTP/1.1 200 OK</status>
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
</propstat>
</response>

View File

@@ -5,32 +5,27 @@ use crate::{
use rstest::rstest;
use rustical_dav::resource::{Resource, ResourceService};
use rustical_store::auth::{Principal, PrincipalType::Individual};
use rustical_store_sqlite::{
SqliteStore,
calendar_store::SqliteCalendarStore,
principal_store::SqlitePrincipalStore,
tests::{get_test_calendar_store, get_test_principal_store, get_test_subscription_store},
};
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use rustical_xml::XmlSerializeRoot;
use std::sync::Arc;
#[rstest]
#[tokio::test]
async fn test_principal_resource(
#[from(get_test_calendar_store)]
#[future]
cal_store: SqliteCalendarStore,
#[from(get_test_principal_store)]
#[future]
auth_provider: SqlitePrincipalStore,
#[from(get_test_subscription_store)]
#[future]
sub_store: SqliteStore,
#[from(test_store_context)]
context: TestStoreContext,
) {
let TestStoreContext {
cal_store,
sub_store,
principal_store: auth_provider,
..
} = context.await;
let service = PrincipalResourceService {
cal_store: Arc::new(cal_store.await),
sub_store: Arc::new(sub_store.await),
auth_provider: Arc::new(auth_provider.await),
cal_store: Arc::new(cal_store),
sub_store: Arc::new(sub_store),
auth_provider: Arc::new(auth_provider),
simplified_home_set: false,
};

View File

@@ -22,7 +22,7 @@ base64.workspace = true
serde.workspace = true
tokio.workspace = true
url.workspace = true
rustical_dav.workspace = true
rustical_dav = { workspace = true, features = ["ical"] }
rustical_store.workspace = true
chrono.workspace = true
rustical_xml.workspace = true
@@ -35,6 +35,7 @@ percent-encoding.workspace = true
ical.workspace = true
strum.workspace = true
strum_macros.workspace = true
rstest.workspace = true
[dev-dependencies]
insta.workspace = true

View File

@@ -50,7 +50,7 @@ pub async fn get_object<AS: AddressbookStore>(
let mut resp = Response::builder().status(StatusCode::OK);
let hdrs = resp.headers_mut().unwrap();
hdrs.typed_insert(ETag::from_str(&object.get_etag()).unwrap());
hdrs.typed_insert(ContentType::from_str("text/vcard").unwrap());
hdrs.typed_insert(ContentType::from_str("text/vcard; charset=utf-8").unwrap());
if matches!(method, Method::HEAD) {
Ok(resp.body(Body::empty()).unwrap())
} else {

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use crate::{
Error,
address_object::{
@@ -22,8 +24,8 @@ pub struct AddressObjectResource {
}
impl ResourceName for AddressObjectResource {
fn get_name(&self) -> String {
format!("{}.vcf", self.object.get_id())
fn get_name(&self) -> Cow<'_, str> {
Cow::from(format!("{}.vcf", self.object.get_id()))
}
}

View File

@@ -46,7 +46,7 @@ pub async fn route_get<AS: AddressbookStore, S: SubscriptionStore>(
let mut resp = Response::builder().status(StatusCode::OK);
let hdrs = resp.headers_mut().unwrap();
hdrs.typed_insert(ContentType::from_str("text/vcard").unwrap());
hdrs.typed_insert(ContentType::from_str("text/vcard; charset=utf-8").unwrap());
let filename = format!("{principal}_{addressbook_id}.vcf");
let filename = utf8_percent_encode(&filename, CONTROLS);
hdrs.insert(

View File

@@ -36,7 +36,7 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
card_mut.set_property(Property {
name: "UID".to_owned(),
value: Some(uuid::Uuid::new_v4().to_string()),
params: None,
params: vec![],
});
card = card_mut.verify().unwrap();
}

View File

@@ -0,0 +1,134 @@
use crate::{
address_object::AddressObjectPropWrapperName,
addressbook::methods::report::addressbook_query::PropFilterElement,
};
use derive_more::{From, Into};
use ical::property::Property;
use rustical_dav::xml::{PropfindType, TextMatchElement};
use rustical_ical::{AddressObject, UtcDateTime};
use rustical_xml::{ValueDeserialize, XmlDeserialize, XmlRootTag};
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
pub struct TimeRangeElement {
#[xml(ty = "attr")]
pub(crate) start: Option<UtcDateTime>,
#[xml(ty = "attr")]
pub(crate) end: Option<UtcDateTime>,
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
// https://www.rfc-editor.org/rfc/rfc4791#section-9.7.3
pub struct ParamFilterElement {
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
pub(crate) is_not_defined: Option<()>,
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
pub(crate) text_match: Option<TextMatchElement>,
#[xml(ty = "attr")]
pub(crate) name: String,
}
impl ParamFilterElement {
#[must_use]
pub fn match_property(&self, prop: &Property) -> bool {
let Some(param) = prop.get_param(&self.name) else {
return self.is_not_defined.is_some();
};
if self.is_not_defined.is_some() {
return false;
}
let Some(text_match) = self.text_match.as_ref() else {
return true;
};
text_match.match_text(param)
}
}
#[derive(Clone, Debug, PartialEq, Eq, Default, From, Into)]
pub struct Allof(pub bool);
impl ValueDeserialize for Allof {
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
Ok(Self(match val {
"allof" => true,
"anyof" => false,
_ => {
return Err(rustical_xml::XmlError::InvalidVariant(format!(
"Invalid test parameter: {val}"
)));
}
}))
}
}
// <!ELEMENT filter (prop-filter*)>
// <!ATTLIST filter test (anyof | allof) "anyof">
// <!-- test value:
// anyof logical OR for prop-filter matches
// allof logical AND for prop-filter matches -->
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug, PartialEq, Eq)]
#[xml(root = "filter", ns = "rustical_dav::namespace::NS_CARDDAV")]
#[allow(dead_code)]
pub struct FilterElement {
#[xml(ty = "attr", default = "Default::default")]
pub test: Allof,
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
pub(crate) prop_filter: Vec<PropFilterElement>,
}
impl FilterElement {
#[must_use]
pub fn matches(&self, addr_object: &AddressObject) -> bool {
let Allof(allof) = self.test;
let mut results = self
.prop_filter
.iter()
.map(|prop_filter| prop_filter.match_component(addr_object));
if allof {
results.all(|x| x)
} else {
results.any(|x| x)
}
}
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
// <!ELEMENT addressbook-query ((DAV:allprop |
// DAV:propname |
// DAV:prop)?, filter, limit?)>
pub struct AddressbookQueryRequest {
#[xml(ty = "untagged")]
pub prop: PropfindType<AddressObjectPropWrapperName>,
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
pub(crate) filter: FilterElement,
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
pub(crate) limit: Option<LimitElement>,
}
// https://datatracker.ietf.org/doc/html/rfc5323#section-5.17
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct LimitElement {
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
pub nresults: NresultsElement,
}
impl From<u64> for LimitElement {
fn from(value: u64) -> Self {
Self {
nresults: NresultsElement(value),
}
}
}
impl From<LimitElement> for u64 {
fn from(value: LimitElement) -> Self {
value.nresults.0
}
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
pub struct NresultsElement(#[xml(ty = "text")] pub u64);

View File

@@ -0,0 +1,22 @@
use crate::Error;
mod elements;
mod prop_filter;
pub use elements::*;
#[allow(unused_imports)]
pub use prop_filter::{PropFilterElement, PropFilterable};
use rustical_ical::AddressObject;
use rustical_store::AddressbookStore;
#[cfg(test)]
mod tests;
pub async fn get_objects_addressbook_query<AS: AddressbookStore>(
addr_query: &AddressbookQueryRequest,
principal: &str,
addressbook_id: &str,
store: &AS,
) -> Result<Vec<AddressObject>, Error> {
let mut objects = store.get_objects(principal, addressbook_id).await?;
objects.retain(|object| addr_query.filter.matches(object));
Ok(objects)
}

View File

@@ -0,0 +1,73 @@
use super::{Allof, ParamFilterElement};
use ical::{parser::Component, property::Property};
use rustical_dav::xml::TextMatchElement;
use rustical_ical::AddressObject;
use rustical_xml::XmlDeserialize;
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
// <!ELEMENT prop-filter (is-not-defined |
// (text-match*, param-filter*))>
//
// <!ATTLIST prop-filter name CDATA #REQUIRED
// test (anyof | allof) "anyof">
// <!-- name value: a vCard property name (e.g., "NICKNAME")
// test value:
// anyof logical OR for text-match/param-filter matches
// allof logical AND for text-match/param-filter matches -->
pub struct PropFilterElement {
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
pub(crate) is_not_defined: Option<()>,
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
pub(crate) text_match: Vec<TextMatchElement>,
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", flatten)]
pub(crate) param_filter: Vec<ParamFilterElement>,
#[xml(ty = "attr", default = "Default::default")]
pub test: Allof,
#[xml(ty = "attr")]
pub(crate) name: String,
}
impl PropFilterElement {
#[must_use]
pub fn match_property(&self, property: &Property) -> bool {
let Allof(allof) = self.test;
let text_matches = self
.text_match
.iter()
.map(|text_match| text_match.match_property(property));
let param_matches = self
.param_filter
.iter()
.map(|param_filter| param_filter.match_property(property));
let mut matches = text_matches.chain(param_matches);
if allof {
matches.all(|a| a)
} else {
matches.any(|a| a)
}
}
pub fn match_component(&self, comp: &impl PropFilterable) -> bool {
let properties = comp.get_named_properties(&self.name);
if self.is_not_defined.is_some() {
return properties.is_empty();
}
// The filter matches when one property instance matches
properties.iter().any(|prop| self.match_property(prop))
}
}
pub trait PropFilterable {
fn get_named_properties(&self, name: &str) -> Vec<&Property>;
}
impl PropFilterable for AddressObject {
fn get_named_properties(&self, name: &str) -> Vec<&Property> {
self.get_vcard().get_named_properties(name)
}
}

View File

@@ -0,0 +1,70 @@
use super::FilterElement;
use rstest::rstest;
use rustical_ical::AddressObject;
use rustical_xml::XmlDocument;
const VCF_1: &str = r"BEGIN:VCARD
VERSION:4.0
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr,M.Sc.
BDAY:--0203
GENDER:M
EMAIL;TYPE=work:simon.perreault@viagenie.ca
END:VCARD";
const VCF_2: &str = r"BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;Mr.;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
ADR;TYPE=WORK;PREF=1;LABEL=100 Waters Edge\\nBaytown\\, LA 30314\\nUnited S
tates of America:;;100 Waters Edge;Baytown;LA;30314;United States of Ameri
ca
ADR;TYPE=HOME;LABEL=42 Plantation St.\\nBaytown\\, LA 30314\\nUnited States
of America:;;42 Plantation St.;Baytown;LA;30314;United States of America
EMAIL:forrestgump@example.com
REV:20080424T195243Z
x-qq:21588891
UID:890a9da4-bb6d-4afb-9f32-b5eff6494a53
END:VCARD
";
const FILTER_1: &str = r#"
<?xml version="1.0" encoding="utf-8" ?>
<C:filter xmlns:C="urn:ietf:params:xml:ns:carddav">
<C:prop-filter name="EMAIL" test="allof">
<C:text-match collation="i;ascii-casemap">simon.perreault@viagenie.ca</C:text-match>
<C:param-filter name="TYPE">
<C:text-match match-type="equals" collation="i;unicode-casemap">WORK</C:text-match>
</C:param-filter>
</C:prop-filter>
</C:filter>
"#;
const FILTER_2: &str = r#"
<?xml version="1.0" encoding="utf-8" ?>
<C:filter xmlns:C="urn:ietf:params:xml:ns:carddav">
<C:prop-filter name="EMAIL" test="anyof">
<C:text-match collation="i;ascii-casemap">forrestgump@example.com</C:text-match>
<C:param-filter name="TYPE">
<C:text-match match-type="equals" collation="i;ascii-casemap">WORK</C:text-match>
</C:param-filter>
</C:prop-filter>
</C:filter>
"#;
#[rstest]
#[case(VCF_1, FILTER_1, true)]
#[case(VCF_2, FILTER_1, false)]
#[case(VCF_1, FILTER_2, true)]
#[case(VCF_2, FILTER_2, true)]
fn test_filter(#[case] vcf: &str, #[case] filter: &str, #[case] matches: bool) {
dbg!(vcf);
let obj = AddressObject::from_vcf(String::new(), vcf.to_owned()).unwrap();
let filter = FilterElement::parse_str(filter).unwrap();
assert_eq!(matches, filter.matches(&obj));
}

View File

@@ -1,6 +1,14 @@
use crate::{
CardDavPrincipalUri, Error, address_object::AddressObjectPropWrapperName,
addressbook::AddressbookResourceService,
CardDavPrincipalUri, Error,
address_object::{
AddressObjectPropWrapper, AddressObjectPropWrapperName, resource::AddressObjectResource,
},
addressbook::{
AddressbookResourceService,
methods::report::addressbook_query::{
AddressbookQueryRequest, get_objects_addressbook_query,
},
},
};
use addressbook_multiget::{AddressbookMultigetRequest, handle_addressbook_multiget};
use axum::{
@@ -8,19 +16,30 @@ use axum::{
extract::{OriginalUri, Path, State},
response::IntoResponse,
};
use rustical_dav::xml::{PropfindType, sync_collection::SyncCollectionRequest};
use http::StatusCode;
use rustical_dav::{
resource::{PrincipalUri, Resource},
xml::{
MultistatusElement, PropfindType, multistatus::ResponseElement,
sync_collection::SyncCollectionRequest,
},
};
use rustical_ical::AddressObject;
use rustical_store::{AddressbookStore, SubscriptionStore, auth::Principal};
use rustical_xml::{XmlDeserialize, XmlDocument};
use sync_collection::handle_sync_collection;
use tracing::instrument;
mod addressbook_multiget;
mod addressbook_query;
mod sync_collection;
#[derive(XmlDeserialize, XmlDocument, Clone, Debug, PartialEq)]
pub(crate) enum ReportRequest {
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
AddressbookMultiget(AddressbookMultigetRequest),
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
AddressbookQuery(AddressbookQueryRequest),
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
SyncCollection(SyncCollectionRequest<AddressObjectPropWrapperName>),
}
@@ -29,11 +48,49 @@ impl ReportRequest {
const fn props(&self) -> &PropfindType<AddressObjectPropWrapperName> {
match self {
Self::AddressbookMultiget(AddressbookMultigetRequest { prop, .. })
| Self::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
| Self::SyncCollection(SyncCollectionRequest { prop, .. })
| Self::AddressbookQuery(AddressbookQueryRequest { prop, .. }) => prop,
}
}
}
fn objects_response(
objects: Vec<AddressObject>,
not_found: Vec<String>,
path: &str,
principal: &str,
puri: &impl PrincipalUri,
user: &Principal,
prop: &PropfindType<AddressObjectPropWrapperName>,
) -> Result<MultistatusElement<AddressObjectPropWrapper, String>, Error> {
let mut responses = Vec::new();
for object in objects {
let path = format!("{}/{}.vcf", path, object.get_id());
responses.push(
AddressObjectResource {
object,
principal: principal.to_owned(),
}
.propfind(&path, prop, None, puri, user)?,
);
}
let not_found_responses = not_found
.into_iter()
.map(|path| ResponseElement {
href: path,
status: Some(StatusCode::NOT_FOUND),
..Default::default()
})
.collect();
Ok(MultistatusElement {
responses,
member_responses: not_found_responses,
..Default::default()
})
}
#[instrument(skip(addr_store))]
pub async fn route_report_addressbook<AS: AddressbookStore, S: SubscriptionStore>(
Path((principal, addressbook_id)): Path<(String, String)>,
@@ -75,13 +132,36 @@ pub async fn route_report_addressbook<AS: AddressbookStore, S: SubscriptionStore
)
.await?
}
ReportRequest::AddressbookQuery(addr_query) => {
let objects = get_objects_addressbook_query(
addr_query,
&principal,
&addressbook_id,
addr_store.as_ref(),
)
.await?;
objects_response(
objects,
vec![],
uri.path(),
&principal,
&puri,
&user,
&addr_query.prop,
)?
}
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::address_object::AddressObjectPropName;
use crate::{
address_object::AddressObjectPropName,
addressbook::methods::report::addressbook_query::{
Allof, FilterElement, LimitElement, NresultsElement, PropFilterElement,
},
};
use rustical_dav::xml::{PropElement, sync_collection::SyncLevel};
#[test]
@@ -144,4 +224,50 @@ mod tests {
})
);
}
#[test]
fn test_xml_addressbook_query() {
let report_request = ReportRequest::parse_str(
r#"
<?xml version="1.0" encoding="utf-8"?>
<card:addressbook-query xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">
<d:prop>
<d:getetag/>
</d:prop>
<card:filter>
<card:prop-filter name="FN"/>
</card:filter>
<card:limit>
<card:nresults>100</card:nresults>
</card:limit>
</card:addressbook-query>
"#,
)
.unwrap();
assert_eq!(
report_request,
ReportRequest::AddressbookQuery(AddressbookQueryRequest {
prop: rustical_dav::xml::PropfindType::Prop(PropElement(
vec![AddressObjectPropWrapperName::AddressObject(
AddressObjectPropName::Getetag
),],
vec![]
)),
filter: FilterElement {
test: Allof::default(),
prop_filter: vec![PropFilterElement {
name: "FN".to_owned(),
is_not_defined: None,
text_match: vec![],
param_filter: vec![],
test: Allof::default()
}],
},
limit: Some(LimitElement {
nresults: NresultsElement(100)
})
})
);
}
}

View File

@@ -1,6 +1,7 @@
use derive_more::{From, Into};
use rustical_dav::{
extensions::{CommonPropertiesProp, SyncTokenExtensionProp},
xml::SupportedReportSet,
xml::{SupportedReportSet, TextCollation},
};
use rustical_dav_push::DavPushExtensionProp;
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
@@ -14,9 +15,11 @@ pub enum AddressbookProp {
AddressbookDescription(Option<String>),
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", skip_deserializing)]
SupportedAddressData(SupportedAddressData),
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV", skip_deserializing)]
SupportedCollationSet(SupportedCollationSet),
#[xml(ns = "rustical_dav::namespace::NS_DAV", skip_deserializing)]
SupportedReportSet(SupportedReportSet<ReportMethod>),
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
MaxResourceSize(i64),
}
@@ -60,6 +63,29 @@ impl Default for SupportedAddressData {
}
}
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq, From, Into)]
pub struct SupportedCollation(#[xml(ty = "text")] pub TextCollation);
#[derive(Debug, Clone, XmlSerialize, XmlDeserialize, PartialEq, Eq)]
pub struct SupportedCollationSet(
#[xml(
ns = "rustical_dav::namespace::NS_CARDDAV",
flatten,
rename = "supported-collation"
)]
pub Vec<SupportedCollation>,
);
impl Default for SupportedCollationSet {
fn default() -> Self {
Self(vec![
SupportedCollation(TextCollation::AsciiCasemap),
SupportedCollation(TextCollation::UnicodeCasemap),
SupportedCollation(TextCollation::Octet),
])
}
}
#[derive(Debug, Clone, XmlSerialize, PartialEq, Eq, VariantArray)]
pub enum ReportMethod {
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]

View File

@@ -2,6 +2,7 @@ use super::prop::SupportedAddressData;
use crate::Error;
use crate::addressbook::prop::{
AddressbookProp, AddressbookPropName, AddressbookPropWrapper, AddressbookPropWrapperName,
SupportedCollationSet,
};
use derive_more::derive::{From, Into};
use rustical_dav::extensions::{CommonPropertiesExtension, SyncTokenExtension};
@@ -11,13 +12,14 @@ use rustical_dav::xml::{Resourcetype, ResourcetypeInner, SupportedReportSet};
use rustical_dav_push::DavPushExtension;
use rustical_store::Addressbook;
use rustical_store::auth::Principal;
use std::borrow::Cow;
#[derive(Clone, Debug, From, Into)]
pub struct AddressbookResource(pub(crate) Addressbook);
impl ResourceName for AddressbookResource {
fn get_name(&self) -> String {
self.0.id.clone()
fn get_name(&self) -> Cow<'_, str> {
Cow::from(&self.0.id)
}
}
@@ -61,6 +63,9 @@ impl Resource for AddressbookResource {
AddressbookPropName::MaxResourceSize => {
AddressbookProp::MaxResourceSize(10_000_000)
}
AddressbookPropName::SupportedCollationSet => {
AddressbookProp::SupportedCollationSet(SupportedCollationSet::default())
}
AddressbookPropName::SupportedReportSet => {
AddressbookProp::SupportedReportSet(SupportedReportSet::all())
}
@@ -93,6 +98,7 @@ impl Resource for AddressbookResource {
Ok(())
}
AddressbookProp::MaxResourceSize(_)
| AddressbookProp::SupportedCollationSet(_)
| AddressbookProp::SupportedReportSet(_)
| AddressbookProp::SupportedAddressData(_) => {
Err(rustical_dav::Error::PropReadOnly)
@@ -115,6 +121,7 @@ impl Resource for AddressbookResource {
Ok(())
}
AddressbookPropName::MaxResourceSize
| AddressbookPropName::SupportedCollationSet
| AddressbookPropName::SupportedReportSet
| AddressbookPropName::SupportedAddressData => {
Err(rustical_dav::Error::PropReadOnly)

View File

@@ -31,6 +31,23 @@ ResponseElement {
},
),
),
Addressbook(
SupportedCollationSet(
SupportedCollationSet(
[
SupportedCollation(
AsciiCasemap,
),
SupportedCollation(
UnicodeCasemap,
),
SupportedCollation(
Octet,
),
],
),
),
),
Addressbook(
SupportedReportSet(
SupportedReportSet {

View File

@@ -3,57 +3,62 @@ source: crates/carddav/src/addressbook/tests.rs
expression: response.serialize_to_string().unwrap()
---
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:">
<href>/carddav/principal/user/yeet/</href>
<propstat>
<prop>
<CARD:supported-address-data>
<CARD:address-data-type content-type="text/vcard" version="3.0"/>
<CARD:address-data-type content-type="text/vcard" version="4.0"/>
</CARD:supported-address-data>
<supported-report-set>
<supported-report>
<report>
<CARD:addressbook-multiget/>
<prop xmlns="DAV:">
<supported-address-data xmlns="urn:ietf:params:xml:ns:carddav">
<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="3.0"/>
<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="4.0"/>
</supported-address-data>
<supported-collation-set xmlns="urn:ietf:params:xml:ns:carddav">
<supported-collation xmlns="urn:ietf:params:xml:ns:carddav">i;ascii-casemap</supported-collation>
<supported-collation xmlns="urn:ietf:params:xml:ns:carddav">i;unicode-casemap</supported-collation>
<supported-collation xmlns="urn:ietf:params:xml:ns:carddav">i;octet</supported-collation>
</supported-collation-set>
<supported-report-set xmlns="DAV:">
<supported-report xmlns="DAV:">
<report xmlns="DAV:">
<addressbook-multiget xmlns="urn:ietf:params:xml:ns:carddav"/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
<supported-report xmlns="DAV:">
<report xmlns="DAV:">
<sync-collection xmlns="DAV:"/>
</report>
</supported-report>
</supported-report-set>
<max-resource-size>10000000</max-resource-size>
<sync-token>github.com/lennart-k/rustical/ns/0</sync-token>
<CS:getctag>github.com/lennart-k/rustical/ns/0</CS:getctag>
<PUSH:transports>
<PUSH:web-push/>
</PUSH:transports>
<PUSH:topic>asdasd</PUSH:topic>
<PUSH:supported-triggers>
<PUSH:content-update>
<depth>1</depth>
</PUSH:content-update>
<PUSH:property-update>
<depth>1</depth>
</PUSH:property-update>
</PUSH:supported-triggers>
<resourcetype>
<collection/>
<CARD:addressbook/>
<max-resource-size xmlns="urn:ietf:params:xml:ns:carddav">10000000</max-resource-size>
<sync-token xmlns="DAV:">github.com/lennart-k/rustical/ns/0</sync-token>
<getctag xmlns="http://calendarserver.org/ns/">github.com/lennart-k/rustical/ns/0</getctag>
<transports xmlns="https://bitfire.at/webdav-push">
<web-push xmlns="https://bitfire.at/webdav-push"/>
</transports>
<topic xmlns="https://bitfire.at/webdav-push">asdasd</topic>
<supported-triggers xmlns="https://bitfire.at/webdav-push">
<content-update xmlns="https://bitfire.at/webdav-push">
<depth xmlns="DAV:">1</depth>
</content-update>
<property-update xmlns="https://bitfire.at/webdav-push">
<depth xmlns="DAV:">1</depth>
</property-update>
</supported-triggers>
<resourcetype xmlns="DAV:">
<collection xmlns="DAV:"/>
<addressbook xmlns="urn:ietf:params:xml:ns:carddav"/>
</resourcetype>
<current-user-principal>
<href>/carddav/principal/user/</href>
<current-user-principal xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<current-user-privilege-set xmlns="DAV:">
<privilege>
<all/>
</privilege>
</current-user-privilege-set>
<owner>
<href>/carddav/principal/user/</href>
<owner xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/user/</href>
</owner>
</prop>
<status>HTTP/1.1 200 OK</status>
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
</propstat>
</response>

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use crate::Error;
use rustical_dav::extensions::CommonPropertiesExtension;
use rustical_dav::privileges::UserPrivilegeSet;
@@ -21,8 +23,8 @@ pub struct PrincipalResource {
}
impl ResourceName for PrincipalResource {
fn get_name(&self) -> String {
self.principal.id.clone()
fn get_name(&self) -> Cow<'_, str> {
Cow::from(&self.principal.id)
}
}

View File

@@ -3,43 +3,43 @@ source: crates/carddav/src/principal/tests.rs
expression: response.serialize_to_string().unwrap()
---
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:">
<href>/carddav/principal/user/</href>
<propstat>
<prop>
<principal-URL>
<href>/carddav/principal/user/</href>
<prop xmlns="DAV:">
<principal-URL xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/user/</href>
</principal-URL>
<group-membership>
<href>/carddav/principal/group/</href>
<group-membership xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/group/</href>
</group-membership>
<group-member-set>
<group-member-set xmlns="DAV:">
</group-member-set>
<alternate-URI-set/>
<principal-collection-set>
<href>/carddav/principal/</href>
<alternate-URI-set xmlns="DAV:"/>
<principal-collection-set xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/</href>
</principal-collection-set>
<CARD:addressbook-home-set>
<href>/carddav/principal/group/</href>
<href>/carddav/principal/user/</href>
</CARD:addressbook-home-set>
<resourcetype>
<collection/>
<principal/>
<addressbook-home-set xmlns="urn:ietf:params:xml:ns:carddav">
<href xmlns="DAV:">/carddav/principal/group/</href>
<href xmlns="DAV:">/carddav/principal/user/</href>
</addressbook-home-set>
<resourcetype xmlns="DAV:">
<collection xmlns="DAV:"/>
<principal xmlns="DAV:"/>
</resourcetype>
<displayname>user</displayname>
<current-user-principal>
<href>/carddav/principal/user/</href>
<displayname xmlns="DAV:">user</displayname>
<current-user-principal xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<current-user-privilege-set xmlns="DAV:">
<privilege>
<all/>
</privilege>
</current-user-privilege-set>
<owner>
<href>/carddav/principal/user/</href>
<owner xmlns="DAV:">
<href xmlns="DAV:">/carddav/principal/user/</href>
</owner>
</prop>
<status>HTTP/1.1 200 OK</status>
<status xmlns="DAV:">HTTP/1.1 200 OK</status>
</propstat>
</response>

View File

@@ -28,3 +28,7 @@ headers.workspace = true
strum.workspace = true
matchit.workspace = true
matchit-serde.workspace = true
ical = { workspace = true, optional = true }
[features]
ical = ["dep:ical"]

View File

@@ -53,7 +53,6 @@ pub async fn route_delete<R: ResourceService>(
}
if let Some(if_match) = if_match {
dbg!(&if_match);
if !resource.satisfies_if_match(&if_match) {
// Precondition failed
return Err(crate::Error::PreconditionFailed.into());

View File

@@ -11,6 +11,7 @@ pub use resource_service::ResourceService;
use rustical_xml::{
EnumVariants, NamespaceOwned, PropName, XmlDeserialize, XmlDocument, XmlSerialize,
};
use std::borrow::Cow;
use std::str::FromStr;
mod axum_methods;
@@ -30,7 +31,7 @@ pub trait ResourcePropName: FromStr {}
impl<T: FromStr> ResourcePropName for T {}
pub trait ResourceName {
fn get_name(&self) -> String;
fn get_name(&self) -> Cow<'_, str>;
}
pub trait Resource: Clone + Send + 'static {

View File

@@ -15,3 +15,7 @@ mod report_set;
pub use report_set::SupportedReportSet;
mod group;
pub use group::*;
#[cfg(feature = "ical")]
mod text_match;
#[cfg(feature = "ical")]
pub use text_match::*;

View File

@@ -42,13 +42,6 @@ pub enum PropstatWrapper<T: XmlSerialize> {
// responsedescription?) >
#[derive(XmlSerialize, XmlRootTag, Debug)]
#[xml(ns = "crate::namespace::NS_DAV", root = "response")]
#[xml(ns_prefix(
crate::namespace::NS_DAV = "",
crate::namespace::NS_CARDDAV = "CARD",
crate::namespace::NS_CALDAV = "CAL",
crate::namespace::NS_CALENDARSERVER = "CS",
crate::namespace::NS_DAVPUSH = "PUSH"
))]
pub struct ResponseElement<PropstatType: XmlSerialize> {
pub href: String,
#[xml(serialize_with = "xml_serialize_optional_status")]

View File

@@ -0,0 +1,154 @@
use ical::property::Property;
use rustical_xml::{ValueDeserialize, XmlDeserialize};
use std::borrow::Cow;
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub enum TextCollation {
#[default]
AsciiCasemap,
UnicodeCasemap,
Octet,
}
impl TextCollation {
#[must_use]
pub fn normalise<'a>(&self, value: &'a str) -> Cow<'a, str> {
match self {
// https://datatracker.ietf.org/doc/html/rfc4790#section-9.2
Self::AsciiCasemap => Cow::from(value.to_ascii_uppercase()),
Self::UnicodeCasemap => Cow::from(value.to_uppercase()),
Self::Octet => Cow::from(value),
}
}
}
impl AsRef<str> for TextCollation {
fn as_ref(&self) -> &str {
match self {
Self::AsciiCasemap => "i;ascii-casemap",
Self::UnicodeCasemap => "i;unicode-casemap",
Self::Octet => "i;octet",
}
}
}
impl ValueDeserialize for TextCollation {
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
match val {
"i;ascii-casemap" => Ok(Self::AsciiCasemap),
"i;unicode-casemap" => Ok(Self::UnicodeCasemap),
"i;octet" => Ok(Self::Octet),
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
"Invalid collation: {val}"
))),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct NegateCondition(pub bool);
impl ValueDeserialize for NegateCondition {
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
match val {
"yes" => Ok(Self(true)),
"no" => Ok(Self(false)),
_ => Err(rustical_xml::XmlError::InvalidVariant(format!(
"Invalid negate-condition parameter: {val}"
))),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub enum MatchType {
Equals,
#[default]
Contains,
StartsWith,
EndsWith,
}
impl MatchType {
#[must_use]
pub fn match_text(&self, collation: &TextCollation, needle: &str, haystack: &str) -> bool {
let haystack = collation.normalise(haystack);
let needle = collation.normalise(needle);
match &self {
Self::Equals => haystack == needle,
Self::Contains => haystack.contains(needle.as_ref()),
Self::StartsWith => haystack.starts_with(needle.as_ref()),
Self::EndsWith => haystack.ends_with(needle.as_ref()),
}
}
}
impl ValueDeserialize for MatchType {
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
Ok(match val {
"equals" => Self::Equals,
"contains" => Self::Contains,
"starts-with" => Self::StartsWith,
"ends-with" => Self::EndsWith,
_ => {
return Err(rustical_xml::XmlError::InvalidVariant(format!(
"Invalid match-type parameter: {val}"
)));
}
})
}
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)]
pub struct TextMatchElement {
#[xml(ty = "attr", default = "Default::default")]
pub collation: TextCollation,
#[xml(ty = "attr", default = "Default::default")]
pub negate_condition: NegateCondition,
#[xml(ty = "attr", default = "Default::default")]
pub match_type: MatchType,
#[xml(ty = "text")]
pub needle: String,
}
impl TextMatchElement {
#[must_use]
pub fn match_text(&self, haystack: &str) -> bool {
let Self {
collation,
negate_condition,
needle,
match_type,
} = self;
let matches = match_type.match_text(collation, needle, haystack);
// XOR
negate_condition.0 ^ matches
}
#[must_use]
pub fn match_property(&self, property: &Property) -> bool {
let text = property.value.as_deref().unwrap_or("");
self.match_text(text)
}
}
#[cfg(test)]
mod tests {
use super::TextCollation;
use crate::xml::MatchType;
#[test]
fn test_collation() {
assert!(!MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrÜN", "grünsd"));
assert!(MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrüN", "grün"));
assert!(!MatchType::Contains.match_text(&TextCollation::Octet, "GrüN", "grün"));
assert!(MatchType::Contains.match_text(&TextCollation::UnicodeCasemap, "GrÜN", "grün"));
assert!(MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrüN", "grün"));
assert!(MatchType::Contains.match_text(&TextCollation::AsciiCasemap, "GrüN", "grün"));
assert!(MatchType::StartsWith.match_text(&TextCollation::Octet, "hello", "hello you"));
assert!(MatchType::EndsWith.match_text(&TextCollation::Octet, "mama", "joe mama"));
assert!(MatchType::Equals.match_text(&TextCollation::UnicodeCasemap, "GrÜN", "grün"));
}
}

View File

@@ -11,8 +11,8 @@
]
},
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.5",
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.6",
"lit": "npm:lit@^3.3.1",
"vite": "npm:vite@^7.2.7"
"vite": "npm:vite@^7.3.0"
}
}

View File

@@ -1,145 +1,145 @@
{
"version": "5",
"specifiers": {
"npm:@deno/vite-plugin@^1.0.5": "1.0.5_vite@7.2.7__picomatch@4.0.3",
"npm:@deno/vite-plugin@^1.0.6": "1.0.6_vite@7.3.0__picomatch@4.0.3",
"npm:lit@^3.3.1": "3.3.1",
"npm:vite@*": "7.2.7_picomatch@4.0.3",
"npm:vite@^7.2.7": "7.2.7_picomatch@4.0.3"
"npm:vite@*": "7.3.0_picomatch@4.0.3",
"npm:vite@^7.3.0": "7.3.0_picomatch@4.0.3"
},
"npm": {
"@deno/vite-plugin@1.0.5_vite@7.2.7__picomatch@4.0.3": {
"integrity": "sha512-tLja5n4dyMhcze1NzvSs2iiriBymfBlDCZIrjMTxb9O2ru0gvmV6mn5oBD2teNw5Sd92cj3YJzKwsAs8tMJXlg==",
"@deno/vite-plugin@1.0.6_vite@7.3.0__picomatch@4.0.3": {
"integrity": "sha512-Sh5XqvFuKAwjARTesi0n6xRpEXm1V0UeqKh+SxIrexCofxOaieNDMqXZD02RiZCg0mrJ43V8eCMuVrDfq6mLmg==",
"dependencies": [
"vite"
]
},
"@esbuild/aix-ppc64@0.25.12": {
"integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==",
"@esbuild/aix-ppc64@0.27.1": {
"integrity": "sha512-HHB50pdsBX6k47S4u5g/CaLjqS3qwaOVE5ILsq64jyzgMhLuCuZ8rGzM9yhsAjfjkbgUPMzZEPa7DAp7yz6vuA==",
"os": ["aix"],
"cpu": ["ppc64"]
},
"@esbuild/android-arm64@0.25.12": {
"integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==",
"@esbuild/android-arm64@0.27.1": {
"integrity": "sha512-45fuKmAJpxnQWixOGCrS+ro4Uvb4Re9+UTieUY2f8AEc+t7d4AaZ6eUJ3Hva7dtrxAAWHtlEFsXFMAgNnGU9uQ==",
"os": ["android"],
"cpu": ["arm64"]
},
"@esbuild/android-arm@0.25.12": {
"integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==",
"@esbuild/android-arm@0.27.1": {
"integrity": "sha512-kFqa6/UcaTbGm/NncN9kzVOODjhZW8e+FRdSeypWe6j33gzclHtwlANs26JrupOntlcWmB0u8+8HZo8s7thHvg==",
"os": ["android"],
"cpu": ["arm"]
},
"@esbuild/android-x64@0.25.12": {
"integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==",
"@esbuild/android-x64@0.27.1": {
"integrity": "sha512-LBEpOz0BsgMEeHgenf5aqmn/lLNTFXVfoWMUox8CtWWYK9X4jmQzWjoGoNb8lmAYml/tQ/Ysvm8q7szu7BoxRQ==",
"os": ["android"],
"cpu": ["x64"]
},
"@esbuild/darwin-arm64@0.25.12": {
"integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==",
"@esbuild/darwin-arm64@0.27.1": {
"integrity": "sha512-veg7fL8eMSCVKL7IW4pxb54QERtedFDfY/ASrumK/SbFsXnRazxY4YykN/THYqFnFwJ0aVjiUrVG2PwcdAEqQQ==",
"os": ["darwin"],
"cpu": ["arm64"]
},
"@esbuild/darwin-x64@0.25.12": {
"integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==",
"@esbuild/darwin-x64@0.27.1": {
"integrity": "sha512-+3ELd+nTzhfWb07Vol7EZ+5PTbJ/u74nC6iv4/lwIU99Ip5uuY6QoIf0Hn4m2HoV0qcnRivN3KSqc+FyCHjoVQ==",
"os": ["darwin"],
"cpu": ["x64"]
},
"@esbuild/freebsd-arm64@0.25.12": {
"integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==",
"@esbuild/freebsd-arm64@0.27.1": {
"integrity": "sha512-/8Rfgns4XD9XOSXlzUDepG8PX+AVWHliYlUkFI3K3GB6tqbdjYqdhcb4BKRd7C0BhZSoaCxhv8kTcBrcZWP+xg==",
"os": ["freebsd"],
"cpu": ["arm64"]
},
"@esbuild/freebsd-x64@0.25.12": {
"integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==",
"@esbuild/freebsd-x64@0.27.1": {
"integrity": "sha512-GITpD8dK9C+r+5yRT/UKVT36h/DQLOHdwGVwwoHidlnA168oD3uxA878XloXebK4Ul3gDBBIvEdL7go9gCUFzQ==",
"os": ["freebsd"],
"cpu": ["x64"]
},
"@esbuild/linux-arm64@0.25.12": {
"integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==",
"@esbuild/linux-arm64@0.27.1": {
"integrity": "sha512-W9//kCrh/6in9rWIBdKaMtuTTzNj6jSeG/haWBADqLLa9P8O5YSRDzgD5y9QBok4AYlzS6ARHifAb75V6G670Q==",
"os": ["linux"],
"cpu": ["arm64"]
},
"@esbuild/linux-arm@0.25.12": {
"integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==",
"@esbuild/linux-arm@0.27.1": {
"integrity": "sha512-ieMID0JRZY/ZeCrsFQ3Y3NlHNCqIhTprJfDgSB3/lv5jJZ8FX3hqPyXWhe+gvS5ARMBJ242PM+VNz/ctNj//eA==",
"os": ["linux"],
"cpu": ["arm"]
},
"@esbuild/linux-ia32@0.25.12": {
"integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==",
"@esbuild/linux-ia32@0.27.1": {
"integrity": "sha512-VIUV4z8GD8rtSVMfAj1aXFahsi/+tcoXXNYmXgzISL+KB381vbSTNdeZHHHIYqFyXcoEhu9n5cT+05tRv13rlw==",
"os": ["linux"],
"cpu": ["ia32"]
},
"@esbuild/linux-loong64@0.25.12": {
"integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==",
"@esbuild/linux-loong64@0.27.1": {
"integrity": "sha512-l4rfiiJRN7sTNI//ff65zJ9z8U+k6zcCg0LALU5iEWzY+a1mVZ8iWC1k5EsNKThZ7XCQ6YWtsZ8EWYm7r1UEsg==",
"os": ["linux"],
"cpu": ["loong64"]
},
"@esbuild/linux-mips64el@0.25.12": {
"integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==",
"@esbuild/linux-mips64el@0.27.1": {
"integrity": "sha512-U0bEuAOLvO/DWFdygTHWY8C067FXz+UbzKgxYhXC0fDieFa0kDIra1FAhsAARRJbvEyso8aAqvPdNxzWuStBnA==",
"os": ["linux"],
"cpu": ["mips64el"]
},
"@esbuild/linux-ppc64@0.25.12": {
"integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==",
"@esbuild/linux-ppc64@0.27.1": {
"integrity": "sha512-NzdQ/Xwu6vPSf/GkdmRNsOfIeSGnh7muundsWItmBsVpMoNPVpM61qNzAVY3pZ1glzzAxLR40UyYM23eaDDbYQ==",
"os": ["linux"],
"cpu": ["ppc64"]
},
"@esbuild/linux-riscv64@0.25.12": {
"integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==",
"@esbuild/linux-riscv64@0.27.1": {
"integrity": "sha512-7zlw8p3IApcsN7mFw0O1Z1PyEk6PlKMu18roImfl3iQHTnr/yAfYv6s4hXPidbDoI2Q0pW+5xeoM4eTCC0UdrQ==",
"os": ["linux"],
"cpu": ["riscv64"]
},
"@esbuild/linux-s390x@0.25.12": {
"integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==",
"@esbuild/linux-s390x@0.27.1": {
"integrity": "sha512-cGj5wli+G+nkVQdZo3+7FDKC25Uh4ZVwOAK6A06Hsvgr8WqBBuOy/1s+PUEd/6Je+vjfm6stX0kmib5b/O2Ykw==",
"os": ["linux"],
"cpu": ["s390x"]
},
"@esbuild/linux-x64@0.25.12": {
"integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==",
"@esbuild/linux-x64@0.27.1": {
"integrity": "sha512-z3H/HYI9MM0HTv3hQZ81f+AKb+yEoCRlUby1F80vbQ5XdzEMyY/9iNlAmhqiBKw4MJXwfgsh7ERGEOhrM1niMA==",
"os": ["linux"],
"cpu": ["x64"]
},
"@esbuild/netbsd-arm64@0.25.12": {
"integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==",
"@esbuild/netbsd-arm64@0.27.1": {
"integrity": "sha512-wzC24DxAvk8Em01YmVXyjl96Mr+ecTPyOuADAvjGg+fyBpGmxmcr2E5ttf7Im8D0sXZihpxzO1isus8MdjMCXQ==",
"os": ["netbsd"],
"cpu": ["arm64"]
},
"@esbuild/netbsd-x64@0.25.12": {
"integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==",
"@esbuild/netbsd-x64@0.27.1": {
"integrity": "sha512-1YQ8ybGi2yIXswu6eNzJsrYIGFpnlzEWRl6iR5gMgmsrR0FcNoV1m9k9sc3PuP5rUBLshOZylc9nqSgymI+TYg==",
"os": ["netbsd"],
"cpu": ["x64"]
},
"@esbuild/openbsd-arm64@0.25.12": {
"integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==",
"@esbuild/openbsd-arm64@0.27.1": {
"integrity": "sha512-5Z+DzLCrq5wmU7RDaMDe2DVXMRm2tTDvX2KU14JJVBN2CT/qov7XVix85QoJqHltpvAOZUAc3ndU56HSMWrv8g==",
"os": ["openbsd"],
"cpu": ["arm64"]
},
"@esbuild/openbsd-x64@0.25.12": {
"integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==",
"@esbuild/openbsd-x64@0.27.1": {
"integrity": "sha512-Q73ENzIdPF5jap4wqLtsfh8YbYSZ8Q0wnxplOlZUOyZy7B4ZKW8DXGWgTCZmF8VWD7Tciwv5F4NsRf6vYlZtqg==",
"os": ["openbsd"],
"cpu": ["x64"]
},
"@esbuild/openharmony-arm64@0.25.12": {
"integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==",
"@esbuild/openharmony-arm64@0.27.1": {
"integrity": "sha512-ajbHrGM/XiK+sXM0JzEbJAen+0E+JMQZ2l4RR4VFwvV9JEERx+oxtgkpoKv1SevhjavK2z2ReHk32pjzktWbGg==",
"os": ["openharmony"],
"cpu": ["arm64"]
},
"@esbuild/sunos-x64@0.25.12": {
"integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==",
"@esbuild/sunos-x64@0.27.1": {
"integrity": "sha512-IPUW+y4VIjuDVn+OMzHc5FV4GubIwPnsz6ubkvN8cuhEqH81NovB53IUlrlBkPMEPxvNnf79MGBoz8rZ2iW8HA==",
"os": ["sunos"],
"cpu": ["x64"]
},
"@esbuild/win32-arm64@0.25.12": {
"integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==",
"@esbuild/win32-arm64@0.27.1": {
"integrity": "sha512-RIVRWiljWA6CdVu8zkWcRmGP7iRRIIwvhDKem8UMBjPql2TXM5PkDVvvrzMtj1V+WFPB4K7zkIGM7VzRtFkjdg==",
"os": ["win32"],
"cpu": ["arm64"]
},
"@esbuild/win32-ia32@0.25.12": {
"integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==",
"@esbuild/win32-ia32@0.27.1": {
"integrity": "sha512-2BR5M8CPbptC1AK5JbJT1fWrHLvejwZidKx3UMSF0ecHMa+smhi16drIrCEggkgviBwLYd5nwrFLSl5Kho96RQ==",
"os": ["win32"],
"cpu": ["ia32"]
},
"@esbuild/win32-x64@0.25.12": {
"integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==",
"@esbuild/win32-x64@0.27.1": {
"integrity": "sha512-d5X6RMYv6taIymSk8JBP+nxv8DQAMY6A51GPgusqLdK9wBz5wWIXy1KjTck6HnjE9hqJzJRdk+1p/t5soSbCtw==",
"os": ["win32"],
"cpu": ["x64"]
},
@@ -268,8 +268,8 @@
"@types/trusted-types@2.0.7": {
"integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw=="
},
"esbuild@0.25.12": {
"integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==",
"esbuild@0.27.1": {
"integrity": "sha512-yY35KZckJJuVVPXpvjgxiCuVEJT67F6zDeVTv4rizyPrfGBUpZQsvmxnN+C371c2esD/hNMjj4tpBhuueLN7aA==",
"optionalDependencies": [
"@esbuild/aix-ppc64",
"@esbuild/android-arm",
@@ -397,8 +397,8 @@
"picomatch"
]
},
"vite@7.2.7_picomatch@4.0.3": {
"integrity": "sha512-ITcnkFeR3+fI8P1wMgItjGrR10170d8auB4EpMLPqmx6uxElH3a/hHGQabSHKdqd4FXWO1nFIp9rRn7JQ34ACQ==",
"vite@7.3.0_picomatch@4.0.3": {
"integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==",
"dependencies": [
"esbuild",
"fdir",
@@ -415,9 +415,9 @@
},
"workspace": {
"dependencies": [
"npm:@deno/vite-plugin@^1.0.5",
"npm:@deno/vite-plugin@^1.0.6",
"npm:lit@^3.3.1",
"npm:vite@^7.2.7"
"npm:vite@^7.3.0"
]
}
}

View File

@@ -1,4 +1,4 @@
const t$3 = globalThis, e$4 = t$3.ShadowRoot && (void 0 === t$3.ShadyCSS || t$3.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, s$3 = Symbol(), o$6 = /* @__PURE__ */ new WeakMap();
const t$3 = globalThis, e$4 = t$3.ShadowRoot && (void 0 === t$3.ShadyCSS || t$3.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, s$3 = /* @__PURE__ */ Symbol(), o$6 = /* @__PURE__ */ new WeakMap();
let n$5 = class n {
constructor(t2, e2, o2) {
if (this._$cssResult$ = true, o2 !== s$3) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
@@ -57,7 +57,7 @@ const { is: i$3, defineProperty: e$3, getOwnPropertyDescriptor: h$3, getOwnPrope
}
return i3;
} }, f$3 = (t2, s2) => !i$3(t2, s2), b$1 = { attribute: true, type: String, converter: u$1, reflect: false, useDefault: false, hasChanged: f$3 };
Symbol.metadata ??= Symbol("metadata"), a$1.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
Symbol.metadata ??= /* @__PURE__ */ Symbol("metadata"), a$1.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
let y$1 = class y extends HTMLElement {
static addInitializer(t2) {
this._$Ei(), (this.l ??= []).push(t2);
@@ -67,7 +67,7 @@ let y$1 = class y extends HTMLElement {
}
static createProperty(t2, s2 = b$1) {
if (s2.state && (s2.attribute = false), this._$Ei(), this.prototype.hasOwnProperty(t2) && ((s2 = Object.create(s2)).wrapped = true), this.elementProperties.set(t2, s2), !s2.noAccessor) {
const i3 = Symbol(), h2 = this.getPropertyDescriptor(t2, i3, s2);
const i3 = /* @__PURE__ */ Symbol(), h2 = this.getPropertyDescriptor(t2, i3, s2);
void 0 !== h2 && e$3(this.prototype, t2, h2);
}
}
@@ -241,7 +241,7 @@ let y$1 = class y extends HTMLElement {
};
y$1.elementStyles = [], y$1.shadowRootOptions = { mode: "open" }, y$1[d$1("elementProperties")] = /* @__PURE__ */ new Map(), y$1[d$1("finalized")] = /* @__PURE__ */ new Map(), p$1?.({ ReactiveElement: y$1 }), (a$1.reactiveElementVersions ??= []).push("2.1.1");
const t$2 = globalThis, i$2 = t$2.trustedTypes, s$2 = i$2 ? i$2.createPolicy("lit-html", { createHTML: (t2) => t2 }) : void 0, e$2 = "$lit$", h$2 = `lit$${Math.random().toFixed(9).slice(2)}$`, o$4 = "?" + h$2, n$3 = `<${o$4}>`, r$2 = document, l = () => r$2.createComment(""), c$1 = (t2) => null === t2 || "object" != typeof t2 && "function" != typeof t2, a = Array.isArray, u = (t2) => a(t2) || "function" == typeof t2?.[Symbol.iterator], d = "[ \n\f\r]", f$2 = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, v = /-->/g, _ = />/g, m = RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^
\f\r"'\`<>=]|("|')|))|$)`, "g"), p = /'/g, g = /"/g, $ = /^(?:script|style|textarea|title)$/i, y2 = (t2) => (i3, ...s2) => ({ _$litType$: t2, strings: i3, values: s2 }), x = y2(1), b = y2(2), T = Symbol.for("lit-noChange"), E = Symbol.for("lit-nothing"), A = /* @__PURE__ */ new WeakMap(), C = r$2.createTreeWalker(r$2, 129);
\f\r"'\`<>=]|("|')|))|$)`, "g"), p = /'/g, g = /"/g, $ = /^(?:script|style|textarea|title)$/i, y2 = (t2) => (i3, ...s2) => ({ _$litType$: t2, strings: i3, values: s2 }), x = y2(1), b = y2(2), T = /* @__PURE__ */ Symbol.for("lit-noChange"), E = /* @__PURE__ */ Symbol.for("lit-nothing"), A = /* @__PURE__ */ new WeakMap(), C = r$2.createTreeWalker(r$2, 129);
function P(t2, i3) {
if (!a(t2) || !t2.hasOwnProperty("raw")) throw Error("invalid template strings array");
return void 0 !== s$2 ? s$2.createHTML(i3) : i3;

View File

@@ -9,9 +9,9 @@ use axum::{
extract::Path,
response::{Html, IntoResponse, Response},
};
use axum_extra::{TypedHeader, extract::Host};
use axum_extra::TypedHeader;
use chrono::{Duration, Utc};
use headers::UserAgent;
use headers::{Host, UserAgent};
use http::StatusCode;
use rustical_store::auth::{AuthenticationProvider, Principal};
use serde::{Deserialize, Serialize};
@@ -21,7 +21,7 @@ use tracing::instrument;
pub async fn post_nextcloud_login(
Extension(state): Extension<Arc<NextcloudFlows>>,
TypedHeader(user_agent): TypedHeader<UserAgent>,
Host(host): Host,
TypedHeader(host): TypedHeader<Host>,
) -> Json<NextcloudLoginResponse> {
let flow_id = uuid::Uuid::new_v4().to_string();
let token = uuid::Uuid::new_v4().to_string();
@@ -150,7 +150,7 @@ pub async fn post_nextcloud_flow(
user: Principal,
Extension(state): Extension<Arc<NextcloudFlows>>,
Path(flow_id): Path<String>,
Host(host): Host,
TypedHeader(host): TypedHeader<Host>,
Form(form): Form<NextcloudAuthorizeForm>,
) -> Result<Response, rustical_store::Error> {
if let Some(flow) = state.flows.write().await.get_mut(&flow_id) {

View File

@@ -7,8 +7,8 @@ use axum::{
extract::Path,
response::{IntoResponse, Redirect, Response},
};
use axum_extra::extract::Host;
use headers::{ContentType, HeaderMapExt};
use axum_extra::TypedHeader;
use headers::{ContentType, HeaderMapExt, Host};
use http::{HeaderValue, StatusCode, header};
use percent_encoding::{CONTROLS, utf8_percent_encode};
use rand::{Rng, distr::Alphanumeric};
@@ -50,7 +50,7 @@ pub async fn route_post_app_token<AP: AuthenticationProvider>(
user: Principal,
Extension(auth_provider): Extension<Arc<AP>>,
Path(user_id): Path<String>,
Host(hostname): Host,
TypedHeader(host): TypedHeader<Host>,
Form(PostAppTokenForm { apple, name }): Form<PostAppTokenForm>,
) -> Result<Response, rustical_store::Error> {
assert!(!name.is_empty());
@@ -66,10 +66,10 @@ pub async fn route_post_app_token<AP: AuthenticationProvider>(
if apple {
let profile = AppleConfig {
token_name: name,
account_description: format!("{}@{}", &user.id, &hostname),
hostname: hostname.clone(),
caldav_principal_url: format!("https://{hostname}/caldav-compat/principal/{user_id}"),
carddav_principal_url: format!("https://{hostname}/carddav/principal/{user_id}"),
account_description: format!("{}@{}", &user.id, &host),
hostname: host.to_string(),
caldav_principal_url: format!("https://{host}/caldav-compat/principal/{user_id}"),
carddav_principal_url: format!("https://{host}/carddav/principal/{user_id}"),
user: user.id.clone(),
token,
caldav_profile_uuid: Uuid::new_v4(),

View File

@@ -1,5 +1,3 @@
use std::sync::Arc;
use crate::{FrontendConfig, OidcConfig, pages::DefaultLayoutData};
use askama::Template;
use askama_web::WebTemplate;
@@ -8,10 +6,12 @@ use axum::{
extract::Query,
response::{IntoResponse, Redirect, Response},
};
use axum_extra::extract::Host;
use axum_extra::TypedHeader;
use headers::Host;
use http::StatusCode;
use rustical_store::auth::AuthenticationProvider;
use serde::Deserialize;
use std::sync::Arc;
use tower_sessions::Session;
use tracing::{instrument, warn};
use url::Url;
@@ -73,7 +73,7 @@ pub async fn route_post_login<AP: AuthenticationProvider>(
Extension(auth_provider): Extension<Arc<AP>>,
Extension(config): Extension<FrontendConfig>,
session: Session,
Host(host): Host,
TypedHeader(host): TypedHeader<Host>,
Form(PostLoginForm {
username,
password,

View File

@@ -1,5 +1,6 @@
use std::sync::Arc;
use crate::pages::user::{Section, UserPage};
use askama::Template;
use askama_web::WebTemplate;
use axum::{
@@ -7,13 +8,11 @@ use axum::{
extract::Path,
response::{IntoResponse, Redirect},
};
use axum_extra::{TypedHeader, extract::Host};
use headers::UserAgent;
use axum_extra::TypedHeader;
use headers::{Host, UserAgent};
use http::StatusCode;
use rustical_store::auth::{AppToken, AuthenticationProvider, Principal};
use crate::pages::user::{Section, UserPage};
impl Section for ProfileSection {
fn name() -> &'static str {
"profile"
@@ -33,7 +32,7 @@ pub async fn route_user_named<AP: AuthenticationProvider>(
Path(user_id): Path<String>,
Extension(auth_provider): Extension<Arc<AP>>,
TypedHeader(user_agent): TypedHeader<UserAgent>,
Host(host): Host,
TypedHeader(host): TypedHeader<Host>,
user: Principal,
) -> impl IntoResponse {
if user_id != user.id {
@@ -41,7 +40,10 @@ pub async fn route_user_named<AP: AuthenticationProvider>(
}
let is_apple = user_agent.as_str().contains("Apple") || user_agent.as_str().contains("Mac OS");
let davx5_hostname = user_agent.as_str().contains("Android").then_some(host);
let davx5_hostname = user_agent
.as_str()
.contains("Android")
.then_some(host.to_string());
UserPage {
section: ProfileSection {

View File

@@ -179,4 +179,9 @@ END:VCALENDAR",
}
Ok(out)
}
#[must_use]
pub const fn get_vcard(&self) -> &VcardContact {
&self.vcard
}
}

View File

@@ -99,85 +99,85 @@ impl EventObject {
end: Option<DateTime<Utc>>,
overrides: &[Self],
) -> Result<Vec<IcalEvent>, Error> {
if let Some(mut rrule_set) = self.recurrence_ruleset()? {
if let Some(start) = start {
rrule_set = rrule_set.after(start.with_timezone(&rrule::Tz::UTC));
}
if let Some(end) = end {
rrule_set = rrule_set.before(end.with_timezone(&rrule::Tz::UTC));
}
let mut events = vec![];
let dates = rrule_set.all(2048).dates;
let dtstart = self.get_dtstart()?.expect("We must have a DTSTART here");
let computed_duration = self
.get_dtend()?
.map(|dtend| dtend.as_datetime().into_owned() - dtstart.as_datetime().into_owned());
let Some(mut rrule_set) = self.recurrence_ruleset()? else {
return Ok(vec![self.event.clone()]);
};
'recurrence: for date in dates {
let date = CalDateTime::from(date);
let dateformat = if dtstart.is_date() {
date.format_date()
} else {
date.format()
};
for ev_override in overrides {
if let Some(override_id) = &ev_override
.event
.get_recurrence_id()
.as_ref()
.expect("overrides have a recurrence id")
.value
&& override_id == &dateformat
{
// We have an override for this occurence
//
events.push(ev_override.event.clone());
continue 'recurrence;
}
}
let mut ev = self.event.clone().mutable();
ev.remove_property("RRULE");
ev.remove_property("RDATE");
ev.remove_property("EXDATE");
ev.remove_property("EXRULE");
let dtstart_prop = ev
.get_property("DTSTART")
.expect("We must have a DTSTART here")
.clone();
ev.remove_property("DTSTART");
ev.remove_property("DTEND");
ev.set_property(Property {
name: "RECURRENCE-ID".to_string(),
value: Some(dateformat.clone()),
params: None,
});
ev.set_property(Property {
name: "DTSTART".to_string(),
value: Some(dateformat),
params: dtstart_prop.params.clone(),
});
if let Some(duration) = computed_duration {
let dtend = date + duration;
let dtendformat = if dtstart.is_date() {
dtend.format_date()
} else {
dtend.format()
};
ev.set_property(Property {
name: "DTEND".to_string(),
value: Some(dtendformat),
params: dtstart_prop.params,
});
}
events.push(ev.verify()?);
}
Ok(events)
} else {
Ok(vec![self.event.clone()])
if let Some(start) = start {
rrule_set = rrule_set.after(start.with_timezone(&rrule::Tz::UTC));
}
if let Some(end) = end {
rrule_set = rrule_set.before(end.with_timezone(&rrule::Tz::UTC));
}
let mut events = vec![];
let dates = rrule_set.all(2048).dates;
let dtstart = self.get_dtstart()?.expect("We must have a DTSTART here");
let computed_duration = self
.get_dtend()?
.map(|dtend| dtend.as_datetime().into_owned() - dtstart.as_datetime().as_ref());
'recurrence: for date in dates {
let date = CalDateTime::from(date);
let dateformat = if dtstart.is_date() {
date.format_date()
} else {
date.format()
};
for ev_override in overrides {
if let Some(override_id) = &ev_override
.event
.get_recurrence_id()
.as_ref()
.expect("overrides have a recurrence id")
.value
&& override_id == &dateformat
{
// We have an override for this occurence
//
events.push(ev_override.event.clone());
continue 'recurrence;
}
}
let mut ev = self.event.clone().mutable();
ev.remove_property("RRULE");
ev.remove_property("RDATE");
ev.remove_property("EXDATE");
ev.remove_property("EXRULE");
let dtstart_prop = ev
.get_property("DTSTART")
.expect("We must have a DTSTART here")
.clone();
ev.remove_property("DTSTART");
ev.remove_property("DTEND");
ev.set_property(Property {
name: "RECURRENCE-ID".to_string(),
value: Some(dateformat.clone()),
params: vec![],
});
ev.set_property(Property {
name: "DTSTART".to_string(),
value: Some(dateformat),
params: dtstart_prop.params.clone(),
});
if let Some(duration) = computed_duration {
let dtend = date + duration;
let dtendformat = if dtstart.is_date() {
dtend.format_date()
} else {
dtend.format()
};
ev.set_property(Property {
name: "DTEND".to_string(),
value: Some(dtendformat),
params: dtstart_prop.params,
});
}
events.push(ev.verify()?);
}
Ok(events)
}
}

View File

@@ -328,4 +328,12 @@ impl CalendarObject {
.iter()
.find(|property| property.name == name)
}
#[must_use]
pub fn get_named_properties(&self, name: &str) -> Vec<&Property> {
self.properties
.iter()
.filter(|property| property.name == name)
.collect()
}
}

View File

@@ -5,10 +5,11 @@ use axum::{
extract::Query,
response::{IntoResponse, Redirect, Response},
};
use axum_extra::extract::Host;
use axum_extra::TypedHeader;
pub use config::OidcConfig;
use config::UserIdClaim;
use error::OidcError;
use headers::Host;
use openidconnect::{
AuthenticationFlow, AuthorizationCode, CsrfToken, EndpointMaybeSet, EndpointNotSet,
EndpointSet, IssuerUrl, Nonce, OAuth2TokenResponse, PkceCodeChallenge, PkceCodeVerifier,
@@ -100,7 +101,7 @@ pub struct GetOidcForm {
pub async fn route_post_oidc(
Extension(oidc_config): Extension<OidcConfig>,
session: Session,
Host(host): Host,
TypedHeader(host): TypedHeader<Host>,
Form(GetOidcForm { redirect_uri }): Form<GetOidcForm>,
) -> Result<Response, OidcError> {
let callback_uri = format!("https://{host}/frontend/login/oidc/callback");
@@ -155,7 +156,7 @@ pub async fn route_get_oidc_callback<US: UserStore + Clone>(
Extension(service_config): Extension<OidcServiceConfig>,
session: Session,
Query(AuthCallbackQuery { code, iss, state }): Query<AuthCallbackQuery>,
Host(host): Host,
TypedHeader(host): TypedHeader<Host>,
) -> Result<Response, OidcError> {
let callback_uri = format!("https://{host}/frontend/login/oidc/callback");

View File

@@ -77,13 +77,23 @@ pub trait CalendarStore: Send + Sync + 'static {
object_id: &str,
show_deleted: bool,
) -> Result<CalendarObject, Error>;
async fn put_objects(
&self,
principal: String,
cal_id: String,
objects: Vec<CalendarObject>,
overwrite: bool,
) -> Result<(), Error>;
async fn put_object(
&self,
principal: String,
cal_id: String,
object: CalendarObject,
overwrite: bool,
) -> Result<(), Error>;
) -> Result<(), Error> {
self.put_objects(principal, cal_id, vec![object], overwrite)
.await
}
async fn delete_object(
&self,
principal: &str,

View File

@@ -147,15 +147,15 @@ impl CalendarStore for CombinedCalendarStore {
.await
}
async fn put_object(
async fn put_objects(
&self,
principal: String,
cal_id: String,
object: rustical_ical::CalendarObject,
objects: Vec<rustical_ical::CalendarObject>,
overwrite: bool,
) -> Result<(), crate::Error> {
self.store_for_id(&cal_id)
.put_object(principal, cal_id, object, overwrite)
.put_objects(principal, cal_id, objects, overwrite)
.await
}

View File

@@ -11,8 +11,13 @@ publish = false
[features]
test = ["dep:rstest"]
[[bench]]
name = "insert_calendar_object"
harness = false
[dev-dependencies]
rstest.workspace = true
criterion.workspace = true
[dependencies]
tokio.workspace = true

View File

@@ -0,0 +1,47 @@
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Ximian//NONSGML Evolution Calendar//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;UNTIL=20370329T010000Z;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;UNTIL=20361026T010000Z;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:fa915b604e6e3f36772501ff869439e6a3c5cf67
DTSTAMP:20250726T112617Z
DTSTART;VALUE=DATE:20250806
DTEND;VALUE=DATE:20250807
SEQUENCE:2
SUMMARY:all day event
TRANSP:OPAQUE
CLASS:PUBLIC
CREATED:20250726T144426Z
LAST-MODIFIED:20250726T144426Z
BEGIN:VALARM
TRIGGER:-PT30M
REPEAT:2
DURATION:PT15M
ACTION:DISPLAY
DESCRIPTION:Breakfast meeting with executive\n
team at 8:30 AM EST.
END:VALARM
END:VEVENT
END:VCALENDAR

View File

@@ -0,0 +1,70 @@
use criterion::{Criterion, criterion_group, criterion_main};
use rustical_ical::{CalendarObject, CalendarObjectType};
use rustical_store::{Calendar, CalendarMetadata, CalendarStore};
use rustical_store_sqlite::tests::test_store_context;
fn benchmark(c: &mut Criterion) {
let runtime = tokio::runtime::Runtime::new().unwrap();
let cal_store = runtime.block_on(async {
let cal_store = test_store_context().await.cal_store;
cal_store
.insert_calendar(Calendar {
meta: CalendarMetadata {
displayname: Some("Yeet".to_owned()),
order: 0,
description: None,
color: None,
},
principal: "user".to_owned(),
id: "okwow".to_owned(),
timezone_id: None,
deleted_at: None,
synctoken: 0,
subscription_url: None,
push_topic: "asd".to_owned(),
components: vec![
CalendarObjectType::Event,
CalendarObjectType::Todo,
CalendarObjectType::Journal,
],
})
.await
.unwrap();
cal_store
});
let object = CalendarObject::from_ics(include_str!("ical_event.ics").to_owned(), None).unwrap();
let batch_size = 1000;
let objects: Vec<_> = std::iter::repeat_n(object.clone(), batch_size).collect();
c.bench_function("put_batch", |b| {
b.to_async(&runtime).iter(async || {
// yeet
cal_store
.put_objects("user".to_owned(), "okwow".to_owned(), objects.clone(), true)
.await
.unwrap();
});
});
c.bench_function("put_single", |b| {
b.to_async(&runtime).iter(async || {
// yeet
for _ in 0..1000 {
cal_store
.put_object("user".to_owned(), "okwow".to_owned(), object.clone(), true)
.await
.unwrap();
}
});
});
runtime
.block_on(cal_store.delete_calendar("user", "okwow", false))
.unwrap();
}
criterion_group!(benches, benchmark);
criterion_main!(benches);

View File

@@ -394,11 +394,11 @@ impl CalendarStore for SqliteAddressbookStore {
}
#[instrument]
async fn put_object(
async fn put_objects(
&self,
_principal: String,
_cal_id: String,
_object: CalendarObject,
_objects: Vec<CalendarObject>,
_overwrite: bool,
) -> Result<(), Error> {
Err(Error::ReadOnly)

View File

@@ -27,7 +27,7 @@ impl TryFrom<AddressObjectRow> for AddressObject {
}
}
#[derive(Debug, Constructor)]
#[derive(Debug, Clone, Constructor)]
pub struct SqliteAddressbookStore {
db: SqlitePool,
sender: Sender<CollectionOperation>,

View File

@@ -87,7 +87,7 @@ impl From<CalendarRow> for Calendar {
}
}
#[derive(Debug, Constructor)]
#[derive(Debug, Clone, Constructor)]
pub struct SqliteCalendarStore {
db: SqlitePool,
sender: Sender<CollectionOperation>,
@@ -776,11 +776,11 @@ impl CalendarStore for SqliteCalendarStore {
}
#[instrument]
async fn put_object(
async fn put_objects(
&self,
principal: String,
cal_id: String,
object: CalendarObject,
objects: Vec<CalendarObject>,
overwrite: bool,
) -> Result<(), Error> {
let mut tx = self
@@ -789,33 +789,37 @@ impl CalendarStore for SqliteCalendarStore {
.await
.map_err(crate::Error::from)?;
let object_id = object.get_id().to_owned();
let calendar = Self::_get_calendar(&mut *tx, &principal, &cal_id, true).await?;
if calendar.subscription_url.is_some() {
// We cannot commit an object to a subscription calendar
return Err(Error::ReadOnly);
}
Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?;
let sync_token = Self::log_object_operation(
&mut tx,
&principal,
&cal_id,
&object_id,
ChangeOperation::Add,
)
.await?;
let mut sync_token = None;
for object in objects {
sync_token = Some(
Self::log_object_operation(
&mut tx,
&principal,
&cal_id,
object.get_id(),
ChangeOperation::Add,
)
.await?,
);
Self::_put_object(&mut *tx, &principal, &cal_id, &object, overwrite).await?;
}
tx.commit().await.map_err(crate::Error::from)?;
self.send_push_notification(
CollectionOperationInfo::Content { sync_token },
self.get_calendar(&principal, &cal_id, true)
.await?
.push_topic,
);
if let Some(sync_token) = sync_token {
self.send_push_notification(
CollectionOperationInfo::Content { sync_token },
self.get_calendar(&principal, &cal_id, true)
.await?
.push_topic,
);
}
Ok(())
}

View File

@@ -24,7 +24,7 @@ pub(crate) enum ChangeOperation {
Delete,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct SqliteStore {
db: SqlitePool,
}

View File

@@ -41,7 +41,7 @@ impl TryFrom<PrincipalRow> for Principal {
}
}
#[derive(Debug, Constructor)]
#[derive(Debug, Clone, Constructor)]
pub struct SqlitePrincipalStore {
db: SqlitePool,
}

View File

@@ -1,17 +1,17 @@
#[cfg(test)]
mod tests {
use crate::{addressbook_store::SqliteAddressbookStore, tests::get_test_addressbook_store};
use crate::tests::{TestStoreContext, test_store_context};
use rstest::rstest;
use rustical_store::{Addressbook, AddressbookStore};
#[rstest]
#[tokio::test]
async fn test_addressbook_store(
#[from(get_test_addressbook_store)]
#[from(test_store_context)]
#[future]
addr_store: SqliteAddressbookStore,
context: TestStoreContext,
) {
let addr_store = addr_store.await;
let addr_store = context.await.addr_store;
let cal = Addressbook {
id: "addr".to_string(),

View File

@@ -1,17 +1,19 @@
#[cfg(test)]
mod tests {
use crate::{calendar_store::SqliteCalendarStore, tests::get_test_calendar_store};
use crate::tests::{TestStoreContext, test_store_context};
use rstest::rstest;
use rustical_store::{Calendar, CalendarMetadata, CalendarStore};
#[rstest]
#[tokio::test]
async fn test_calendar_store(
#[from(get_test_calendar_store)]
#[future]
cal_store: SqliteCalendarStore,
#[from(test_store_context)]
context: TestStoreContext,
) {
let cal_store = cal_store.await;
let TestStoreContext { cal_store, .. } = context.await;
let cal_store = cal_store;
let cal = Calendar {
principal: "fake-user".to_string(),

View File

@@ -2,64 +2,59 @@ use crate::{
SqliteStore, addressbook_store::SqliteAddressbookStore, calendar_store::SqliteCalendarStore,
principal_store::SqlitePrincipalStore,
};
use rustical_store::{
Secret,
auth::{AuthenticationProvider, Principal, PrincipalType},
};
use rstest::fixture;
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
use sqlx::SqlitePool;
use tokio::sync::OnceCell;
static DB: OnceCell<SqlitePool> = OnceCell::const_new();
mod addressbook_store;
mod calendar_store;
async fn get_test_db() -> SqlitePool {
DB.get_or_init(async || {
let db = SqlitePool::connect("sqlite::memory:").await.unwrap();
sqlx::migrate!("./migrations").run(&db).await.unwrap();
let db = SqlitePool::connect("sqlite::memory:").await.unwrap();
sqlx::migrate!("./migrations").run(&db).await.unwrap();
// Populate with test data
let principal_store = SqlitePrincipalStore::new(db.clone());
principal_store
.insert_principal(
Principal {
id: "user".to_owned(),
displayname: None,
memberships: vec![],
password: None,
principal_type: PrincipalType::Individual,
},
false,
)
.await
.unwrap();
principal_store
.add_app_token("user", "test".to_string(), "pass".to_string())
.await
.unwrap();
// Populate with test data
let principal_store = SqlitePrincipalStore::new(db.clone());
principal_store
.insert_principal(
Principal {
id: "user".to_owned(),
displayname: None,
memberships: vec![],
password: None,
principal_type: PrincipalType::Individual,
},
false,
)
.await
.unwrap();
principal_store
.add_app_token("user", "test".to_string(), "pass".to_string())
.await
.unwrap();
db
})
.await
.clone()
db
}
#[rstest::fixture]
pub async fn get_test_addressbook_store() -> SqliteAddressbookStore {
let (send, _recv) = tokio::sync::mpsc::channel(1000);
SqliteAddressbookStore::new(get_test_db().await, send)
#[derive(Debug, Clone)]
pub struct TestStoreContext {
pub db: SqlitePool,
pub addr_store: SqliteAddressbookStore,
pub cal_store: SqliteCalendarStore,
pub principal_store: SqlitePrincipalStore,
pub sub_store: SqliteStore,
}
#[rstest::fixture]
pub async fn get_test_calendar_store() -> SqliteCalendarStore {
let (send, _recv) = tokio::sync::mpsc::channel(1000);
SqliteCalendarStore::new(get_test_db().await, send)
}
#[rstest::fixture]
pub async fn get_test_subscription_store() -> SqliteStore {
SqliteStore::new(get_test_db().await)
}
#[rstest::fixture]
pub async fn get_test_principal_store() -> SqlitePrincipalStore {
SqlitePrincipalStore::new(get_test_db().await)
#[fixture]
pub async fn test_store_context() -> TestStoreContext {
let (send_addr, _recv) = tokio::sync::mpsc::channel(1);
let (send_cal, _recv) = tokio::sync::mpsc::channel(1);
let db = get_test_db().await;
TestStoreContext {
db: db.clone(),
addr_store: SqliteAddressbookStore::new(db.clone(), send_addr),
cal_store: SqliteCalendarStore::new(db.clone(), send_cal),
principal_store: SqlitePrincipalStore::new(db.clone()),
sub_store: SqliteStore::new(db),
}
}

View File

@@ -59,6 +59,8 @@ markdown_extensions:
- admonition
- attr_list
- pymdownx.tabbed
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg

View File

@@ -5,7 +5,7 @@ use headers::{Authorization, HeaderMapExt};
use http::{HeaderValue, StatusCode};
use rstest::rstest;
use rustical_store::{CalendarMetadata, CalendarStore};
use rustical_store_sqlite::{calendar_store::SqliteCalendarStore, tests::get_test_calendar_store};
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt;
fn mkcalendar_template(
@@ -48,15 +48,13 @@ fn mkcalendar_template(
#[rstest]
#[tokio::test]
async fn test_caldav_calendar(
#[from(get_app)]
#[from(test_store_context)]
#[future]
app: axum::Router,
#[from(get_test_calendar_store)]
#[future]
cal_store: SqliteCalendarStore,
context: TestStoreContext,
) {
let app = app.await;
let cal_store = cal_store.await;
let context = context.await;
let app = get_app(context.clone());
let cal_store = context.cal_store;
let mut calendar_meta = CalendarMetadata {
displayname: Some("Calendar".to_string()),

View File

@@ -4,6 +4,7 @@ use axum::extract::Request;
use headers::{Authorization, HeaderMapExt};
use http::{HeaderValue, StatusCode};
use rstest::rstest;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt;
mod calendar;
@@ -11,11 +12,11 @@ mod calendar;
#[rstest]
#[tokio::test]
async fn test_caldav_root(
#[from(get_app)]
#[from(test_store_context)]
#[future]
app: axum::Router,
context: TestStoreContext,
) {
let app = app.await;
let app = get_app(context.await);
let request_template = || {
Request::builder()
@@ -53,11 +54,11 @@ async fn test_caldav_root(
#[rstest]
#[tokio::test]
async fn test_caldav_principal(
#[from(get_app)]
#[from(test_store_context)]
#[future]
app: axum::Router,
context: TestStoreContext,
) {
let app = app.await;
let app = get_app(context.await);
let request_template = || {
Request::builder()

View File

@@ -3,7 +3,7 @@ source: src/integration_tests/caldav/calendar.rs
expression: body
---
BEGIN:VCALENDAR
VERSION:4.0
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:RustiCal
X-WR-CALNAME:Calendar

View File

@@ -4,7 +4,7 @@ expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop>
@@ -136,6 +136,7 @@ END:VCALENDAR
</CAL:supported-calendar-data>
<CAL:supported-collation-set>
<CAL:supported-collation>i;ascii-casemap</CAL:supported-collation>
<CAL:supported-collation>i;unicode-casemap</CAL:supported-collation>
<CAL:supported-collation>i;octet</CAL:supported-collation>
</CAL:supported-collation-set>
<max-resource-size>10000000</max-resource-size>

View File

@@ -4,7 +4,7 @@ expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/caldav/principal/user/calendar</href>
<propstat>
<prop>

View File

@@ -4,7 +4,7 @@ expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/caldav/</href>
<propstat>
<prop>

View File

@@ -4,7 +4,7 @@ expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/caldav/principal/user/</href>
<propstat>
<prop>

View File

@@ -4,7 +4,7 @@ expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/caldav/principal/user/</href>
<propstat>
<prop>
@@ -50,192 +50,4 @@ expression: body
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<href>/caldav/principal/user/calendar/</href>
<propstat>
<prop>
<calendar-color xmlns="http://apple.com/ns/ical/">#00FF00</calendar-color>
<CAL:calendar-description>Description</CAL:calendar-description>
<CAL:calendar-timezone>BEGIN:VCALENDAR
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
LAST-MODIFIED:20250723T190331Z
X-LIC-LOCATION:Europe/Berlin
X-PROLEPTIC-TZNAME:LMT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+005328
TZOFFSETTO:+0100
DTSTART:18930401T000000
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19160430T230000
RDATE:19400401T020000
RDATE:19430329T020000
RDATE:19460414T020000
RDATE:19470406T030000
RDATE:19480418T020000
RDATE:19490410T020000
RDATE:19800406T020000
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19161001T010000
RDATE:19421102T030000
RDATE:19431004T030000
RDATE:19441002T030000
RDATE:19451118T030000
RDATE:19461007T030000
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19170416T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=3MO;UNTIL=19180415T010000Z
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19170917T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=3MO;UNTIL=19180916T010000Z
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19440403T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1MO;UNTIL=19450402T010000Z
END:DAYLIGHT
BEGIN:DAYLIGHT
TZNAME:CEMT
TZOFFSETFROM:+0200
TZOFFSETTO:+0300
DTSTART:19450524T020000
RDATE:19470511T030000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0300
TZOFFSETTO:+0200
DTSTART:19450924T030000
RDATE:19470629T030000
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0100
TZOFFSETTO:+0100
DTSTART:19460101T000000
RDATE:19800101T000000
END:STANDARD
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19471005T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU;UNTIL=19491002T010000Z
END:STANDARD
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU;UNTIL=19950924T010000Z
END:STANDARD
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
</CAL:calendar-timezone>
<CAL:timezone-service-set>
<href>https://www.iana.org/time-zones</href>
</CAL:timezone-service-set>
<CAL:calendar-timezone-id>Europe/Berlin</CAL:calendar-timezone-id>
<calendar-order xmlns="http://apple.com/ns/ical/">0</calendar-order>
<CAL:supported-calendar-component-set>
<CAL:comp name="VEVENT"/>
<CAL:comp name="VTODO"/>
<CAL:comp name="VJOURNAL"/>
</CAL:supported-calendar-component-set>
<CAL:supported-calendar-data>
<CAL:calendar-data content-type="text/calendar" version="2.0"/>
</CAL:supported-calendar-data>
<CAL:supported-collation-set>
<CAL:supported-collation>i;ascii-casemap</CAL:supported-collation>
<CAL:supported-collation>i;octet</CAL:supported-collation>
</CAL:supported-collation-set>
<max-resource-size>10000000</max-resource-size>
<supported-report-set>
<supported-report>
<report>
<CAL:calendar-query/>
</report>
</supported-report>
<supported-report>
<report>
<CAL:calendar-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
</supported-report-set>
<CAL:min-date-time>-2621430101T000000Z</CAL:min-date-time>
<CAL:max-date-time>+2621421231T235959Z</CAL:max-date-time>
<sync-token>github.com/lennart-k/rustical/ns/0</sync-token>
<CS:getctag>github.com/lennart-k/rustical/ns/0</CS:getctag>
<PUSH:transports>
<PUSH:web-push/>
</PUSH:transports>
<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>
<PUSH:supported-triggers>
<PUSH:content-update>
<depth>1</depth>
</PUSH:content-update>
<PUSH:property-update>
<depth>1</depth>
</PUSH:property-update>
</PUSH:supported-triggers>
<resourcetype>
<collection/>
<CAL:calendar/>
</resourcetype>
<displayname>Calendar</displayname>
<current-user-principal>
<href>/caldav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<privilege>
<all/>
</privilege>
</current-user-privilege-set>
<owner>
<href>/caldav/principal/user/</href>
</owner>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@@ -0,0 +1,194 @@
use crate::integration_tests::{ResponseExtractString, get_app};
use axum::body::Body;
use axum::extract::Request;
use headers::{Authorization, HeaderMapExt};
use http::{HeaderValue, StatusCode};
use rstest::rstest;
use rustical_store::AddressbookStore;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt;
fn mkcol_template(displayname: &str, description: &str) -> String {
format!(
r#"
<?xml version='1.0' encoding='UTF-8' ?>
<mkcol xmlns="DAV:" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
<set>
<prop>
<resourcetype>
<collection />
<CARD:addressbook />
</resourcetype>
<displayname>{displayname}</displayname>
<CARD:addressbook-description>{description}</CARD:addressbook-description>
</prop>
</set>
</mkcol>
"#,
)
}
#[rstest]
#[tokio::test]
async fn test_carddav_addressbook(
#[from(test_store_context)]
#[future]
context: TestStoreContext,
) {
let context = context.await;
let app = get_app(context.clone());
let addr_store = context.addr_store;
let (mut displayname, mut description) = (
Some("Contacts".to_owned()),
Some("Amazing contacts!".to_owned()),
);
let (principal, addr_id) = ("user", "contacts");
let url = format!("/carddav/principal/{principal}/{addr_id}");
let request_template = || {
Request::builder()
.method("MKCOL")
.uri(&url)
.body(Body::from(mkcol_template(
displayname.as_ref().unwrap(),
description.as_ref().unwrap(),
)))
.unwrap()
};
// Try OPTIONS without authentication
let request = Request::builder()
.method("OPTIONS")
.uri(&url)
.body(Body::empty())
.unwrap();
let response = app.clone().oneshot(request).await.unwrap();
insta::assert_debug_snapshot!(response, @r#"
Response {
status: 200,
version: HTTP/1.1,
headers: {
"dav": "1, 3, access-control, addressbook, webdav-push",
"allow": "PROPFIND, PROPPATCH, COPY, MOVE, DELETE, OPTIONS, REPORT, GET, HEAD, POST, MKCOL, IMPORT",
},
body: Body(
UnsyncBoxBody,
),
}
"#);
// Try without authentication
let request = request_template();
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
// Try with correct credentials
let mut request = request_template();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::CREATED);
let body = response.extract_string().await;
insta::assert_snapshot!("mkcol_body", body);
let mut request = Request::builder()
.method("GET")
.uri(&url)
.body(Body::empty())
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = response.extract_string().await;
insta::assert_snapshot!("get_body", body);
let saved_addressbook = addr_store
.get_addressbook(principal, addr_id, false)
.await
.unwrap();
assert_eq!(
(saved_addressbook.displayname, saved_addressbook.description),
(displayname, description)
);
let mut request = Request::builder()
.method("PROPFIND")
.uri(&url)
.body(Body::empty())
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::MULTI_STATUS);
let body = response.extract_string().await;
insta::with_settings!({
filters => vec![
(r"<PUSH:topic>[0-9a-f-]+</PUSH:topic>", "<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>")
]
}, {
insta::assert_snapshot!("propfind_body", body);
});
let proppatch_request: &str = r#"
<propertyupdate xmlns="DAV:" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
<set>
<prop>
<displayname>New Displayname</displayname>
<CARD:addressbook-description>Test</CARD:addressbook-description>
</prop>
</set>
<remove>
<prop>
<CARD:addressbook-description />
</prop>
</remove>
</propertyupdate>
"#;
let mut request = Request::builder()
.method("PROPPATCH")
.uri(&url)
.body(Body::from(proppatch_request))
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::MULTI_STATUS);
let body = response.extract_string().await;
insta::assert_snapshot!("proppatch_body", body);
displayname = Some("New Displayname".to_string());
description = None;
let saved_addressbook = addr_store
.get_addressbook(principal, addr_id, false)
.await
.unwrap();
assert_eq!(
(saved_addressbook.displayname, saved_addressbook.description),
(displayname, description)
);
let mut request = Request::builder()
.method("DELETE")
.uri(&url)
.header("X-No-Trashbin", HeaderValue::from_static("1"))
.body(Body::empty())
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = response.extract_string().await;
insta::assert_snapshot!("delete_body", body);
assert!(matches!(
addr_store.get_addressbook(principal, addr_id, false).await,
Err(rustical_store::Error::NotFound)
));
}

View File

@@ -0,0 +1,73 @@
use crate::integration_tests::{ResponseExtractString, get_app};
use axum::body::Body;
use axum::extract::Request;
use headers::{Authorization, HeaderMapExt};
use http::StatusCode;
use rstest::rstest;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt;
#[rstest]
#[tokio::test]
async fn test_import(
#[from(test_store_context)]
#[future]
context: TestStoreContext,
) {
let context = context.await;
let app = get_app(context.clone());
let (principal, addr_id) = ("user", "contacts");
let url = format!("/carddav/principal/{principal}/{addr_id}");
let request_template = || {
Request::builder()
.method("IMPORT")
.uri(&url)
.body(Body::from(
r"BEGIN:VCARD
VERSION:4.0
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr,M.Sc.
BDAY:--0203
GENDER:M
EMAIL;TYPE=work:simon.perreault@viagenie.ca
END:VCARD",
))
.unwrap()
};
// Try without authentication
let request = request_template();
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
// Try with correct credentials
let mut request = request_template();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = response.extract_string().await;
insta::assert_snapshot!("import_body", body);
let mut request = Request::builder()
.method("GET")
.uri(&url)
.body(Body::empty())
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = response.extract_string().await;
insta::with_settings!({
filters => vec![
(r"UID:.+", "UID:[UID]")
]
}, {
insta::assert_snapshot!("get_body", body);
});
}

View File

@@ -4,16 +4,20 @@ use axum::extract::Request;
use headers::{Authorization, HeaderMapExt};
use http::StatusCode;
use rstest::rstest;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt;
mod addressbook;
mod addressbook_import;
#[rstest]
#[tokio::test]
async fn test_carddav_root(
#[from(get_app)]
#[from(test_store_context)]
#[future]
app: axum::Router,
context: TestStoreContext,
) {
let app = app.await;
let app = get_app(context.await);
let request_template = || {
Request::builder()

View File

@@ -0,0 +1,5 @@
---
source: src/integration_tests/carddav/addressbook.rs
expression: body
---

View File

@@ -0,0 +1,5 @@
---
source: src/integration_tests/carddav/addressbook.rs
expression: body
---

View File

@@ -0,0 +1,5 @@
---
source: src/integration_tests/carddav/addressbook.rs
expression: body
---

View File

@@ -0,0 +1,68 @@
---
source: src/integration_tests/carddav/addressbook.rs
expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/carddav/principal/user/contacts/</href>
<propstat>
<prop>
<CARD:addressbook-description>Amazing contacts!</CARD:addressbook-description>
<CARD:supported-address-data>
<CARD:address-data-type content-type="text/vcard" version="3.0"/>
<CARD:address-data-type content-type="text/vcard" version="4.0"/>
</CARD:supported-address-data>
<CARD:supported-collation-set>
<CARD:supported-collation>i;ascii-casemap</CARD:supported-collation>
<CARD:supported-collation>i;unicode-casemap</CARD:supported-collation>
<CARD:supported-collation>i;octet</CARD:supported-collation>
</CARD:supported-collation-set>
<supported-report-set>
<supported-report>
<report>
<CARD:addressbook-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
</supported-report-set>
<CARD:max-resource-size>10000000</CARD:max-resource-size>
<sync-token>github.com/lennart-k/rustical/ns/0</sync-token>
<CS:getctag>github.com/lennart-k/rustical/ns/0</CS:getctag>
<PUSH:transports>
<PUSH:web-push/>
</PUSH:transports>
<PUSH:topic>[PUSH_TOPIC]</PUSH:topic>
<PUSH:supported-triggers>
<PUSH:content-update>
<depth>1</depth>
</PUSH:content-update>
<PUSH:property-update>
<depth>1</depth>
</PUSH:property-update>
</PUSH:supported-triggers>
<resourcetype>
<collection/>
<CARD:addressbook/>
</resourcetype>
<displayname>Contacts</displayname>
<current-user-principal>
<href>/carddav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<privilege>
<all/>
</privilege>
</current-user-privilege-set>
<owner>
<href>/carddav/principal/user/</href>
</owner>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@@ -0,0 +1,28 @@
---
source: src/integration_tests/carddav/addressbook.rs
expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/carddav/principal/user/contacts</href>
<propstat>
<prop>
<displayname xmlns="DAV:"/>
<addressbook-description xmlns="urn:ietf:params:xml:ns:carddav"/>
<addressbook-description/>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
<propstat>
<prop>
</prop>
<status>HTTP/1.1 404 Not Found</status>
</propstat>
<propstat>
<prop>
</prop>
<status>HTTP/1.1 409 Conflict</status>
</propstat>
</response>
</multistatus>

View File

@@ -0,0 +1,13 @@
---
source: src/integration_tests/carddav/addressbook_import.rs
expression: body
---
BEGIN:VCARD
VERSION:4.0
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr,M.Sc.
BDAY:--0203
GENDER:M
EMAIL;TYPE=work:simon.perreault@viagenie.ca
UID:[UID]
END:VCARD

View File

@@ -0,0 +1,5 @@
---
source: src/integration_tests/carddav/addressbook_import.rs
expression: body
---

View File

@@ -4,7 +4,7 @@ expression: body
---
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<response>
<href>/carddav/</href>
<propstat>
<prop>

View File

@@ -3,44 +3,24 @@ use axum::extract::Request;
use axum::{body::Body, response::Response};
use rstest::rstest;
use rustical_frontend::FrontendConfig;
use rustical_store_sqlite::{
SqliteStore,
addressbook_store::SqliteAddressbookStore,
calendar_store::SqliteCalendarStore,
principal_store::SqlitePrincipalStore,
tests::{
get_test_addressbook_store, get_test_calendar_store, get_test_principal_store,
get_test_subscription_store,
},
};
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use std::sync::Arc;
use tower::ServiceExt;
#[rstest::fixture]
pub async fn get_app(
#[from(get_test_calendar_store)]
#[future]
cal_store: SqliteCalendarStore,
#[from(get_test_addressbook_store)]
#[future]
addr_store: SqliteAddressbookStore,
#[from(get_test_principal_store)]
#[future]
principal_store: SqlitePrincipalStore,
#[from(get_test_subscription_store)]
#[future]
sub_store: SqliteStore,
) -> axum::Router {
let addr_store = Arc::new(addr_store.await);
let cal_store = Arc::new(cal_store.await);
let sub_store = Arc::new(sub_store.await);
let principal_store = Arc::new(principal_store.await);
make_app(
pub fn get_app(context: TestStoreContext) -> axum::Router {
let TestStoreContext {
addr_store,
cal_store,
sub_store,
principal_store,
sub_store,
..
} = context;
make_app(
Arc::new(addr_store),
Arc::new(cal_store),
Arc::new(sub_store),
Arc::new(principal_store),
FrontendConfig {
enabled: true,
allow_password_login: true,
@@ -70,11 +50,11 @@ impl ResponseExtractString for Response {
#[rstest]
#[tokio::test]
async fn test_ping(
#[from(get_app)]
#[from(test_store_context)]
#[future]
app: axum::Router,
context: TestStoreContext,
) {
let app = app.await;
let app = get_app(context.await);
let response = app
.oneshot(Request::builder().uri("/ping").body(Body::empty()).unwrap())