From ca2c01591b33804be131b9112e703e17641d6c83 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Fri, 14 Feb 2020 10:31:37 +0100 Subject: Handle exception thrown during base64 decoding Issue-ID: AAF-995 Signed-off-by: Bartosz Gardziejewski Change-Id: I37e47382dc998bead008c47e34e3de417312fefb --- .../certification/CsrModelFactoryTest.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'certService/src/test/java/org/onap') diff --git a/certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java b/certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java index 77594ed7..5f48b2bf 100644 --- a/certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java +++ b/certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java @@ -106,4 +106,42 @@ class CsrModelFactoryTest { assertTrue(actualMessage.contains(expectedMessage)); } + + @Test + void shouldThrowCsrDecryptionExceptionWhenCsrIsNotInBase64Encoding() { + // given + String encoderPK = new String(Base64.encode(TEST_PK.getBytes())); + String wrongCsr = "Not Base 64 Csr"; + + // when + Exception exception = assertThrows( + CsrDecryptionException.class, () -> csrModelFactory + .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) + ); + + String expectedMessage = "Incorrect CSR, decryption failed"; + String actualMessage = exception.getMessage(); + + // then + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + void shouldThrowKeyDecryptionExceptionWhenPKIsNotInBase64Encoding() { + // given + String encoderPK = "Not Base64 Key"; + String wrongCsr = new String(Base64.encode(TEST_CSR.getBytes())); + + // when + Exception exception = assertThrows( + KeyDecryptionException.class, () -> csrModelFactory + .createCsrModel(new StringBase64(wrongCsr), new StringBase64(encoderPK)) + ); + + String expectedMessage = "Incorrect Key, decryption failed"; + String actualMessage = exception.getMessage(); + + // then + assertTrue(actualMessage.contains(expectedMessage)); + } } -- cgit 1.2.3-korg