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.cmpv2client.exceptions.CmpClientException;
import org.onap.oom.certservice.cmpv2client.exceptions.CmpServerException;
}
@Test
- void shouldReturnCorrectCmpCertificateForCorrectKeyUpdateResponse() throws CmpClientException, IOException {
+ void shouldReturnCorrectCmpCertificateForCorrectKeyUpdateResponse() throws CmpClientException, IOException, CertificateDecryptionException {
// given
setCsrModelAndServerTestDefaultValues();
// when
Cmpv2CertificationModel cmpClientResult =
- cmpClient.updateCertificate(csrModel, server, ClientTestData.TEST_CERTIFICATE_UPDATE_MODEL);
+ cmpClient.executeKeyUpdateRequest(csrModel, server, ClientTestData.createCorrectOldCertificateModel());
+
+ // then
+ assertNotNull(cmpClientResult);
+ assertThat(cmpClientResult.getCertificateChain()).isNotEmpty();
+ assertThat(cmpClientResult.getCertificateChain()).isNotEmpty();
+
+ }
+
+ @Test
+ void shouldReturnCorrectCmpCertificateForCorrectCertificationRequest() throws CmpClientException, IOException {
+
+ // given
+ setCsrModelAndServerTestDefaultValues();
+ when(httpClient.execute(any())).thenReturn(httpResponse);
+ when(httpResponse.getEntity()).thenReturn(httpEntity);
+
+ doAnswer(
+ invocation -> {
+ OutputStream os = invocation.getArgument(0);
+ os.write(BASE64_DECODER.decode(ClientTestData.CR_CORRECT_SERVER_RESPONSE_ENCODED.getBytes()));
+ return null;
+ })
+ .when(httpEntity)
+ .writeTo(any(OutputStream.class));
+ CmpClientImpl cmpClient = new CmpClientImpl(httpClient);
+
+ // when
+ Cmpv2CertificationModel cmpClientResult =
+ cmpClient.executeCertificationRequest(csrModel, server);
// then
assertNotNull(cmpClientResult);
setCsrModelAndServerTestDefaultValues();
CmpClientImpl cmpClient = new CmpClientImpl(httpClient);
- assertThatExceptionOfType(CmpClientException.class)
- .isThrownBy(() -> cmpClient.updateCertificate(csrModel, server, ClientTestData.TEST_CERTIFICATE_UPDATE_MODEL_WITH_WRONG_PRIVATE_KEY))
- .withMessageContaining("Cannot parse old private key");
+ assertThatExceptionOfType(CertificateDecryptionException.class)
+ .isThrownBy(() -> cmpClient.executeKeyUpdateRequest(csrModel, server, ClientTestData.createOldCertificateModelWithWrongPrivateKey()))
+ .withMessageContaining("Cannot convert certificate or key");
}
CmpClientImpl cmpClient = new CmpClientImpl(httpClient);
// When // Then
- assertThatExceptionOfType(CmpClientException.class)
- .isThrownBy(() -> cmpClient.updateCertificate(csrModel, server, ClientTestData.TEST_CERTIFICATE_UPDATE_MODEL_WITH_WRONG_OLD_CERT))
- .withMessageContaining("Cannot parse old certificate");
+ assertThatExceptionOfType(CertificateDecryptionException.class)
+ .isThrownBy(() -> cmpClient.executeKeyUpdateRequest(csrModel, server, ClientTestData.createOldCertificateModelWithWrongCert()))
+ .withMessageContaining("Incorrect certificate, decryption failed");
}
CmpClientImpl cmpClient = spy(new CmpClientImpl(httpClient));
// when
Cmpv2CertificationModel cmpClientResult =
- cmpClient.createCertificate(csrModel, server, notBefore, notAfter);
+ cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter);
// then
assertNotNull(cmpClientResult);
}
// then
Assertions.assertThrows(
CmpClientException.class,
- () -> cmpClient.createCertificate(csrModel, server, notBefore, notAfter));
+ () -> cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter));
}
@Test
// then
Assertions.assertThrows(
CmpServerException.class,
- () -> cmpClient.createCertificate(csrModel, server, notBefore, notAfter));
+ () -> cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter));
}
CmpClientImpl cmpClient = new CmpClientImpl(httpClient);
assertThatExceptionOfType(CmpClientException.class)
- .isThrownBy(() -> cmpClient.createCertificate(csrModel, server, notBefore, notAfter))
+ .isThrownBy(() -> cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter))
.withMessageContaining("CMP response does not contain Protection Algorithm field");
}
// then
Assertions.assertThrows(
IllegalArgumentException.class,
- () -> cmpClient.createCertificate(csrModel, server, notBefore, notAfter));
+ () -> cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter));
}
@Test
// then
Assertions.assertThrows(
CmpClientException.class,
- () -> cmpClient.createCertificate(csrModel, server, notBefore, notAfter));
+ () -> cmpClient.executeInitializationRequest(csrModel, server, notBefore, notAfter));
}
private void setCsrModelAndServerValues(String iak, String rv, String externalCaUrl, Date notBefore, Date notAfter) {