diff options
author | 2020-11-18 07:55:55 +0100 | |
---|---|---|
committer | 2020-11-20 12:05:42 +0100 | |
commit | fd94a0f31c85d941330b43dcb2baa8ad4aa39270 (patch) | |
tree | c35b3fddbd5eebb618807f1894a52964fa6dd90d /certService/src/test/java/org/onap | |
parent | 75ee4a9d489b53b2abd6b44b1a1a46635a703d44 (diff) |
[OOM CERT-SERVICE-API] Add support for URI, IP, E-mail in SANs
Issue-ID: OOM-2632
Change-Id: I903c31ebe05521e281753cb847001ba99275f758
Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com>
Diffstat (limited to 'certService/src/test/java/org/onap')
4 files changed, 118 insertions, 109 deletions
diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/CsrModelFactoryTest.java b/certService/src/test/java/org/onap/oom/certservice/certification/CsrModelFactoryTest.java index 75a6e81c..88cc6fb8 100644 --- a/certService/src/test/java/org/onap/oom/certservice/certification/CsrModelFactoryTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/certification/CsrModelFactoryTest.java @@ -54,18 +54,12 @@ class CsrModelFactoryTest { // when CsrModel decryptedCsr = csrModelFactory - .createCsrModel(new StringBase64(encoderCsr), new StringBase64(encoderPK)); + .createCsrModel(new StringBase64(encoderCsr), new StringBase64(encoderPK)); - // then - assertTrue( - decryptedCsr.toString() - .contains( - "C=US,ST=California,L=San-Francisco,O=Linux-Foundation," - + "OU=ONAP,CN=onap.org,E=tester@onap.org") - && - decryptedCsr.toString() - .contains("SANs: [gerrit.onap.org, test.onap.org, onap.com]") - ); + assertTrue(decryptedCsr.toString() + .contains(TestData.EXPECTED_CERT_SUBJECT)); + assertTrue(decryptedCsr.toString() + .contains(TestData.EXPECTED_CERT_SANS)); } @Test @@ -76,8 +70,8 @@ class CsrModelFactoryTest { // when Exception exception = assertThrows( - CsrDecryptionException.class, () -> csrModelFactory - .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) + CsrDecryptionException.class, () -> csrModelFactory + .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) ); String expectedMessage = "Incorrect CSR, decryption failed"; @@ -95,8 +89,8 @@ class CsrModelFactoryTest { // when Exception exception = assertThrows( - KeyDecryptionException.class, () -> csrModelFactory - .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) + KeyDecryptionException.class, () -> csrModelFactory + .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) ); String expectedMessage = "Incorrect Key, decryption failed"; @@ -115,8 +109,8 @@ class CsrModelFactoryTest { // when Exception exception = assertThrows( - CsrDecryptionException.class, () -> csrModelFactory - .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) + CsrDecryptionException.class, () -> csrModelFactory + .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) ); String expectedMessage = "Incorrect CSR, decryption failed"; @@ -134,8 +128,8 @@ class CsrModelFactoryTest { // when Exception exception = assertThrows( - KeyDecryptionException.class, () -> csrModelFactory - .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) + KeyDecryptionException.class, () -> csrModelFactory + .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) ); String expectedMessage = "Incorrect Key, decryption failed"; diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/TestData.java b/certService/src/test/java/org/onap/oom/certservice/certification/TestData.java index 81c16128..1c883f8e 100644 --- a/certService/src/test/java/org/onap/oom/certservice/certification/TestData.java +++ b/certService/src/test/java/org/onap/oom/certservice/certification/TestData.java @@ -25,71 +25,78 @@ public final class TestData { private TestData() { } - public static final String TEST_CSR = "" - + "-----BEGIN CERTIFICATE REQUEST-----\n" - + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh\n" - + "MRYwFAYDVQQHDA1TYW4tRnJhbmNpc2NvMRkwFwYDVQQKDBBMaW51eC1Gb3VuZGF0\n" - + "aW9uMQ0wCwYDVQQLDARPTkFQMREwDwYDVQQDDAhvbmFwLm9yZzEeMBwGCSqGSIb3\n" - + "DQEJARYPdGVzdGVyQG9uYXAub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" - + "CgKCAQEA13K1LrQ1L6eL7B8K4kucNct0sSjZe7Ww91V40s6mjcWajeFJk+pObZKz\n" - + "BfnImkVJwxdNMDD6tX16wykbGfQPyh4BBiAjLVk9XSeoPHFRBQ4LKTuyPtXhEXyr\n" - + "qwatYXGWZE554qq64pbReddOUJHgMc38SrOk/eMAKxB0uRrXpA0mPH7zwIZ4X8g2\n" - + "PoxJKI1BSYc8kOvvujsGSMw3e5nS8A+doFUwVi3jJMnaVCoZrvJbtREfXHZqBLQ5\n" - + "XQ8mNpIFfmGYF/tvW/O6LBdlZkuAQ9i4FBgf5+HdIVZOXrn09ksIZxW6vxIvAVi0\n" - + "5AOSgXictyphcNP2i/erBeCQCVB7MwIDAQABoEYwRAYJKoZIhvcNAQkOMTcwNTAz\n" - + "BgNVHREELDAqgg9nZXJyaXQub25hcC5vcmeCDXRlc3Qub25hcC5vcmeCCG9uYXAu\n" - + "Y29tMA0GCSqGSIb3DQEBCwUAA4IBAQBXH2nRwodQRJTuyrLe/VSg3PUdcPyAx2Ew\n" - + "63tWiGO+qWo8rK2a9Rr/t/zkQe2lx6NHqcMc2Rt6NeKGbrAvHGxTiYM35gktBdxG\n" - + "UaQS1ymrBWHAwbC+kv78r+5lCfafNm/EVdhUZbEw+crsw2wx4iKEW0byS4Ln0o5g\n" - + "aXVUW3i4G5FaYiYBUIDsujDdnH1IoxunEA6pDzDv1h6R9/TYu6Se8HToREIjOPBZ\n" - + "pDI5lDRu0YmI8r+TmAU3tTT1sY2WVxYDnhJut9ofegfMPQV4FIohxtPcCfoLSWti\n" - + "ml6jbcFqDvlzq3B3CXH9HU3jdJt33iSjCQGsSqy6bmCOdMS6XTPU\n" - + "-----END CERTIFICATE REQUEST-----\n"; + public static final String LOCALHOST_IP_IN_HEX = "#7f000001"; //127.0.0.1 + + public static final String EXPECTED_CERT_SUBJECT = "C=US,ST=California,L=San-Francisco,O=Linux-Foundation,OU=ONAP,CN=onap.org"; + public static final String EXPECTED_CERT_SANS = + "SANs: [localhost, onap.org, test.onap.org, onap@onap.org, " + LOCALHOST_IP_IN_HEX + ", onap://cluster.local/]"; + + + public static final String TEST_CSR = "-----BEGIN CERTIFICATE REQUEST-----\n" + + "MIIDNTCCAh0CAQAwdzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWEx\n" + + "FjAUBgNVBAcTDVNhbi1GcmFuY2lzY28xGTAXBgNVBAoTEExpbnV4LUZvdW5kYXRp\n" + + "b24xDTALBgNVBAsTBE9OQVAxETAPBgNVBAMTCG9uYXAub3JnMIIBIjANBgkqhkiG\n" + + "9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxRYVFOosyABMq+yANz9phmYyfmHbw9F9r3Ca\n" + + "v1oZ2xw1LbF2HGBq8F45nXfMjX2H+Lxk8m/XmIDb+9lzINU6J6xmDrKZiiif5ORa\n" + + "oRENfQZNWkAWPguWyKGtHk6ueeSjS8D0SWwloc1g0hB3GREffocuJ24K+t2nXglf\n" + + "7XVgmHxjiE8k+pD3SUo5rA7Fx1TmLguEA8aCRGaYg/aofCNe9hDm34iqUzm5tPPQ\n" + + "OgR3Lpqx2JW0iJYbQXmX3cG/RE0qFl+rgrNhCd8ptX7IUiWtQmttssR3bE8JVgaf\n" + + "x9EU9GZ5dZXifSFJzs42UY7X6DPiQDFerfWRNc3dRTYBlkbTiwIDAQABoHkwdwYJ\n" + + "KoZIhvcNAQkOMWowaDBZBgNVHREEUjBQgglsb2NhbGhvc3SCCG9uYXAub3Jngg10\n" + + "ZXN0Lm9uYXAub3JngQ1vbmFwQG9uYXAub3JnhwR/AAABhhVvbmFwOi8vY2x1c3Rl\n" + + "ci5sb2NhbC8wCwYDVR0PBAQDAgWgMA0GCSqGSIb3DQEBCwUAA4IBAQAk9lRwbWyL\n" + + "VRWSM5cBiRK2nCKhfur20khHFQgYcPAD8BRXEk5/F0KBSBMNGMrBgOYqq3IYsoMc\n" + + "mvs9KKVqIV3+lBej2QTF3cxdHYPTrCvvkoheMYt5qqjkrQRbiydzj7/wvflmBXs1\n" + + "7TViU+TqoJ8q5DWTEvv0X5t/WF6sSIxFHHKD7otDXPW5CAeqXO5A99bTrSiXmVAH\n" + + "72/n/JFHueURv+NbpHyBNXweezNnB5BDrrqduabkhn31ThA0wzePDNR02aXwxxHn\n" + + "77sSa3iuAN3IaVWYfxCOX4fEw8F+wMAAMTiWItM8Lc9DT5rsYeRHAZmOMVEnowc2\n" + + "3eKLFeWDIi2Z\n" + + "-----END CERTIFICATE REQUEST-----\n"; public static final String TEST_WRONG_CSR = "" - + "-----BEGIN CERTIFICATE REQUEST-----\n" - + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh\n" - + "MRYwFAYDVQQHDA1TYW4tRnJhbmNpc2NvMRkwFwYDVQQKDBBMaW51eC1Gb3VuZGF0\n" - + "aW9uMQ0wCwYDVQQLDARPTkFQMREwDwYDVQQDDAhvbmFwLm9yZzEeMBwGCSqGSIb3\n" - + "-----END CERTIFICATE REQUEST-----\n"; + + "-----BEGIN CERTIFICATE REQUEST-----\n" + + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh\n" + + "MRYwFAYDVQQHDA1TYW4tRnJhbmNpc2NvMRkwFwYDVQQKDBBMaW51eC1Gb3VuZGF0\n" + + "aW9uMQ0wCwYDVQQLDARPTkFQMREwDwYDVQQDDAhvbmFwLm9yZzEeMBwGCSqGSIb3\n" + + "-----END CERTIFICATE REQUEST-----\n"; public static final String TEST_PK = "-----BEGIN PRIVATE KEY-----\n" - + "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDXcrUutDUvp4vs\n" - + "HwriS5w1y3SxKNl7tbD3VXjSzqaNxZ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U8yWBTtuk+3KgGn9Oxk\n" - + "+Z4rdP06LwKBgA4b09zIW6NhaTubWBKhJHv/wvO0lj+bu7J8LyKUbBqVpXPlUXGW\n" - + "wfSv/aUZetuVfO3WRkPfupB8R16Ml+TSsgwwljhnRMCHUKA2qwyXnA5WJbSCeVkn\n" - + "Vrc/8Gy1M53SQHtg6L079DDWm44QS9ltzXU6Adlgnm+htVEWmxi4UZ+dAoGAfr6z\n" - + "+LG7+GcCA2AruEIgOe7wErkpHV+am+8nOymMxeV8FFJCmxbFQ9vYKTDdhfOfZvbM\n" - + "+BYG8E8VQmAAyyNOqENK+j+mlgrrEp4/0t2r5L/VhW5V8hoqelcGTc+gKZ8IkswJ\n" - + "N58Owc8wcJQF8TFKXBGaXVTxTSyKVIpZ778AeV8CgYAAvuicDkdwWv5EhDFf3aTI\n" - + "wfRFYflA6oiygnI63HzVyY4a+SyZs+nQpB5HBDo+Lyz8RaVRC5E7jQ8kiXJpxAu7\n" - + "1wnspz+pa3q61yR32N+zGuub71FXdLWSOlys6rzJqvqYihKxY22C2TyDyBCR2tMj\n" - + "mdnshXNAJfKkfghkJhFHrg==\n" - + "-----END PRIVATE KEY-----"; + + "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFFhUU6izIAEyr\n" + + "7IA3P2mGZjJ+YdvD0X2vcJq/WhnbHDUtsXYcYGrwXjmdd8yNfYf4vGTyb9eYgNv7\n" + + "2XMg1TonrGYOspmKKJ/k5FqhEQ19Bk1aQBY+C5bIoa0eTq555KNLwPRJbCWhzWDS\n" + + "EHcZER9+hy4nbgr63adeCV/tdWCYfGOITyT6kPdJSjmsDsXHVOYuC4QDxoJEZpiD\n" + + "9qh8I172EObfiKpTObm089A6BHcumrHYlbSIlhtBeZfdwb9ETSoWX6uCs2EJ3ym1\n" + + "fshSJa1Ca22yxHdsTwlWBp/H0RT0Znl1leJ9IUnOzjZRjtfoM+JAMV6t9ZE1zd1F\n" + + "NgGWRtOLAgM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THbObpsv9A8OIbpTuR4m3W3\n" + + "JsiavrxPZDdH99r9N6KQvG9omCQTp1qlEAaaQsJVAoGBAO4ccgmzbku62OKLIAqy\n" + + "JN4Z8i9PaCEPgqfs0THMIKuj1l8FO723zTZMwsBWgZ4Gd32EbYW9tbwvLblGdd6H\n" + + "xAXLfLjRWefKm6i2iIdkeNMJmTTCYjHFyoTe84Miq9d3cEnW7s055Pm1uxRPXYk+\n" + + "GFRpHltg2qX2u6M8ryskAMah\n" + + "-----END PRIVATE KEY-----\n"; public static final String TEST_PEM = "" - + "-----BEGIN CERTIFICATE REQUEST-----\n" - + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh\n" - + "-----END CERTIFICATE REQUEST-----\n"; + + "-----BEGIN CERTIFICATE REQUEST-----\n" + + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh\n" + + "-----END CERTIFICATE REQUEST-----\n"; public static final String TEST_WRONG_PEM = "" - + "-----BEGIN WRONG REQUEST-----" - + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh" - + "-----END WRONG REQUEST-----"; + + "-----BEGIN WRONG REQUEST-----" + + "MIIDIzCCAgsCAQAwgZcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlh" + + "-----END WRONG REQUEST-----"; } diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/model/CsrModelTest.java b/certService/src/test/java/org/onap/oom/certservice/certification/model/CsrModelTest.java index 7981b271..84c1cca0 100644 --- a/certService/src/test/java/org/onap/oom/certservice/certification/model/CsrModelTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/certification/model/CsrModelTest.java @@ -20,12 +20,16 @@ package org.onap.oom.certservice.certification.model; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.util.io.pem.PemObject; import org.junit.jupiter.api.Test; import org.onap.oom.certservice.certification.Pkcs10CertificationRequestFactory; import org.onap.oom.certservice.certification.PemObjectFactory; +import org.onap.oom.certservice.certification.TestData; import org.onap.oom.certservice.certification.exception.CsrDecryptionException; import org.onap.oom.certservice.certification.exception.DecryptionException; import org.onap.oom.certservice.certification.exception.KeyDecryptionException; @@ -37,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.onap.oom.certservice.certification.TestData.LOCALHOST_IP_IN_HEX; import static org.onap.oom.certservice.certification.TestData.TEST_CSR; import static org.onap.oom.certservice.certification.TestData.TEST_PEM; import static org.onap.oom.certservice.certification.TestData.TEST_PK; @@ -45,9 +50,9 @@ import static org.onap.oom.certservice.certification.TestData.TEST_PK; class CsrModelTest { private final Pkcs10CertificationRequestFactory certificationRequestFactory - = new Pkcs10CertificationRequestFactory(); + = new Pkcs10CertificationRequestFactory(); private final PemObjectFactory pemObjectFactory - = new PemObjectFactory(); + = new PemObjectFactory(); @Test void shouldByConstructedAndReturnProperFields() throws DecryptionException, IOException { @@ -58,20 +63,22 @@ class CsrModelTest { // When CsrModel csrModel = generateTestCsrModel(testCsr); - + List<String> sansList = Arrays.stream(csrModel.getSans()) + .map(generalName -> generalName.getName().toString()) + .collect(Collectors.toList()); // Then assertThat(csrModel.getCsr()) - .isEqualTo(testCsr); + .isEqualTo(testCsr); assertThat(csrModel.getPrivateKey().getEncoded()) - .contains(testPrivateKey.getContent()); + .contains(testPrivateKey.getContent()); assertThat(csrModel.getPublicKey().getEncoded()) - .contains(testPublicKey.getContent()); - assertThat(csrModel.getSans()) - .contains( - "gerrit.onap.org", "test.onap.org", "onap.com"); + .contains(testPublicKey.getContent()); + assertThat(sansList) + .contains("localhost", "onap.org", "test.onap.org", "onap@onap.org", LOCALHOST_IP_IN_HEX, + "onap://cluster.local/"); + assertThat(csrModel.getSubjectData().toString()) - .contains( - "C=US,ST=California,L=San-Francisco,O=Linux-Foundation,OU=ONAP,CN=onap.org,E=tester@onap.org"); + .contains(TestData.EXPECTED_CERT_SUBJECT); } @Test @@ -81,14 +88,14 @@ class CsrModelTest { PKCS10CertificationRequest testCsr = mock(PKCS10CertificationRequest.class); SubjectPublicKeyInfo wrongKryInfo = mock(SubjectPublicKeyInfo.class); when(testCsr.getSubjectPublicKeyInfo()) - .thenReturn(wrongKryInfo); + .thenReturn(wrongKryInfo); when(wrongKryInfo.getEncoded()) - .thenThrow(new IOException()); + .thenThrow(new IOException()); // When Exception exception = assertThrows( - CsrDecryptionException.class, - () -> new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build() + CsrDecryptionException.class, + () -> new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build() ); String expectedMessage = "Reading Public Key from CSR failed"; @@ -105,14 +112,14 @@ class CsrModelTest { PKCS10CertificationRequest testCsr = mock(PKCS10CertificationRequest.class); SubjectPublicKeyInfo wrongKryInfo = mock(SubjectPublicKeyInfo.class); when(testCsr.getSubjectPublicKeyInfo()) - .thenReturn(wrongKryInfo); + .thenReturn(wrongKryInfo); when(wrongKryInfo.getEncoded()) - .thenThrow(new IOException()); + .thenThrow(new IOException()); // When Exception exception = assertThrows( - KeyDecryptionException.class, - () -> new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build() + KeyDecryptionException.class, + () -> new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build() ); String expectedMessage = "Converting Private Key failed"; @@ -130,14 +137,14 @@ class CsrModelTest { PKCS10CertificationRequest testCsr = mock(PKCS10CertificationRequest.class); SubjectPublicKeyInfo wrongKryInfo = mock(SubjectPublicKeyInfo.class); when(testCsr.getSubjectPublicKeyInfo()) - .thenReturn(wrongKryInfo); + .thenReturn(wrongKryInfo); when(wrongKryInfo.getEncoded()) - .thenReturn(testPublicKey.getContent()); + .thenReturn(testPublicKey.getContent()); // When Exception exception = assertThrows( - KeyDecryptionException.class, - () -> new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build() + KeyDecryptionException.class, + () -> new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build() ); String expectedMessage = "Converting Public Key from CSR failed"; @@ -150,20 +157,20 @@ class CsrModelTest { private PemObject getPemPrivateKey() throws KeyDecryptionException { PemObjectFactory pemObjectFactory = new PemObjectFactory(); return pemObjectFactory.createPemObject(TEST_PK).orElseThrow( - () -> new KeyDecryptionException("Private key decoding fail") + () -> new KeyDecryptionException("Private key decoding fail") ); } private PemObject getPemWrongKey() throws KeyDecryptionException { PemObjectFactory pemObjectFactory = new PemObjectFactory(); return pemObjectFactory.createPemObject(TEST_PEM).orElseThrow( - () -> new KeyDecryptionException("Private key decoding fail") + () -> new KeyDecryptionException("Private key decoding fail") ); } private CsrModel generateTestCsrModel(PKCS10CertificationRequest testCsr) throws DecryptionException { PemObject testPrivateKey = pemObjectFactory.createPemObject(TEST_PK).orElseThrow( - () -> new DecryptionException("Incorrect Private Key, decryption failed") + () -> new DecryptionException("Incorrect Private Key, decryption failed") ); return new CsrModel.CsrModelBuilder(testCsr, testPrivateKey).build(); } @@ -175,11 +182,11 @@ class CsrModelTest { private PKCS10CertificationRequest generateTestCertificationRequest() throws DecryptionException { return pemObjectFactory.createPemObject(TEST_CSR) - .flatMap( - certificationRequestFactory::createPkcs10CertificationRequest - ).orElseThrow( - () -> new DecryptionException("Incorrect CSR, decryption failed") - ); + .flatMap( + certificationRequestFactory::createPkcs10CertificationRequest + ).orElseThrow( + () -> new DecryptionException("Incorrect CSR, decryption failed") + ); } } diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java index 984e8c77..b09025b2 100644 --- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java @@ -52,6 +52,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x500.X500NameBuilder; import org.bouncycastle.asn1.x500.style.BCStyle; +import org.bouncycastle.asn1.x509.GeneralName; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -273,7 +274,7 @@ class Cmpv2ClientTest { } private void setCsrModelAndServerValues(String iak, String rv, String externalCaUrl, Date notBefore, Date notAfter) { - csrModel = new CsrModel(null, dn, keyPair.getPrivate(), keyPair.getPublic(), Collections.emptyList()); + csrModel = new CsrModel(null, dn, keyPair.getPrivate(), keyPair.getPublic(), new GeneralName[0]); Authentication authentication = new Authentication(); authentication.setIak(iak); |