Skip to content

Commit

Permalink
fixup! JAMES-2182 Fix rights for CREATE
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Oct 21, 2024
1 parent aa0b28c commit babafcd
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void hasInboxShouldBeTrueWhenINBOXIsCreated() throws Exception {

@Test
void shareeShouldBeAbleToCreateMailbox() throws Exception {
assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
session = mailboxManager.createSystemSession(USER_1);
MailboxPath mailboxPath = MailboxPath.inbox(session);
mailboxManager.createMailbox(mailboxPath, session);
Expand All @@ -294,6 +295,7 @@ void shareeShouldBeAbleToCreateMailbox() throws Exception {

@Test
void shareeShouldBeAbleToCreateMailboxChildren() throws Exception {
assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
session = mailboxManager.createSystemSession(USER_1);
MailboxPath mailboxPath = MailboxPath.inbox(session);
mailboxManager.createMailbox(mailboxPath, session);
Expand All @@ -317,6 +319,7 @@ void shareeShouldBeAbleToCreateMailboxChildren() throws Exception {

@Test
void shareeShouldBeAbleToCreateMailboxChildrenIntermediatePaths() throws Exception {
assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
session = mailboxManager.createSystemSession(USER_1);
MailboxPath mailboxPath = MailboxPath.inbox(session);
mailboxManager.createMailbox(mailboxPath, session);
Expand All @@ -340,6 +343,7 @@ void shareeShouldBeAbleToCreateMailboxChildrenIntermediatePaths() throws Excepti

@Test
void shareeShouldBeAbleToDeleteMailbox() throws Exception {
assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
session = mailboxManager.createSystemSession(USER_1);
MailboxPath mailboxPath = MailboxPath.forUser(USER_1, "child");
mailboxManager.createMailbox(mailboxPath, session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ trait MailboxSetMethodContract {
val mailboxId: MailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)

server.getProbe(classOf[ACLProbeImpl])
.replaceRights(path, BOB.asString, new MailboxACL.Rfc4314Rights(Right.Lookup, Right.Read, Right.CreateMailbox))
.replaceRights(path, BOB.asString, new MailboxACL.Rfc4314Rights(Right.Lookup, Right.Read))
val request =
s"""
|{
Expand Down Expand Up @@ -2173,6 +2173,84 @@ trait MailboxSetMethodContract {
|}""".stripMargin)
}

@Test
def mailboxSetShouldCreateChildMailboxWhenSharedParentMailboxWithCreateRight(server: GuiceJamesServer): Unit = {
val path = MailboxPath.forUser(ANDRE, "mailbox")
val mailboxId: MailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)

server.getProbe(classOf[ACLProbeImpl])
.replaceRights(path, BOB.asString, new MailboxACL.Rfc4314Rights(Right.Lookup, Right.Read, Right.CreateMailbox))
val request =
s"""
|{
| "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail" ],
| "methodCalls": [
| [
| "Mailbox/set",
| {
| "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
| "create": {
| "C42": {
| "name": "childMailbox",
| "parentId":"${mailboxId.serialize}"
| }
| }
| },
| "c1"
| ]
| ]
|}
|""".stripMargin

val response = `given`
.header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
.body(request)
.when
.post
.`then`
.log().ifValidationFails()
.statusCode(SC_OK)
.contentType(JSON)
.extract
.body
.asString

assertThatJson(response)
.whenIgnoringPaths("methodResponses[0][1].newState", "methodResponses[0][1].oldState")
.isEqualTo(
s"""{
| "sessionState": "${SESSION_STATE.value}",
| "methodResponses": [[
| "Mailbox/set",
| {
| "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
| "created":{
| "C42":{
| "id":"3",
| "isSubscribed":true,
| "myRights":{
| "mayAddItems":true,
| "mayCreateChild":true,
| "mayDelete":true,
| "mayReadItems":true,
| "mayRemoveItems":true,
| "mayRename":true,
| "maySetKeywords":true,
| "maySetSeen":true,
| "maySubmit":true
| },
| "sortOrder":1000,
| "totalEmails":0,
| "totalThreads":0,
| "unreadEmails":0,
| "unreadThreads":0
| }
| }
| },
| "c1"]]
|}""".stripMargin)
}

@Test
@Tag(CategoryTags.BASIC_FEATURE)
def deleteShouldSucceedWhenMailboxExists(server: GuiceJamesServer): Unit = {
Expand Down

0 comments on commit babafcd

Please sign in to comment.