-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
James-4097 Allow disabling same-domain requirement when assigning rig…
…hts (#2573)
- Loading branch information
1 parent
f6eb81f
commit 4c4d6d3
Showing
11 changed files
with
113 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,23 @@ | |
import static org.apache.james.mailbox.fixture.MailboxFixture.CEDRIC; | ||
import static org.apache.james.mailbox.fixture.MailboxFixture.INBOX_ALICE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import jakarta.mail.Flags; | ||
|
||
import org.apache.james.core.Username; | ||
import org.apache.james.events.Event; | ||
import org.apache.james.events.EventBus; | ||
import org.apache.james.mailbox.MailboxSession; | ||
import org.apache.james.mailbox.MailboxSessionUtil; | ||
import org.apache.james.mailbox.acl.ACLDiff; | ||
import org.apache.james.mailbox.acl.MailboxACLResolver; | ||
import org.apache.james.mailbox.acl.UnionMailboxACLResolver; | ||
import org.apache.james.mailbox.events.MailboxIdRegistrationKey; | ||
import org.apache.james.mailbox.exception.DifferentDomainException; | ||
import org.apache.james.mailbox.exception.MailboxException; | ||
import org.apache.james.mailbox.exception.MailboxNotFoundException; | ||
|
@@ -65,14 +70,15 @@ class StoreRightManagerTest { | |
MailboxSession aliceSession; | ||
MailboxACLResolver mailboxAclResolver; | ||
MailboxMapper mockedMailboxMapper; | ||
EventBus eventBus; | ||
|
||
@BeforeEach | ||
void setup() { | ||
aliceSession = MailboxSessionUtil.create(MailboxFixture.ALICE); | ||
MailboxSessionMapperFactory mockedMapperFactory = mock(MailboxSessionMapperFactory.class); | ||
mockedMailboxMapper = mock(MailboxMapper.class); | ||
mailboxAclResolver = new UnionMailboxACLResolver(); | ||
EventBus eventBus = mock(EventBus.class); | ||
eventBus = mock(EventBus.class); | ||
when(mockedMapperFactory.getMailboxMapper(aliceSession)) | ||
.thenReturn(mockedMailboxMapper); | ||
|
||
|
@@ -259,22 +265,37 @@ void areDomainsDifferentShouldReturnFalseWhenDomainsAreIdentical() { | |
} | ||
|
||
@Test | ||
void assertSharesBelongsToUserDomainShouldThrowWhenOneDomainIsDifferent() throws Exception { | ||
void assertUserHasAccessToShareeDomainsShouldThrowWhenOneDomainIsDifferent() throws Exception { | ||
MailboxACL mailboxACL = new MailboxACL(new MailboxACL.Entry("[email protected]", Right.Write), | ||
new MailboxACL.Entry("[email protected]", Right.Write), | ||
new MailboxACL.Entry("[email protected]", Right.Write)); | ||
|
||
assertThatThrownBy(() -> storeRightManager.assertSharesBelongsToUserDomain(Username.of("[email protected]"), mailboxACL.getEntries())) | ||
assertThatThrownBy(() -> storeRightManager.assertUserHasAccessToShareeDomains(Username.of("[email protected]"), mailboxACL.getEntries())) | ||
.isInstanceOf(DifferentDomainException.class); | ||
} | ||
|
||
@Test | ||
void assertSharesBelongsToUserDomainShouldNotThrowWhenDomainsAreIdentical() throws Exception { | ||
void assertUserHasAccessToShareeDomainsShouldNotThrowWhenDomainsAreIdentical() throws Exception { | ||
MailboxACL mailboxACL = new MailboxACL(new MailboxACL.Entry("[email protected]", Right.Write), | ||
new MailboxACL.Entry("[email protected]", Right.Write), | ||
new MailboxACL.Entry("[email protected]", Right.Write)); | ||
|
||
storeRightManager.assertSharesBelongsToUserDomain(Username.of("[email protected]"), mailboxACL.getEntries()); | ||
storeRightManager.assertUserHasAccessToShareeDomains(Username.of("[email protected]"), mailboxACL.getEntries()); | ||
} | ||
|
||
@Test | ||
void assertUserHasAccessToShareDomainsShouldNotThrowOnDifferentDomainsWhenCrossDomainAccessEnabled() throws Exception { | ||
try { | ||
StoreRightManager.IS_CROSS_DOMAIN_ACCESS_ALLOWED = true; | ||
|
||
MailboxACL mailboxACL = new MailboxACL(new MailboxACL.Entry("[email protected]", Right.Write), | ||
new MailboxACL.Entry("[email protected]", Right.Write), | ||
new MailboxACL.Entry("[email protected]", Right.Write)); | ||
|
||
storeRightManager.assertUserHasAccessToShareeDomains(Username.of("[email protected]"), mailboxACL.getEntries()); | ||
} finally { | ||
StoreRightManager.IS_CROSS_DOMAIN_ACCESS_ALLOWED = false; | ||
} | ||
} | ||
|
||
@Test | ||
|
@@ -288,4 +309,30 @@ void applyRightsCommandShouldThrowWhenDomainsAreDifferent() { | |
assertThatThrownBy(() -> storeRightManager.applyRightsCommand(mailboxPath, aclCommand, aliceSession)) | ||
.isInstanceOf(DifferentDomainException.class); | ||
} | ||
|
||
@Test | ||
void applyRightsCommandShouldNotThrowOnDifferentDomainsWhenCrossDomainEnabled() throws MailboxException { | ||
try { | ||
StoreRightManager.IS_CROSS_DOMAIN_ACCESS_ALLOWED = true; | ||
|
||
MailboxPath mailboxPath = MailboxPath.forUser(Username.of("[email protected]"), "mailbox"); | ||
Mailbox mailbox = new Mailbox(mailboxPath, UID_VALIDITY, MAILBOX_ID); | ||
mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE.asString(), Right.Administer))); | ||
ACLCommand aclCommand = MailboxACL.command() | ||
.forUser(Username.of("[email protected]")) | ||
.rights(Right.Read) | ||
.asAddition(); | ||
|
||
when(mockedMailboxMapper.findMailboxByPath(mailboxPath)).thenReturn(Mono.just(mailbox)); | ||
when(mockedMailboxMapper.updateACL(mailbox, aclCommand)).thenReturn(Mono.just(ACLDiff.computeDiff(MailboxACL.EMPTY, new MailboxACL( | ||
new MailboxACL.Entry("[email protected]", Right.Read) | ||
)))); | ||
when(eventBus.dispatch(any(Event.class), any(MailboxIdRegistrationKey.class))).thenReturn(Mono.empty()); | ||
|
||
assertThatCode(() -> storeRightManager.applyRightsCommand(mailboxPath, aclCommand, aliceSession)) | ||
.doesNotThrowAnyException(); | ||
} finally { | ||
StoreRightManager.IS_CROSS_DOMAIN_ACCESS_ALLOWED = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters