forked from mercedes-benz/sechub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide native S3 storage mercedes-benz#74
- refactored JobStorage and StorageService - introducing interface for job storage - instead file paths we use input streams now - divided s3 and filesystem parts - storage service does now check if s3 setup done, if not fallback to filesystem variant. If even filesystem setup not done initialization fails - SchedulerUploadService does now always store uploaded source code temporary on disk, validate it there and after this store content into shared volume or s3. So only valid content is available in job storage. Temporary files are always deleted after storage was done - integrated minio client - added s3mock dependency for integration tests - add some s3 storage tests (currently one fails, maybe a minio problem, see minio/minio-java#710 ) On behalf of Daimler TSS GmbH.
- Loading branch information
Showing
23 changed files
with
734 additions
and
293 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
...-checkmarx/src/main/java/com/daimler/sechub/adapter/checkmarx/CheckmarxAdapterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.daimler.sechub.adapter.checkmarx; | ||
|
||
import java.io.InputStream; | ||
|
||
import com.daimler.sechub.adapter.AdapterConfig; | ||
|
||
public interface CheckmarxAdapterConfig extends AdapterConfig { | ||
|
||
String getTeamIdForNewProjects(); | ||
String getPathToZipFile(); | ||
|
||
InputStream getSourceCodeZipFileInputStream(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...ntest/src/test/java/com/daimler/sechub/integrationtest/storage/MinioS3JobStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.daimler.sechub.integrationtest.storage; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.io.StringWriter; | ||
import java.nio.charset.Charset; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.UUID; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.adobe.testing.s3mock.junit4.S3MockRule; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.daimler.sechub.sharedkernel.storage.s3.MinioS3JobStorage; | ||
|
||
import io.minio.MinioClient; | ||
|
||
public class MinioS3JobStorageTest { | ||
|
||
@ClassRule | ||
public static final S3MockRule S3_MOCK_RULE = S3MockRule.builder().silent().build(); | ||
|
||
private static AmazonS3 amazonTestClient; | ||
|
||
private static MinioClient minioClient; | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
amazonTestClient = S3_MOCK_RULE.createS3Client(); | ||
minioClient = new MinioClient("http://localhost:" + S3_MOCK_RULE.getHttpPort()); | ||
} | ||
|
||
@Test | ||
public void a_new_storage_does_not_create_a_new_bucket() throws Exception { | ||
|
||
/* execute */ | ||
new MinioS3JobStorage(minioClient, "bucket1", "projectName", UUID.randomUUID()); | ||
|
||
/* test */ | ||
assertTrue(amazonTestClient.listBuckets().isEmpty()); // also no bucket2 from former test execution... | ||
|
||
} | ||
|
||
@Test | ||
public void after_store_the_inputstream_is_closed() throws Exception { | ||
|
||
/* prepare */ | ||
MinioS3JobStorage storage = new MinioS3JobStorage(minioClient, "bucket2", "projectName", UUID.randomUUID()); | ||
|
||
Path tmpFile = Files.createTempFile("storage_test", ".txt"); | ||
|
||
/* execute */ | ||
InputStream inputStream = new FileInputStream(tmpFile.toFile()); | ||
InputStream inputStreamSpy = Mockito.spy(inputStream); | ||
storage.store("testB", inputStreamSpy); | ||
|
||
/* test */ | ||
Mockito.verify(inputStreamSpy).close(); // stream must be closed | ||
|
||
} | ||
|
||
@Test | ||
public void store_stores_textfile_correct_and_can_be_fetched() throws Exception { | ||
|
||
/* prepare */ | ||
UUID jobjUUID = UUID.randomUUID(); | ||
String testContent="line1\nline2"; | ||
MinioS3JobStorage storage = new MinioS3JobStorage(minioClient, "bucket2", "projectName", jobjUUID); | ||
|
||
Path tmpFile = Files.createTempFile("storage_test", ".txt"); | ||
BufferedWriter bw = Files.newBufferedWriter(tmpFile); | ||
|
||
bw.write(testContent); | ||
bw.close(); | ||
|
||
/* execute */ | ||
storage.store("testA", new FileInputStream(tmpFile.toFile())); | ||
|
||
/* test */ | ||
String objectName = "jobstorage/projectName/"+jobjUUID+"/testA"; | ||
assertTrue(amazonTestClient.doesObjectExist("bucket2", objectName)); // test location is as expected | ||
|
||
MinioS3JobStorage storage2 = new MinioS3JobStorage(minioClient, "bucket2", "projectName", jobjUUID); | ||
InputStream loadedStream = storage2.fetch("testA"); | ||
StringWriter writer = new StringWriter(); | ||
IOUtils.copy(loadedStream, writer,Charset.defaultCharset()); | ||
|
||
String loaded = writer.toString(); | ||
|
||
assertEquals(testContent,loaded); // test content can be fetched | ||
|
||
} | ||
|
||
@Test | ||
public void stored_object_is_deleted_by_deleteall() throws Exception { | ||
/* prepare */ | ||
UUID jobUUID = UUID.randomUUID(); | ||
MinioS3JobStorage storage = new MinioS3JobStorage(minioClient, "bucket2", "projectName", jobUUID); | ||
|
||
Path tmpFile = Files.createTempFile("storage_test", ".txt"); | ||
|
||
/* execute */ | ||
InputStream inputStream = new FileInputStream(tmpFile.toFile()); | ||
InputStream inputStreamSpy = Mockito.spy(inputStream); | ||
storage.store("testC", inputStreamSpy); | ||
|
||
String objectName = "jobstorage/projectName/"+jobUUID+"/testC"; | ||
assertTrue(amazonTestClient.doesObjectExist("bucket2", objectName)); | ||
|
||
/* execute */ | ||
storage.deleteAll(); | ||
|
||
/* test */ | ||
assertFalse(amazonTestClient.doesObjectExist("bucket2", objectName)); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.