This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 2d6826ddca3812c392571991863ad65a8dc7e9ab Author: Quan Tran <[email protected]> AuthorDate: Mon Jul 13 19:49:12 2026 +0700 [BUILD] DelegatedAccountGetMethodContract: isolate using different users --- .../DistributedDelegatedAccountGetMethodTest.java | 2 +- .../DelegatedAccountGetMethodContract.scala | 127 +++++++++++++-------- .../MemoryDelegatedAccountGetMethodTest.java | 2 +- .../PostgresDelegatedAccountGetMethodTest.java | 2 +- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedDelegatedAccountGetMethodTest.java b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedDelegatedAccountGetMethodTest.java index 39eeb4ba66..c597f1481c 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedDelegatedAccountGetMethodTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedDelegatedAccountGetMethodTest.java @@ -21,6 +21,6 @@ package org.apache.james.jmap.rfc8621.distributed; import org.apache.james.jmap.rfc8621.contract.DelegatedAccountGetMethodContract; -public class DistributedDelegatedAccountGetMethodTest extends DistributedBase implements DelegatedAccountGetMethodContract { +public class DistributedDelegatedAccountGetMethodTest extends PerClassDistributedBase implements DelegatedAccountGetMethodContract { } diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DelegatedAccountGetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DelegatedAccountGetMethodContract.scala index dbce110212..92dd5a669d 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DelegatedAccountGetMethodContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DelegatedAccountGetMethodContract.scala @@ -19,6 +19,11 @@ package org.apache.james.jmap.rfc8621.contract +import java.nio.charset.StandardCharsets +import java.util.UUID +import java.util.concurrent.atomic + +import com.google.common.hash.Hashing import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT import io.restassured.RestAssured.{`given`, requestSpecification} import io.restassured.http.ContentType.JSON @@ -26,31 +31,55 @@ import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson import net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER import org.apache.http.HttpStatus.SC_OK import org.apache.james.GuiceJamesServer +import org.apache.james.core.Username import org.apache.james.jmap.core.ResponseObject.SESSION_STATE import org.apache.james.jmap.delegation.DelegationId import org.apache.james.jmap.http.UserCredential -import org.apache.james.jmap.rfc8621.contract.DelegatedAccountGetMethodContract.BOB_ACCOUNT_ID -import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, ANDRE, ANDRE_ACCOUNT_ID, ANDRE_PASSWORD, BOB, BOB_PASSWORD, CEDRIC, DOMAIN, authScheme, baseRequestSpecBuilder} +import org.apache.james.jmap.rfc8621.contract.Fixture._ import org.apache.james.jmap.rfc8621.contract.probe.DelegationProbe import org.apache.james.utils.DataProbeImpl import org.junit.jupiter.api.{BeforeEach, Test} -object DelegatedAccountGetMethodContract { - val BOB_ACCOUNT_ID: String = Fixture.ACCOUNT_ID +object DelegatedAccountGetMethodContractContext { + case class TestContext(bobUsername: Username, bobAccountId: String, andreUsername: Username, andreAccountId: String, cedricUsername: Username) + + val currentContext: atomic.AtomicReference[TestContext] = new atomic.AtomicReference[TestContext]() } + trait DelegatedAccountGetMethodContract { + import DelegatedAccountGetMethodContractContext.{TestContext, currentContext} + + def bobUsername: Username = currentContext.get().bobUsername + def bobAccountId: String = currentContext.get().bobAccountId + def andreUsername: Username = currentContext.get().andreUsername + def andreAccountId: String = currentContext.get().andreAccountId + def cedricUsername: Username = currentContext.get().cedricUsername + + private def accountId(username: Username): String = + Hashing.sha256().hashString(username.asString(), StandardCharsets.UTF_8).toString @BeforeEach def setUp(server: GuiceJamesServer): Unit = { + val uniqueSuffix = UUID.randomUUID().toString.replace("-", "").take(8) + val bob = Username.fromLocalPartWithDomain(s"bob$uniqueSuffix", DOMAIN) + val andre = Username.fromLocalPartWithDomain(s"andre$uniqueSuffix", DOMAIN) + val cedric = Username.fromLocalPartWithDomain(s"cedric$uniqueSuffix", DOMAIN) + currentContext.set(TestContext( + bobUsername = bob, + bobAccountId = accountId(bob), + andreUsername = andre, + andreAccountId = accountId(andre), + cedricUsername = cedric)) + server.getProbe(classOf[DataProbeImpl]) .fluent .addDomain(DOMAIN.asString) - .addUser(BOB.asString, BOB_PASSWORD) - .addUser(ANDRE.asString(), ANDRE_PASSWORD) - .addUser(CEDRIC.asString(), "cedric_pass") + .addUser(bob.asString, BOB_PASSWORD) + .addUser(andre.asString(), ANDRE_PASSWORD) + .addUser(cedric.asString(), "cedric_pass") requestSpecification = baseRequestSpecBuilder(server) - .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD))) + .setAuth(authScheme(UserCredential(bob, BOB_PASSWORD))) .addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) .build } @@ -66,7 +95,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": null | }, | "c1"]] @@ -86,7 +115,7 @@ trait DelegatedAccountGetMethodContract { | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [], | "notFound": [] | }, @@ -97,7 +126,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldReturnListWhenAuthorized(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) val response: String = `given` .body(s"""{ @@ -107,7 +136,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": null | }, | "c1"]] @@ -130,12 +159,12 @@ trait DelegatedAccountGetMethodContract { | [ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "notFound": [], | "list": [ | { - | "id": "${DelegationId.from(ANDRE, BOB).serialize}", - | "username": "${ANDRE.asString()}" + | "id": "${DelegationId.from(andreUsername, bobUsername).serialize}", + | "username": "${andreUsername.asString()}" | } | ] | }, @@ -148,7 +177,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldReturnEmptyListWhenIdsAreEmpty(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) val response = `given` .body( @@ -159,7 +188,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": [] | }, | "c1"]] @@ -179,7 +208,7 @@ trait DelegatedAccountGetMethodContract { | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [], | "notFound": [] | }, @@ -190,7 +219,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldReturnNotFoundWhenIdDoesNotExist(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) val response = `given` .body( @@ -201,7 +230,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": ["notFound1"] | }, | "c1"]] @@ -221,7 +250,7 @@ trait DelegatedAccountGetMethodContract { | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [], | "notFound": [ "notFound1" ] | }, @@ -232,10 +261,10 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldReturnNotFoundAndListWhenMixCases(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) .serialize server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(CEDRIC, BOB) + .addAuthorizedUser(cedricUsername, bobUsername) .serialize val response = `given` @@ -247,8 +276,8 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", - | "ids": [ "notFound1", "${DelegationId.from(ANDRE, BOB).serialize}", "${DelegationId.from(CEDRIC, BOB).serialize}" ] + | "accountId": "$bobAccountId", + | "ids": [ "notFound1", "${DelegationId.from(andreUsername, bobUsername).serialize}", "${DelegationId.from(cedricUsername, bobUsername).serialize}" ] | }, | "c1"]] |}""".stripMargin) @@ -261,21 +290,23 @@ trait DelegatedAccountGetMethodContract { .body .asString - assertThatJson(response).isEqualTo( + assertThatJson(response) + .withOptions(IGNORING_ARRAY_ORDER) + .isEqualTo( s"""{ | "sessionState": "${SESSION_STATE.value}", | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [ | { - | "id": "${DelegationId.from(ANDRE, BOB).serialize}", - | "username": "${ANDRE.asString()}" + | "id": "${DelegationId.from(andreUsername, bobUsername).serialize}", + | "username": "${andreUsername.asString()}" | }, | { - | "id": "${DelegationId.from(CEDRIC, BOB).serialize}", - | "username": "${CEDRIC.asString()}" + | "id": "${DelegationId.from(cedricUsername, bobUsername).serialize}", + | "username": "${cedricUsername.asString()}" | } | ], | "notFound": [ "notFound1" ] @@ -287,7 +318,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldNotReturnDelegateOfOtherUser(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(CEDRIC, ANDRE) + .addAuthorizedUser(cedricUsername, andreUsername) val response = `given` .body( @@ -298,7 +329,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": null | }, | "c1"]] @@ -318,7 +349,7 @@ trait DelegatedAccountGetMethodContract { | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [], | "notFound": [] | }, @@ -329,7 +360,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldNotReturnDelegateOfOtherUserWhenProvideIds(server: GuiceJamesServer): Unit = { val delegateId = server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, CEDRIC) + .addAuthorizedUser(andreUsername, cedricUsername) .serialize val response = `given` @@ -341,7 +372,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": ["$delegateId"] | }, | "c1"]] @@ -361,7 +392,7 @@ trait DelegatedAccountGetMethodContract { | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [], | "notFound": [ "$delegateId" ] | }, @@ -372,9 +403,9 @@ trait DelegatedAccountGetMethodContract { @Test def bobShouldNotGetDelegatedAccountListOfAliceEvenAuthorized(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(CEDRIC, ANDRE) + .addAuthorizedUser(cedricUsername, andreUsername) val response = `given` .body( @@ -385,7 +416,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$ANDRE_ACCOUNT_ID", + | "accountId": "$andreAccountId", | "ids": null | }, | "c1"]] @@ -420,7 +451,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetReturnIdWhenNoPropertiesRequested(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) val response = `given` .body( @@ -431,7 +462,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "${Fixture.ACCOUNT_ID}", + | "accountId": "$bobAccountId", | "ids": null, | "properties": [] | }, @@ -452,9 +483,9 @@ trait DelegatedAccountGetMethodContract { | "methodResponses": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "list": [ - | { "id" : "${DelegationId.from(ANDRE, BOB).serialize}" } + | { "id" : "${DelegationId.from(andreUsername, bobUsername).serialize}" } | ], | "notFound": [] | }, @@ -465,7 +496,7 @@ trait DelegatedAccountGetMethodContract { @Test def delegatedAccountGetShouldFailWhenInvalidProperties(server: GuiceJamesServer): Unit = { server.getProbe(classOf[DelegationProbe]) - .addAuthorizedUser(ANDRE, BOB) + .addAuthorizedUser(andreUsername, bobUsername) val response = `given` .body( @@ -476,7 +507,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": null, | "properties": ["invalid"] | }, @@ -555,7 +586,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": null | }, | "c1"]] @@ -594,7 +625,7 @@ trait DelegatedAccountGetMethodContract { | "methodCalls": [[ | "DelegatedAccount/get", | { - | "accountId": "$BOB_ACCOUNT_ID", + | "accountId": "$bobAccountId", | "ids": null | }, | "c1"]] diff --git a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryDelegatedAccountGetMethodTest.java b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryDelegatedAccountGetMethodTest.java index 27c5f62d67..c27817943c 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryDelegatedAccountGetMethodTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryDelegatedAccountGetMethodTest.java @@ -21,6 +21,6 @@ package org.apache.james.jmap.rfc8621.memory; import org.apache.james.jmap.rfc8621.contract.DelegatedAccountGetMethodContract; -public class MemoryDelegatedAccountGetMethodTest extends MemoryBase implements DelegatedAccountGetMethodContract { +public class MemoryDelegatedAccountGetMethodTest extends PerClassMemoryBase implements DelegatedAccountGetMethodContract { } diff --git a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresDelegatedAccountGetMethodTest.java b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresDelegatedAccountGetMethodTest.java index b95cb50b1d..6a1c6d27cf 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresDelegatedAccountGetMethodTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresDelegatedAccountGetMethodTest.java @@ -21,5 +21,5 @@ package org.apache.james.jmap.rfc8621.postgres; import org.apache.james.jmap.rfc8621.contract.DelegatedAccountGetMethodContract; -public class PostgresDelegatedAccountGetMethodTest extends PostgresBase implements DelegatedAccountGetMethodContract { +public class PostgresDelegatedAccountGetMethodTest extends PerClassPostgresBase implements DelegatedAccountGetMethodContract { } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
