Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update James SHA-1 (postgresql) #1269

Open
wants to merge 5 commits into
base: postgresql
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion james-project
Submodule james-project updated 893 files
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -22,15 +23,15 @@ 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
}

@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())
Expand All @@ -39,15 +40,15 @@ 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
}

@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())
Expand All @@ -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())
Expand All @@ -66,15 +67,15 @@ 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
}

@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())
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -149,15 +150,15 @@ 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())
}

@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 = () =>
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +46,7 @@ public BlobIdList blobIdList() {

@Override
public BlobId.Factory blobIdFactory() {
return new HashBlobId.Factory();
return new PlainBlobId.Factory();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +41,7 @@ public BlobIdList blobIdList() {

@Override
public BlobId.Factory blobIdFactory() {
return new HashBlobId.Factory();
return new PlainBlobId.Factory();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ImmutableNode> 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);
Expand Down Expand Up @@ -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<ImmutableNode> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public EnumSet<MailboxManager.SearchCapabilities> getSupportedCapabilities(EnumS
public ExecutionMode getExecutionMode() {
throw new NotImplementedException("not implemented");
}

@Override
public void postReindexing() {
throw new NotImplementedException("not implemented");
}
}
Loading