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 9b413320f8923b54914232611be015569137b845 Author: Quan Tran <[email protected]> AuthorDate: Mon Jul 13 20:04:45 2026 +0700 [BUILD] BlobCopyContract: isolate using different users --- .../distributed/DistributedBlobCopyTest.java | 1 + .../jmap/rfc8621/contract/BlobCopyContract.scala | 36 +++++++++++++++++----- .../jmap/rfc8621/memory/MemoryBlobCopyTest.java | 1 + .../rfc8621/postgres/PostgresBlobCopyTest.java | 1 + 4 files changed, 32 insertions(+), 7 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/DistributedBlobCopyTest.java b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedBlobCopyTest.java index 1f5468a9d3..6bcdf731d3 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedBlobCopyTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedBlobCopyTest.java @@ -58,5 +58,6 @@ public class DistributedBlobCopyTest implements BlobCopyContract { .server(configuration -> CassandraRabbitMQJamesServerMain.createServer(configuration) .overrideWith(new TestJMAPServerModule(ImmutableMap.of("upload.quota.limit", BlobCopyContract$.MODULE$.TWENTY_KILO_BYTES_UPLOAD_QUOTA_LIMIT())), new DelegationProbeModule())) + .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS) .build(); } 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/BlobCopyContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/BlobCopyContract.scala index 03abf2c1d7..8051006539 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/BlobCopyContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/BlobCopyContract.scala @@ -21,6 +21,8 @@ package org.apache.james.jmap.rfc8621.contract import java.io.ByteArrayInputStream import java.nio.charset.StandardCharsets +import java.util.UUID +import java.util.concurrent.atomic.AtomicReference import com.google.common.base.Strings import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT @@ -30,10 +32,11 @@ import io.restassured.path.json.JsonPath import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson import org.apache.http.HttpStatus.{SC_CREATED, SC_OK} import org.apache.james.GuiceJamesServer +import org.apache.james.core.Username import org.apache.james.jmap.core.AccountId import org.apache.james.jmap.http.UserCredential -import org.apache.james.jmap.rfc8621.contract.BlobCopyContract.{ALICE_ACCOUNT_ID, TEN_KILO_BYTES} -import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, ALICE, ALICE_PASSWORD, ANDRE, ANDRE_ACCOUNT_ID, ANDRE_PASSWORD, BOB, BOB_PASSWORD, DOMAIN, _2_DOT_DOMAIN, authScheme, baseRequestSpecBuilder, ACCOUNT_ID => BOB_ACCOUNT_ID} +import org.apache.james.jmap.rfc8621.contract.BlobCopyContract.TEN_KILO_BYTES +import org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, ALICE_PASSWORD, ANDRE_PASSWORD, BOB_PASSWORD, DOMAIN, _2_DOT_DOMAIN, authScheme, baseRequestSpecBuilder} import org.apache.james.junit.categories.BasicFeature import org.apache.james.utils.DataProbeImpl import org.assertj.core.api.Assertions.assertThat @@ -43,22 +46,41 @@ import org.junit.jupiter.api.{BeforeEach, Test} object BlobCopyContract { val TWENTY_KILO_BYTES_UPLOAD_QUOTA_LIMIT: String = "20K" val TEN_KILO_BYTES: Array[Byte] = Strings.repeat("0123456789\r\n", 853).getBytes(StandardCharsets.UTF_8) - val ALICE_ACCOUNT_ID: String = AccountId.from(ALICE).toOption.get.id.value + + case class TestContext(bob: Username, alice: Username, andre: Username) + + val currentContext: AtomicReference[TestContext] = new AtomicReference[TestContext]() } trait BlobCopyContract { + import BlobCopyContract.currentContext + + def BOB: Username = currentContext.get().bob + def ALICE: Username = currentContext.get().alice + def ANDRE: Username = currentContext.get().andre + def accountId(username: Username): String = AccountId.from(username).toOption.get.id.value + def BOB_ACCOUNT_ID: String = accountId(BOB) + def ALICE_ACCOUNT_ID: String = accountId(ALICE) + def ANDRE_ACCOUNT_ID: String = accountId(ANDRE) + @BeforeEach def setUp(server: GuiceJamesServer): Unit = { + val uniqueSuffix = UUID.randomUUID().toString.replace("-", "").take(8) + val bob = Username.fromLocalPartWithDomain(s"bob$uniqueSuffix", DOMAIN) + val alice = Username.fromLocalPartWithDomain(s"alice$uniqueSuffix", _2_DOT_DOMAIN) + val andre = Username.fromLocalPartWithDomain(s"andre$uniqueSuffix", DOMAIN) + currentContext.set(BlobCopyContract.TestContext(bob, alice, andre)) + server.getProbe(classOf[DataProbeImpl]) .fluent .addDomain(DOMAIN.asString) .addDomain(_2_DOT_DOMAIN.asString()) - .addUser(BOB.asString, BOB_PASSWORD) - .addUser(ALICE.asString(), ALICE_PASSWORD) - .addUser(ANDRE.asString(), ANDRE_PASSWORD) + .addUser(bob.asString, BOB_PASSWORD) + .addUser(alice.asString, ALICE_PASSWORD) + .addUser(andre.asString, ANDRE_PASSWORD) requestSpecification = baseRequestSpecBuilder(server) - .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD))) + .setAuth(authScheme(UserCredential(bob, BOB_PASSWORD))) .build } 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/MemoryBlobCopyTest.java b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryBlobCopyTest.java index 8f585fe9f8..578571f282 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryBlobCopyTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryBlobCopyTest.java @@ -45,5 +45,6 @@ public class MemoryBlobCopyTest implements BlobCopyContract { .server(configuration -> MemoryJamesServerMain.createServer(configuration) .overrideWith(new TestJMAPServerModule(ImmutableMap.of("upload.quota.limit", BlobCopyContract$.MODULE$.TWENTY_KILO_BYTES_UPLOAD_QUOTA_LIMIT())), new DelegationProbeModule())) + .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS) .build(); } 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/PostgresBlobCopyTest.java b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresBlobCopyTest.java index 8795e0593b..81ce38132e 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresBlobCopyTest.java +++ b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresBlobCopyTest.java @@ -57,5 +57,6 @@ public class PostgresBlobCopyTest implements BlobCopyContract { .server(configuration -> PostgresJamesServerMain.createServer(configuration) .overrideWith(new TestJMAPServerModule(ImmutableMap.of("upload.quota.limit", BlobCopyContract$.MODULE$.TWENTY_KILO_BYTES_UPLOAD_QUOTA_LIMIT()))) .overrideWith(new DelegationProbeModule())) + .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS) .build(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
