aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--certService/Dockerfile2
-rw-r--r--certService/README.md16
-rw-r--r--certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java3
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java8
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java102
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java11
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvValidationUtils.java4
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForClient.java32
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForCsr.java48
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java8
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactory.java14
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java44
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java54
13 files changed, 205 insertions, 141 deletions
diff --git a/certService/Dockerfile b/certService/Dockerfile
index 5060c6bf..770dab97 100644
--- a/certService/Dockerfile
+++ b/certService/Dockerfile
@@ -4,7 +4,7 @@ ARG VERSION=${version}
RUN groupadd certService && useradd -g certService certService
-RUN apt-get update && apt-get install -y vim
+RUN apt-get update && apt-get install -y vim curl
RUN chown -R certService:certService /var/log
diff --git a/certService/README.md b/certService/README.md
index 23cb2cf6..4780a904 100644
--- a/certService/README.md
+++ b/certService/README.md
@@ -84,15 +84,23 @@ curl localhost:8080/actuator/health
```
Should return {"status":"UP"}
-### Running CSITs
-Pull csit repository
+### AAF CertService CSITs
+#### CSIT repository
```
https://gerrit.onap.org/r/admin/repos/integration/csit
```
-Go to created directory and run
+
+####How to run tests locally
+1. Checkout CSIT repository
+2. Configure CSIT local environment
+3. Inside CSIT directory execute
```
-sudo ./run-csit.sh plans/aaf/cert-service
+sudo ./run-csit.sh plans/aaf/certservice
```
+
+####Jenkins build
+https://jenkins.onap.org/view/CSIT/job/aaf-master-csit-certservice/
+
### Logs locally
path:
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java b/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java
index a6dd5fcf..94530100 100644
--- a/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java
+++ b/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java
@@ -51,12 +51,11 @@ class CmpServersConfigLoader {
try {
servers = loadConfigFromFile(path).getCmpv2Servers();
servers.forEach(validator::validate);
- LOGGER.info(String.format("CMP Servers configuration successfully loaded from file '%s'", path));
+ LOGGER.info("CMP Servers configuration successfully loaded from file {}", path);
} catch (IOException e) {
LOGGER.error("Exception occurred during CMP Servers configuration loading: ", e);
} catch (InvalidParameterException e) {
LOGGER.error("Validation of CMPv2 servers configuration failed:", e);
- throw e;
}
return servers;
diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java
index cf8c07a1..d14dc7b7 100644
--- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java
+++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoaderTest.java
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ContextConfiguration(classes = CertServiceApplication.class)
class CmpServersConfigLoaderTest {
private static final String EXISTING_CONFIG_FILENAME = "cmpServers.json";
- private static final String NONEXISTING_CONFIG_FILENAME = "nonexisting_cmpServers.json";
+ private static final String NONEXISTING_CONFIG_FILENAME = "nonExisting_cmpServers.json";
private static final Map<String, String> EXPECTED_FIRST_CMP_SERVER = Map.of(
"CA_NAME", "TEST",
"URL", "http://127.0.0.1/ejbca/publicweb/cmp/cmp",
@@ -61,7 +61,7 @@ class CmpServersConfigLoaderTest {
private CmpServersConfigLoader configLoader;
@Test
- public void shouldLoadCmpServersConfigWhenFileAvailable() {
+ void shouldLoadCmpServersConfigWhenFileAvailable() {
// Given
String path = getClass().getClassLoader().getResource(EXISTING_CONFIG_FILENAME).getFile();
@@ -75,8 +75,8 @@ class CmpServersConfigLoaderTest {
verifyThatCmpServerEquals(cmpServers.get(1), EXPECTED_SECOND_CMP_SERVER);
}
- @Test()
- public void shouldReturnEmptyListWhenFileMissing() {
+ @Test
+ void shouldReturnEmptyListWhenFileMissing() {
// When
List<Cmpv2Server> cmpServers = configLoader.load(NONEXISTING_CONFIG_FILENAME);
diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java
index 43094f09..7184384c 100644
--- a/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java
+++ b/certService/src/test/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigTest.java
@@ -20,16 +20,17 @@
package org.onap.aaf.certservice.certification.configuration;
+import org.bouncycastle.asn1.x500.X500Name;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
import org.mockito.Mockito;
-import org.onap.aaf.certservice.CertServiceApplication;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.onap.aaf.certservice.certification.configuration.model.Authentication;
+import org.onap.aaf.certservice.certification.configuration.model.CaMode;
import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import java.util.List;
@@ -37,29 +38,61 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.startsWith;
-@ExtendWith(SpringExtension.class)
-@ContextConfiguration(classes = CertServiceApplication.class)
-@TestPropertySource(properties = {"app.config.path=/fake/path/to/config"})
+@ExtendWith(MockitoExtension.class)
class CmpServersConfigTest {
- private static final List<Cmpv2Server> SAMPLE_CMP_SERVERS = List.of(
- new Cmpv2Server(),
- new Cmpv2Server()
- );
+ private static final String APP_CONFIG_PATH = "/fake/path/to/config";
- @MockBean
+ private static final List<Cmpv2Server> SAMPLE_CMP_SERVERS = generateTestConfiguration();
+
+ @Mock
private CmpServersConfigLoader cmpServersConfigLoader;
- @Autowired
private CmpServersConfig cmpServersConfig;
+ @BeforeEach
+ void setUp() {
+ cmpServersConfig = new CmpServersConfig(APP_CONFIG_PATH, cmpServersConfigLoader);
+ }
+
+ @Test
+ void shouldCallLoaderWithPathFromPropertiesWhenCreated() {
+ this.cmpServersConfig.loadConfiguration(); // Manual PostConstruct call
+ Mockito.verify(cmpServersConfigLoader).load(startsWith(APP_CONFIG_PATH));
+ }
+
+ @Test
+ void shouldReturnLoadedServersWhenGetCalled() {
+ // Given
+ Mockito.when(cmpServersConfigLoader.load(any())).thenReturn(SAMPLE_CMP_SERVERS);
+ this.cmpServersConfig.loadConfiguration(); // Manual PostConstruct call
+
+ // When
+ List<Cmpv2Server> receivedCmpServers = this.cmpServersConfig.getCmpServers();
+
+ // Then
+ assertThat(receivedCmpServers).containsAll(SAMPLE_CMP_SERVERS);
+ }
+
@Test
- public void shouldCallLoaderWithPathFromPropertiesWhenCreated() {
- Mockito.verify(cmpServersConfigLoader).load(startsWith("/fake/path/to/config"));
+ void shouldReturnLoadedServersAfterRefreshWhenGetCalled() {
+ // Given
+ Mockito.when(cmpServersConfigLoader.load(any())).thenReturn(SAMPLE_CMP_SERVERS);
+
+ List<Cmpv2Server> receivedCmpServers = this.cmpServersConfig.getCmpServers();
+ assertThat(receivedCmpServers).isNull();
+
+ this.cmpServersConfig.onRefreshScope(new RefreshScopeRefreshedEvent());
+
+ // When
+ receivedCmpServers = this.cmpServersConfig.getCmpServers();
+
+ // Then
+ assertThat(receivedCmpServers).containsAll(SAMPLE_CMP_SERVERS);
}
@Test
- public void shouldReturnLoadedServersWhenGetCalled() {
+ void shouldNotReturnIakAndRvWhenToStringMethodIsUsed() {
// Given
Mockito.when(cmpServersConfigLoader.load(any())).thenReturn(SAMPLE_CMP_SERVERS);
this.cmpServersConfig.loadConfiguration(); // Manual PostConstruct call
@@ -68,6 +101,35 @@ class CmpServersConfigTest {
List<Cmpv2Server> receivedCmpServers = this.cmpServersConfig.getCmpServers();
// Then
- assertThat(receivedCmpServers).hasSize(SAMPLE_CMP_SERVERS.size());
+ receivedCmpServers.forEach((server)-> assertThat(server.toString())
+ .doesNotContain(
+ server.getAuthentication().getIak(),
+ server.getAuthentication().getRv()
+ ));
+ }
+
+ private static List<Cmpv2Server> generateTestConfiguration() {
+ Cmpv2Server testServer1 = new Cmpv2Server();
+ testServer1.setCaName("TEST_CA1");
+ testServer1.setIssuerDN(new X500Name("CN=testIssuer"));
+ testServer1.setUrl("http://test.ca.server");
+ Authentication testAuthentication1 = new Authentication();
+ testAuthentication1.setIak("testIak");
+ testAuthentication1.setRv("testRv");
+ testServer1.setAuthentication(testAuthentication1);
+ testServer1.setCaMode(CaMode.RA);
+
+ Cmpv2Server testServer2 = new Cmpv2Server();
+ testServer2.setCaName("TEST_CA2");
+ testServer2.setIssuerDN(new X500Name("CN=testIssuer2"));
+ testServer2.setUrl("http://test.ca.server");
+ Authentication testAuthentication2 = new Authentication();
+ testAuthentication2.setIak("test2Iak");
+ testAuthentication2.setRv("test2Rv");
+ testServer2.setAuthentication(testAuthentication2);
+ testServer2.setCaMode(CaMode.CLIENT);
+
+ return List.of(testServer1, testServer2);
}
-} \ No newline at end of file
+
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
index beccd383..25a152bf 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
@@ -19,8 +19,15 @@
*/
package org.onap.aaf.certservice.client.configuration;
+import java.util.Optional;
+
public class EnvProvider {
- public String readEnvVariable(String envVariable) {
- return System.getProperty(envVariable);
+ public Optional<String> readEnvVariable(String envVariableName) {
+ return Optional.ofNullable(System.getenv(envVariableName))
+ .filter(EnvProvider::isEnvPresent);
+ }
+
+ private static Boolean isEnvPresent(String envValue) {
+ return !"".equals(envValue);
}
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvValidationUtils.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvValidationUtils.java
index b87df5be..e65d688d 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvValidationUtils.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvValidationUtils.java
@@ -34,10 +34,6 @@ public final class EnvValidationUtils {
return caName.matches("^[a-zA-Z0-9]*$");
}
- public static Boolean isEnvExists(String envValue) {
- return envValue != null && !"".equals(envValue);
- }
-
public static Boolean isCountryValid(String country) {
return country.matches("^([A-Z][A-Z])$");
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForClient.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForClient.java
index aad64f5b..1ce76370 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForClient.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForClient.java
@@ -19,33 +19,31 @@
*/
package org.onap.aaf.certservice.client.configuration;
+import java.util.Optional;
+
public class EnvsForClient {
- private static final EnvProvider envProvider = new EnvProvider();
- private final String urlToCertService;
- private final String requestTimeOut;
- private final String outputPath;
- private final String caName;
+ private final EnvProvider envProvider = new EnvProvider();
public EnvsForClient() {
- this.urlToCertService = envProvider.readEnvVariable(ClientConfigurationEnvs.REQUEST_URL.toString());
- this.requestTimeOut = envProvider.readEnvVariable(ClientConfigurationEnvs.REQUEST_TIMEOUT.toString());
- this.outputPath = envProvider.readEnvVariable(ClientConfigurationEnvs.OUTPUT_PATH.toString());
- this.caName = envProvider.readEnvVariable(ClientConfigurationEnvs.CA_NAME.toString());
}
- public String getUrlToCertService() {
- return urlToCertService;
+ public Optional<String> getUrlToCertService() {
+ return readEnv(ClientConfigurationEnvs.REQUEST_URL);
+ }
+
+ public Optional<String> getRequestTimeOut() {
+ return readEnv(ClientConfigurationEnvs.REQUEST_TIMEOUT);
}
- public String getRequestTimeOut() {
- return requestTimeOut;
+ public Optional<String> getOutputPath() {
+ return readEnv(ClientConfigurationEnvs.OUTPUT_PATH);
}
- public String getOutputPath() {
- return outputPath;
+ public Optional<String> getCaName() {
+ return readEnv(ClientConfigurationEnvs.CA_NAME);
}
- public String getCaName() {
- return caName;
+ private Optional<String> readEnv(ClientConfigurationEnvs envName) {
+ return envProvider.readEnvVariable(envName.toString());
}
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForCsr.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForCsr.java
index 0c948d3f..77efc198 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForCsr.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForCsr.java
@@ -19,52 +19,42 @@
*/
package org.onap.aaf.certservice.client.configuration;
+import java.util.Optional;
public class EnvsForCsr {
private final EnvProvider envProvider = new EnvProvider();
- private String commonName;
- private String organization;
- private String organizationUnit;
- private String location;
- private String state;
- private String country;
- private String subjectAlternativesName;
- public EnvsForCsr() {
- this.commonName = envProvider.readEnvVariable(CsrConfigurationEnvs.COMMON_NAME.toString());
- this.organization = envProvider.readEnvVariable(CsrConfigurationEnvs.ORGANIZATION.toString());
- this.organizationUnit = envProvider.readEnvVariable(CsrConfigurationEnvs.ORGANIZATION_UNIT.toString());
- this.location = envProvider.readEnvVariable(CsrConfigurationEnvs.LOCATION.toString());
- this.state = envProvider.readEnvVariable(CsrConfigurationEnvs.STATE.toString());
- this.country = envProvider.readEnvVariable(CsrConfigurationEnvs.COUNTRY.toString());
- this.subjectAlternativesName = envProvider.readEnvVariable(CsrConfigurationEnvs.SANS.toString());
+ public EnvsForCsr() {}
+
+ public Optional<String> getCommonName() {
+ return readEnv(CsrConfigurationEnvs.COMMON_NAME);
}
- public String getCommonName() {
- return commonName;
+ public Optional<String> getOrganization() {
+ return readEnv(CsrConfigurationEnvs.ORGANIZATION);
}
- public String getOrganization() {
- return organization;
+ public Optional<String> getOrganizationUnit() {
+ return readEnv(CsrConfigurationEnvs.ORGANIZATION_UNIT);
}
- public String getOrganizationUnit() {
- return organizationUnit;
+ public Optional<String> getLocation() {
+ return readEnv(CsrConfigurationEnvs.LOCATION);
}
- public String getLocation() {
- return location;
+ public Optional<String> getState() {
+ return readEnv(CsrConfigurationEnvs.STATE);
}
- public String getState() {
- return state;
+ public Optional<String> getCountry() {
+ return readEnv(CsrConfigurationEnvs.COUNTRY);
}
- public String getCountry() {
- return country;
+ public Optional<String> getSubjectAlternativesName() {
+ return readEnv(CsrConfigurationEnvs.SANS);
}
- public String getSubjectAlternativesName() {
- return subjectAlternativesName;
+ private Optional<String> readEnv(CsrConfigurationEnvs envName) {
+ return envProvider.readEnvVariable(envName.toString());
}
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java
index 96b1fb8b..b7ee5d32 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactory.java
@@ -42,18 +42,18 @@ public class ClientConfigurationFactory implements AbstractConfigurationFactory<
ClientConfiguration configuration = new ClientConfiguration();
- Optional.ofNullable(envsForClient.getUrlToCertService()).filter(EnvValidationUtils::isEnvExists)
+ envsForClient.getUrlToCertService()
.map(configuration::setUrlToCertService);
- Optional.ofNullable(envsForClient.getRequestTimeOut()).filter(EnvValidationUtils::isEnvExists)
+ envsForClient.getRequestTimeOut()
.map(timeout -> configuration.setRequestTimeout(Integer.valueOf(timeout)));
- Optional.ofNullable(envsForClient.getOutputPath()).filter(EnvValidationUtils::isEnvExists)
+ envsForClient.getOutputPath()
.filter(EnvValidationUtils::isPathValid)
.map(configuration::setCertsOutputPath)
.orElseThrow(() -> new ClientConfigurationException(ClientConfigurationEnvs.OUTPUT_PATH + " is invalid."));
- Optional.ofNullable(envsForClient.getCaName()).filter(EnvValidationUtils::isEnvExists)
+ envsForClient.getCaName()
.filter(EnvValidationUtils::isAlphaNumeric)
.map(configuration::setCaName)
.orElseThrow(() -> new ClientConfigurationException(ClientConfigurationEnvs.CA_NAME + " is invalid."));
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactory.java
index 61e1b3c3..1e5d5c53 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactory.java
@@ -43,32 +43,32 @@ public class CsrConfigurationFactory implements AbstractConfigurationFactory<Csr
CsrConfiguration configuration = new CsrConfiguration();
- Optional.ofNullable(envsForCsr.getCommonName()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getCommonName()
.filter(EnvValidationUtils::isCommonNameValid)
.map(configuration::setCommonName)
.orElseThrow(() -> new CsrConfigurationException(CsrConfigurationEnvs.COMMON_NAME + " is invalid."));
- Optional.ofNullable(envsForCsr.getOrganization()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getOrganization()
.filter(org -> !EnvValidationUtils.isSpecialCharsPresent(org))
.map(configuration::setOrganization)
.orElseThrow(() -> new CsrConfigurationException(CsrConfigurationEnvs.ORGANIZATION + " is invalid."));
- Optional.ofNullable(envsForCsr.getState()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getState()
.map(configuration::setState)
.orElseThrow(() -> new CsrConfigurationException(CsrConfigurationEnvs.STATE + " is invalid."));
- Optional.ofNullable(envsForCsr.getCountry()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getCountry()
.filter(EnvValidationUtils::isCountryValid)
.map(configuration::setCountry)
.orElseThrow(() -> new CsrConfigurationException(CsrConfigurationEnvs.COUNTRY + " is invalid."));
- Optional.ofNullable(envsForCsr.getOrganizationUnit()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getOrganizationUnit()
.map(configuration::setOrganizationUnit);
- Optional.ofNullable(envsForCsr.getLocation()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getLocation()
.map(configuration::setLocation);
- Optional.ofNullable(envsForCsr.getSubjectAlternativesName()).filter(EnvValidationUtils::isEnvExists)
+ envsForCsr.getSubjectAlternativesName()
.map(configuration::setSubjectAlternativeNames);
return configuration;
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java
index f355de1a..2c875c24 100644
--- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java
+++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java
@@ -26,6 +26,8 @@ import org.onap.aaf.certservice.client.configuration.EnvsForClient;
import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException;
import org.onap.aaf.certservice.client.configuration.factory.ClientConfigurationFactory;
+import java.util.Optional;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
@@ -33,22 +35,22 @@ import static org.mockito.Mockito.when;
public class ClientConfigurationFactoryTest {
- final String CA_NAME_VALID = "caaaftest2";
- final String TIME_OUT_VALID = "30000";
- final String OUTPUT_PATH_VALID = "/opt/app/osaaf";
- final String URL_TO_CERT_SERVICE_VALID = "http://cert-service:8080/v1/certificate/";
- final String CA_NAME_INVALID = "caaaftest2#$";
- final String OUTPUT_PATH_INVALID = "/opt//app/osaaf";
+ private final String CA_NAME_VALID = "caaaftest2";
+ private final String TIME_OUT_VALID = "30000";
+ private final String OUTPUT_PATH_VALID = "/opt/app/osaaf";
+ private final String URL_TO_CERT_SERVICE_VALID = "http://cert-service:8080/v1/certificate/";
+ private final String CA_NAME_INVALID = "caaaftest2#$";
+ private final String OUTPUT_PATH_INVALID = "/opt//app/osaaf";
private EnvsForClient envsForClient = mock(EnvsForClient.class);
@Test
void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() throws ClientConfigurationException {
// given
- when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID);
- when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID);
- when(envsForClient.getRequestTimeOut()).thenReturn(TIME_OUT_VALID);
- when(envsForClient.getUrlToCertService()).thenReturn(URL_TO_CERT_SERVICE_VALID);
+ when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_VALID));
+ when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID));
+ when(envsForClient.getRequestTimeOut()).thenReturn(Optional.of(TIME_OUT_VALID));
+ when(envsForClient.getUrlToCertService()).thenReturn(Optional.of(URL_TO_CERT_SERVICE_VALID));
// when
ClientConfiguration configuration = new ClientConfigurationFactory(envsForClient).create();
@@ -63,8 +65,8 @@ public class ClientConfigurationFactoryTest {
@Test
void create_shouldReturnSuccessWhenDefaultVariablesAreNotSet() throws ClientConfigurationException {
// given
- when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID);
- when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID);
+ when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_VALID));
+ when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID));
// when
ClientConfiguration configuration = new ClientConfigurationFactory(envsForClient).create();
@@ -79,7 +81,7 @@ public class ClientConfigurationFactoryTest {
@Test
void create_shouldReturnClientExceptionWhenRequiredVariableIsNotSet() {
// given
- when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID);
+ when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID));
// when
ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory(envsForClient);
@@ -93,10 +95,10 @@ public class ClientConfigurationFactoryTest {
@Test
void create_shouldReturnClientExceptionWhenCANameContainsSpecialCharacters() {
// given
- when(envsForClient.getCaName()).thenReturn(CA_NAME_INVALID);
- when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID);
- when(envsForClient.getRequestTimeOut()).thenReturn(TIME_OUT_VALID);
- when(envsForClient.getUrlToCertService()).thenReturn(URL_TO_CERT_SERVICE_VALID);
+ when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_INVALID));
+ when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID));
+ when(envsForClient.getRequestTimeOut()).thenReturn(Optional.of(TIME_OUT_VALID));
+ when(envsForClient.getUrlToCertService()).thenReturn(Optional.of(URL_TO_CERT_SERVICE_VALID));
// when
ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory(envsForClient);
@@ -110,10 +112,10 @@ public class ClientConfigurationFactoryTest {
@Test
void create_shouldReturnClientExceptionWhenOutputPathContainsSpecialCharacters() {
// given
- when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID);
- when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_INVALID);
- when(envsForClient.getRequestTimeOut()).thenReturn(TIME_OUT_VALID);
- when(envsForClient.getUrlToCertService()).thenReturn(URL_TO_CERT_SERVICE_VALID);
+ when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_VALID));
+ when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_INVALID));
+ when(envsForClient.getRequestTimeOut()).thenReturn(Optional.of(TIME_OUT_VALID));
+ when(envsForClient.getUrlToCertService()).thenReturn(Optional.of(URL_TO_CERT_SERVICE_VALID));
// when
ClientConfigurationFactory configurationFactory = new ClientConfigurationFactory(envsForClient);
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java
index 695a9e4b..707094c0 100644
--- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java
+++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java
@@ -26,6 +26,8 @@ import org.onap.aaf.certservice.client.configuration.EnvsForCsr;
import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException;
import org.onap.aaf.certservice.client.configuration.factory.CsrConfigurationFactory;
+import java.util.Optional;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
@@ -33,14 +35,14 @@ import static org.mockito.Mockito.when;
public class CsrConfigurationFactoryTest {
- final String COMMON_NAME_VALID = "onap.org";
- final String SANS_VALID = "test-name";
- final String COUNTRY_VALID = "US";
- final String LOCATION_VALID = "San-Francisco";
- final String ORGANIZATION_VALID = "Linux-Foundation";
- final String ORGANIZATION_UNIT_VALID = "ONAP";
- final String STATE_VALID = "California";
- final String COMMON_NAME_INVALID = "onap.org*&";
+ private final String COMMON_NAME_VALID = "onap.org";
+ private final String SANS_VALID = "test-name";
+ private final String COUNTRY_VALID = "US";
+ private final String LOCATION_VALID = "San-Francisco";
+ private final String ORGANIZATION_VALID = "Linux-Foundation";
+ private final String ORGANIZATION_UNIT_VALID = "ONAP";
+ private final String STATE_VALID = "California";
+ private final String COMMON_NAME_INVALID = "onap.org*&";
private EnvsForCsr envsForCsr = mock(EnvsForCsr.class);
@@ -48,13 +50,13 @@ public class CsrConfigurationFactoryTest {
@Test
void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() throws CsrConfigurationException {
// given
- when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_VALID);
- when(envsForCsr.getSubjectAlternativesName()).thenReturn(SANS_VALID);
- when(envsForCsr.getCountry()).thenReturn(COUNTRY_VALID);
- when(envsForCsr.getLocation()).thenReturn(LOCATION_VALID);
- when(envsForCsr.getOrganization()).thenReturn(ORGANIZATION_VALID);
- when(envsForCsr.getOrganizationUnit()).thenReturn(ORGANIZATION_UNIT_VALID);
- when(envsForCsr.getState()).thenReturn(STATE_VALID);
+ when(envsForCsr.getCommonName()).thenReturn(Optional.of(COMMON_NAME_VALID));
+ when(envsForCsr.getSubjectAlternativesName()).thenReturn(Optional.of(SANS_VALID));
+ when(envsForCsr.getCountry()).thenReturn(Optional.of(COUNTRY_VALID));
+ when(envsForCsr.getLocation()).thenReturn(Optional.of(LOCATION_VALID));
+ when(envsForCsr.getOrganization()).thenReturn(Optional.of(ORGANIZATION_VALID));
+ when(envsForCsr.getOrganizationUnit()).thenReturn(Optional.of(ORGANIZATION_UNIT_VALID));
+ when(envsForCsr.getState()).thenReturn(Optional.of(STATE_VALID));
// when
CsrConfiguration configuration = new CsrConfigurationFactory(envsForCsr).create();
@@ -72,10 +74,10 @@ public class CsrConfigurationFactoryTest {
@Test
void create_shouldReturnSuccessWhenNotRequiredVariablesAreNotSet() throws CsrConfigurationException {
// given
- when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_VALID);
- when(envsForCsr.getState()).thenReturn(STATE_VALID);
- when(envsForCsr.getCountry()).thenReturn(COUNTRY_VALID);
- when(envsForCsr.getOrganization()).thenReturn(ORGANIZATION_VALID);
+ when(envsForCsr.getCommonName()).thenReturn(Optional.of(COMMON_NAME_VALID));
+ when(envsForCsr.getState()).thenReturn(Optional.of(STATE_VALID));
+ when(envsForCsr.getCountry()).thenReturn(Optional.of(COUNTRY_VALID));
+ when(envsForCsr.getOrganization()).thenReturn(Optional.of(ORGANIZATION_VALID));
// when
CsrConfiguration configuration = new CsrConfigurationFactory(envsForCsr).create();
@@ -91,13 +93,13 @@ public class CsrConfigurationFactoryTest {
@Test
void create_shouldReturnCsrConfigurationExceptionWhenCommonNameContainsSpecialCharacters() {
// given
- when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_INVALID);
- when(envsForCsr.getSubjectAlternativesName()).thenReturn(SANS_VALID);
- when(envsForCsr.getCountry()).thenReturn(COUNTRY_VALID);
- when(envsForCsr.getLocation()).thenReturn(LOCATION_VALID);
- when(envsForCsr.getOrganization()).thenReturn(ORGANIZATION_VALID);
- when(envsForCsr.getOrganizationUnit()).thenReturn(ORGANIZATION_UNIT_VALID);
- when(envsForCsr.getState()).thenReturn(SANS_VALID);
+ when(envsForCsr.getCommonName()).thenReturn(Optional.of(COMMON_NAME_INVALID));
+ when(envsForCsr.getSubjectAlternativesName()).thenReturn(Optional.of(SANS_VALID));
+ when(envsForCsr.getCountry()).thenReturn(Optional.of(COUNTRY_VALID));
+ when(envsForCsr.getLocation()).thenReturn(Optional.of(LOCATION_VALID));
+ when(envsForCsr.getOrganization()).thenReturn(Optional.of(ORGANIZATION_VALID));
+ when(envsForCsr.getOrganizationUnit()).thenReturn(Optional.of(ORGANIZATION_UNIT_VALID));
+ when(envsForCsr.getState()).thenReturn(Optional.of(SANS_VALID));
// when
CsrConfigurationFactory configurationFactory = new CsrConfigurationFactory(envsForCsr);