WebDAV permissions and logging (closes #1362)

This commit is contained in:
mdecimus
2025-05-09 15:47:09 +02:00
parent fe7d646966
commit 095c501a66
50 changed files with 1031 additions and 273 deletions

View File

@@ -6,7 +6,7 @@
use ahash::AHashSet;
use directory::{
QueryBy, Type,
Permission, QueryBy, Type,
backend::{
RcptType,
internal::{
@@ -774,6 +774,7 @@ pub trait TestInternalDirectory {
async fn create_test_group(&self, login: &str, name: &str, emails: &[&str]) -> u32;
async fn create_test_list(&self, login: &str, name: &str, emails: &[&str]) -> u32;
async fn set_test_quota(&self, login: &str, quota: u32);
async fn add_permissions(&self, login: &str, permissions: impl IntoIterator<Item = Permission>);
async fn add_to_group(&self, login: &str, group: &str) -> ChangedPrincipals;
async fn remove_from_group(&self, login: &str, group: &str) -> ChangedPrincipals;
async fn remove_test_alias(&self, login: &str, alias: &str);
@@ -898,6 +899,28 @@ impl TestInternalDirectory for Store {
.unwrap();
}
async fn add_permissions(
&self,
login: &str,
permissions: impl IntoIterator<Item = Permission>,
) {
self.update_principal(
UpdatePrincipal::by_name(login).with_updates(
permissions
.into_iter()
.map(|p| {
PrincipalUpdate::add_item(
PrincipalField::EnabledPermissions,
PrincipalValue::String(p.name().to_string()),
)
})
.collect(),
),
)
.await
.unwrap();
}
async fn add_to_group(&self, login: &str, group: &str) -> ChangedPrincipals {
self.update_principal(UpdatePrincipal::by_name(login).with_updates(vec![
PrincipalUpdate::add_item(

View File

@@ -16,7 +16,10 @@ pub async fn test(test: &WebDavTest) {
.await
.with_header(
"dav",
"1, 2, 3, access-control, extended-mkcol, calendar-access, addressbook",
concat!(
"1, 2, 3, access-control, extended-mkcol, ",
"calendar-access, calendar-no-timezone, addressbook"
),
)
.with_header(
"allow",

View File

@@ -70,6 +70,28 @@ pub async fn test(test: &WebDavTest) {
);
client.validate_values(&hierarchy).await;
// Delete cache an resync
test.clear_cache();
let response = client
.sync_collection(
&user_base_path,
prev_sync_token,
Depth::Infinity,
None,
["D:getetag"],
)
.await;
let sync_token = response.sync_token();
let changed_hrefs = response.hrefs();
assert_ne!(sync_token, prev_sync_token);
assert_eq!(
changed_hrefs,
hierarchy.iter().map(|x| x.0.as_str()).collect::<Vec<_>>(),
"lengths {} & {}",
changed_hrefs.len(),
hierarchy.len()
);
// Copying and moving to the same or root containers is invalid
for method in ["COPY", "MOVE"] {
for destination in [

View File

@@ -22,6 +22,7 @@ use common::{
manager::boot::build_ipc,
};
use dav_proto::schema::property::{DavProperty, WebDavProperty};
use directory::Permission;
use groupware::{DavResourceName, cache::GroupwareCache};
use http::HttpSessionManager;
use hyper::{HeaderMap, Method, StatusCode, header::AUTHORIZATION};
@@ -201,6 +202,12 @@ async fn init_webdav_tests(store_id: &str, delete_if_exists: bool) -> WebDavTest
*account,
DummyWebDavClient::new(account_id, account, secret, email),
);
store
.add_permissions(
account,
[Permission::DavPrincipalList, Permission::DavPrincipalSearch],
)
.await;
if *account == "mike" {
store.set_test_quota(account, 1024).await;
}
@@ -232,8 +239,7 @@ impl WebDavTest {
.unwrap()
}
pub async fn assert_is_empty(&self) {
assert_is_empty(self.server.clone()).await;
pub fn clear_cache(&self) {
for cache in [
&self.server.inner.cache.events,
&self.server.inner.cache.contacts,
@@ -242,6 +248,11 @@ impl WebDavTest {
cache.clear();
}
}
pub async fn assert_is_empty(&self) {
assert_is_empty(self.server.clone()).await;
self.clear_cache();
}
}
#[allow(dead_code)]