aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2020-12-02 09:14:51 +0100
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2020-12-02 09:26:54 +0100
commitc435e2cb9c2aa02315e5ca5df9515b056dc681e8 (patch)
treedb64a4437d0f1007f91557f11728551bf3bbe631
parentb9afa7d1d25f63a68dcb03fda523cd968323bddc (diff)
[OOM CERT-SERVICE-CLIENT] Fix null pointer when sans empty2.3.1
Issue-ID: OOM-2632 Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com> Change-Id: I5e05eb2923b96313cb1d37eb844862289d6acae1
-rw-r--r--certService/pom.xml4
-rw-r--r--certService/version.properties2
-rw-r--r--certServiceClient/pom.xml4
-rw-r--r--certServiceClient/src/main/java/org/onap/oom/certservice/client/certification/CsrFactory.java3
-rw-r--r--certServiceClient/src/test/java/org/onap/oom/certservice/client/certification/CsrFactoryTest.java50
-rw-r--r--certServiceClient/version.properties2
-rw-r--r--certServiceK8sExternalProvider/pom.xml2
-rw-r--r--certServicePostProcessor/pom.xml4
-rw-r--r--pom.xml2
-rw-r--r--version.properties2
10 files changed, 53 insertions, 22 deletions
diff --git a/certService/pom.xml b/certService/pom.xml
index e3e98174..e6a8672e 100644
--- a/certService/pom.xml
+++ b/certService/pom.xml
@@ -18,10 +18,10 @@
<parent>
<groupId>org.onap.oom.platform.cert-service</groupId>
<artifactId>oom-certservice</artifactId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>oom-certservice-api</artifactId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
<name>oom-certservice-api</name>
<description>OOM Certification Service Api</description>
<packaging>jar</packaging>
diff --git a/certService/version.properties b/certService/version.properties
index 8d40756c..f1c5779d 100644
--- a/certService/version.properties
+++ b/certService/version.properties
@@ -1,6 +1,6 @@
major=2
minor=3
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT
diff --git a/certServiceClient/pom.xml b/certServiceClient/pom.xml
index d0cb5bd1..b1b2af92 100644
--- a/certServiceClient/pom.xml
+++ b/certServiceClient/pom.xml
@@ -18,12 +18,12 @@
<parent>
<artifactId>oom-certservice</artifactId>
<groupId>org.onap.oom.platform.cert-service</groupId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>oom-certservice-client</artifactId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
<name>oom-certservice-client</name>
<description>OOM Certification Service Api Client</description>
<packaging>jar</packaging>
diff --git a/certServiceClient/src/main/java/org/onap/oom/certservice/client/certification/CsrFactory.java b/certServiceClient/src/main/java/org/onap/oom/certservice/client/certification/CsrFactory.java
index 1215e699..4612854d 100644
--- a/certServiceClient/src/main/java/org/onap/oom/certservice/client/certification/CsrFactory.java
+++ b/certServiceClient/src/main/java/org/onap/oom/certservice/client/certification/CsrFactory.java
@@ -34,6 +34,7 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.security.auth.x500.X500Principal;
+import org.apache.commons.collections.CollectionUtils;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.Extensions;
@@ -98,7 +99,7 @@ public class CsrFactory {
JcaPKCS10CertificationRequestBuilder builder = new JcaPKCS10CertificationRequestBuilder(subject,
keyPair.getPublic());
- if (!configuration.getSans().isEmpty()) {
+ if (!CollectionUtils.isEmpty(configuration.getSans())) {
builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, generateSansExtension());
}
diff --git a/certServiceClient/src/test/java/org/onap/oom/certservice/client/certification/CsrFactoryTest.java b/certServiceClient/src/test/java/org/onap/oom/certservice/client/certification/CsrFactoryTest.java
index ab9fc921..27c20e0e 100644
--- a/certServiceClient/src/test/java/org/onap/oom/certservice/client/certification/CsrFactoryTest.java
+++ b/certServiceClient/src/test/java/org/onap/oom/certservice/client/certification/CsrFactoryTest.java
@@ -35,27 +35,57 @@ import org.onap.oom.certservice.client.configuration.model.San;
class CsrFactoryTest {
- CsrConfiguration config = mock(CsrConfiguration.class);
+ private CsrConfiguration config = mock(CsrConfiguration.class);
@Test
void createEncodedCsr_shouldSucceedWhenAllFieldsAreSetCorrectly()
throws KeyPairGenerationException, CsrGenerationException {
- KeyPair keyPair =
- new KeyPairFactory(EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM,
- EncryptionAlgorithmConstants.KEY_SIZE).create();
- San san1 = new San("onapexample.com", GeneralName.dNSName);
- San san2 = new San("onapexample.com.pl", GeneralName.dNSName);
+ KeyPair keyPair = createKeyPair();
+
+ mockRequiredConfigFields();
+ mockOptionalConfigFields();
+
+ assertThat(new CsrFactory(config).createCsrInPem(keyPair)).isNotEmpty();
+ }
+ @Test
+ void createEncodedCsr_shouldSucceedWhenRequiredFieldsAreSetCorrectly()
+ throws KeyPairGenerationException, CsrGenerationException {
+
+ KeyPair keyPair = createKeyPair();
+
+ mockRequiredConfigFields();
+ mockOptionalConfigFieldsEmpty();
+
+ assertThat(new CsrFactory(config).createCsrInPem(keyPair)).isNotEmpty();
+ }
+
+ private KeyPair createKeyPair() {
+ return new KeyPairFactory(EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM,
+ EncryptionAlgorithmConstants.KEY_SIZE).create();
+ }
+
+ private void mockRequiredConfigFields() {
when(config.getCommonName()).thenReturn("onap.org");
- when(config.getSans()).thenReturn(List.of(san1, san2));
+ when(config.getOrganization()).thenReturn("Linux-Foundation");
when(config.getCountry()).thenReturn("US");
+ when(config.getState()).thenReturn("California");
+ }
+
+ private void mockOptionalConfigFields() {
+ San san1 = new San("onapexample.com", GeneralName.dNSName);
+ San san2 = new San("onapexample.com.pl", GeneralName.dNSName);
+
when(config.getLocation()).thenReturn("San-Francisco");
- when(config.getOrganization()).thenReturn("Linux-Foundation");
+ when(config.getSans()).thenReturn(List.of(san1, san2));
when(config.getOrganizationUnit()).thenReturn("ONAP");
- when(config.getState()).thenReturn("California");
+ }
- assertThat(new CsrFactory(config).createCsrInPem(keyPair)).isNotEmpty();
+ private void mockOptionalConfigFieldsEmpty() {
+ when(config.getLocation()).thenReturn(null);
+ when(config.getSans()).thenReturn(null);
+ when(config.getOrganizationUnit()).thenReturn(null);
}
}
diff --git a/certServiceClient/version.properties b/certServiceClient/version.properties
index 8d40756c..f1c5779d 100644
--- a/certServiceClient/version.properties
+++ b/certServiceClient/version.properties
@@ -1,6 +1,6 @@
major=2
minor=3
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT
diff --git a/certServiceK8sExternalProvider/pom.xml b/certServiceK8sExternalProvider/pom.xml
index 22c4757e..fe1d657f 100644
--- a/certServiceK8sExternalProvider/pom.xml
+++ b/certServiceK8sExternalProvider/pom.xml
@@ -5,7 +5,7 @@
<parent>
<artifactId>oom-certservice</artifactId>
<groupId>org.onap.oom.platform.cert-service</groupId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
diff --git a/certServicePostProcessor/pom.xml b/certServicePostProcessor/pom.xml
index bd79d85d..66444649 100644
--- a/certServicePostProcessor/pom.xml
+++ b/certServicePostProcessor/pom.xml
@@ -5,12 +5,12 @@
<parent>
<artifactId>oom-certservice</artifactId>
<groupId>org.onap.oom.platform.cert-service</groupId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>oom-certservice-post-processor</artifactId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
<name>oom-certservice-post-processor</name>
<description>An application which conducts certificate post-processing like: merging truststores, copying keystores.</description>
<packaging>jar</packaging>
diff --git a/pom.xml b/pom.xml
index a1738a1c..7dee166c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
</parent>
<groupId>org.onap.oom.platform.cert-service</groupId>
<artifactId>oom-certservice</artifactId>
- <version>2.3.0-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
<name>oom-certservice</name>
<description>OOM Certification Service</description>
<packaging>pom</packaging>
diff --git a/version.properties b/version.properties
index 8d40756c..f1c5779d 100644
--- a/version.properties
+++ b/version.properties
@@ -1,6 +1,6 @@
major=2
minor=3
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT