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 2f08ce4d79543e5097a2831a22cef86979ee1845
Author: Quan Tran <[email protected]>
AuthorDate: Mon Jul 13 19:56:28 2026 +0700

    [BUILD] AuthenticationContract: isolate using different users
---
 .../distributed/DistributedAuthenticationTest.java | 34 +---------------------
 ....java => PerEnclosingClassDistributedBase.java} | 17 ++++++-----
 .../rfc8621/contract/AuthenticationContract.scala  | 30 ++++++++++++-------
 ...est.java => PerEnclosingClassPostgresBase.java} | 11 +++++--
 .../postgres/PostgresAuthenticationTest.java       | 34 +---------------------
 5 files changed, 39 insertions(+), 87 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/DistributedAuthenticationTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedAuthenticationTest.java
index 3870a593a4..f65ccb213b 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedAuthenticationTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedAuthenticationTest.java
@@ -19,39 +19,7 @@
 
 package org.apache.james.jmap.rfc8621.distributed;
 
-import org.apache.james.CassandraExtension;
-import org.apache.james.CassandraRabbitMQJamesConfiguration;
-import org.apache.james.CassandraRabbitMQJamesServerMain;
-import org.apache.james.DockerOpenSearchExtension;
-import org.apache.james.JamesServerBuilder;
-import org.apache.james.JamesServerExtension;
-import org.apache.james.SearchConfiguration;
 import org.apache.james.jmap.rfc8621.contract.AuthenticationContract;
-import org.apache.james.modules.AwsS3BlobStoreExtension;
-import org.apache.james.modules.RabbitMQExtension;
-import org.apache.james.modules.TestJMAPServerModule;
-import org.apache.james.modules.blobstore.BlobStoreConfiguration;
-import org.junit.jupiter.api.extension.RegisterExtension;
 
-class DistributedAuthenticationTest implements AuthenticationContract {
-    @RegisterExtension
-    static JamesServerExtension testExtension = new 
JamesServerBuilder<CassandraRabbitMQJamesConfiguration>(tmpDir ->
-        CassandraRabbitMQJamesConfiguration.builder()
-            .workingDirectory(tmpDir)
-            .configurationFromClasspath()
-            .blobStore(BlobStoreConfiguration.builder()
-                    .s3()
-                    .disableCache()
-                    .deduplication()
-                    .noCryptoConfig())
-            .searchConfiguration(SearchConfiguration.openSearch())
-            .build())
-        .extension(new DockerOpenSearchExtension())
-        .extension(new CassandraExtension())
-        .extension(new RabbitMQExtension())
-        .extension(new AwsS3BlobStoreExtension())
-        .server(configuration -> 
CassandraRabbitMQJamesServerMain.createServer(configuration)
-            .overrideWith(new TestJMAPServerModule()))
-        .lifeCycle(JamesServerExtension.Lifecycle.PER_ENCLOSING_CLASS)
-        .build();
+class DistributedAuthenticationTest extends PerEnclosingClassDistributedBase 
implements AuthenticationContract {
 }
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/DistributedAuthenticationTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/PerEnclosingClassDistributedBase.java
similarity index 82%
copy from 
server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedAuthenticationTest.java
copy to 
server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/PerEnclosingClassDistributedBase.java
index 3870a593a4..897bee1983 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedAuthenticationTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/PerEnclosingClassDistributedBase.java
@@ -26,24 +26,27 @@ import org.apache.james.DockerOpenSearchExtension;
 import org.apache.james.JamesServerBuilder;
 import org.apache.james.JamesServerExtension;
 import org.apache.james.SearchConfiguration;
-import org.apache.james.jmap.rfc8621.contract.AuthenticationContract;
+import org.apache.james.jmap.rfc8621.contract.IdentityProbeModule;
+import org.apache.james.jmap.rfc8621.contract.JmapPreviewProbeModule;
+import org.apache.james.jmap.rfc8621.contract.probe.DelegationProbeModule;
 import org.apache.james.modules.AwsS3BlobStoreExtension;
 import org.apache.james.modules.RabbitMQExtension;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.blobstore.BlobStoreConfiguration;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
-class DistributedAuthenticationTest implements AuthenticationContract {
+public class PerEnclosingClassDistributedBase {
     @RegisterExtension
     static JamesServerExtension testExtension = new 
JamesServerBuilder<CassandraRabbitMQJamesConfiguration>(tmpDir ->
         CassandraRabbitMQJamesConfiguration.builder()
             .workingDirectory(tmpDir)
             .configurationFromClasspath()
+            .enableJMAP()
             .blobStore(BlobStoreConfiguration.builder()
-                    .s3()
-                    .disableCache()
-                    .deduplication()
-                    .noCryptoConfig())
+                .s3()
+                .disableCache()
+                .deduplication()
+                .noCryptoConfig())
             .searchConfiguration(SearchConfiguration.openSearch())
             .build())
         .extension(new DockerOpenSearchExtension())
@@ -51,7 +54,7 @@ class DistributedAuthenticationTest implements 
AuthenticationContract {
         .extension(new RabbitMQExtension())
         .extension(new AwsS3BlobStoreExtension())
         .server(configuration -> 
CassandraRabbitMQJamesServerMain.createServer(configuration)
-            .overrideWith(new TestJMAPServerModule()))
+            .overrideWith(new TestJMAPServerModule(), new 
DelegationProbeModule(), new IdentityProbeModule(), new 
JmapPreviewProbeModule()))
         .lifeCycle(JamesServerExtension.Lifecycle.PER_ENCLOSING_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/AuthenticationContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/AuthenticationContract.scala
index 4369683c8b..b9e2d2df53 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/AuthenticationContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/AuthenticationContract.scala
@@ -19,19 +19,28 @@
 
 package org.apache.james.jmap.rfc8621.contract
 
+import java.util.UUID
+
 import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT
 import io.restassured.RestAssured.{`given`, requestSpecification}
 import io.restassured.authentication.NoAuthScheme
 import io.restassured.http.Header
 import org.apache.http.HttpStatus.{SC_BAD_REQUEST, SC_OK, SC_UNAUTHORIZED}
 import org.apache.james.GuiceJamesServer
-import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
ALICE, ALICE_PASSWORD, AUTHORIZATION_HEADER, BOB, BOB_BASIC_AUTH_HEADER, 
BOB_PASSWORD, DOMAIN, DOMAIN_WITH_SPACE, ECHO_REQUEST_OBJECT, 
INVALID_JWT_TOKEN, UNKNOWN_USER_TOKEN, USER, USER_PASSWORD, USER_TOKEN, 
_2_DOT_DOMAIN, baseRequestSpecBuilder, getHeadersWith, toBase64}
+import org.apache.james.core.Username
+import 
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HEADER, 
AUTHORIZATION_HEADER, DOMAIN, DOMAIN_WITH_SPACE, ECHO_REQUEST_OBJECT, 
INVALID_JWT_TOKEN, UNKNOWN_USER_TOKEN, USER, USER_PASSWORD, USER_TOKEN, 
_2_DOT_DOMAIN, baseRequestSpecBuilder, getHeadersWith, toBase64}
 import org.apache.james.jmap.rfc8621.contract.tags.CategoryTags
 import org.apache.james.utils.DataProbeImpl
 import org.hamcrest.Matchers.{containsString, equalTo}
 import org.junit.jupiter.api.{BeforeAll, Nested, Tag, Test}
 
 object AuthenticationContract {
+  val bob: Username = 
Username.fromLocalPartWithDomain(s"bob${UUID.randomUUID()}", DOMAIN)
+  val bobPassword: String = s"bobpassword${UUID.randomUUID()}"
+  val bobBasicAuthHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${bob.asString}:$bobPassword")}")
+  val alice: Username = 
Username.fromLocalPartWithDomain(s"alice${UUID.randomUUID()}", _2_DOT_DOMAIN)
+  val alicePassword: String = s"alicepassword${UUID.randomUUID()}"
+
   @BeforeAll
   def setup(server: GuiceJamesServer): Unit = {
     server.getProbe(classOf[DataProbeImpl])
@@ -39,8 +48,8 @@ object AuthenticationContract {
       .addDomain(DOMAIN.asString)
       .addDomain(_2_DOT_DOMAIN.asString)
       .addUser(USER.asString, USER_PASSWORD)
-      .addUser(ALICE.asString, ALICE_PASSWORD)
-      .addUser(BOB.asString, BOB_PASSWORD)
+      .addUser(alice.asString, alicePassword)
+      .addUser(bob.asString, bobPassword)
 
     requestSpecification = baseRequestSpecBuilder(server)
       .setAuth(new NoAuthScheme)
@@ -55,7 +64,7 @@ trait AuthenticationContract {
     @Test
     def shouldRespond400WhenBothAuthentication(): Unit = {
       `given`
-        .headers(getHeadersWith(BOB_BASIC_AUTH_HEADER))
+        .headers(getHeadersWith(AuthenticationContract.bobBasicAuthHeader))
         .header(new Header(AUTHORIZATION_HEADER, s"Bearer $USER_TOKEN"))
         .body(ECHO_REQUEST_OBJECT)
       .when
@@ -88,7 +97,7 @@ trait AuthenticationContract {
     @Tag(CategoryTags.BASIC_FEATURE)
     def postShouldRespond200WhenHasCredentials(): Unit = {
       `given`
-        .headers(getHeadersWith(BOB_BASIC_AUTH_HEADER))
+        .headers(getHeadersWith(AuthenticationContract.bobBasicAuthHeader))
         .body(ECHO_REQUEST_OBJECT)
       .when
         .post
@@ -98,7 +107,7 @@ trait AuthenticationContract {
 
     @Test
     def postShouldRespond401WhenCredentialsWithInvalidUser(): Unit = {
-      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${BOB.getLocalPart}@@$DOMAIN:$BOB_PASSWORD")}")
+      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${AuthenticationContract.bob.getLocalPart}@@$DOMAIN:${AuthenticationContract.bobPassword}")}")
       `given`
         .headers(getHeadersWith(authHeader))
         .body(ECHO_REQUEST_OBJECT)
@@ -113,7 +122,7 @@ trait AuthenticationContract {
 
     @Test
     def postShouldRespond200WhenCredentialsWith2DotDomain(): Unit = {
-      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${ALICE.asString}:$ALICE_PASSWORD")}")
+      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${AuthenticationContract.alice.asString}:${AuthenticationContract.alicePassword}")}")
       `given`
         .headers(getHeadersWith(authHeader))
         .body(ECHO_REQUEST_OBJECT)
@@ -125,7 +134,7 @@ trait AuthenticationContract {
 
     @Test
     def postShouldRespond401WhenCredentialsWithSpaceDomain(): Unit = {
-      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${BOB.getLocalPart}@$DOMAIN_WITH_SPACE:$BOB_PASSWORD")}")
+      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${AuthenticationContract.bob.getLocalPart}@$DOMAIN_WITH_SPACE:${AuthenticationContract.bobPassword}")}")
       `given`
         .headers(getHeadersWith(authHeader))
         .body(ECHO_REQUEST_OBJECT)
@@ -140,7 +149,7 @@ trait AuthenticationContract {
 
     @Test
     def postShouldRespond401WhenUserNotFound(): Unit = {
-      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"usernotfound@$DOMAIN:$BOB_PASSWORD")}")
+      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"usernotfound@$DOMAIN:${AuthenticationContract.bobPassword}")}")
       `given`
         .headers(getHeadersWith(authHeader))
         .body(ECHO_REQUEST_OBJECT)
@@ -156,7 +165,7 @@ trait AuthenticationContract {
     @Test
     @Tag(CategoryTags.BASIC_FEATURE)
     def postShouldRespond401WhenWrongPassword(): Unit = {
-      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${BOB.asString}:WRONG_PASSWORD")}")
+      val authHeader: Header = new Header(AUTHORIZATION_HEADER, s"Basic 
${toBase64(s"${AuthenticationContract.bob.asString}:WRONG_PASSWORD")}")
       `given`
         .headers(getHeadersWith(authHeader))
         .body(ECHO_REQUEST_OBJECT)
@@ -216,4 +225,3 @@ trait AuthenticationContract {
     }
   }
 }
-
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/PostgresAuthenticationTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PerEnclosingClassPostgresBase.java
similarity index 85%
copy from 
server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresAuthenticationTest.java
copy to 
server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PerEnclosingClassPostgresBase.java
index 57e4f56dca..fa31fb16ce 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresAuthenticationTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PerEnclosingClassPostgresBase.java
@@ -27,13 +27,15 @@ import org.apache.james.PostgresJamesConfiguration;
 import org.apache.james.PostgresJamesServerMain;
 import org.apache.james.SearchConfiguration;
 import org.apache.james.backends.postgres.PostgresExtension;
-import org.apache.james.jmap.rfc8621.contract.AuthenticationContract;
+import org.apache.james.jmap.rfc8621.contract.IdentityProbeModule;
+import org.apache.james.jmap.rfc8621.contract.JmapPreviewProbeModule;
+import org.apache.james.jmap.rfc8621.contract.probe.DelegationProbeModule;
 import org.apache.james.modules.RabbitMQExtension;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.blobstore.BlobStoreConfiguration;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class PostgresAuthenticationTest implements AuthenticationContract {
+public class PerEnclosingClassPostgresBase {
     @RegisterExtension
     static JamesServerExtension testExtension = new 
JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
         PostgresJamesConfiguration.builder()
@@ -51,7 +53,10 @@ public class PostgresAuthenticationTest implements 
AuthenticationContract {
         .extension(PostgresExtension.empty())
         .extension(new RabbitMQExtension())
         .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
-            .overrideWith(new TestJMAPServerModule()))
+            .overrideWith(new TestJMAPServerModule())
+            .overrideWith(new DelegationProbeModule())
+            .overrideWith(new IdentityProbeModule())
+            .overrideWith(new JmapPreviewProbeModule()))
         .lifeCycle(JamesServerExtension.Lifecycle.PER_ENCLOSING_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/PostgresAuthenticationTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresAuthenticationTest.java
index 57e4f56dca..cc11ba42b8 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresAuthenticationTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/postgres-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/postgres/PostgresAuthenticationTest.java
@@ -19,39 +19,7 @@
 
 package org.apache.james.jmap.rfc8621.postgres;
 
-import static 
org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;
-
-import org.apache.james.JamesServerBuilder;
-import org.apache.james.JamesServerExtension;
-import org.apache.james.PostgresJamesConfiguration;
-import org.apache.james.PostgresJamesServerMain;
-import org.apache.james.SearchConfiguration;
-import org.apache.james.backends.postgres.PostgresExtension;
 import org.apache.james.jmap.rfc8621.contract.AuthenticationContract;
-import org.apache.james.modules.RabbitMQExtension;
-import org.apache.james.modules.TestJMAPServerModule;
-import org.apache.james.modules.blobstore.BlobStoreConfiguration;
-import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class PostgresAuthenticationTest implements AuthenticationContract {
-    @RegisterExtension
-    static JamesServerExtension testExtension = new 
JamesServerBuilder<PostgresJamesConfiguration>(tmpDir ->
-        PostgresJamesConfiguration.builder()
-            .workingDirectory(tmpDir)
-            .configurationFromClasspath()
-            .searchConfiguration(SearchConfiguration.scanning())
-            .usersRepository(DEFAULT)
-            .eventBusImpl(PostgresJamesConfiguration.EventBusImpl.RABBITMQ)
-            .blobStore(BlobStoreConfiguration.builder()
-                .postgres()
-                .disableCache()
-                .deduplication()
-                .noCryptoConfig())
-            .build())
-        .extension(PostgresExtension.empty())
-        .extension(new RabbitMQExtension())
-        .server(configuration -> 
PostgresJamesServerMain.createServer(configuration)
-            .overrideWith(new TestJMAPServerModule()))
-        .lifeCycle(JamesServerExtension.Lifecycle.PER_ENCLOSING_CLASS)
-        .build();
+public class PostgresAuthenticationTest extends PerEnclosingClassPostgresBase 
implements AuthenticationContract {
 }


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

Reply via email to