Skip to content

Commit

Permalink
Merge pull request DSpace#9266 from 4Science/DURACOM-211-S3store-is-a…
Browse files Browse the repository at this point in the history
…lways-enabled

S3store is always enabled
  • Loading branch information
kshepherd authored Feb 27, 2024
2 parents a158a9b + 2beb604 commit 30074f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public boolean isEnabled() {
@Override
public void init() throws IOException {

if (this.isInitialized()) {
if (this.isInitialized() || !this.isEnabled()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

Expand All @@ -42,6 +43,7 @@
import io.findify.s3mock.S3Mock;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.BooleanUtils;
import org.dspace.AbstractIntegrationTestWithDatabase;
import org.dspace.app.matcher.LambdaMatcher;
import org.dspace.authorize.AuthorizeException;
Expand All @@ -53,13 +55,16 @@
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.Utils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;



/**
* @author Luca Giamminonni (luca.giamminonni at 4science.com)
*/
Expand All @@ -77,9 +82,13 @@ public class S3BitStoreServiceIT extends AbstractIntegrationTestWithDatabase {

private File s3Directory;

private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();


@Before
public void setup() throws Exception {

configurationService.setProperty("assetstore.s3.enabled", "true");
s3Directory = new File(System.getProperty("java.io.tmpdir"), "s3");

s3Mock = S3Mock.create(8001, s3Directory.getAbsolutePath());
Expand All @@ -88,7 +97,8 @@ public void setup() throws Exception {
amazonS3Client = createAmazonS3Client();

s3BitStoreService = new S3BitStoreService(amazonS3Client);

s3BitStoreService.setEnabled(BooleanUtils.toBoolean(
configurationService.getProperty("assetstore.s3.enabled")));
context.turnOffAuthorisationSystem();

parentCommunity = CommunityBuilder.createCommunity(context)
Expand Down Expand Up @@ -382,6 +392,17 @@ public void givenBitStreamIdentifierWithSlashesWhenSanitizedThenSlashesMustBeRem
assertThat(computedPath, Matchers.not(Matchers.containsString(File.separator)));
}

@Test
public void testDoNotInitializeConfigured() throws Exception {
String assetstores3enabledOldValue = configurationService.getProperty("assetstore.s3.enabled");
configurationService.setProperty("assetstore.s3.enabled", "false");
s3BitStoreService = new S3BitStoreService(amazonS3Client);
s3BitStoreService.init();
assertFalse(s3BitStoreService.isInitialized());
assertFalse(s3BitStoreService.isEnabled());
configurationService.setProperty("assetstore.s3.enabled", assetstores3enabledOldValue);
}

private byte[] generateChecksum(String content) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
Expand Down

0 comments on commit 30074f8

Please sign in to comment.