Skip to content

Commit

Permalink
rename-datasafe-business-integration-test-files-for-clear-separation
Browse files Browse the repository at this point in the history
  • Loading branch information
Elwizzy12 committed Apr 11, 2024
1 parent 8853a63 commit 6b83afc
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

@Slf4j
@RequiredArgsConstructor
public abstract class BaseE2EIT extends WithStorageProvider {
public abstract class BaseE2ETest extends WithStorageProvider {

protected static final String PRIVATE_COMPONENT = "private";
protected static final String PRIVATE_FILES_COMPONENT = PRIVATE_COMPONENT + "/files";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* Tests that validates basic functionality - storing data to inbox, privatespace, listing files, etc.
*/
@Slf4j
class BasicFunctionalityIT extends BaseE2EIT {
class BasicFunctionalityIT extends BaseE2ETest {

private static final int LARGE_SIZE = 10 * 1024 * 1024 + 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Tests that validates basic functionality - storing data to inbox, privatespace, listing files, etc. using UTF-8 paths.
*/
@Slf4j
class BasicFunctionalityUtf8IT extends BaseE2EIT {
class BasicFunctionalityUtf8IT extends BaseE2ETest {

private static final String MESSAGE_ONE = "Hello here 1";
private static final String FOLDER = "folder1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* Multithreaded test of basic operations.
*/
@Slf4j
class BasicFunctionalityWithConcurrencyIT extends BaseE2EIT {
class BasicFunctionalityWithConcurrencyIT extends BaseE2ETest {

private static final int TIMEOUT_S = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

class BasicFunctionalityWithPasswordChangeIT extends BaseE2EIT {
class BasicFunctionalityWithPasswordChangeIT extends BaseE2ETest {

@SneakyThrows
@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* attacker is unable to modify encrypted text without being detected.
*/
@Slf4j
class DataTamperingResistanceIT extends BaseE2EIT {
class DataTamperingResistanceIT extends BaseE2ETest {

private static final Set<Character> NOT_TO_REPLACE_IN_PATH = ImmutableSet.of('=', '/');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
public class KeyStoreTypeCompareIT extends BaseE2EIT {
public class KeyStoreTypeCompareIT extends BaseE2ETest {
private final static int NUMBER_WRITES = 100;
private final static int NUMBER_READS = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import static org.assertj.core.api.Assertions.assertThat;

class ProfileContainsDatasafeVersionTest extends BaseE2EIT {
class ProfileContainsDatasafeVersionTest extends BaseE2ETest {

@Test
@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package de.adorsys.datasafe.business.impl.e2e;

import de.adorsys.datasafe.business.impl.service.DaggerDefaultDatasafeServices;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
import de.adorsys.datasafe.directory.impl.profile.config.DefaultDFSConfig;
Expand All @@ -12,59 +11,52 @@
import de.adorsys.datasafe.types.api.actions.WriteRequest;
import de.adorsys.datasafe.types.api.resource.AbsoluteLocation;
import de.adorsys.datasafe.types.api.resource.BasePrivateResource;
import de.adorsys.datasafe.types.api.resource.ResolvedResource;
import de.adorsys.datasafe.types.api.resource.Uri;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;

class SchemeDelegationTest extends WithStorageProvider {

private Path fsPath;
private Uri minioPath;
private StorageService minio;
private StorageService filesystem;
private DefaultDatasafeServices datasafeServices;

@BeforeEach
void initialize(@TempDir Path tempDir) {
WithStorageProvider.StorageDescriptor minioDescriptor = minio();
this.fsPath = tempDir;
this.minio = minioDescriptor.getStorageService().get();
this.filesystem = new FileSystemStorageService(tempDir);
this.minioPath = minioDescriptor.getLocation();
StorageService multiDfs = new SchemeDelegatingStorage(
ImmutableMap.of(
"s3", minio,
"file", filesystem
)
);

this.datasafeServices = DaggerDefaultDatasafeServices
.builder()
.config(new ProfilesOnFsDataOnMinio(minioPath, tempDir))

class SchemeDelegationTest extends WithStorageProvider {

private Path fsPath;
private Uri minioPath;
private StorageService minio;
private StorageService filesystem;
private DefaultDatasafeServices datasafeServices;

@BeforeEach
void initialize(@TempDir Path tempDir) {
WithStorageProvider.StorageDescriptor minioDescriptor = minio();
this.fsPath = tempDir;
this.minio = minioDescriptor.getStorageService().get();
this.filesystem = new FileSystemStorageService(tempDir);
this.minioPath = minioDescriptor.getLocation();
StorageService multiDfs = new SchemeDelegatingStorage(
ImmutableMap.of(
"s3", minio,
"file", filesystem
)
);
.storage(multiDfs)
.storage(multiDfs)
.build();
}

@Test
@SneakyThrows
void testProfileOnFsDataOnMinioWorks() {
UserIDAuth userJohn = new UserIDAuth("john", ReadKeyPasswordTestFactory.getForString("doe"));
UserIDAuth userJohn = new UserIDAuth("john", "doe");

// John's profile will be saved to filesystem
datasafeServices.userProfile().registerUsingDefaults(userJohn);
Expand All @@ -76,38 +68,25 @@ void testProfileOnFsDataOnMinioWorks() {
}

// Profiles are on FS
assertThat(listFs())
assertThat(Files.walk(fsPath))
.extracting(it -> fsPath.relativize(it))
.extracting(Path::toString)
.containsExactlyInAnyOrder("", "public-john", "private-john");
// File and keystore/pub keys are on minio
assertThat(listMinio())
assertThat(minio.list(new AbsoluteLocation<>(BasePrivateResource.forPrivate(minioPath.resolve("")))))
.extracting(it -> minioPath.relativize(it.location()))
.extracting(it -> it.asURI().toString())
.contains("users/john/private/keystore", "users/john/public/pubkeys")
.anyMatch(it -> it.startsWith("users/john/private/files/"))
.hasSize(3);
}

private List<AbsoluteLocation<ResolvedResource>> listMinio() {
try (Stream<AbsoluteLocation<ResolvedResource>> ls =
minio.list(new AbsoluteLocation<>(BasePrivateResource.forPrivate(minioPath.resolve(""))))) {
return ls.collect(Collectors.toList());
}
}

private List<Path> listFs() throws IOException {
try (Stream<Path> ls = Files.walk(fsPath)) {
return ls.collect(Collectors.toList());
}
}

static class ProfilesOnFsDataOnMinio extends DefaultDFSConfig {

private final Path profilesPath;

ProfilesOnFsDataOnMinio(Uri minioBucketPath, Path profilesPath) {
super(minioBucketPath, new ReadStorePassword("PAZZWORT"));
super(minioBucketPath, "PAZZWORT");
this.profilesPath = profilesPath;
}

Expand All @@ -125,4 +104,4 @@ public AbsoluteLocation privateProfile(UserID forUser) {
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisabledIfSystemProperty(named = WithStorageProvider.SKIP_CEPH, matches = "true")
class StorageBasedVersioningIT extends BaseE2EIT {
class StorageBasedVersioningIT extends BaseE2ETest {

private static final String FILE = "file.txt";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Validates software versioned operations.
*/
@Slf4j
public class VersionedDataIT extends BaseE2EIT {
public class VersionedDataIT extends BaseE2ETest {

private static final String MESSAGE_ONE = "Hello here 1";
private static final String MESSAGE_TWO = "Hello here 2";
Expand Down

0 comments on commit 6b83afc

Please sign in to comment.