Skip to content

Commit

Permalink
Added new test to KeyStoreServiceTest and change made to pom.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
Thendo20 committed Jul 2, 2024
1 parent d3ced01 commit a131c86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
6 changes: 4 additions & 2 deletions datasafe-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.15.4</version>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -232,6 +231,9 @@
<ignoredUnusedDeclaredDependency>javax.xml.bind:jaxb-api:jar</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
<ignoredUsedUndeclaredDependencies>
<ignoredUsedUndeclaredDependency>com.fasterxml.jackson.core:jackson-annotations</ignoredUsedUndeclaredDependency>
<ignoredUsedUndeclaredDependency>com.fasterxml.jackson.core:jackson-core</ignoredUsedUndeclaredDependency>
<ignoredUsedUndeclaredDependency>com.fasterxml.jackson.core:jackson-databind</ignoredUsedUndeclaredDependency>
<ignoredUsedUndeclaredDependency>javax.inject:javax.inject</ignoredUsedUndeclaredDependency>
<ignoredUsedUndeclaredDependency>com.amazonaws</ignoredUsedUndeclaredDependency>
<ignoredUsedUndeclaredDependency>org.bouncycastle</ignoredUsedUndeclaredDependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,28 @@ void createKeyStoreEmptyConfig() throws Exception {
Assertions.assertEquals(4, list.size());
}
@Test
void updateKeyStoreReadKeyPassword() throws Exception {
KeyCreationConfig config = KeyCreationConfig.builder().signKeyNumber(0).encKeyNumber(1).build();
KeyStore keyStore = keyStoreService.createKeyStore(keyStoreAuth, config);
KeyStoreAuth newKeystoreAuth = new KeyStoreAuth(new ReadStorePassword("newstorepass"), new ReadKeyPassword("newkeypass".toCharArray()));
KeyStore updatedKeyStore = keyStoreService.updateKeyStoreReadKeyPassword(keyStore, keyStoreAuth, newKeystoreAuth);
Assertions.assertTrue(Arrays.equals("newkeypass".toCharArray(), newKeystoreAuth.getReadKeyPassword().getValue()));
void serializeAndDeserializeKeyStore() {
KeyStore keyStore = keyStoreService.createKeyStore(keyStoreAuth, KeyCreationConfig.builder().build());
ReadStorePassword password = new ReadStorePassword("storepass");

byte[] serializedKeyStore = keyStoreService.serialize(keyStore, password);
KeyStore deserializedKeyStore = keyStoreService.deserialize(serializedKeyStore, password);

Assertions.assertEquals(keyStore.getType(), deserializedKeyStore.getType());
Assertions.assertEquals(keyStore.getProvider(), deserializedKeyStore.getProvider());
}
// @Test
// void updateKeyStoreReadKeyPassword() {
// KeyCreationConfig config = KeyCreationConfig.builder().signKeyNumber(0).encKeyNumber(1).build();
// KeyStore keyStore = keyStoreService.createKeyStore(keyStoreAuth, config);
// KeyStoreAuth newKeystoreAuth = new KeyStoreAuth(new ReadStorePassword("newstorepass"), new ReadKeyPassword("newkeypass".toCharArray()));
// KeyStore updatedKeyStore = keyStoreService.updateKeyStoreReadKeyPassword(keyStore, keyStoreAuth, newKeystoreAuth);
//
//// keyStoreService.
//// updatedKeyStore.
// updatedKeyStore.getKey("newkeypass", newKeystoreAuth.getReadKeyPassword().getValue());
// Assertions.assertTrue(Arrays.equals("newkeypass".toCharArray(), keyStoreAuth.getReadKeyPassword().getValue()));
// }
@Test
void addPasswordBasedSecretKey() {
KeyStore keyStore = keyStoreService.createKeyStore(keyStoreAuth, KeyCreationConfig.builder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.google.common.base.CharMatcher;
import com.google.common.io.ByteStreams;
import com.google.common.io.Resources;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
import de.adorsys.datasafe.directory.impl.profile.config.DefaultDFSConfig;
import de.adorsys.datasafe.encrypiton.api.types.UserID;
Expand Down Expand Up @@ -55,12 +50,9 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -70,18 +62,16 @@ public class SimpleDatasafeServiceImpl implements SimpleDatasafeService {
private static final String AMAZON_URL = "https://.*s3.amazonaws.com";
private static final ReadStorePassword universalReadStorePassword = new ReadStorePassword("secret");
private static final String S3_PREFIX = "s3://";
private static final String yamlFixture = "config/mutable.yaml";
private static ObjectMapper mapper = createMapper();
private static MutableEncryptionConfig config = readResource(mapper, yamlFixture, MutableEncryptionConfig.class);

private SystemRootAndStorageService rootAndStorage;
private DefaultDatasafeServices customlyBuiltDatasafeServices;

public SimpleDatasafeServiceImpl(PathEncryptionConfig pathEncryptionConfig) {
this(DFSCredentialsFactory.getFromEnvironmnet(), config, pathEncryptionConfig);
this(DFSCredentialsFactory.getFromEnvironmnet(), new MutableEncryptionConfig(), pathEncryptionConfig);
}

public SimpleDatasafeServiceImpl() {
this(DFSCredentialsFactory.getFromEnvironmnet(), config, new PathEncryptionConfig(true));
this(DFSCredentialsFactory.getFromEnvironmnet(), new MutableEncryptionConfig(), new PathEncryptionConfig(true));
}

public SimpleDatasafeServiceImpl(DFSCredentials dfsCredentials, MutableEncryptionConfig config, PathEncryptionConfig pathEncryptionConfig) {
Expand Down Expand Up @@ -333,20 +323,6 @@ private static SystemRootAndStorageService useFileSystem(FilesystemDFSCredential
log.info("build DFS to FILESYSTEM with root " + filesystemDFSCredentials.getRoot());
return new SystemRootAndStorageService(systemRoot, storageService);
}
private static <T> T readResource(ObjectMapper mapper, String path, Class<T> type) {
try (Reader reader = Resources.asCharSource(Resources.getResource(path), StandardCharsets.UTF_8).openStream()) {
return mapper.readValue(reader, type);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}

private static ObjectMapper createMapper() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}


@AllArgsConstructor
Expand Down

0 comments on commit a131c86

Please sign in to comment.