[OOM CERT-SERVICE-CLIENT] Fix null pointer when sans empty 85/115985/3 2.3.1
authorRemigiusz Janeczek <remigiusz.janeczek@nokia.com>
Wed, 2 Dec 2020 08:14:51 +0000 (09:14 +0100)
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>
Wed, 2 Dec 2020 08:26:54 +0000 (09:26 +0100)
Issue-ID: OOM-2632
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: I5e05eb2923b96313cb1d37eb844862289d6acae1

certService/pom.xml
certService/version.properties
certServiceClient/pom.xml
certServiceClient/src/main/java/org/onap/oom/certservice/client/certification/CsrFactory.java
certServiceClient/src/test/java/org/onap/oom/certservice/client/certification/CsrFactoryTest.java
certServiceClient/version.properties
certServiceK8sExternalProvider/pom.xml
certServicePostProcessor/pom.xml
pom.xml
version.properties

index e3e9817..e6a8672 100644 (file)
     <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>
index 8d40756..f1c5779 100644 (file)
@@ -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
index d0cb5bd..b1b2af9 100644 (file)
     <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>
index 1215e69..4612854 100644 (file)
@@ -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());
         }
 
index ab9fc92..27c20e0 100644 (file)
@@ -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);
     }
 }
 
index 8d40756..f1c5779 100644 (file)
@@ -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
index 22c4757..fe1d657 100644 (file)
@@ -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>
 
index bd79d85..6644464 100644 (file)
@@ -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 a1738a1..7dee166 100644 (file)
--- 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>
index 8d40756..f1c5779 100644 (file)
@@ -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