Compare commits

..

12 Commits

Author SHA1 Message Date
Lennart K
602c0e5637 version 0.12.4 2026-01-31 14:18:49 +01:00
Lennart K
41eed732eb Update caldata-rs 2026-01-31 14:17:10 +01:00
Lennart K
cc333f7182 Add test to make sure that objects from Thunderbird are accepted
see #173
2026-01-31 14:16:57 +01:00
Lennart K
5ec40b97e3 update .gitignore 2026-01-31 14:07:34 +01:00
Lennart K
008e40e17f integration tests: Also use health command 2026-01-29 11:26:20 +01:00
Lennart K
0703b7b470 Add another integration test 2026-01-29 10:25:00 +01:00
Lennart K
233cf2ea37 fix test snapshots 2026-01-28 21:05:56 +01:00
Lennart K
494f31f992 Add more abstract integration test 2026-01-28 20:54:55 +01:00
Lennart K
c1758e2cba cmd_default: Add notifier to detect when rustical has started 2026-01-28 20:16:41 +01:00
Lennart K
af60a446ad refactoring of integration tests 2026-01-28 18:38:03 +01:00
Lennart K
c763a682ed update .gitignore 2026-01-27 23:07:19 +01:00
Lennart K
8ab9c61b0f Move commands to lib.rs 2026-01-27 23:06:57 +01:00
84 changed files with 1053 additions and 484 deletions

4
.gitignore vendored
View File

@@ -3,7 +3,7 @@ crates/*/target
# For libraries ignore Cargo.lock # For libraries ignore Cargo.lock
crates/*/Cargo.lock crates/*/Cargo.lock
db.sqlite3* **/*.sqlite3*
config.toml config.toml
principals.toml principals.toml
@@ -18,3 +18,5 @@ site
**/.vite **/.vite
**/*.snap.new **/*.snap.new
**/*.drawio

49
Cargo.lock generated
View File

@@ -567,18 +567,18 @@ checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
[[package]] [[package]]
name = "caldata" name = "caldata"
version = "0.14.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36de4a8034d98c95e7fe874b828272d823cfbd68e9571fe7bf6c419e852cbe2" checksum = "e18d0b0cbc271e44b6f0dc262c9469f10f10f8af3fa00c3ebcc10e49ac91d478"
dependencies = [ dependencies = [
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"derive_more", "derive_more",
"itertools 0.14.0", "itertools 0.14.0",
"lazy_static", "lazy_static",
"log",
"phf 0.13.1", "phf 0.13.1",
"regex", "regex",
"rrule",
"thiserror 2.0.18", "thiserror 2.0.18",
"vtimezones-rs", "vtimezones-rs",
] ]
@@ -3169,19 +3169,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "rrule"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "720acfb4980b9d8a6a430f6d7a11933e701ebbeba5eee39cc9d8c5f932aaff74"
dependencies = [
"chrono",
"chrono-tz",
"log",
"regex",
"thiserror 2.0.18",
]
[[package]] [[package]]
name = "rsa" name = "rsa"
version = "0.9.10" version = "0.9.10"
@@ -3309,7 +3296,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical" name = "rustical"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argon2", "argon2",
@@ -3319,6 +3306,7 @@ dependencies = [
"caldata", "caldata",
"clap", "clap",
"figment", "figment",
"futures-util",
"headers", "headers",
"http", "http",
"insta", "insta",
@@ -3343,7 +3331,9 @@ dependencies = [
"serde", "serde",
"similar-asserts", "similar-asserts",
"sqlx", "sqlx",
"tempfile",
"tokio", "tokio",
"tokio-util",
"toml 0.9.11+spec-1.1.0", "toml 0.9.11+spec-1.1.0",
"tower", "tower",
"tower-http", "tower-http",
@@ -3356,7 +3346,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_caldav" name = "rustical_caldav"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"async-std", "async-std",
"async-trait", "async-trait",
@@ -3398,7 +3388,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_carddav" name = "rustical_carddav"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
@@ -3432,7 +3422,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_dav" name = "rustical_dav"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
@@ -3458,7 +3448,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_dav_push" name = "rustical_dav_push"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
@@ -3483,7 +3473,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_frontend" name = "rustical_frontend"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"askama", "askama",
"askama_web", "askama_web",
@@ -3519,7 +3509,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_ical" name = "rustical_ical"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"axum", "axum",
"caldata", "caldata",
@@ -3527,7 +3517,6 @@ dependencies = [
"chrono-tz", "chrono-tz",
"derive_more", "derive_more",
"regex", "regex",
"rrule",
"rstest", "rstest",
"rustical_xml", "rustical_xml",
"serde", "serde",
@@ -3538,7 +3527,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_oidc" name = "rustical_oidc"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
@@ -3554,7 +3543,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_store" name = "rustical_store"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@@ -3568,7 +3557,6 @@ dependencies = [
"headers", "headers",
"http", "http",
"regex", "regex",
"rrule",
"rstest", "rstest",
"rstest_reuse", "rstest_reuse",
"rustical_dav", "rustical_dav",
@@ -3587,7 +3575,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_store_sqlite" name = "rustical_store_sqlite"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"caldata", "caldata",
@@ -3612,7 +3600,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_xml" name = "rustical_xml"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"quick-xml", "quick-xml",
"thiserror 2.0.18", "thiserror 2.0.18",
@@ -4471,6 +4459,7 @@ dependencies = [
"bytes", "bytes",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"futures-util",
"pin-project-lite", "pin-project-lite",
"tokio", "tokio",
] ]
@@ -5434,7 +5423,7 @@ checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
[[package]] [[package]]
name = "xml_derive" name = "xml_derive"
version = "0.12.3" version = "0.12.4"
dependencies = [ dependencies = [
"darling 0.23.0", "darling 0.23.0",
"heck", "heck",

View File

@@ -2,7 +2,7 @@
members = ["crates/*"] members = ["crates/*"]
[workspace.package] [workspace.package]
version = "0.12.3" version = "0.12.4"
rust-version = "1.92" rust-version = "1.92"
edition = "2024" edition = "2024"
description = "A CalDAV server" description = "A CalDAV server"
@@ -32,8 +32,11 @@ opentelemetry = [
"dep:tracing-opentelemetry", "dep:tracing-opentelemetry",
] ]
[profile.dev] [lib]
debug = 0 doc = true
name = "rustical"
path = "src/lib.rs"
test = true
[workspace.dependencies] [workspace.dependencies]
rustical_dav = { path = "./crates/dav/", features = ["ical"] } rustical_dav = { path = "./crates/dav/", features = ["ical"] }
@@ -70,6 +73,7 @@ tokio = { version = "1.48", features = [
"rt-multi-thread", "rt-multi-thread",
"full", "full",
] } ] }
tokio-util = { version = "0.7", features = ["rt"] }
url = "2.5" url = "2.5"
base64 = "0.22" base64 = "0.22"
thiserror = "2.0" thiserror = "2.0"
@@ -107,7 +111,7 @@ strum = "0.27"
strum_macros = "0.27" strum_macros = "0.27"
serde_json = { version = "1.0", features = ["raw_value"] } serde_json = { version = "1.0", features = ["raw_value"] }
sqlx-sqlite = { version = "0.8", features = ["bundled"] } sqlx-sqlite = { version = "0.8", features = ["bundled"] }
caldata = { version = "0.14.0", features = ["chrono-tz", "vtimezones-rs"] } caldata = { version = "0.15.0", features = ["chrono-tz", "vtimezones-rs"] }
toml = "0.9" toml = "0.9"
tower = "0.5" tower = "0.5"
tower-http = { version = "0.6", features = [ tower-http = { version = "0.6", features = [
@@ -120,7 +124,6 @@ chrono-tz = "0.10"
chrono-humanize = "0.2" chrono-humanize = "0.2"
rand = "0.9" rand = "0.9"
axum-extra = { version = "0.12", features = ["typed-header"] } axum-extra = { version = "0.12", features = ["typed-header"] }
rrule = "0.14"
argon2 = "0.5" argon2 = "0.5"
rpassword = "7.4" rpassword = "7.4"
password-hash = { version = "0.5" } password-hash = { version = "0.5" }
@@ -152,6 +155,7 @@ rstest.workspace = true
rustical_store_sqlite = { workspace = true, features = ["test"] } rustical_store_sqlite = { workspace = true, features = ["test"] }
insta.workspace = true insta.workspace = true
similar-asserts.workspace = true similar-asserts.workspace = true
tempfile = "3.24"
[dependencies] [dependencies]
rustical_store.workspace = true rustical_store.workspace = true
@@ -163,6 +167,7 @@ caldata.workspace = true
toml.workspace = true toml.workspace = true
serde.workspace = true serde.workspace = true
tokio.workspace = true tokio.workspace = true
tokio-util.workspace = true
tracing.workspace = true tracing.workspace = true
anyhow.workspace = true anyhow.workspace = true
clap.workspace = true clap.workspace = true
@@ -201,3 +206,4 @@ tower-http.workspace = true
axum-extra.workspace = true axum-extra.workspace = true
headers.workspace = true headers.workspace = true
http.workspace = true http.workspace = true
futures-util.workspace = true

View File

@@ -43,28 +43,28 @@ pub async fn route_get<C: CalendarStore, S: SubscriptionStore>(
if let Some(displayname) = calendar.meta.displayname { if let Some(displayname) = calendar.meta.displayname {
props.push(ContentLine { props.push(ContentLine {
name: "X-WR-CALNAME".to_owned(), name: "X-WR-CALNAME".to_owned(),
value: Some(displayname), value: displayname,
params: vec![].into(), params: vec![].into(),
}); });
} }
if let Some(description) = calendar.meta.description { if let Some(description) = calendar.meta.description {
props.push(ContentLine { props.push(ContentLine {
name: "X-WR-CALDESC".to_owned(), name: "X-WR-CALDESC".to_owned(),
value: Some(description), value: description,
params: vec![].into(), params: vec![].into(),
}); });
} }
if let Some(color) = calendar.meta.color { if let Some(color) = calendar.meta.color {
props.push(ContentLine { props.push(ContentLine {
name: "X-WR-CALCOLOR".to_owned(), name: "X-WR-CALCOLOR".to_owned(),
value: Some(color), value: color,
params: vec![].into(), params: vec![].into(),
}); });
} }
if let Some(timezone_id) = calendar.timezone_id { if let Some(timezone_id) = calendar.timezone_id {
props.push(ContentLine { props.push(ContentLine {
name: "X-WR-TIMEZONE".to_owned(), name: "X-WR-TIMEZONE".to_owned(),
value: Some(timezone_id), value: timezone_id,
params: vec![].into(), params: vec![].into(),
}); });
} }

View File

@@ -35,16 +35,16 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
// Extract calendar metadata // Extract calendar metadata
let displayname = cal let displayname = cal
.get_property("X-WR-CALNAME") .get_property("X-WR-CALNAME")
.and_then(|prop| prop.value.clone()); .map(|prop| prop.value.clone());
let description = cal let description = cal
.get_property("X-WR-CALDESC") .get_property("X-WR-CALDESC")
.and_then(|prop| prop.value.clone()); .map(|prop| prop.value.clone());
let color = cal let color = cal
.get_property("X-WR-CALCOLOR") .get_property("X-WR-CALCOLOR")
.and_then(|prop| prop.value.clone()); .map(|prop| prop.value.clone());
let timezone_id = cal let timezone_id = cal
.get_property("X-WR-TIMEZONE") .get_property("X-WR-TIMEZONE")
.and_then(|prop| prop.value.clone()); .map(|prop| prop.value.clone());
// These properties should not appear in the expanded calendar objects // These properties should not appear in the expanded calendar objects
cal.remove_property("X-WR-CALNAME"); cal.remove_property("X-WR-CALNAME");
cal.remove_property("X-WR-CALDESC"); cal.remove_property("X-WR-CALDESC");

View File

@@ -34,7 +34,7 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
let mut card_mut = card.mutable(); let mut card_mut = card.mutable();
card_mut.add_content_line(ContentLine { card_mut.add_content_line(ContentLine {
name: "UID".to_owned(), name: "UID".to_owned(),
value: Some(uuid::Uuid::new_v4().to_string()), value: uuid::Uuid::new_v4().to_string(),
params: vec![].into(), params: vec![].into(),
}); });
card = card_mut.build(&ParserOptions::default(), None).unwrap(); card = card_mut.build(&ParserOptions::default(), None).unwrap();

View File

@@ -129,8 +129,7 @@ impl TextMatchElement {
} }
#[must_use] #[must_use]
pub fn match_property(&self, property: &ContentLine) -> bool { pub fn match_property(&self, property: &ContentLine) -> bool {
let text = property.value.as_deref().unwrap_or(""); self.match_text(&property.value)
self.match_text(text)
} }
} }

View File

@@ -17,7 +17,6 @@ derive_more.workspace = true
rustical_xml.workspace = true rustical_xml.workspace = true
caldata.workspace = true caldata.workspace = true
regex.workspace = true regex.workspace = true
rrule.workspace = true
serde.workspace = true serde.workspace = true
sha2.workspace = true sha2.workspace = true
axum.workspace = true axum.workspace = true

View File

@@ -13,7 +13,7 @@ use caldata::{
IcalUIDProperty, IcalVERSIONProperty, IcalVersion, VcardANNIVERSARYProperty, IcalUIDProperty, IcalVERSIONProperty, IcalVersion, VcardANNIVERSARYProperty,
VcardBDAYProperty, VcardFNProperty, VcardBDAYProperty, VcardFNProperty,
}, },
types::{CalDate, PartialDate, Timezone}, types::{CalDate, PartialDate, Tz},
}; };
use chrono::{NaiveDate, Utc}; use chrono::{NaiveDate, Utc};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
@@ -73,7 +73,7 @@ impl AddressObject {
let Some(dtstart) = NaiveDate::from_ymd_opt(year.unwrap_or(1900), month, day) else { let Some(dtstart) = NaiveDate::from_ymd_opt(year.unwrap_or(1900), month, day) else {
return Ok(None); return Ok(None);
}; };
let start_date = CalDate(dtstart, Timezone::Local); let start_date = CalDate(dtstart, Tz::Local);
let Some(end_date) = start_date.succ_opt() else { let Some(end_date) = start_date.succ_opt() else {
// start_date is MAX_DATE, this should never happen but FAPP also not raise an error // start_date is MAX_DATE, this should never happen but FAPP also not raise an error
return Ok(None); return Ok(None);
@@ -90,14 +90,14 @@ impl AddressObject {
IcalDTENDProperty(end_date.into(), vec![].into()).into(), IcalDTENDProperty(end_date.into(), vec![].into()).into(),
IcalUIDProperty(uid, vec![].into()).into(), IcalUIDProperty(uid, vec![].into()).into(),
IcalRRULEProperty( IcalRRULEProperty(
rrule::RRule::from_str("FREQ=YEARLY").unwrap(), caldata::rrule::RRule::from_str("FREQ=YEARLY").unwrap(),
vec![].into(), vec![].into(),
) )
.into(), .into(),
IcalSUMMARYProperty(summary.clone(), vec![].into()).into(), IcalSUMMARYProperty(summary.clone(), vec![].into()).into(),
ContentLine { ContentLine {
name: "TRANSP".to_owned(), name: "TRANSP".to_owned(),
value: Some("TRANSPARENT".to_owned()), value: "TRANSPARENT".to_owned(),
..Default::default() ..Default::default()
}, },
], ],
@@ -105,17 +105,17 @@ impl AddressObject {
properties: vec![ properties: vec![
ContentLine { ContentLine {
name: "TRIGGER".to_owned(), name: "TRIGGER".to_owned(),
value: Some("-PT0M".to_owned()), value: "-PT0M".to_owned(),
params: vec![("VALUE".to_owned(), vec!["DURATION".to_owned()])].into(), params: vec![("VALUE".to_owned(), vec!["DURATION".to_owned()])].into(),
}, },
ContentLine { ContentLine {
name: "ACTION".to_owned(), name: "ACTION".to_owned(),
value: Some("DISPLAY".to_owned()), value: "DISPLAY".to_owned(),
..Default::default() ..Default::default()
}, },
ContentLine { ContentLine {
name: "DESCRIPTION".to_owned(), name: "DESCRIPTION".to_owned(),
value: Some(summary), value: summary,
..Default::default() ..Default::default()
}, },
], ],

View File

@@ -27,7 +27,6 @@ rustical_dav.workspace = true
rustical_ical.workspace = true rustical_ical.workspace = true
axum.workspace = true axum.workspace = true
http.workspace = true http.workspace = true
rrule.workspace = true
headers.workspace = true headers.workspace = true
tower.workspace = true tower.workspace = true
futures-core.workspace = true futures-core.workspace = true

View File

@@ -37,11 +37,11 @@ impl SqliteStore {
} }
pub async fn create_db_pool(db_url: &str, migrate: bool) -> Result<Pool<Sqlite>, sqlx::Error> { pub async fn create_db_pool(db_url: &str, migrate: bool) -> Result<Pool<Sqlite>, sqlx::Error> {
let options: SqliteConnectOptions = db_url.parse()?;
let db = SqlitePool::connect_with( let db = SqlitePool::connect_with(
SqliteConnectOptions::new() options
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal) .journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
.synchronous(sqlx::sqlite::SqliteSynchronous::Normal)
.filename(db_url)
.create_if_missing(true), .create_if_missing(true),
) )
.await?; .await?;

View File

@@ -1,6 +1,6 @@
use crate::{ use crate::{
SqliteStore, addressbook_store::SqliteAddressbookStore, calendar_store::SqliteCalendarStore, SqliteStore, addressbook_store::SqliteAddressbookStore, calendar_store::SqliteCalendarStore,
principal_store::SqlitePrincipalStore, create_db_pool, principal_store::SqlitePrincipalStore,
}; };
use rstest::fixture; use rstest::fixture;
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType}; use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
@@ -9,12 +9,23 @@ use sqlx::SqlitePool;
mod addressbook_store; mod addressbook_store;
mod calendar_store; mod calendar_store;
async fn get_test_db() -> SqlitePool { #[derive(Debug, Clone)]
let db = SqlitePool::connect("sqlite::memory:").await.unwrap(); pub struct TestStoreContext {
sqlx::migrate!("./migrations").run(&db).await.unwrap(); pub db: SqlitePool,
pub addr_store: SqliteAddressbookStore,
pub cal_store: SqliteCalendarStore,
pub principal_store: SqlitePrincipalStore,
pub sub_store: SqliteStore,
}
#[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 = create_db_pool(":memory:", true).await.unwrap();
// Populate with test data
let principal_store = SqlitePrincipalStore::new(db.clone()); let principal_store = SqlitePrincipalStore::new(db.clone());
// Populate with test data
principal_store principal_store
.insert_principal( .insert_principal(
Principal { Principal {
@@ -33,28 +44,11 @@ async fn get_test_db() -> SqlitePool {
.await .await
.unwrap(); .unwrap();
db
}
#[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,
}
#[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 { TestStoreContext {
db: db.clone(), db: db.clone(),
addr_store: SqliteAddressbookStore::new(db.clone(), send_addr, false), addr_store: SqliteAddressbookStore::new(db.clone(), send_addr, false),
cal_store: SqliteCalendarStore::new(db.clone(), send_cal, false), cal_store: SqliteCalendarStore::new(db.clone(), send_cal, false),
principal_store: SqlitePrincipalStore::new(db.clone()), principal_store,
sub_store: SqliteStore::new(db), sub_store: SqliteStore::new(db),
} }
} }

View File

@@ -32,7 +32,8 @@ use tracing::field::display;
#[allow( #[allow(
clippy::too_many_arguments, clippy::too_many_arguments,
clippy::too_many_lines, clippy::too_many_lines,
clippy::cognitive_complexity clippy::cognitive_complexity,
clippy::missing_panics_doc
)] )]
pub fn make_app< pub fn make_app<
AS: AddressbookStore + PrefixedCalendarStore, AS: AddressbookStore + PrefixedCalendarStore,
@@ -109,9 +110,9 @@ pub fn make_app<
options(async || { options(async || {
let mut resp = Response::builder().status(StatusCode::OK); let mut resp = Response::builder().status(StatusCode::OK);
resp.headers_mut() resp.headers_mut()
.unwrap() .expect("this always works")
.insert("DAV", HeaderValue::from_static("1")); .insert("DAV", HeaderValue::from_static("1"));
resp.body(Body::empty()).unwrap() resp.body(Body::empty()).expect("empty body always works")
}), }),
); );

View File

@@ -2,11 +2,12 @@ use crate::config::HttpConfig;
use clap::Parser; use clap::Parser;
use http::Method; use http::Method;
#[derive(Parser, Debug)] #[derive(Parser, Debug, Default)]
pub struct HealthArgs {} pub struct HealthArgs {}
/// Healthcheck for running rustical instance /// Healthcheck for running rustical instance
/// Currently just pings to see if it's reachable via HTTP /// Currently just pings to see if it's reachable via HTTP
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_health(http_config: HttpConfig, _health_args: HealthArgs) -> anyhow::Result<()> { pub async fn cmd_health(http_config: HttpConfig, _health_args: HealthArgs) -> anyhow::Result<()> {
let client = reqwest::ClientBuilder::new().build().unwrap(); let client = reqwest::ClientBuilder::new().build().unwrap();

View File

@@ -33,7 +33,8 @@ pub struct MembershipArgs {
command: MembershipCommand, command: MembershipCommand,
} }
pub async fn handle_membership_command( #[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_membership(
user_store: &impl AuthenticationProvider, user_store: &impl AuthenticationProvider,
MembershipArgs { command }: MembershipArgs, MembershipArgs { command }: MembershipArgs,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {

View File

@@ -6,13 +6,17 @@ use clap::Parser;
use rustical_caldav::CalDavConfig; use rustical_caldav::CalDavConfig;
use rustical_frontend::FrontendConfig; use rustical_frontend::FrontendConfig;
pub mod health; mod health;
pub mod membership; pub mod membership;
pub mod principals; pub mod principals;
pub use health::{HealthArgs, cmd_health};
pub use principals::{PrincipalsArgs, cmd_principals};
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
pub struct GenConfigArgs {} pub struct GenConfigArgs {}
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> { pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
let config = Config { let config = Config {
http: HttpConfig::default(), http: HttpConfig::default(),

View File

@@ -1,56 +1,49 @@
use super::membership::{MembershipArgs, handle_membership_command}; use super::membership::MembershipArgs;
use crate::{config::Config, get_data_stores}; use crate::{config::Config, get_data_stores, membership::cmd_membership};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use figment::{
Figment,
providers::{Env, Format, Toml},
};
use password_hash::{PasswordHasher, SaltString, rand_core::OsRng}; use password_hash::{PasswordHasher, SaltString, rand_core::OsRng};
use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType}; use rustical_store::auth::{AuthenticationProvider, Principal, PrincipalType};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
pub struct PrincipalsArgs { pub struct PrincipalsArgs {
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
config_file: String,
#[command(subcommand)] #[command(subcommand)]
command: Command, pub command: PrincipalsCommand,
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
struct CreateArgs { pub struct CreateArgs {
id: String, pub id: String,
#[arg(value_enum, short, long)] #[arg(value_enum, short, long)]
principal_type: Option<PrincipalType>, pub principal_type: Option<PrincipalType>,
#[arg(short, long)] #[arg(short, long)]
name: Option<String>, pub name: Option<String>,
#[arg(long, help = "Ask for password input")] #[arg(long, help = "Ask for password input")]
password: bool, pub password: bool,
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
struct RemoveArgs { pub struct RemoveArgs {
id: String, pub id: String,
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
struct EditArgs { pub struct EditArgs {
id: String, pub id: String,
#[arg(long, help = "Ask for password input")] #[arg(long, help = "Ask for password input")]
password: bool, pub password: bool,
#[arg( #[arg(
long, long,
help = "Remove password (If you only want to use OIDC for example)" help = "Remove password (If you only want to use OIDC for example)"
)] )]
remove_password: bool, pub remove_password: bool,
#[arg(short, long, help = "Change principal displayname")] #[arg(short, long, help = "Change principal displayname")]
name: Option<String>, pub name: Option<String>,
#[arg(value_enum, short, long, help = "Change the principal type")] #[arg(value_enum, short, long, help = "Change the principal type")]
principal_type: Option<PrincipalType>, pub principal_type: Option<PrincipalType>,
} }
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
enum Command { pub enum PrincipalsCommand {
List, List,
Create(CreateArgs), Create(CreateArgs),
Remove(RemoveArgs), Remove(RemoveArgs),
@@ -58,16 +51,12 @@ enum Command {
Membership(MembershipArgs), Membership(MembershipArgs),
} }
pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> { #[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
let config: Config = Figment::new() pub async fn cmd_principals(args: PrincipalsArgs, config: Config) -> anyhow::Result<()> {
.merge(Toml::file(&args.config_file))
.merge(Env::prefixed("RUSTICAL_").split("__"))
.extract()?;
let (_, _, _, principal_store, _) = get_data_stores(true, &config.data_store).await?; let (_, _, _, principal_store, _) = get_data_stores(true, &config.data_store).await?;
match args.command { match args.command {
Command::List => { PrincipalsCommand::List => {
for principal in principal_store.get_principals().await? { for principal in principal_store.get_principals().await? {
println!( println!(
"{} (displayname={}) [{}]", "{} (displayname={}) [{}]",
@@ -77,7 +66,7 @@ pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
); );
} }
} }
Command::Create(CreateArgs { PrincipalsCommand::Create(CreateArgs {
id, id,
principal_type, principal_type,
name, name,
@@ -111,11 +100,11 @@ pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
.await?; .await?;
println!("Principal created"); println!("Principal created");
} }
Command::Remove(RemoveArgs { id }) => { PrincipalsCommand::Remove(RemoveArgs { id }) => {
principal_store.remove_principal(&id).await?; principal_store.remove_principal(&id).await?;
println!("Principal {id} removed"); println!("Principal {id} removed");
} }
Command::Edit(EditArgs { PrincipalsCommand::Edit(EditArgs {
id, id,
remove_password, remove_password,
password, password,
@@ -151,8 +140,8 @@ pub async fn cmd_principals(args: PrincipalsArgs) -> anyhow::Result<()> {
principal_store.insert_principal(principal, true).await?; principal_store.insert_principal(principal, true).await?;
println!("Principal {id} updated"); println!("Principal {id} updated");
} }
Command::Membership(args) => { PrincipalsCommand::Membership(args) => {
handle_membership_command(principal_store.as_ref(), args).await?; cmd_membership(principal_store.as_ref(), args).await?;
} }
} }
Ok(()) Ok(())

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,107 +0,0 @@
---
source: src/integration_tests/caldav/calendar_import.rs
expression: body
---
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:RustiCal
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
DTSTAMP:20060206T001121Z
DTSTART;TZID=US/Eastern:20060104T140000
DURATION:PT1H
RECURRENCE-ID;TZID=US/Eastern:20060104T120000
SUMMARY:Event #2 bis
UID:[UID]
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20060206T001102Z
DTSTART;TZID=US/Eastern:20060102T100000
DURATION:PT1H
SUMMARY:Event #1
Description:Go Steelers!
UID:[UID]
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20060206T001121Z
DTSTART;TZID=US/Eastern:20060102T120000
DURATION:PT1H
RRULE:FREQ=DAILY;COUNT=5
SUMMARY:Event #2
UID:[UID]
END:VEVENT
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:[UID]
END:VEVENT
BEGIN:VTODO
DTSTAMP:20060205T235335Z
DUE;VALUE=DATE:20060104
STATUS:NEEDS-ACTION
SUMMARY:Task #1
UID:[UID]
BEGIN:VALARM
ACTION:AUDIO
TRIGGER;RELATED=START:-PT10M
END:VALARM
END:VTODO
BEGIN:VTODO
DTSTAMP:20060205T235300Z
DUE;VALUE=DATE:20060106
LAST-MODIFIED:20060205T235308Z
SEQUENCE:1
STATUS:NEEDS-ACTION
SUMMARY:Task #2
UID:[UID]
BEGIN:VALARM
ACTION:AUDIO
TRIGGER;RELATED=START:-PT10M
END:VALARM
END:VTODO
BEGIN:VTODO
COMPLETED:20051223T122322Z
DTSTAMP:20060205T235400Z
DUE;VALUE=DATE:20051225
LAST-MODIFIED:20060205T235308Z
SEQUENCE:1
STATUS:COMPLETED
SUMMARY:Task #3
UID:[UID]
END:VTODO
BEGIN:VTODO
DTSTAMP:20060205T235600Z
DUE;VALUE=DATE:20060101
LAST-MODIFIED:20060205T235308Z
SEQUENCE:1
STATUS:CANCELLED
SUMMARY:Task #4
UID:[UID]
END:VTODO
END:VCALENDAR

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,13 +0,0 @@
---
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

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

View File

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

View File

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

165
src/lib.rs Normal file
View File

@@ -0,0 +1,165 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
use crate::config::Config;
use anyhow::Result;
use app::make_app;
use axum::ServiceExt;
use axum::extract::Request;
use clap::{Parser, Subcommand};
use config::{DataStoreConfig, SqliteDataStoreConfig};
use rustical_dav_push::DavPushController;
use rustical_store::auth::AuthenticationProvider;
use rustical_store::{
AddressbookStore, CalendarStore, CollectionOperation, PrefixedCalendarStore, SubscriptionStore,
};
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
use rustical_store_sqlite::principal_store::SqlitePrincipalStore;
use rustical_store_sqlite::{SqliteStore, create_db_pool};
use setup_tracing::setup_tracing;
use std::sync::Arc;
use tokio::sync::Notify;
use tokio::sync::mpsc::Receiver;
use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer;
use tracing::{info, warn};
pub mod app;
mod commands;
pub use commands::*;
pub mod config;
mod setup_tracing;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
pub config_file: String,
#[arg(long, env, help = "Do no run database migrations (only for sql store)")]
pub no_migrations: bool,
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Debug, Subcommand)]
pub enum Command {
GenConfig(commands::GenConfigArgs),
Principals(PrincipalsArgs),
#[command(
about = "Healthcheck for running instance (Used for HEALTHCHECK in Docker container)"
)]
Health(HealthArgs),
}
#[allow(clippy::missing_errors_doc)]
pub async fn get_data_stores(
migrate: bool,
config: &DataStoreConfig,
) -> Result<(
Arc<impl AddressbookStore + PrefixedCalendarStore>,
Arc<impl CalendarStore>,
Arc<impl SubscriptionStore>,
Arc<impl AuthenticationProvider>,
Receiver<CollectionOperation>,
)> {
Ok(match &config {
DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url,
run_repairs,
skip_broken,
}) => {
let db = create_db_pool(db_url, migrate).await?;
// Channel to watch for changes (for DAV Push)
let (send, recv) = tokio::sync::mpsc::channel(1000);
let addressbook_store = Arc::new(SqliteAddressbookStore::new(
db.clone(),
send.clone(),
*skip_broken,
));
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
if *run_repairs {
info!("Running repair tasks");
addressbook_store.repair_orphans().await?;
cal_store.repair_invalid_version_4_0().await?;
cal_store.repair_orphans().await?;
}
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
let principal_store = Arc::new(SqlitePrincipalStore::new(db));
// Validate all calendar objects
for principal in principal_store.get_principals().await? {
cal_store.validate_objects(&principal.id).await?;
addressbook_store.validate_objects(&principal.id).await?;
}
(
addressbook_store,
cal_store,
subscription_store,
principal_store,
recv,
)
}
})
}
#[allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
pub async fn cmd_default(
args: Args,
config: Config,
start_notifier: Option<Arc<Notify>>,
tracing: bool,
) -> Result<()> {
if tracing {
setup_tracing(&config.tracing);
}
let (addr_store, cal_store, subscription_store, principal_store, update_recv) =
get_data_stores(!args.no_migrations, &config.data_store).await?;
let mut tasks = vec![];
if config.dav_push.enabled {
let dav_push_controller = DavPushController::new(
config.dav_push.allowed_push_servers,
subscription_store.clone(),
);
tasks.push(tokio::spawn(async move {
dav_push_controller.notifier(update_recv).await;
}));
}
let app = make_app(
addr_store.clone(),
cal_store.clone(),
subscription_store.clone(),
principal_store.clone(),
config.frontend.clone(),
config.oidc.clone(),
config.caldav,
&config.nextcloud_login,
config.dav_push.enabled,
config.http.session_cookie_samesite_strict,
config.http.payload_limit_mb,
);
let app = ServiceExt::<Request>::into_make_service(
NormalizePathLayer::trim_trailing_slash().layer(app),
);
let address = format!("{}:{}", config.http.host, config.http.port);
let listener = tokio::net::TcpListener::bind(&address).await?;
tasks.push(tokio::spawn(async move {
info!("RustiCal serving on http://{address}");
if let Some(start_notifier) = start_notifier {
start_notifier.notify_waiters();
}
axum::serve(listener, app).await.unwrap();
}));
for task in tasks {
task.await?;
}
Ok(())
}

View File

@@ -1,112 +1,12 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)] #![warn(clippy::all, clippy::pedantic, clippy::nursery)]
use crate::commands::health::{HealthArgs, cmd_health};
use crate::config::Config;
use anyhow::Result; use anyhow::Result;
use app::make_app; use clap::Parser;
use axum::ServiceExt;
use axum::extract::Request;
use clap::{Parser, Subcommand};
use commands::cmd_gen_config;
use commands::principals::{PrincipalsArgs, cmd_principals};
use config::{DataStoreConfig, SqliteDataStoreConfig};
use figment::Figment; use figment::Figment;
use figment::providers::{Env, Format, Toml}; use figment::providers::{Env, Format, Toml};
use rustical_dav_push::DavPushController; use rustical::config::Config;
use rustical_store::auth::AuthenticationProvider; use rustical::{Args, Command};
use rustical_store::{ use rustical::{cmd_default, cmd_gen_config, cmd_health, cmd_principals};
AddressbookStore, CalendarStore, CollectionOperation, PrefixedCalendarStore, SubscriptionStore, use tracing::warn;
};
use rustical_store_sqlite::addressbook_store::SqliteAddressbookStore;
use rustical_store_sqlite::calendar_store::SqliteCalendarStore;
use rustical_store_sqlite::principal_store::SqlitePrincipalStore;
use rustical_store_sqlite::{SqliteStore, create_db_pool};
use setup_tracing::setup_tracing;
use std::sync::Arc;
use tokio::sync::mpsc::Receiver;
use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer;
use tracing::{info, warn};
mod app;
mod commands;
mod config;
#[cfg(test)]
pub mod integration_tests;
mod setup_tracing;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long, env, default_value = "/etc/rustical/config.toml")]
config_file: String,
#[arg(long, env, help = "Do no run database migrations (only for sql store)")]
no_migrations: bool,
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Debug, Subcommand)]
enum Command {
GenConfig(commands::GenConfigArgs),
Principals(PrincipalsArgs),
#[command(
about = "Healthcheck for running instance (Used for HEALTHCHECK in Docker container)"
)]
Health(HealthArgs),
}
async fn get_data_stores(
migrate: bool,
config: &DataStoreConfig,
) -> Result<(
Arc<impl AddressbookStore + PrefixedCalendarStore>,
Arc<impl CalendarStore>,
Arc<impl SubscriptionStore>,
Arc<impl AuthenticationProvider>,
Receiver<CollectionOperation>,
)> {
Ok(match &config {
DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url,
run_repairs,
skip_broken,
}) => {
let db = create_db_pool(db_url, migrate).await?;
// Channel to watch for changes (for DAV Push)
let (send, recv) = tokio::sync::mpsc::channel(1000);
let addressbook_store = Arc::new(SqliteAddressbookStore::new(
db.clone(),
send.clone(),
*skip_broken,
));
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
if *run_repairs {
info!("Running repair tasks");
addressbook_store.repair_orphans().await?;
cal_store.repair_invalid_version_4_0().await?;
cal_store.repair_orphans().await?;
}
let subscription_store = Arc::new(SqliteStore::new(db.clone()));
let principal_store = Arc::new(SqlitePrincipalStore::new(db));
// Validate all calendar objects
for principal in principal_store.get_principals().await? {
cal_store.validate_objects(&principal.id).await?;
addressbook_store.validate_objects(&principal.id).await?;
}
(
addressbook_store,
cal_store,
subscription_store,
principal_store,
recv,
)
}
})
}
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@@ -120,60 +20,17 @@ async fn main() -> Result<()> {
}; };
match args.command { match args.command {
Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args)?, Some(Command::GenConfig(gen_config_args)) => cmd_gen_config(gen_config_args),
Some(Command::Principals(principals_args)) => cmd_principals(principals_args).await?, Some(Command::Principals(principals_args)) => {
cmd_principals(principals_args, parse_config()?).await
}
Some(Command::Health(health_args)) => { Some(Command::Health(health_args)) => {
let config: Config = parse_config()?; let config: Config = parse_config()?;
cmd_health(config.http, health_args).await?; cmd_health(config.http, health_args).await
} }
None => { None => {
let config: Config = parse_config()?; let config: Config = parse_config()?;
cmd_default(args, config, None, true).await
setup_tracing(&config.tracing);
let (addr_store, cal_store, subscription_store, principal_store, update_recv) =
get_data_stores(!args.no_migrations, &config.data_store).await?;
let mut tasks = vec![];
if config.dav_push.enabled {
let dav_push_controller = DavPushController::new(
config.dav_push.allowed_push_servers,
subscription_store.clone(),
);
tasks.push(tokio::spawn(async move {
dav_push_controller.notifier(update_recv).await;
}));
}
let app = make_app(
addr_store.clone(),
cal_store.clone(),
subscription_store.clone(),
principal_store.clone(),
config.frontend.clone(),
config.oidc.clone(),
config.caldav,
&config.nextcloud_login,
config.dav_push.enabled,
config.http.session_cookie_samesite_strict,
config.http.payload_limit_mb,
);
let app = ServiceExt::<Request>::into_make_service(
NormalizePathLayer::trim_trailing_slash().layer(app),
);
let address = format!("{}:{}", config.http.host, config.http.port);
let listener = tokio::net::TcpListener::bind(&address).await?;
tasks.push(tokio::spawn(async move {
info!("RustiCal serving on http://{address}");
axum::serve(listener, app).await.unwrap();
}));
for task in tasks {
task.await?;
}
} }
} }
Ok(())
} }

84
tests/common/mod.rs Normal file
View File

@@ -0,0 +1,84 @@
use rustical::{
Args, cmd_default,
config::{Config, DataStoreConfig, HttpConfig, SqliteDataStoreConfig},
};
use std::{
collections::HashSet,
net::{Ipv4Addr, SocketAddrV4, TcpListener},
sync::{Arc, Mutex, OnceLock},
thread::{self, JoinHandle},
};
use tokio::sync::Notify;
use tokio_util::sync::CancellationToken;
// When running multiple integration tests we need to make sure that they don't get the same port
static BOUND_PORTS: OnceLock<Mutex<HashSet<u16>>> = OnceLock::new();
pub fn find_free_port() -> Option<u16> {
let bound_ports = BOUND_PORTS.get_or_init(Mutex::default);
let mut bound_ports_write = bound_ports.lock().unwrap();
let mut port = 15000;
// Frees the socket on drop such that this function returns a free port
while TcpListener::bind(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port)).is_err()
|| bound_ports_write.contains(&port)
{
port += 1;
if port >= 16000 {
return None;
}
}
bound_ports_write.insert(port);
Some(port)
}
pub fn rustical_process(
db_url: Option<String>,
) -> (CancellationToken, u16, JoinHandle<()>, Arc<Notify>) {
let port = find_free_port().unwrap();
let token = CancellationToken::new();
let cloned_token = token.clone();
let start_notify = Arc::new(Notify::new());
let cloned_start_notify = start_notify.clone();
let main_process = thread::spawn(move || {
let rt = tokio::runtime::Runtime::new().unwrap();
let fut = async {
cmd_default(
Args {
config_file: "asldajldakjsdkj".to_owned(),
no_migrations: false,
command: None,
},
Config {
data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url: db_url.unwrap_or(":memory:".to_owned()),
run_repairs: true,
skip_broken: false,
}),
http: HttpConfig {
host: "127.0.0.1".to_owned(),
port,
..Default::default()
},
frontend: Default::default(),
oidc: None,
tracing: Default::default(),
dav_push: Default::default(),
nextcloud_login: Default::default(),
caldav: Default::default(),
},
Some(cloned_start_notify),
false,
)
.await
};
rt.block_on(async {
tokio::select! {
_ = cloned_token.cancelled() => {},
_ = fut => {}
}
});
});
(token, port, main_process, start_notify)
}

137
tests/http_integration.rs Normal file
View File

@@ -0,0 +1,137 @@
// This integration test checks whether the HTTP server works by actually running rustical in a new
// thread.
use common::rustical_process;
use http::{Method, StatusCode};
use rustical::{
PrincipalsArgs, cmd_health, cmd_principals,
config::{Config, DataStoreConfig, HttpConfig, SqliteDataStoreConfig},
principals::{CreateArgs, PrincipalsCommand},
};
use rustical_store::auth::{AuthenticationProvider, PrincipalType};
use rustical_store_sqlite::{create_db_pool, principal_store::SqlitePrincipalStore};
use std::time::Duration;
mod common;
pub async fn test_runner<O, F>(db_path: Option<String>, inner: F)
where
O: IntoFuture<Output = ()>,
// <O as IntoFuture>::IntoFuture: UnwindSafe,
F: FnOnce(u16) -> O,
{
// Start RustiCal process
let (token, port, main_process, start_notify) = rustical_process(db_path);
// Wait for RustiCal server to listen
tokio::time::timeout(Duration::new(2, 0), start_notify.notified())
.await
.unwrap();
// We use catch_unwind to make sure we'll always correctly stop RustiCal
// Otherwise, our process would just run indefinitely
inner(port).into_future().await;
// Signal RustiCal to stop
token.cancel();
main_process.join().unwrap();
}
#[tokio::test]
async fn test_ping() {
test_runner(None, async |port| {
let origin = format!("http://localhost:{port}");
let resp = reqwest::get(origin.clone() + "/ping").await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
// Ensure that path normalisation works as intended
let resp = reqwest::get(origin + "/ping/").await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
cmd_health(
HttpConfig {
host: "localhost".to_owned(),
port,
..Default::default()
},
Default::default(),
)
.await
.unwrap();
})
.await
}
// When setting a use password from the CLI we effectively have two processes accessing the same
// database: The server and the CLI.
// This test ensures that the server correctly picks up the changes made by the CLI.
#[tokio::test]
async fn test_initial_setup() {
let db_tempfile = tempfile::NamedTempFile::with_suffix(".rustical-test.sqlite3").unwrap();
let db_path = db_tempfile.path().to_string_lossy().into_owned();
test_runner(Some(db_path.clone()), async |port| {
let origin = format!("http://localhost:{port}");
// Create principal
cmd_principals(
PrincipalsArgs {
command: PrincipalsCommand::Create(CreateArgs {
id: "user".to_owned(),
name: Some("Test User".to_owned()),
password: false,
principal_type: Some(PrincipalType::Individual),
}),
},
Config {
data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url: db_path.clone(),
run_repairs: true,
skip_broken: false,
}),
http: Default::default(),
frontend: Default::default(),
oidc: None,
tracing: Default::default(),
dav_push: Default::default(),
nextcloud_login: Default::default(),
caldav: Default::default(),
},
)
.await
.unwrap();
// Bodge to set password without using command (since that reads stdin)
let db = create_db_pool(&db_path, false).await.unwrap();
let principal_store = SqlitePrincipalStore::new(db);
let app_token = "token";
principal_store
.add_app_token("user", "Test Token".to_owned(), app_token.to_owned())
.await
.unwrap();
let url = origin.clone() + "/caldav/principal/user";
let resp = reqwest::Client::new()
.request(Method::from_bytes(b"PROPFIND").unwrap(), &url)
.send()
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::UNAUTHORIZED);
let resp = reqwest::Client::new()
.request(Method::from_bytes(b"PROPFIND").unwrap(), &url)
.basic_auth("user", Some("token"))
.send()
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::MULTI_STATUS);
principal_store.remove_principal("user").await.unwrap();
let resp = reqwest::Client::new()
.request(Method::from_bytes(b"PROPFIND").unwrap(), &url)
.send()
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::UNAUTHORIZED);
})
.await;
}

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};

View File

@@ -1,3 +1,4 @@
use super::{ResponseExtractString, calendar::mkcalendar_template, get_app};
use axum::body::Body; use axum::body::Body;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};
use http::{Request, StatusCode}; use http::{Request, StatusCode};
@@ -6,10 +7,6 @@ use rustical_store::CalendarMetadata;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context}; use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt; use tower::ServiceExt;
use crate::integration_tests::{
ResponseExtractString, caldav::calendar::mkcalendar_template, get_app,
};
#[rstest] #[rstest]
#[tokio::test] #[tokio::test]
async fn test_put_invalid( async fn test_put_invalid(
@@ -75,3 +72,53 @@ END:VCALENDAR";
</error> </error>
"#); "#);
} }
/// Thunderbird creates VTIMEZONE objects with invalid RRULEs.
/// While invalid, we still want to accept them since Thunderbird is quite commonly used.
/// In the future, we might fix invalid timezones ourself.
#[rstest]
#[tokio::test]
async fn test_put_thunderbird(
#[from(test_store_context)]
#[future]
context: TestStoreContext,
) {
let context = context.await;
let app = get_app(context.clone());
let calendar_meta = CalendarMetadata {
displayname: Some("Calendar".to_string()),
description: Some("Description".to_string()),
color: Some("#00FF00".to_string()),
order: 0,
};
let (principal, cal_id) = ("user", "calendar");
let url = format!("/caldav/principal/{principal}/{cal_id}");
let mut request = Request::builder()
.method("MKCALENDAR")
.uri(&url)
.body(Body::from(mkcalendar_template(&calendar_meta)))
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::CREATED);
let ical = include_str!("resources/ical_thunderbird.ics");
let mut request = Request::builder()
.method("PUT")
.uri(format!("{url}/qwue23489.ics"))
.header("If-None-Match", "*")
.header("Content-Type", "text/calendar")
.body(Body::from(ical))
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::CREATED);
}

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};

View File

@@ -0,0 +1,206 @@
BEGIN:VCALENDAR
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
X-TZINFO:Europe/Berlin[2025b]
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+005328
TZNAME:Europe/Berlin(STD)
DTSTART:18930401T000000
RDATE:18930401T000000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19160430T230000
RDATE:19160430T230000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19161001T010000
RDATE:19161001T010000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19170416T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=3MO;UNTIL=19180415T020000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19170917T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=3MO;UNTIL=19180916T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19400401T020000
RDATE:19400401T020000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19421102T030000
RDATE:19421102T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19430329T020000
RDATE:19430329T020000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19440403T020000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1MO;UNTIL=19450402T020000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZOFFSETTO:+030000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(DST)
DTSTART:19450524T020000
RDATE:19450524T020000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19431004T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1MO;UNTIL=19441002T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+030000
TZNAME:Europe/Berlin(DST)
DTSTART:19450924T030000
RDATE:19450924T030000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19451118T030000
RDATE:19451118T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19460414T020000
RDATE:19460414T020000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19470406T030000
RDATE:19470406T030000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZOFFSETTO:+030000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(DST)
DTSTART:19470511T030000
RDATE:19470511T030000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19461007T030000
RDATE:19461007T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+030000
TZNAME:Europe/Berlin(DST)
DTSTART:19470629T030000
RDATE:19470629T030000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19480418T020000
RDATE:19480418T020000
END:DAYLIGHT
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19490410T020000
RDATE:19490410T020000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19471005T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=1SU;UNTIL=19491002T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19800406T020000
RDATE:19800406T020000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19800928T030000
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU;UNTIL=19950924T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:Europe/Berlin(DST)
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU;UNTIL=19960331T020000
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:Europe/Berlin(STD)
DTSTART:19961027T030000
RDATE:19961027T030000
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETTO:+020000
TZOFFSETFROM:+010000
TZNAME:(DST)
DTSTART:19970330T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETTO:+010000
TZOFFSETFROM:+020000
TZNAME:(STD)
DTSTART:19971026T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20260130T134029Z
LAST-MODIFIED:20260130T134029Z
DTSTAMP:20260130T134029Z
UID:620c612d-2b03-4fcf-97c7-8fecd6e18565
DTSTART;TZID=Europe/Berlin:20260130T050000
DTEND;TZID=Europe/Berlin:20260130T070000
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

View File

@@ -0,0 +1,5 @@
---
source: tests/integration_tests/caldav/calendar.rs
expression: body
---

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar.rs source: tests/integration_tests/caldav/calendar.rs
expression: body expression: body
--- ---
BEGIN:VCALENDAR BEGIN:VCALENDAR

View File

@@ -0,0 +1,5 @@
---
source: tests/integration_tests/caldav/calendar.rs
expression: body
---

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar.rs source: tests/integration_tests/caldav/calendar.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar.rs source: tests/integration_tests/caldav/calendar.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar.rs source: tests/integration_tests/caldav/calendar.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar_import.rs source: tests/integration_tests/caldav/calendar_import.rs
expression: body expression: body
--- ---
BEGIN:VCALENDAR BEGIN:VCALENDAR

View File

@@ -0,0 +1,5 @@
---
source: tests/integration_tests/caldav/calendar_import.rs
expression: body
---

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar_import.rs source: tests/integration_tests/caldav/calendar_import.rs
expression: body expression: body
--- ---
BEGIN:VCALENDAR BEGIN:VCALENDAR

View File

@@ -0,0 +1,5 @@
---
source: tests/integration_tests/caldav/calendar_import.rs
expression: body
---

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar_report.rs source: tests/integration_tests/caldav/calendar_report.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar_report.rs source: tests/integration_tests/caldav/calendar_report.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/calendar_report.rs source: tests/integration_tests/caldav/calendar_report.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/mod.rs source: tests/integration_tests/caldav/mod.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/mod.rs source: tests/integration_tests/caldav/mod.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/caldav/mod.rs source: tests/integration_tests/caldav/mod.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};
@@ -27,11 +27,10 @@ async fn test_import(
.body(Body::from( .body(Body::from(
r"BEGIN:VCARD r"BEGIN:VCARD
VERSION:4.0 VERSION:4.0
FN:Simon Perreault FN:John Doe
N:Perreault;Simon;;;ing. jr,M.Sc. N:Doe;John;;;,
BDAY:--0203 BDAY:--0203
GENDER:M GENDER:M
EMAIL;TYPE=work:simon.perreault@viagenie.ca
END:VCARD", END:VCARD",
)) ))
.unwrap() .unwrap()

View File

@@ -1,4 +1,4 @@
use crate::integration_tests::{ResponseExtractString, get_app}; use super::{ResponseExtractString, get_app};
use axum::body::Body; use axum::body::Body;
use axum::extract::Request; use axum::extract::Request;
use headers::{Authorization, HeaderMapExt}; use headers::{Authorization, HeaderMapExt};

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/carddav/addressbook.rs source: tests/integration_tests/carddav/addressbook.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/carddav/addressbook.rs source: tests/integration_tests/carddav/addressbook.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/carddav/addressbook.rs source: tests/integration_tests/carddav/addressbook.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

@@ -0,0 +1,12 @@
---
source: tests/integration_tests/carddav/addressbook_import.rs
expression: body
---
BEGIN:VCARD
VERSION:4.0
FN:John Doe
N:Doe;John;;;,
BDAY:--0203
GENDER:M
UID:[UID]
END:VCARD

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
--- ---
source: src/integration_tests/carddav/mod.rs source: tests/integration_tests/carddav/mod.rs
expression: body expression: body
--- ---
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,35 @@
---
source: tests/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/newcard.vcf</href>
<propstat>
<prop>
<getetag>&quot;ea0bf4a2ce7ef84606a4cf9235776dbc11b3e7ce351ddf35f27cbc0088acca7e&quot;</getetag>
<CARD:address-data>BEGIN:VCARD
VERSION:3.0
FN:Cyrus Daboo
N:Daboo;Cyrus
ADR;TYPE=POSTAL:;2822 Email HQ;Suite 2821;RFCVille;PA;15213;USA
EMAIL;TYPE=INTERNET,PREF:cyrus@example.com
NICKNAME:me
NOTE:Example VCard.
ORG:Self Employed
TEL;TYPE=WORK,VOICE:412 605 0499
TEL;TYPE=FAX:412 605 0705
URL:http://www.example.com
UID:1234-5678-9000-1
END:VCARD
</CARD:address-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/home/bernard/addressbook/vcf1.vcf</href>
<status>HTTP/1.1 404 Not Found</status>
</response>
</multistatus>

View File

@@ -0,0 +1,68 @@
---
source: tests/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: tests/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,12 @@
---
source: tests/integration_tests/carddav/addressbook_import.rs
expression: body
---
BEGIN:VCARD
VERSION:4.0
FN:John Doe
N:Doe;John;;;,
BDAY:--0203
GENDER:M
UID:[UID]
END:VCARD

View File

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

View File

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

View File

@@ -0,0 +1,27 @@
---
source: tests/integration_tests/carddav/mod.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/</href>
<propstat>
<prop>
<resourcetype>
<collection/>
</resourcetype>
<displayname>RustiCal DAV root</displayname>
<current-user-principal>
<href>/carddav/principal/user/</href>
</current-user-principal>
<current-user-privilege-set>
<privilege>
<all/>
</privilege>
</current-user-privilege-set>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

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

View File

@@ -1,7 +1,7 @@
use crate::{app::make_app, config::NextcloudLoginConfig};
use axum::extract::Request; use axum::extract::Request;
use axum::{body::Body, response::Response}; use axum::{body::Body, response::Response};
use rstest::rstest; use rstest::rstest;
use rustical::{app::make_app, config::NextcloudLoginConfig};
use rustical_caldav::CalDavConfig; use rustical_caldav::CalDavConfig;
use rustical_frontend::FrontendConfig; use rustical_frontend::FrontendConfig;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context}; use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};

View File

@@ -0,0 +1,3 @@
// This file is just an entrypoint for integration_tests
// since the test runner only looks for files to run.
mod integration_tests;