diff options
author | Tomasz Wrobel <tomasz.wrobel@nokia.com> | 2021-07-07 17:07:45 +0200 |
---|---|---|
committer | Tomasz Wrobel <tomasz.wrobel@nokia.com> | 2021-07-09 10:01:29 +0200 |
commit | 73be781127f3748a9aa9d51e4e9671917c785efd (patch) | |
tree | a94519ebbaac58d8f0f1c47b53ce36f159f1d053 | |
parent | bc86a9547761abf886262cdc08c1096fca11da7d (diff) |
[OOM-CERT-SERVICE] Add Unit test for private key in pkcs1 format
Issue-ID: OOM-2753
Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com>
Change-Id: I91000b223c30eae1cd9f4d48be9e8197e239e1d2
-rw-r--r-- | certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java | 10 | ||||
-rw-r--r-- | certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java | 56 |
2 files changed, 58 insertions, 8 deletions
diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java index cfee3af6..845361ef 100644 --- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java +++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java @@ -35,6 +35,8 @@ public final class ClientTestData { private static final String WRONG_OLD_CERT = "wrong old cert"; private static final String WRONG_OLD_PRIVATE_KEY = "wrong old private key"; + private static final String TEST_ENCODED_PRIVATE_KEY_IN_PKCS8 = "LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2Z0lCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktnd2dnU2tBZ0VBQW9JQkFRRFNOS0pCUU5XRmF0ajUKUmRhTmQyMGdnTnBOVUVaYzgxU1Y1d0hLeHEwUy9rT0llTG8rekI5c3lkUUJLWm9JRXJPL3JIekwzb0VCNW5YNQp4NVBkeTViYUdYTzRQZDVCUStrSXRHckFnNzVrRldmT3VHNU9GWUxpWldMU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pwcnZBCmRDNFdjYnJhNE1wTFFKczZqNWJoUFJ1QlRsSXBnZEVhdkVSM1J5bUVGUTBSRHdER2thSndNbkdVVTlqSWdFN3AKR282RG5aV2RJZEFoRlN2Q3RybERLL1NGYmVKM3RTNlMrSUxXUDgydWU3Q0UwSnYrUEVoUnc5aWVreE5hRElNbwpzeXcvM2tnSUNnckV3RjJzUHY5UnVLQ212V3NrMkdKaHRRcXZSK3FFRE5FQW15aXJodFh6L214QUZ0dy9ualpVCjBBPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQoK"; @@ -53,6 +55,14 @@ public final class ClientTestData { return createOldCertificateModel(TEST_ENCODED_OLD_CERT, WRONG_OLD_PRIVATE_KEY); } + static final OldCertificateModel createOldCertificateModelWithPrivateKeyInPKCS1() throws CertificateDecryptionException { + return createOldCertificateModel(TEST_ENCODED_OLD_CERT, TEST_ENCODED_PRIVATE_KEY_IN_PKCS1); + } + + static final OldCertificateModel createOldCertificateModelWithPrivateKeyInPKCS8() throws CertificateDecryptionException { + return createOldCertificateModel(TEST_ENCODED_OLD_CERT, TEST_ENCODED_PRIVATE_KEY_IN_PKCS8); + } + private static final OldCertificateModel createOldCertificateModel(String certificate, String privateKey) throws CertificateDecryptionException { StringBase64 base64EncodedCertificate = new StringBase64(certificate); return factory.createCertificateModel(base64EncodedCertificate, privateKey); 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 b44d6447..93dcbb77 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 @@ -19,12 +19,15 @@ package org.onap.oom.certservice.cmpv2client; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; +import static org.onap.oom.certservice.cmpv2client.ClientTestData.createOldCertificateModelWithPrivateKeyInPKCS1; +import static org.onap.oom.certservice.cmpv2client.ClientTestData.createOldCertificateModelWithPrivateKeyInPKCS8; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -49,6 +52,7 @@ import java.util.Base64; import java.util.Base64.Decoder; import java.util.Date; +import java.util.stream.Stream; import org.apache.commons.io.IOUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; @@ -73,11 +77,15 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.onap.oom.certservice.certification.configuration.model.Authentication; import org.onap.oom.certservice.certification.configuration.model.Cmpv2Server; import org.onap.oom.certservice.certification.exception.CertificateDecryptionException; import org.onap.oom.certservice.certification.model.CsrModel; +import org.onap.oom.certservice.certification.model.OldCertificateModel; import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException; import org.onap.oom.certservice.cmpv2client.exceptions.CmpServerException; import org.onap.oom.certservice.cmpv2client.impl.CmpClientImpl; @@ -149,14 +157,7 @@ class Cmpv2ClientTest { when(httpClient.execute(any())).thenReturn(httpResponse); when(httpResponse.getEntity()).thenReturn(httpEntity); - doAnswer( - invocation -> { - OutputStream os = invocation.getArgument(0); - os.write(BASE64_DECODER.decode(ClientTestData.KUR_CORRECT_SERVER_RESPONSE_ENCODED.getBytes())); - return null; - }) - .when(httpEntity) - .writeTo(any(OutputStream.class)); + mockCorrectKeyUpdateResponse(); CmpClientImpl cmpClient = new CmpClientImpl(httpClient); // when @@ -199,6 +200,26 @@ class Cmpv2ClientTest { } + @ParameterizedTest + @MethodSource("getTestUpdateModelWithSupportedPrivateKeys") + void shouldNotThrowExceptionForPrivateKeyInExpectedFormat(OldCertificateModel oldCertificateModel) + throws IOException { + + // given + setCsrModelAndServerTestDefaultValues(); + when(httpClient.execute(any())).thenReturn(httpResponse); + when(httpResponse.getEntity()).thenReturn(httpEntity); + + mockCorrectKeyUpdateResponse(); + CmpClientImpl cmpClient = new CmpClientImpl(httpClient); + + // when // then + assertDoesNotThrow(() -> cmpClient + .executeKeyUpdateRequest(csrModel, server, oldCertificateModel) + ); + + } + @Test void shouldThrowCmpClientExceptionWhenCannotParseOldPrivateKey() { setCsrModelAndServerTestDefaultValues(); @@ -415,6 +436,17 @@ class Cmpv2ClientTest { () -> cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter)); } + private void mockCorrectKeyUpdateResponse() throws IOException { + doAnswer( + invocation -> { + OutputStream os = invocation.getArgument(0); + os.write(BASE64_DECODER.decode(ClientTestData.KUR_CORRECT_SERVER_RESPONSE_ENCODED.getBytes())); + return null; + }) + .when(httpEntity) + .writeTo(any(OutputStream.class)); + } + private void setCsrModelAndServerValues(String iak, String rv, String externalCaUrl, Date notBefore, Date notAfter) { csrModel = new CsrModel(null, dn, keyPair.getPrivate(), keyPair.getPublic(), new GeneralName[0]); @@ -469,4 +501,12 @@ class Cmpv2ClientTest { .build(); } + private static Stream<Arguments> getTestUpdateModelWithSupportedPrivateKeys() + throws CertificateDecryptionException { + return Stream.of( + Arguments.of(createOldCertificateModelWithPrivateKeyInPKCS1()), + Arguments.of(createOldCertificateModelWithPrivateKeyInPKCS8()) + ); + } + } |