diff options
author | 2020-02-14 10:31:37 +0100 | |
---|---|---|
committer | 2020-02-14 10:31:37 +0100 | |
commit | ca2c01591b33804be131b9112e703e17641d6c83 (patch) | |
tree | faf8702e7ebd88d43f1bf33e40f8dc73c9bedfa4 /certService/src/test/java | |
parent | c663e2f61287e612e351df2360306fb5a257a8bf (diff) |
Handle exception thrown during base64 decoding
Issue-ID: AAF-995
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I37e47382dc998bead008c47e34e3de417312fefb
Diffstat (limited to 'certService/src/test/java')
-rw-r--r-- | certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java | 38 |
1 files changed, 38 insertions, 0 deletions
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)); + } } |