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

S3 store is always enabled despite configuration #410

Closed
wants to merge 3 commits into from
Closed
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
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