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

    [BUILD] SessionRoutesContract: isolate using different users
---
 .../distributed/DistributedSessionRouteTest.java   |  2 +-
 .../rfc8621/contract/SessionRoutesContract.scala   | 51 +++++++++++++++++-----
 .../rfc8621/memory/MemorySessionRouteTest.java     |  2 +-
 .../postgres/PostgresSessionRoutesTest.java        |  2 +-
 4 files changed, 44 insertions(+), 13 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/DistributedSessionRouteTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedSessionRouteTest.java
index 18a721e711..84b188c553 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedSessionRouteTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedSessionRouteTest.java
@@ -21,6 +21,6 @@ package org.apache.james.jmap.rfc8621.distributed;
 
 import org.apache.james.jmap.rfc8621.contract.SessionRoutesContract;
 
-public class DistributedSessionRouteTest extends DistributedBase implements 
SessionRoutesContract {
+public class DistributedSessionRouteTest extends PerClassDistributedBase 
implements SessionRoutesContract {
 
 }
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/SessionRoutesContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/SessionRoutesContract.scala
index 7ae75bdf50..ad132216f3 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/SessionRoutesContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/SessionRoutesContract.scala
@@ -19,7 +19,9 @@
 package org.apache.james.jmap.rfc8621.contract
 
 import java.nio.charset.StandardCharsets
+import java.util.UUID
 
+import com.google.common.hash.Hashing
 import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
 import io.restassured.RestAssured._
 import io.restassured.builder.RequestSpecBuilder
@@ -30,7 +32,9 @@ import io.restassured.http.ContentType.JSON
 import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
 import org.apache.http.HttpStatus.SC_OK
 import org.apache.james.GuiceJamesServer
+import org.apache.james.core.Username
 import org.apache.james.jmap.JmapGuiceProbe
+import org.apache.james.jmap.api.model.AccountId
 import org.apache.james.jmap.http.UserCredential
 import org.apache.james.jmap.rfc8621.contract.Fixture._
 import 
org.apache.james.jmap.rfc8621.contract.SessionRoutesContract.{EXPECTED_BASE_PATH,
 expected_session_object}
@@ -39,6 +43,11 @@ import org.apache.james.utils.DataProbeImpl
 import org.hamcrest.Matchers
 import org.junit.jupiter.api.{BeforeEach, Tag, Test}
 
+object SessionRoutesContractContext {
+  case class TestContext(bobUsername: Username, bobAccountId: String, 
andreUsername: Username)
+  val currentContext: java.util.concurrent.atomic.AtomicReference[TestContext] 
= new java.util.concurrent.atomic.AtomicReference[TestContext]()
+}
+
 object SessionRoutesContract {
   private val expected_session_object: String = """{
                          |  "capabilities" : {
@@ -142,14 +151,29 @@ object SessionRoutesContract {
 }
 
 trait SessionRoutesContract {
+  import SessionRoutesContractContext.currentContext
+
+  def bobUsername: Username = currentContext.get().bobUsername
+  def bobAccountId: String = currentContext.get().bobAccountId
+  def andreUsername: Username = currentContext.get().andreUsername
+
+  private def expectedSessionObject: String = expected_session_object
+    
.replace("29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", 
bobAccountId)
+    .replace("[email protected]", bobUsername.asString)
+
 
   @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)
+    currentContext.set(SessionRoutesContractContext.TestContext(
+      bob, Hashing.sha256().hashString(bob.asString, 
StandardCharsets.UTF_8).toString, andre))
     server.getProbe(classOf[DataProbeImpl])
       .fluent
       .addDomain(DOMAIN.asString)
-      .addUser(BOB.asString, BOB_PASSWORD)
-      .addUser(ANDRE.asString, ANDRE_PASSWORD)
+      .addUser(bobUsername.asString, BOB_PASSWORD)
+      .addUser(andreUsername.asString, ANDRE_PASSWORD)
 
     val jmapGuiceProbe: JmapGuiceProbe = 
server.getProbe(classOf[JmapGuiceProbe])
     requestSpecification = new RequestSpecBuilder()
@@ -160,7 +184,7 @@ trait SessionRoutesContract {
       .getJmapPort
       .getValue)
     .setBasePath(EXPECTED_BASE_PATH)
-        .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD)))
+        .setAuth(authScheme(UserCredential(bobUsername, BOB_PASSWORD)))
       .build
   }
 
@@ -178,7 +202,10 @@ trait SessionRoutesContract {
         .body()
         .asString()
 
-    assertThatJson(sessionJson).isEqualTo(expected_session_object)
+    assertThatJson(sessionJson).isEqualTo(
+      expected_session_object
+        
.replace("29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", 
bobAccountId)
+        .replace("[email protected]", bobUsername.asString))
   }
 
   @Test
@@ -213,12 +240,12 @@ trait SessionRoutesContract {
       .body()
       .asString()
 
-    assertThatJson(sessionJson).isEqualTo(expected_session_object)
+    assertThatJson(sessionJson).isEqualTo(expectedSessionObject)
   }
 
   @Test
   def getResponseShouldReturnDelegatedUsersWhenDelegated(server: 
GuiceJamesServer): Unit = {
-     server.getProbe(classOf[DataProbeImpl]).addAuthorizedUser(ANDRE, BOB)
+     server.getProbe(classOf[DataProbeImpl]).addAuthorizedUser(andreUsername, 
bobUsername)
 
     val sessionJson: String = `given`()
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
@@ -332,12 +359,16 @@ trait SessionRoutesContract {
                    |            
"urn:apache:james:params:jmap:mail:identity:sortorder": {}
                    |        }
                    |    }
-                   |}""".stripMargin)
+                   |}""".stripMargin
+        
.replace("29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6", 
bobAccountId)
+        
.replace("1e8584548eca20f26faf6becc1704a0f352839f12c208a47fbd486d60f491f7c", 
Hashing.sha256().hashString(andreUsername.asString, 
StandardCharsets.UTF_8).toString)
+        .replace("[email protected]", bobUsername.asString)
+        .replace("[email protected]", andreUsername.asString))
   }
 
   @Test
   def getResponseShouldNotReturnDelegatedUsersWhenNotDelegated(server: 
GuiceJamesServer): Unit = {
-    server.getProbe(classOf[DataProbeImpl]).addAuthorizedUser(BOB, ANDRE)
+    server.getProbe(classOf[DataProbeImpl]).addAuthorizedUser(bobUsername, 
andreUsername)
 
     val sessionJson: String = `given`()
       .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
@@ -349,7 +380,7 @@ trait SessionRoutesContract {
       .body()
       .asString()
 
-    assertThatJson(sessionJson).isEqualTo(expected_session_object)
+    assertThatJson(sessionJson).isEqualTo(expectedSessionObject)
   }
 
-}
\ No newline at end of file
+}
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/MemorySessionRouteTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemorySessionRouteTest.java
index 54004c7c3d..c5fb496d1e 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemorySessionRouteTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/memory/MemorySessionRouteTest.java
@@ -21,6 +21,6 @@ package org.apache.james.jmap.rfc8621.memory;
 
 import org.apache.james.jmap.rfc8621.contract.SessionRoutesContract;
 
-public class MemorySessionRouteTest extends MemoryBase implements 
SessionRoutesContract {
+public class MemorySessionRouteTest extends PerClassMemoryBase implements 
SessionRoutesContract {
 
 }
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/PostgresSessionRoutesTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresSessionRoutesTest.java
index 9957ff3cf5..ff631dbb34 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresSessionRoutesTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresSessionRoutesTest.java
@@ -21,5 +21,5 @@ package org.apache.james.jmap.rfc8621.postgres;
 
 import org.apache.james.jmap.rfc8621.contract.SessionRoutesContract;
 
-public class PostgresSessionRoutesTest extends PostgresBase implements 
SessionRoutesContract {
+public class PostgresSessionRoutesTest extends PerClassPostgresBase implements 
SessionRoutesContract {
 }


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

Reply via email to