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 cd983da9e17071d2f4de6e9cba2e99c6f18ce396
Author: Quan Tran <[email protected]>
AuthorDate: Mon Jul 13 22:58:38 2026 +0700

    [BUILD] CustomMethodContract: isolate using different users
---
 .../rfc8621/contract/CustomMethodContract.scala    | 36 ++++++++++++++--------
 .../rfc8621/memory/MemoryCustomMethodTest.java     |  1 +
 .../rfc8621/postgres/PostgresCustomMethodTest.java |  1 +
 3 files changed, 25 insertions(+), 13 deletions(-)

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/CustomMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomMethodContract.scala
index a35a7a0eaa..4ecec0b99d 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomMethodContract.scala
@@ -23,7 +23,10 @@ import java.io.{ByteArrayInputStream, InputStream}
 import java.lang.Boolean.valueOf
 import java.net.URI
 import java.nio.charset.StandardCharsets
+import java.util.Base64
+import java.util.UUID
 
+import com.google.common.hash.Hashing
 import com.google.inject.AbstractModule
 import com.google.inject.multibindings.Multibinder
 import eu.timepit.refined.auto._
@@ -74,6 +77,7 @@ import scala.util.{Success, Try}
 object CustomMethodContract {
   val CUSTOM: CapabilityIdentifier = "urn:apache:james:params:jmap:custom"
   val eventId = EventId.of("6e0dd59d-660e-4d9b-b22f-0354479f47b4")
+  private val currentUsername = new ThreadLocal[Username]()
 
   private val expected_session_object: String =
     s"""{
@@ -271,27 +275,30 @@ class JmapEventBusProbe @Inject() (@Named("JMAP") 
jmapEventBus: EventBus) extend
 }
 
 trait CustomMethodContract {
+  def bobUsername: Username = CustomMethodContract.currentUsername.get()
+  def bobAccountId: String = Hashing.sha256().hashString(bobUsername.asString, 
StandardCharsets.UTF_8).toString
 
   private lazy val backend: SttpBackend[Identity, WebSockets] = 
OkHttpSyncBackend()
   private lazy implicit val monadError: MonadError[Identity] = IdMonad
 
   @BeforeEach
   def setUp(server: GuiceJamesServer): Unit = {
+    
CustomMethodContract.currentUsername.set(Username.fromLocalPartWithDomain(s"bob${UUID.randomUUID().toString.replace("-",
 "").take(8)}", DOMAIN))
     server.getProbe(classOf[DataProbeImpl])
       .fluent()
       .addDomain(DOMAIN.asString())
-      .addUser(BOB.asString(), BOB_PASSWORD)
+      .addUser(bobUsername.asString(), BOB_PASSWORD)
 
     requestSpecification = baseRequestSpecBuilder(server)
-      .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+      .setAuth(authScheme(UserCredential(bobUsername, BOB_PASSWORD)))
       .build
   }
 
   @Test
   def 
pushShouldSupportCustomTypeNameAndIntStateWhenDataTypesAreMyTypeName(server: 
GuiceJamesServer): Unit = {
-    val accountId: AccountId = AccountId.fromUsername(BOB)
+    val accountId: AccountId = AccountId.fromUsername(bobUsername)
     val intState = CustomTypeName.parseState("1").toOption.get
-    val stateChangeEvent: StateChangeEvent = StateChangeEvent(eventId = 
CustomMethodContract.eventId, username = BOB, map = Map(CustomTypeName -> 
intState))
+    val stateChangeEvent: StateChangeEvent = StateChangeEvent(eventId = 
CustomMethodContract.eventId, username = bobUsername, map = Map(CustomTypeName 
-> intState))
     Thread.sleep(100)
 
     val response: Either[String, String] =
@@ -317,10 +324,10 @@ trait CustomMethodContract {
     Thread.sleep(100)
 
     assertThatJson(response.toOption.get)
-      .isEqualTo("""{
+      .isEqualTo(s"""{
                    |   "@type": "StateChange",
                    |   "changed": {
-                   |           
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6": {
+                   |           "$bobAccountId": {
                    |                   "MyTypeName": "1"
                    |           }
                    |   }
@@ -329,9 +336,9 @@ trait CustomMethodContract {
 
   @Test
   def pushShouldSupportCustomTypeNameAndIntStateWhenDataTypesAreNull(server: 
GuiceJamesServer): Unit = {
-    val accountId: AccountId = AccountId.fromUsername(BOB)
+    val accountId: AccountId = AccountId.fromUsername(bobUsername)
     val intState = CustomTypeName.parseState("1").toOption.get
-    val stateChangeEvent: StateChangeEvent = StateChangeEvent(eventId = 
CustomMethodContract.eventId, username = BOB, map = Map(CustomTypeName -> 
intState))
+    val stateChangeEvent: StateChangeEvent = StateChangeEvent(eventId = 
CustomMethodContract.eventId, username = bobUsername, map = Map(CustomTypeName 
-> intState))
     Thread.sleep(100)
 
     val response: Either[String, String] =
@@ -357,10 +364,10 @@ trait CustomMethodContract {
     Thread.sleep(100)
 
     assertThatJson(response.toOption.get)
-      .isEqualTo("""{
+      .isEqualTo(s"""{
                    |   "@type": "StateChange",
                    |   "changed": {
-                   |           
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6": {
+                   |           "$bobAccountId": {
                    |                   "MyTypeName": "1"
                    |           }
                    |   }
@@ -380,7 +387,10 @@ trait CustomMethodContract {
       .body()
       .asString()
 
-    
assertThatJson(sessionJson).isEqualTo(CustomMethodContract.expected_session_object)
+    assertThatJson(sessionJson).isEqualTo(
+      CustomMethodContract.expected_session_object
+        
.replace("29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", 
bobAccountId)
+        .replace("[email protected]", bobUsername.asString))
   }
 
   @Test
@@ -519,7 +529,7 @@ trait CustomMethodContract {
       .basePath("")
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
     .when
-      .get(s"/download/$accountId/gabouh")
+      .get(s"/download/$bobAccountId/gabouh")
     .`then`
       .statusCode(SC_OK)
       .contentType("application/bytes")
@@ -537,7 +547,7 @@ trait CustomMethodContract {
       .getValue
 
     basicRequest.get(Uri.apply(new URI(s"ws://127.0.0.1:$port/jmap/ws")))
-      .header("Authorization", "Basic Ym9iQGRvbWFpbi50bGQ6Ym9icGFzc3dvcmQ=")
+      .header("Authorization", s"Basic 
${Base64.getEncoder.encodeToString(s"${bobUsername.asString}:$BOB_PASSWORD".getBytes(StandardCharsets.UTF_8))}")
       .header("Accept", ACCEPT_RFC8621_VERSION_HEADER)
   }
 }
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/MemoryCustomMethodTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryCustomMethodTest.java
index 0158a063d1..7b896ff1e4 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryCustomMethodTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemoryCustomMethodTest.java
@@ -41,5 +41,6 @@ public class MemoryCustomMethodTest implements 
CustomMethodContract {
         .server(configuration -> 
MemoryJamesServerMain.createServer(configuration)
             .combineWith(new CustomMethodModule())
             .overrideWith(new TestJMAPServerModule()))
+        .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/PostgresCustomMethodTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresCustomMethodTest.java
index 37f55fe9e1..dff27c80cb 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresCustomMethodTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresCustomMethodTest.java
@@ -54,5 +54,6 @@ public class PostgresCustomMethodTest implements 
CustomMethodContract {
         .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJMAPServerModule())
             .overrideWith(new CustomMethodModule()))
+        .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .build();
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to