From 890f528d5360a6013d29faa89a1a2f7acfb3aef6 Mon Sep 17 00:00:00 2001 From: TungTV Date: Tue, 29 Oct 2024 11:26:59 +0700 Subject: [PATCH 1/5] Update James SHA-1 (postgresql) --- james-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/james-project b/james-project index 12dc905e53..61b6018f2c 160000 --- a/james-project +++ b/james-project @@ -1 +1 @@ -Subproject commit 12dc905e53f3ed75056ffefdda47838ca89c8bff +Subproject commit 61b6018f2cd1eae40e3396388e05bb49f98394bf From efd0ec0b0524ad186d01a8eaa4c9438fdaa3803f Mon Sep 17 00:00:00 2001 From: TungTV Date: Tue, 29 Oct 2024 12:34:49 +0700 Subject: [PATCH 2/5] Adapt from new master code - BlobId.Factory --- .../list/SingleSaveBlobStoreContract.scala | 33 ++++++++++--------- .../blobid/list/SingleSaveBlobStoreTest.java | 4 +-- .../PostgresSingleSaveBlobStoreTest.java | 4 +-- .../publicAsset/CassandraPublicAssetDAO.scala | 4 +-- .../publicAsset/PostgresPublicAssetDAO.scala | 4 +-- .../PublicAssetDeletionTaskStepTest.scala | 4 +-- .../PublicAssetRepositoryContract.scala | 4 +-- .../EncryptedEmailContentStore.scala | 11 +++++++ .../CassandraEncryptedEmailDAO.scala | 6 ++-- ...ssandraEncryptedEmailContentStoreTest.java | 4 +-- .../PostgresEncryptedEmailStoreDAO.java | 12 +++---- ...ostgresEncryptedEmailContentStoreTest.java | 4 +-- ...nMemoryEncryptedEmailContentStoreTest.java | 4 +-- .../InMemoryEncryptedMessageManagerTest.java | 4 +-- .../com/linagora/tmail/team/TeamMailbox.scala | 2 +- 15 files changed, 57 insertions(+), 47 deletions(-) diff --git a/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreContract.scala b/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreContract.scala index 1ffe155b77..f2aff1db16 100644 --- a/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreContract.scala +++ b/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreContract.scala @@ -2,6 +2,7 @@ package com.linagora.tmail.blob.blobid.list import java.io.ByteArrayInputStream import java.time.Duration +import java.util.UUID import com.google.common.io.ByteSource import org.apache.james.blob.api.BlobStoreDAOFixture.{SHORT_BYTEARRAY, TEST_BUCKET_NAME} @@ -22,7 +23,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveBytesShouldSuccessIfBlobIdDoesNotExist(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, SHORT_BYTEARRAY)).block() assertThat(SMono.fromPublisher(blobIdList.isStored(blobId)).block()).isTrue @@ -30,7 +31,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveBytesShouldNoopIfBlobExists(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, SHORT_BYTEARRAY)).block() assertThatCode(() => SMono.fromPublisher(testee.save(defaultBucketName, blobId, SHORT_BYTEARRAY)).block()) @@ -39,7 +40,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveInputStreamShouldSuccessIfBlobIdDoesNotExist(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block() assertThat(SMono.fromPublisher(blobIdList.isStored(blobId)).block()).isTrue @@ -47,7 +48,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveInputStreamShouldNoopIfBlobExists(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block() assertThatCode(() => SMono.fromPublisher(testee.save(defaultBucketName, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block()) @@ -56,7 +57,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveInputStreamConcurrentlyWithTheSameBlobShouldNoop(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) ConcurrentTestRunner.builder .operation((a: Int, b: Int) => SMono.fromPublisher(testee.save(defaultBucketName, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block()) @@ -66,7 +67,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveByteSourceShouldSuccessIfBlobIdDoesNotExist(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block() assertThat(SMono.fromPublisher(blobIdList.isStored(blobId)).block()).isTrue @@ -74,7 +75,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveByteSourceShouldNoopIfBlobExists(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block() assertThatCode(() => SMono.fromPublisher(testee.save(defaultBucketName, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block()) @@ -83,7 +84,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveBytesShouldSucceedInOtherBucketWhenBlobAlreadyInDefaultOne(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, SHORT_BYTEARRAY)).block() SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, SHORT_BYTEARRAY)).block() @@ -94,7 +95,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveInputStreamShouldSucceedInOtherBucketWhenBlobAlreadyInDefaultOne(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block() SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block() @@ -105,7 +106,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveByteSourceShouldSucceedInOtherBucketWhenBlobAlreadyInDefaultOne(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID.toString) SMono.fromPublisher(testee.save(defaultBucketName, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block() SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block() @@ -116,7 +117,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveBytesShouldSucceedInDefaultBucketWhenBlobAlreadyInOtherOne(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID().toString()) SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, SHORT_BYTEARRAY)).block() SMono.fromPublisher(testee.save(defaultBucketName, blobId, SHORT_BYTEARRAY)).block() @@ -127,7 +128,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveInputStreamShouldSucceedInDefaultBucketWhenBlobAlreadyInOtherOne(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID().toString()) SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block() SMono.fromPublisher(testee.save(defaultBucketName, blobId, new ByteArrayInputStream(SHORT_BYTEARRAY))).block() @@ -138,7 +139,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def saveByteSourceShouldSucceedInDefaultBucketWhenBlobAlreadyInOtherOne(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID().toString()) SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block() SMono.fromPublisher(testee.save(defaultBucketName, blobId, ByteSource.wrap(SHORT_BYTEARRAY))).block() @@ -149,7 +150,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def deleteShouldSuccessWithNotDefaultBucket(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID().toString()) SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, SHORT_BYTEARRAY)).block() assertThat(SMono.fromPublisher(testee.delete(TEST_BUCKET_NAME, blobId)).block()) @@ -157,7 +158,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def deleteBucketShouldFailWithDefaultBucket(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID().toString()) SMono.fromPublisher(testee.save(defaultBucketName, blobId, SHORT_BYTEARRAY)).block() val deleteBlobThrowingCallable: ThrowingCallable = () => @@ -171,7 +172,7 @@ trait SingleSaveBlobStoreContract extends BlobStoreDAOContract { @Test def deleteBucketShouldSuccessWithNotDefaultBucket(): Unit = { - val blobId: BlobId = blobIdFactory.randomId() + val blobId: BlobId = blobIdFactory.of(UUID.randomUUID().toString()) SMono.fromPublisher(testee.save(TEST_BUCKET_NAME, blobId, SHORT_BYTEARRAY)).block() assertThat(SMono.fromPublisher(testee.deleteBucket(TEST_BUCKET_NAME)).block()) diff --git a/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreTest.java b/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreTest.java index d68fd841a3..0574cf3f32 100644 --- a/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreTest.java +++ b/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/SingleSaveBlobStoreTest.java @@ -7,7 +7,7 @@ import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.BlobStoreDAO; import org.apache.james.blob.api.BucketName; -import org.apache.james.blob.api.HashBlobId; +import org.apache.james.blob.api.PlainBlobId; import org.apache.james.blob.memory.MemoryBlobStoreDAO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -46,7 +46,7 @@ public BlobIdList blobIdList() { @Override public BlobId.Factory blobIdFactory() { - return new HashBlobId.Factory(); + return new PlainBlobId.Factory(); } @Override diff --git a/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/postgres/PostgresSingleSaveBlobStoreTest.java b/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/postgres/PostgresSingleSaveBlobStoreTest.java index 6530876f72..39eaf04161 100644 --- a/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/postgres/PostgresSingleSaveBlobStoreTest.java +++ b/tmail-backend/blob/blobid-list/src/test/java/com/linagora/tmail/blob/blobid/list/postgres/PostgresSingleSaveBlobStoreTest.java @@ -5,7 +5,7 @@ import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.BlobStoreDAO; import org.apache.james.blob.api.BucketName; -import org.apache.james.blob.api.HashBlobId; +import org.apache.james.blob.api.PlainBlobId; import org.apache.james.blob.memory.MemoryBlobStoreDAO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -41,7 +41,7 @@ public BlobIdList blobIdList() { @Override public BlobId.Factory blobIdFactory() { - return new HashBlobId.Factory(); + return new PlainBlobId.Factory(); } @Override diff --git a/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/CassandraPublicAssetDAO.scala b/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/CassandraPublicAssetDAO.scala index 1f1ffe98ae..c8c87d8362 100644 --- a/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/CassandraPublicAssetDAO.scala +++ b/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/CassandraPublicAssetDAO.scala @@ -134,7 +134,7 @@ class CassandraPublicAssetDAO @Inject()(session: CqlSession, def selectAllBlobIds(): SFlux[BlobId] = SFlux(executor.executeRows(selectAllBlobIdsStatement.bind()) - .map(row => blobIdFactory.from(row.get(BLOB_ID, TypeCodecs.TEXT)))) + .map(row => blobIdFactory.parse(row.get(BLOB_ID, TypeCodecs.TEXT)))) def selectSize(username: Username): SFlux[Long] = SFlux(executor.executeRows(selectSize.bind() @@ -157,7 +157,7 @@ class CassandraPublicAssetDAO @Inject()(session: CqlSession, publicURI = PublicURI.fromString(row.get(PUBLIC_URI, TypeCodecs.TEXT)).toOption.get, size = Size.sanitizeSize(row.get(SIZE, TypeCodecs.BIGINT)), contentType = ImageContentType.from(row.get(CONTENT_TYPE, TypeCodecs.TEXT)).toOption.get, - blobId = blobIdFactory.from(row.get(BLOB_ID, TypeCodecs.TEXT)), + blobId = blobIdFactory.parse(row.get(BLOB_ID, TypeCodecs.TEXT)), identityIds = CollectionConverters.asScala(row.get(IDENTITY_IDS, FROZEN_OF_UUIDS_CODEC)) .map(IdentityId(_)) .toSeq) diff --git a/tmail-backend/jmap/extensions-postgres/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PostgresPublicAssetDAO.scala b/tmail-backend/jmap/extensions-postgres/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PostgresPublicAssetDAO.scala index 84c6bfa444..f9b6dc54d0 100644 --- a/tmail-backend/jmap/extensions-postgres/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PostgresPublicAssetDAO.scala +++ b/tmail-backend/jmap/extensions-postgres/src/main/scala/com/linagora/tmail/james/jmap/publicAsset/PostgresPublicAssetDAO.scala @@ -93,7 +93,7 @@ class PostgresPublicAssetDAO(postgresExecutor: PostgresExecutor, blobIdFactory: def selectAllBlobIds(): SFlux[BlobId] = SFlux(postgresExecutor.executeRows(dslContext => Flux.from(dslContext.select(BLOB_ID) .from(TABLE_NAME))) - .map(record => blobIdFactory.from(record.get(BLOB_ID)))) + .map(record => blobIdFactory.of(record.get(BLOB_ID)))) def deleteAsset(username: Username, assetId: PublicAssetId): SMono[Void] = SMono(postgresExecutor.executeVoid(dslContext => Mono.from(dslContext.deleteFrom(TABLE_NAME) @@ -115,7 +115,7 @@ class PostgresPublicAssetDAO(postgresExecutor: PostgresExecutor, blobIdFactory: publicURI = PublicURI.fromString(record.get(PUBLIC_URI)).toOption.get, size = Size.sanitizeSize(record.get(SIZE)), contentType = ImageContentType.from(record.get(CONTENT_TYPE)).toOption.get, - blobId = blobIdFactory.from(record.get(BLOB_ID)), + blobId = blobIdFactory.of(record.get(BLOB_ID)), identityIds = record.get(IDENTITIES_IDS) .map(IdentityId(_)) .toSeq) diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetDeletionTaskStepTest.scala b/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetDeletionTaskStepTest.scala index 91fb31ea16..1237cac3f0 100644 --- a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetDeletionTaskStepTest.scala +++ b/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetDeletionTaskStepTest.scala @@ -4,7 +4,7 @@ import java.net.URI import com.linagora.tmail.james.jmap.JMAPExtensionConfiguration import com.linagora.tmail.james.jmap.publicAsset.PublicAssetRepositoryContract.{CREATION_REQUEST, USERNAME} -import org.apache.james.blob.api.{BucketName, HashBlobId} +import org.apache.james.blob.api.{BucketName, PlainBlobId} import org.apache.james.blob.memory.MemoryBlobStoreDAO import org.apache.james.core.Username import org.apache.james.server.blob.deduplication.DeDuplicationBlobStore @@ -25,7 +25,7 @@ class PublicAssetDeletionTaskStepTest { def beforeEach(): Unit = { publicAssetRepository = new MemoryPublicAssetRepository(new DeDuplicationBlobStore(new MemoryBlobStoreDAO, BucketName.DEFAULT, - new HashBlobId.Factory()), + new PlainBlobId.Factory()), JMAPExtensionConfiguration(), PUBLIC_ASSET_URI_PREFIX) publicAssetDeletionTaskStep = new PublicAssetDeletionTaskStep(publicAssetRepository); diff --git a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetRepositoryContract.scala b/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetRepositoryContract.scala index 56b5aa5455..b2567b046f 100644 --- a/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetRepositoryContract.scala +++ b/tmail-backend/jmap/extensions/src/test/scala/com/linagora/tmail/james/jmap/publicAsset/PublicAssetRepositoryContract.scala @@ -5,7 +5,7 @@ import java.net.URI import java.util.UUID import com.linagora.tmail.james.jmap.publicAsset.ImageContentType.ImageContentType -import org.apache.james.blob.api.HashBlobId +import org.apache.james.blob.api.PlainBlobId import org.apache.james.core.Username import org.apache.james.jmap.api.model.Size.{Size, sanitizeSize} import org.apache.james.jmap.api.model.{IdentityId, Size} @@ -25,7 +25,7 @@ object PublicAssetRepositoryContract { val IDENTITY_IDS: Seq[IdentityId] = Seq(IdentityId.generate, IdentityId.generate) val ASSET_CONTENT: Array[Byte] = Array[Byte](1, 2, 3) val SIZE: Size = Size.sanitizeSize(ASSET_CONTENT.length) - val BLOBID_FACTORY = new HashBlobId.Factory() + val BLOBID_FACTORY = new PlainBlobId.Factory() val CREATION_REQUEST: PublicAssetCreationRequest = PublicAssetCreationRequest( size = SIZE, diff --git a/tmail-backend/mailbox/encrypted/api/src/main/scala/com/linagora/tmail/encrypted/EncryptedEmailContentStore.scala b/tmail-backend/mailbox/encrypted/api/src/main/scala/com/linagora/tmail/encrypted/EncryptedEmailContentStore.scala index bf247661a1..48ecf77ec1 100644 --- a/tmail-backend/mailbox/encrypted/api/src/main/scala/com/linagora/tmail/encrypted/EncryptedEmailContentStore.scala +++ b/tmail-backend/mailbox/encrypted/api/src/main/scala/com/linagora/tmail/encrypted/EncryptedEmailContentStore.scala @@ -48,6 +48,17 @@ object EncryptedEmailDetailedView { hasAttachment = encryptedEmailContent.hasAttachment, encryptedAttachmentMetadata = encryptedEmailContent.encryptedAttachmentMetadata .map(value => EncryptedAttachmentMetadata(value))) + + def of(id: MessageId, + encryptedPreview: String, + encryptedHtml: String, + hasAttachment: Boolean, + encryptedAttachmentMetadata: Option[String]): EncryptedEmailDetailedView = + EncryptedEmailDetailedView(id = id, + encryptedPreview = EncryptedPreview(encryptedPreview), + encryptedHtml = EncryptedHtml(encryptedHtml), + hasAttachment = hasAttachment, + encryptedAttachmentMetadata = encryptedAttachmentMetadata.map(value => EncryptedAttachmentMetadata(value))) } case class EncryptedAttachmentMetadata(value: String) extends AnyVal diff --git a/tmail-backend/mailbox/encrypted/cassandra/src/main/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailDAO.scala b/tmail-backend/mailbox/encrypted/cassandra/src/main/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailDAO.scala index 59490d1b22..2293e93221 100644 --- a/tmail-backend/mailbox/encrypted/cassandra/src/main/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailDAO.scala +++ b/tmail-backend/mailbox/encrypted/cassandra/src/main/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailDAO.scala @@ -74,7 +74,7 @@ class CassandraEncryptedEmailDAO @Inject()(session: CqlSession, blobIdFactory: B def getBlobId(cassandraMessageId: CassandraMessageId, position: Int): SMono[BlobId] = getMapOfPositionBlobId(cassandraMessageId) .map(positionBlobIdMapping => positionBlobIdMapping.get(position)) - .map(blobIdRaw => blobIdFactory.from(blobIdRaw)) + .map(blobIdFactory.parse) def getBlobIds(cassandraMessageId: CassandraMessageId): SFlux[BlobId] = getMapOfPositionBlobId(cassandraMessageId) @@ -82,11 +82,11 @@ class CassandraEncryptedEmailDAO @Inject()(session: CqlSession, blobIdFactory: B .values .asScala) .flatMapMany(blobIds => SFlux.fromIterable(blobIds)) - .map(blobIdRow => blobIdFactory.from(blobIdRow)) + .map(blobIdFactory.parse) def listBlobIds(): SFlux[BlobId] = SFlux(executor.executeRows(listBlobIdsStatement.bind())) .flatMapIterable(row => row.getMap(POSITION_BLOB_ID_MAPPING, classOf[Integer], classOf[String]).asScala.toMap.values) - .map(blobIdFactory.from) + .map(blobIdFactory.parse) private def readRow(cassandraMessageId: CassandraMessageId, row: Row): EncryptedEmailDetailedView = EncryptedEmailDetailedView( diff --git a/tmail-backend/mailbox/encrypted/cassandra/src/test/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailContentStoreTest.java b/tmail-backend/mailbox/encrypted/cassandra/src/test/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailContentStoreTest.java index 6683f1281c..fb6624b7bf 100644 --- a/tmail-backend/mailbox/encrypted/cassandra/src/test/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailContentStoreTest.java +++ b/tmail-backend/mailbox/encrypted/cassandra/src/test/java/com/linagora/tmail/encrypted/cassandra/CassandraEncryptedEmailContentStoreTest.java @@ -7,8 +7,8 @@ import org.apache.james.backends.cassandra.components.CassandraModule; import org.apache.james.blob.api.BlobStore; import org.apache.james.blob.api.BucketName; -import org.apache.james.blob.api.HashBlobId; import org.apache.james.blob.api.MetricableBlobStore; +import org.apache.james.blob.api.PlainBlobId; import org.apache.james.blob.memory.MemoryBlobStoreFactory; import org.apache.james.mailbox.cassandra.ids.CassandraMessageId; import org.apache.james.mailbox.model.MessageId; @@ -29,7 +29,7 @@ public class CassandraEncryptedEmailContentStoreTest implements EncryptedEmailContentStoreContract { private final CassandraMessageId.Factory messageIdFactory = new CassandraMessageId.Factory(); - private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory(); + private static final PlainBlobId.Factory BLOB_ID_FACTORY = new PlainBlobId.Factory(); private BlobStore blobStore; private CassandraEncryptedEmailDAO cassandraEncryptedEmailDAO; private CassandraEncryptedEmailContentStore cassandraEncryptedEmailContentStore; diff --git a/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/main/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailStoreDAO.java b/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/main/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailStoreDAO.java index f1aaf5b0ab..a8b40bf0bc 100644 --- a/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/main/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailStoreDAO.java +++ b/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/main/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailStoreDAO.java @@ -21,7 +21,6 @@ import org.jooq.postgres.extensions.types.Hstore; import com.google.common.collect.ImmutableMap; -import com.linagora.tmail.encrypted.EncryptedAttachmentMetadata; import com.linagora.tmail.encrypted.EncryptedEmailContent; import com.linagora.tmail.encrypted.EncryptedEmailDetailedView; @@ -64,7 +63,7 @@ public Mono getBlobId(PostgresMessageId messageId, Integer position) { .from(TABLE_NAME) .where(MESSAGE_ID.eq(messageId.asUuid())))) .flatMap(record -> Optional.ofNullable(record.get(0, String.class)).map(Mono::just).orElse(Mono.empty())) - .map(blobIdFactory::from); + .map(blobIdFactory::of); } public Flux getBlobIds(PostgresMessageId messageId) { @@ -73,7 +72,7 @@ public Flux getBlobIds(PostgresMessageId messageId) { .where(MESSAGE_ID.eq(messageId.asUuid())))) .map(record -> record.get(POSITION_BLOB_ID_MAPPING, Hstore.class).data()) .flatMapMany(positionBlobIdMapping -> Flux.fromIterable(positionBlobIdMapping.values())) - .map(blobIdFactory::from); + .map(blobIdFactory::of); } public Flux getAllBlobIds() { @@ -81,7 +80,7 @@ public Flux getAllBlobIds() { .from(TABLE_NAME))) .map(record -> record.get(POSITION_BLOB_ID_MAPPING, Hstore.class).data()) .flatMap(positionBlobIdMapping -> Flux.fromIterable(positionBlobIdMapping.values())) - .map(blobIdFactory::from); + .map(blobIdFactory::of); } public Mono delete(PostgresMessageId messageId) { @@ -96,11 +95,10 @@ private Hstore toHstore(Map positionBlobIdMapping) { } private EncryptedEmailDetailedView readRecord(Record record) { - return new EncryptedEmailDetailedView(PostgresMessageId.Factory.of(record.get(MESSAGE_ID)), + return EncryptedEmailDetailedView.of(PostgresMessageId.Factory.of(record.get(MESSAGE_ID)), record.get(ENCRYPTED_PREVIEW), record.get(ENCRYPTED_HTML), record.get(HAS_ATTACHMENT), - OptionConverters.toScala(Optional.ofNullable(record.get(ENCRYPTED_ATTACHMENT_METADATA)) - .map(EncryptedAttachmentMetadata::new))); + OptionConverters.toScala(Optional.ofNullable(record.get(ENCRYPTED_ATTACHMENT_METADATA)))); } } diff --git a/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/test/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailContentStoreTest.java b/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/test/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailContentStoreTest.java index efa2994797..8668775f96 100644 --- a/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/test/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailContentStoreTest.java +++ b/tmail-backend/mailbox/encrypted/mailbox-encrypted-postgres/src/test/java/com/linagora/tmail/encrypted/postgres/PostgresEncryptedEmailContentStoreTest.java @@ -6,8 +6,8 @@ import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.BlobStore; import org.apache.james.blob.api.BucketName; -import org.apache.james.blob.api.HashBlobId; import org.apache.james.blob.api.MetricableBlobStore; +import org.apache.james.blob.api.PlainBlobId; import org.apache.james.blob.memory.MemoryBlobStoreFactory; import org.apache.james.mailbox.model.MessageId; import org.apache.james.mailbox.postgres.PostgresMessageId; @@ -27,7 +27,7 @@ import reactor.core.publisher.Mono; public class PostgresEncryptedEmailContentStoreTest implements EncryptedEmailContentStoreContract { - private static final BlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory(); + private static final BlobId.Factory BLOB_ID_FACTORY = new PlainBlobId.Factory(); private final PostgresMessageId.Factory messageIdFactory = new PostgresMessageId.Factory(); private BlobStore blobStore; private PostgresEncryptedEmailBlobReferenceSource blobReferenceSource; diff --git a/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedEmailContentStoreTest.java b/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedEmailContentStoreTest.java index 9777c3e16a..37be140250 100644 --- a/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedEmailContentStoreTest.java +++ b/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedEmailContentStoreTest.java @@ -4,8 +4,8 @@ import org.apache.james.blob.api.BlobStore; import org.apache.james.blob.api.BucketName; -import org.apache.james.blob.api.HashBlobId; import org.apache.james.blob.api.MetricableBlobStore; +import org.apache.james.blob.api.PlainBlobId; import org.apache.james.blob.memory.MemoryBlobStoreFactory; import org.apache.james.mailbox.inmemory.InMemoryMessageId; import org.apache.james.mailbox.model.MessageId; @@ -16,7 +16,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; public class InMemoryEncryptedEmailContentStoreTest implements EncryptedEmailContentStoreContract { - private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory(); + private static final PlainBlobId.Factory BLOB_ID_FACTORY = new PlainBlobId.Factory(); private BlobStore blobStore; private InMemoryEncryptedEmailContentStore inMemoryEncryptedEmailContentStore; diff --git a/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedMessageManagerTest.java b/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedMessageManagerTest.java index f3898f0c96..e3e3fb2913 100644 --- a/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedMessageManagerTest.java +++ b/tmail-backend/mailbox/encrypted/memory/src/test/java/com/linagora/tmail/encrypted/InMemoryEncryptedMessageManagerTest.java @@ -12,7 +12,7 @@ import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.BucketName; -import org.apache.james.blob.api.HashBlobId; +import org.apache.james.blob.api.PlainBlobId; import org.apache.james.blob.memory.MemoryBlobStoreDAO; import org.apache.james.jmap.api.model.Preview; import org.apache.james.jmap.utils.JsoupHtmlTextExtractor; @@ -70,7 +70,7 @@ void setUp() throws Exception { keystoreManager = new InMemoryKeystoreManager(); MessageContentExtractor messageContentExtractor = new MessageContentExtractor(); - blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO(), BucketName.DEFAULT, new HashBlobId.Factory()); + blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO(), BucketName.DEFAULT, new PlainBlobId.Factory()); emailContentStore = new InMemoryEncryptedEmailContentStore(blobStore); testee = new EncryptedMessageManager(messageManager, keystoreManager, new ClearEmailContentFactory(new MessageParser(), messageContentExtractor, new Preview.Factory(messageContentExtractor, new JsoupHtmlTextExtractor())), diff --git a/tmail-backend/mailbox/team-mailboxes/src/main/scala/com/linagora/tmail/team/TeamMailbox.scala b/tmail-backend/mailbox/team-mailboxes/src/main/scala/com/linagora/tmail/team/TeamMailbox.scala index e2ad9f4a53..eea1af0575 100644 --- a/tmail-backend/mailbox/team-mailboxes/src/main/scala/com/linagora/tmail/team/TeamMailbox.scala +++ b/tmail-backend/mailbox/team-mailboxes/src/main/scala/com/linagora/tmail/team/TeamMailbox.scala @@ -127,7 +127,7 @@ object TeamMailbox { case class TeamMailbox(domain: Domain, mailboxName: TeamMailboxName) { def owner: Username = Username.fromLocalPartWithDomain("team-mailbox", domain) - def asMailAddress: MailAddress = new MailAddress(mailboxName.value.value, domain) + def asMailAddress: MailAddress = MailAddress.of(mailboxName.value.value, domain) def mailboxPath: MailboxPath = new MailboxPath(TEAM_MAILBOX_NAMESPACE, Username.fromLocalPartWithDomain("team-mailbox", domain), mailboxName.value) From d476294167644adbe36831101358e982818a1a37 Mon Sep 17 00:00:00 2001 From: TungTV Date: Tue, 29 Oct 2024 13:14:27 +0700 Subject: [PATCH 3/5] Adapt new code master - typeStateFactory.parse -> strictParse --- .../james/jmap/firebase/CassandraFirebaseSubscriptionDAO.scala | 2 +- .../james/jmap/firebase/PostgresFirebaseSubscriptionDAO.java | 2 +- .../tmail/james/jmap/json/FirebaseSubscriptionSerializer.scala | 2 +- .../linagora/tmail/james/jmap/model/FirebaseSubscription.scala | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/firebase/CassandraFirebaseSubscriptionDAO.scala b/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/firebase/CassandraFirebaseSubscriptionDAO.scala index 3b7a7eb698..6eeb5265ef 100644 --- a/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/firebase/CassandraFirebaseSubscriptionDAO.scala +++ b/tmail-backend/jmap/extensions-cassandra/src/main/scala/com/linagora/tmail/james/jmap/firebase/CassandraFirebaseSubscriptionDAO.scala @@ -113,6 +113,6 @@ class CassandraFirebaseSubscriptionDAO @Inject()(session: CqlSession, typeStateF private def toTypes(row: Row): Seq[TypeName] = CollectionConverters.asScala(row.get(TYPES, FROZEN_OF_STRINGS_CODEC)) - .flatMap(string => typeStateFactory.parse(string).toSeq) + .flatMap(string => typeStateFactory.strictParse(string).toSeq) .toSeq } diff --git a/tmail-backend/jmap/extensions-postgres/src/main/java/com/linagora/tmail/james/jmap/firebase/PostgresFirebaseSubscriptionDAO.java b/tmail-backend/jmap/extensions-postgres/src/main/java/com/linagora/tmail/james/jmap/firebase/PostgresFirebaseSubscriptionDAO.java index 64168e5af7..fbd54b4b40 100644 --- a/tmail-backend/jmap/extensions-postgres/src/main/java/com/linagora/tmail/james/jmap/firebase/PostgresFirebaseSubscriptionDAO.java +++ b/tmail-backend/jmap/extensions-postgres/src/main/java/com/linagora/tmail/james/jmap/firebase/PostgresFirebaseSubscriptionDAO.java @@ -142,7 +142,7 @@ private FirebaseSubscriptionExpiredTime toExpires(Record record) { private Set extractTypes(Record record) { return Arrays.stream(record.get(TYPES)) - .map(string -> typeStateFactory.parse(string).right().get()) + .map(string -> typeStateFactory.strictParse(string).right().get()) .collect(Collectors.toSet()); } } \ No newline at end of file diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/json/FirebaseSubscriptionSerializer.scala b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/json/FirebaseSubscriptionSerializer.scala index 91859623b6..c2b103fbd3 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/json/FirebaseSubscriptionSerializer.scala +++ b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/json/FirebaseSubscriptionSerializer.scala @@ -62,7 +62,7 @@ class FirebaseSubscriptionSerializer @Inject()(typeStateFactory: TypeStateFactor private implicit val subscriptionExpiredTimeReads: Reads[FirebaseSubscriptionExpiredTime] = Json.valueReads[FirebaseSubscriptionExpiredTime] private implicit val typeNameReads: Reads[TypeName] = { - case JsString(serializeValue) => typeStateFactory.parse(serializeValue) + case JsString(serializeValue) => typeStateFactory.strictParse(serializeValue) .fold(e => JsError(e.getMessage), v => JsSuccess(v)) case _ => JsError() } diff --git a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/model/FirebaseSubscription.scala b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/model/FirebaseSubscription.scala index 14e0501e0b..5258342508 100644 --- a/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/model/FirebaseSubscription.scala +++ b/tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/model/FirebaseSubscription.scala @@ -270,7 +270,7 @@ case class FirebaseSubscriptionPatchObject(value: Map[String, JsValue]) { } private def parseType(jsValue: JsValue, typeStateFactory: TypeStateFactory): Either[FirebasePatchUpdateValidationException, TypeName] = jsValue match { - case JsString(aString) => typeStateFactory.parse(aString).left.map(e => FirebasePatchUpdateValidationException(e.getMessage, Some("types"))) + case JsString(aString) => typeStateFactory.strictParse(aString).left.map(e => FirebasePatchUpdateValidationException(e.getMessage, Some("types"))) case _ => Left(FirebasePatchUpdateValidationException("Expecting an array of JSON strings as an argument", Some("types"))) } } From dce837950a2d996ae43dcd6c5b36bbf2722b5e1b Mon Sep 17 00:00:00 2001 From: TungTV Date: Tue, 29 Oct 2024 13:16:45 +0700 Subject: [PATCH 4/5] Adapt from new master code - Fix compile code --- .../identity/CombinedUsersRepositoryModule.java | 13 +++++++++++-- .../identity/CombinedUsersRepositoryTest.java | 17 +++++++++++++---- .../tmail/james/app/FakeMessageSearchIndex.java | 5 +++++ .../mailets/EnforceRateLimitingPlanTest.scala | 5 +++-- .../webadmin/EmailAddressContactRoutes.java | 6 +++--- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/tmail-backend/combined-identity/src/main/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryModule.java b/tmail-backend/combined-identity/src/main/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryModule.java index 268b24fd3b..3ca6592e93 100644 --- a/tmail-backend/combined-identity/src/main/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryModule.java +++ b/tmail-backend/combined-identity/src/main/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryModule.java @@ -3,6 +3,7 @@ import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.james.server.core.configuration.ConfigurationProvider; import org.apache.james.user.api.UsersRepository; +import org.apache.james.user.ldap.LDAPConnectionFactory; import org.apache.james.user.ldap.LdapRepositoryConfiguration; import org.apache.james.user.ldap.ReadOnlyLDAPUsersDAO; import org.apache.james.user.ldap.ReadOnlyUsersLDAPRepository; @@ -15,6 +16,8 @@ import com.google.inject.Scopes; import com.google.inject.Singleton; import com.google.inject.multibindings.ProvidesIntoSet; +import com.unboundid.ldap.sdk.LDAPConnectionPool; +import com.unboundid.ldap.sdk.LDAPException; public class CombinedUsersRepositoryModule extends AbstractModule { @Override @@ -34,6 +37,12 @@ public LdapRepositoryConfiguration provideConfiguration(ConfigurationProvider co configurationProvider.getConfiguration("usersrepository")); } + @Provides + @Singleton + public LDAPConnectionPool provideConfiguration(LdapRepositoryConfiguration configuration) throws LDAPException { + return new LDAPConnectionFactory(configuration).getLdapConnectionPool(); + } + @ProvidesIntoSet InitializationOperation configureUsersRepository(ConfigurationProvider configurationProvider, CombinedUsersRepository usersRepository) { return InitilizationOperationBuilder @@ -42,11 +51,11 @@ InitializationOperation configureUsersRepository(ConfigurationProvider configura } @ProvidesIntoSet - InitializationOperation configureLdap(LdapRepositoryConfiguration configuration, ReadOnlyLDAPUsersDAO readOnlyLDAPUsersDAO) { + InitializationOperation configureLdap(ConfigurationProvider configurationProvider, ReadOnlyLDAPUsersDAO readOnlyLDAPUsersDAO) { return InitilizationOperationBuilder .forClass(ReadOnlyUsersLDAPRepository.class) .init(() -> { - readOnlyLDAPUsersDAO.configure(configuration); + readOnlyLDAPUsersDAO.configure(configurationProvider.getConfiguration("usersrepository")); readOnlyLDAPUsersDAO.init(); }); } diff --git a/tmail-backend/combined-identity/src/test/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryTest.java b/tmail-backend/combined-identity/src/test/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryTest.java index 5d51948880..00c8f6a278 100644 --- a/tmail-backend/combined-identity/src/test/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryTest.java +++ b/tmail-backend/combined-identity/src/test/java/com/linagora/tmail/combined/identity/CombinedUsersRepositoryTest.java @@ -13,12 +13,15 @@ import org.apache.james.backends.cassandra.CassandraClusterExtension; import org.apache.james.core.Username; import org.apache.james.domainlist.api.DomainList; +import org.apache.james.metrics.api.NoopGaugeRegistry; import org.apache.james.user.api.UsersRepository; import org.apache.james.user.cassandra.CassandraRepositoryConfiguration; import org.apache.james.user.cassandra.CassandraUsersDAO; import org.apache.james.user.cassandra.CassandraUsersRepositoryModule; import org.apache.james.user.ldap.DockerLdapSingleton; +import org.apache.james.user.ldap.LDAPConnectionFactory; import org.apache.james.user.ldap.LdapGenericContainer; +import org.apache.james.user.ldap.LdapRepositoryConfiguration; import org.apache.james.user.ldap.ReadOnlyLDAPUsersDAO; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -60,8 +63,11 @@ class WhenEnableVirtualHosting implements CombinedUsersRepositoryContract.WithVi @BeforeEach void setUp(CombinedTestSystem testSystem) throws Exception { this.testSystem = testSystem; - readOnlyLDAPUsersDAO = new ReadOnlyLDAPUsersDAO(); - readOnlyLDAPUsersDAO.configure(ldapRepositoryConfiguration(ldapContainer, true)); + HierarchicalConfiguration config = ldapRepositoryConfiguration(ldapContainer, true); + LdapRepositoryConfiguration ldapConfiguration = LdapRepositoryConfiguration.from(config); + readOnlyLDAPUsersDAO = new ReadOnlyLDAPUsersDAO(new NoopGaugeRegistry(), new LDAPConnectionFactory(ldapConfiguration).getLdapConnectionPool(), + ldapConfiguration); + readOnlyLDAPUsersDAO.configure(config); readOnlyLDAPUsersDAO.init(); cassandraUsersDAO = new CassandraUsersDAO(cassandraCluster.getCassandraCluster().getConf(), CassandraRepositoryConfiguration.DEFAULT); @@ -99,8 +105,11 @@ class WhenDisableVirtualHosting implements CombinedUsersRepositoryContract.WithO @BeforeEach void setUp(CombinedTestSystem testSystem) throws Exception { this.testSystem = testSystem; - readOnlyLDAPUsersDAO = new ReadOnlyLDAPUsersDAO(); - readOnlyLDAPUsersDAO.configure(ldapRepositoryConfiguration(ldapContainer, false)); + HierarchicalConfiguration config = ldapRepositoryConfiguration(ldapContainer, false); + LdapRepositoryConfiguration ldapConfiguration = LdapRepositoryConfiguration.from(config); + readOnlyLDAPUsersDAO = new ReadOnlyLDAPUsersDAO(new NoopGaugeRegistry(), new LDAPConnectionFactory(ldapConfiguration).getLdapConnectionPool(), + ldapConfiguration); + readOnlyLDAPUsersDAO.configure(config); readOnlyLDAPUsersDAO.init(); cassandraUsersDAO = new CassandraUsersDAO(cassandraCluster.getCassandraCluster().getConf(), CassandraRepositoryConfiguration.DEFAULT); diff --git a/tmail-backend/guice/distributed/src/main/java/com/linagora/tmail/james/app/FakeMessageSearchIndex.java b/tmail-backend/guice/distributed/src/main/java/com/linagora/tmail/james/app/FakeMessageSearchIndex.java index e6f92135aa..e5c8e1e6c3 100644 --- a/tmail-backend/guice/distributed/src/main/java/com/linagora/tmail/james/app/FakeMessageSearchIndex.java +++ b/tmail-backend/guice/distributed/src/main/java/com/linagora/tmail/james/app/FakeMessageSearchIndex.java @@ -81,4 +81,9 @@ public EnumSet getSupportedCapabilities(EnumS public ExecutionMode getExecutionMode() { throw new NotImplementedException("not implemented"); } + + @Override + public void postReindexing() { + throw new NotImplementedException("not implemented"); + } } \ No newline at end of file diff --git a/tmail-backend/mailets/src/test/scala/com/linagora/tmail/mailets/EnforceRateLimitingPlanTest.scala b/tmail-backend/mailets/src/test/scala/com/linagora/tmail/mailets/EnforceRateLimitingPlanTest.scala index 473de9cf66..3d897dc6b9 100644 --- a/tmail-backend/mailets/src/test/scala/com/linagora/tmail/mailets/EnforceRateLimitingPlanTest.scala +++ b/tmail-backend/mailets/src/test/scala/com/linagora/tmail/mailets/EnforceRateLimitingPlanTest.scala @@ -9,11 +9,12 @@ import com.linagora.tmail.mailets.EnforceRateLimitingPlanTest.{USER1, USER2} import com.linagora.tmail.rate.limiter.api.memory.MemoryRateLimitingPlanUserRepository import com.linagora.tmail.rate.limiter.api.{DeliveryLimitations, InMemoryRateLimitingPlanRepository, LimitTypes, OperationLimitationsType, RateLimitation, RateLimitingPlan, RateLimitingPlanCreateRequest, RateLimitingPlanRepository, RateLimitingPlanUserRepository, RelayLimitations, TransitLimitations} import eu.timepit.refined.auto._ -import org.apache.james.backends.redis.{DockerRedis, RedisExtension, StandaloneRedisConfiguration} +import org.apache.james.backends.redis.{DockerRedis, RedisClientFactory, RedisExtension, StandaloneRedisConfiguration} import org.apache.james.core.Username import org.apache.james.metrics.api.NoopGaugeRegistry import org.apache.james.metrics.dropwizard.DropWizardGaugeRegistry import org.apache.james.rate.limiter.redis.RedisRateLimiterFactory +import org.apache.james.server.core.filesystem.FileSystemImpl import org.apache.james.util.Size.parse import org.apache.mailet.base.test.{FakeMail, FakeMailContext, FakeMailetConfig} import org.apache.mailet.{Mail, MailetConfig} @@ -46,7 +47,7 @@ class EnforceRateLimitingPlanTest { def setup(redis: DockerRedis): Unit = { rateLimitationPlanRepository = new InMemoryRateLimitingPlanRepository rateLimitingPlanUserRepository = new MemoryRateLimitingPlanUserRepository - redisRateLimiterFactory = new RedisRateLimiterFactory(StandaloneRedisConfiguration.from(redis.redisURI().toString)) + redisRateLimiterFactory = new RedisRateLimiterFactory(StandaloneRedisConfiguration.from(redis.redisURI().toString), new RedisClientFactory(FileSystemImpl.forTesting)) val rateLimitingPlan: RateLimitingPlan = SMono.fromPublisher(rateLimitationPlanRepository.create(RateLimitingPlanCreateRequest( name = "PaidPlan", diff --git a/tmail-backend/webadmin/webadmin-email-address-contact/src/main/java/com/linagora/tmail/webadmin/EmailAddressContactRoutes.java b/tmail-backend/webadmin/webadmin-email-address-contact/src/main/java/com/linagora/tmail/webadmin/EmailAddressContactRoutes.java index 40c3a183f9..1e5e65dca5 100644 --- a/tmail-backend/webadmin/webadmin-email-address-contact/src/main/java/com/linagora/tmail/webadmin/EmailAddressContactRoutes.java +++ b/tmail-backend/webadmin/webadmin-email-address-contact/src/main/java/com/linagora/tmail/webadmin/EmailAddressContactRoutes.java @@ -154,7 +154,7 @@ public Route deleteContact() { Domain domain = extractDomain(request); try { - MailAddress mailAddress = new MailAddress(extractAddressLocalPart(request), domain); + MailAddress mailAddress = MailAddress.of(extractAddressLocalPart(request), domain); return Mono.from(emailAddressContactSearchEngine.delete(domain, mailAddress)) .then(Mono.just(Responses.returnNoContent(response))) @@ -171,7 +171,7 @@ public Route updateContact() { verifyDomain(domain); try { - MailAddress mailAddress = new MailAddress(extractAddressLocalPart(request), domain); + MailAddress mailAddress = MailAddress.of(extractAddressLocalPart(request), domain); ContactNameUpdateDTO contactNameUpdateDTO = jsonExtractorName.parse(request.body()); return fillUpMissingNameFields(domain, mailAddress, contactNameUpdateDTO) @@ -212,7 +212,7 @@ public Route getContactInfo() { Domain domain = extractDomain(request); try { - MailAddress mailAddress = new MailAddress(extractAddressLocalPart(request), domain); + MailAddress mailAddress = MailAddress.of(extractAddressLocalPart(request), domain); return Mono.from(emailAddressContactSearchEngine.get(domain, mailAddress)) .map(EmailAddressContactResponse::from) From 98afda792646e235d50f6a956341441e7be40629 Mon Sep 17 00:00:00 2001 From: TungTV Date: Tue, 29 Oct 2024 18:19:24 +0700 Subject: [PATCH 5/5] JAMES-3552 Enforce max request size --- .../LinagoraEmailSendMethodContract.scala | 111 +++++++++--------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/tmail-backend/integration-tests/jmap/jmap-integration-tests-common/src/main/scala/com/linagora/tmail/james/common/LinagoraEmailSendMethodContract.scala b/tmail-backend/integration-tests/jmap/jmap-integration-tests-common/src/main/scala/com/linagora/tmail/james/common/LinagoraEmailSendMethodContract.scala index 77268c9fbd..3e8cf4aa3b 100644 --- a/tmail-backend/integration-tests/jmap/jmap-integration-tests-common/src/main/scala/com/linagora/tmail/james/common/LinagoraEmailSendMethodContract.scala +++ b/tmail-backend/integration-tests/jmap/jmap-integration-tests-common/src/main/scala/com/linagora/tmail/james/common/LinagoraEmailSendMethodContract.scala @@ -5,7 +5,7 @@ import java.time.Duration import java.util.concurrent.TimeUnit import com.linagora.tmail.james.common.EncryptHelper.uploadPublicKey -import com.linagora.tmail.james.common.LinagoraEmailSendMethodContract.{BOB_INBOX_PATH, HTML_BODY} +import com.linagora.tmail.james.common.LinagoraEmailSendMethodContract.{BOB_INBOX_PATH, HTML_BODY, bobSendsAMailToAndre, getBobInboxId} import io.netty.handler.codec.http.HttpHeaderNames.ACCEPT import io.restassured.RestAssured.{`given`, requestSpecification} import io.restassured.http.ContentType.JSON @@ -50,52 +50,7 @@ object LinagoraEmailSendMethodContract { val BOB_INBOX_PATH: MailboxPath = MailboxPath.inbox(BOB) val HTML_BODY: String = "
I have the most brilliant plan. Let me tell you all about it. What we do is, we
" -} - -trait LinagoraEmailSendMethodContract { - private lazy val slowPacedPollInterval: Duration = ONE_HUNDRED_MILLISECONDS - private lazy val calmlyAwait: ConditionFactory = Awaitility.`with` - .pollInterval(slowPacedPollInterval) - .and.`with`.pollDelay(slowPacedPollInterval) - .await - private lazy val awaitAtMostTenSeconds: ConditionFactory = calmlyAwait.atMost(10, TimeUnit.SECONDS) - - @BeforeEach - def setUp(server: GuiceJamesServer): Unit = { - server.getProbe(classOf[DataProbeImpl]) - .fluent() - .addDomain(DOMAIN.asString) - .addUser(BOB.asString(), BOB_PASSWORD) - .addUser(ANDRE.asString, ANDRE_PASSWORD) - - requestSpecification = baseRequestSpecBuilder(server) - .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD))) - .addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) - .build() - - val mailboxProbe: MailboxProbeImpl = server.getProbe(classOf[MailboxProbeImpl]) - mailboxProbe.createMailbox(BOB_INBOX_PATH) - mailboxProbe.createMailbox(MailboxPath.inbox(ANDRE)) - - uploadPublicKey(ACCOUNT_ID, requestSpecification) - } - - def randomMessageId: MessageId - - private def buildAndreRequestSpecification(server: GuiceJamesServer): RequestSpecification = - baseRequestSpecBuilder(server) - .setAuth(authScheme(UserCredential(ANDRE, ANDRE_PASSWORD))) - .addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) - .build - - private def listAllMessageResult(guiceJamesServer: GuiceJamesServer, username: Username): List[MessageResult] = - guiceJamesServer.getProbe(classOf[MailboxProbeImpl]) - .searchMessage(MultimailboxesSearchQuery.from(SearchQuery.of(SearchQuery.all())).build, username.asString(), 100) - .asScala - .flatMap(messageId => guiceJamesServer.getProbe(classOf[MessageIdProbe]).getMessages(messageId, username).asScala.headOption) - .toList - - private def bobSendsAMailToAndre(server: GuiceJamesServer): String = + def bobSendsAMailToAndre(server: GuiceJamesServer): String = s""" |{ | "using": [ @@ -150,9 +105,53 @@ trait LinagoraEmailSendMethodContract { | ] |}""".stripMargin - private def getBobInboxId(server: GuiceJamesServer): MailboxId = + def getBobInboxId(server: GuiceJamesServer): MailboxId = server.getProbe(classOf[MailboxProbeImpl]) .getMailboxId(MailboxConstants.USER_NAMESPACE, BOB.asString, MailboxConstants.INBOX) +} + +trait LinagoraEmailSendMethodContract { + private lazy val slowPacedPollInterval: Duration = ONE_HUNDRED_MILLISECONDS + private lazy val calmlyAwait: ConditionFactory = Awaitility.`with` + .pollInterval(slowPacedPollInterval) + .and.`with`.pollDelay(slowPacedPollInterval) + .await + private lazy val awaitAtMostTenSeconds: ConditionFactory = calmlyAwait.atMost(10, TimeUnit.SECONDS) + + @BeforeEach + def setUp(server: GuiceJamesServer): Unit = { + server.getProbe(classOf[DataProbeImpl]) + .fluent() + .addDomain(DOMAIN.asString) + .addUser(BOB.asString(), BOB_PASSWORD) + .addUser(ANDRE.asString, ANDRE_PASSWORD) + + requestSpecification = baseRequestSpecBuilder(server) + .setAuth(authScheme(UserCredential(BOB, BOB_PASSWORD))) + .addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .build() + + val mailboxProbe: MailboxProbeImpl = server.getProbe(classOf[MailboxProbeImpl]) + mailboxProbe.createMailbox(BOB_INBOX_PATH) + mailboxProbe.createMailbox(MailboxPath.inbox(ANDRE)) + + uploadPublicKey(ACCOUNT_ID, requestSpecification) + } + + def randomMessageId: MessageId + + private def buildAndreRequestSpecification(server: GuiceJamesServer): RequestSpecification = + baseRequestSpecBuilder(server) + .setAuth(authScheme(UserCredential(ANDRE, ANDRE_PASSWORD))) + .addHeader(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) + .build + + private def listAllMessageResult(guiceJamesServer: GuiceJamesServer, username: Username): List[MessageResult] = + guiceJamesServer.getProbe(classOf[MailboxProbeImpl]) + .searchMessage(MultimailboxesSearchQuery.from(SearchQuery.of(SearchQuery.all())).build, username.asString(), 100) + .asScala + .flatMap(messageId => guiceJamesServer.getProbe(classOf[MessageIdProbe]).getMessages(messageId, username).asScala.headOption) + .toList @Test def emailSendShouldReturnSuccess(server: GuiceJamesServer): Unit = { @@ -1755,26 +1754,26 @@ trait LinagoraEmailSendMethodContract { .when() .post() .`then` - .statusCode(HttpStatus.SC_OK) + .statusCode(HttpStatus.SC_BAD_REQUEST) .contentType(JSON) .extract() .body() .asString() assertThatJson(response) - .whenIgnoringPaths("methodResponses[0][1].notCreated.K87.description") - .inPath("methodResponses[0][1].notCreated.K87") + .whenIgnoringPaths("detail") .isEqualTo( s"""{ - | "type": "tooLarge" + | "type": "urn:ietf:params:jmap:error:limit", + | "status": 400, + | "limit": "maxSizeRequest" |}""".stripMargin) val description = assertThatJson(response) - .withIgnorePlaceholder("@") - .inPath("methodResponses[0][1].notCreated.K87.description") + .inPath("detail") .asString() - description.endsWith(" bytes while the maximum allowed is 10485760") - description.startsWith("Attempt to create a message of ") + description.endsWith("but maximum allowed is 10000000") + description.startsWith("Request size is exceeded.") } //endregion