mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2025-10-09 03:55:45 +08:00
Token revoke tests
This commit is contained in:
parent
a491c6388f
commit
7142a8caab
3 changed files with 17 additions and 13 deletions
|
@ -254,13 +254,11 @@ impl Server {
|
||||||
|
|
||||||
pub async fn increment_principal_revision(&self, changed_principals: ChangedPrincipals) {
|
pub async fn increment_principal_revision(&self, changed_principals: ChangedPrincipals) {
|
||||||
let mut nested_principals = Vec::new();
|
let mut nested_principals = Vec::new();
|
||||||
let mut fetched_ids = AHashSet::new();
|
|
||||||
|
|
||||||
for (id, changed_principal) in changed_principals.iter() {
|
for (id, changed_principal) in changed_principals.iter() {
|
||||||
self.increment_revision(*id).await;
|
self.increment_revision(*id).await;
|
||||||
if changed_principal.member_change {
|
|
||||||
nested_principals.push(*id);
|
|
||||||
|
|
||||||
|
if changed_principal.member_change {
|
||||||
if changed_principal.typ == Type::Tenant {
|
if changed_principal.typ == Type::Tenant {
|
||||||
match self
|
match self
|
||||||
.store()
|
.store()
|
||||||
|
@ -277,12 +275,7 @@ impl Server {
|
||||||
Ok(principals) => {
|
Ok(principals) => {
|
||||||
for principal in principals.items {
|
for principal in principals.items {
|
||||||
if !changed_principals.contains(principal.id()) {
|
if !changed_principals.contains(principal.id()) {
|
||||||
if principal.typ() == Type::Role {
|
|
||||||
nested_principals.push(principal.id());
|
|
||||||
} else {
|
|
||||||
self.increment_revision(principal.id()).await;
|
self.increment_revision(principal.id()).await;
|
||||||
fetched_ids.insert(principal.id());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,11 +286,14 @@ impl Server {
|
||||||
.account_id(*id));
|
.account_id(*id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
nested_principals.push(*id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !nested_principals.is_empty() {
|
if !nested_principals.is_empty() {
|
||||||
|
let mut fetched_ids = AHashSet::new();
|
||||||
let mut ids = nested_principals.into_iter();
|
let mut ids = nested_principals.into_iter();
|
||||||
let mut ids_stack = vec![];
|
let mut ids_stack = vec![];
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ pub async fn jmap_tests() {
|
||||||
thread_get::test(&mut params).await;
|
thread_get::test(&mut params).await;
|
||||||
thread_merge::test(&mut params).await;
|
thread_merge::test(&mut params).await;
|
||||||
mailbox::test(&mut params).await;
|
mailbox::test(&mut params).await;
|
||||||
delivery::test(&mut params).await;
|
delivery::test(&mut params).await;*/
|
||||||
auth_acl::test(&mut params).await;
|
auth_acl::test(&mut params).await;
|
||||||
auth_limits::test(&mut params).await;
|
auth_limits::test(&mut params).await;
|
||||||
auth_oauth::test(&mut params).await;
|
auth_oauth::test(&mut params).await;
|
||||||
|
@ -395,7 +395,7 @@ pub async fn jmap_tests() {
|
||||||
websocket::test(&mut params).await;
|
websocket::test(&mut params).await;
|
||||||
quota::test(&mut params).await;
|
quota::test(&mut params).await;
|
||||||
crypto::test(&mut params).await;
|
crypto::test(&mut params).await;
|
||||||
blob::test(&mut params).await;*/
|
blob::test(&mut params).await;
|
||||||
permissions::test(¶ms).await;
|
permissions::test(¶ms).await;
|
||||||
purge::test(&mut params).await;
|
purge::test(&mut params).await;
|
||||||
enterprise::test(&mut params).await;
|
enterprise::test(&mut params).await;
|
||||||
|
|
|
@ -50,7 +50,8 @@ pub async fn test(params: &JMAPTest) {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate_permissions(
|
.validate_permissions(
|
||||||
Permission::all().filter(|p| p.is_user_permission() && *p != Permission::Pop3Dele),
|
Permission::all().filter(|p| p.is_user_permission() && *p != Permission::Pop3Dele),
|
||||||
);
|
)
|
||||||
|
.validate_revision(0);
|
||||||
|
|
||||||
// Create multiple roles
|
// Create multiple roles
|
||||||
for (role, permissions, parent_role) in &[
|
for (role, permissions, parent_role) in &[
|
||||||
|
@ -139,7 +140,8 @@ pub async fn test(params: &JMAPTest) {
|
||||||
Permission::ImapList,
|
Permission::ImapList,
|
||||||
Permission::Pop3Authenticate,
|
Permission::Pop3Authenticate,
|
||||||
Permission::Pop3List,
|
Permission::Pop3List,
|
||||||
]);
|
])
|
||||||
|
.validate_revision(1);
|
||||||
|
|
||||||
// Query all principals
|
// Query all principals
|
||||||
api.get::<List<Principal>>("/api/principal")
|
api.get::<List<Principal>>("/api/principal")
|
||||||
|
@ -833,6 +835,7 @@ trait ValidatePermissions {
|
||||||
expected_permissions: impl IntoIterator<Item = Permission>,
|
expected_permissions: impl IntoIterator<Item = Permission>,
|
||||||
) -> Self;
|
) -> Self;
|
||||||
fn validate_tenant(self, tenant_id: u32, tenant_quota: u64) -> Self;
|
fn validate_tenant(self, tenant_id: u32, tenant_quota: u64) -> Self;
|
||||||
|
fn validate_revision(self, revision: u64) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValidatePermissions for Arc<AccessToken> {
|
impl ValidatePermissions for Arc<AccessToken> {
|
||||||
|
@ -877,4 +880,9 @@ impl ValidatePermissions for Arc<AccessToken> {
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_revision(self, revision: u64) -> Self {
|
||||||
|
assert_eq!(self.revision, revision);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue