diff options
author | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2020-02-13 14:55:21 +0100 |
---|---|---|
committer | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2020-02-13 14:55:21 +0100 |
commit | 06f7465cebf967f6c1ffd9970b05158c00aa5ff1 (patch) | |
tree | ad950726b6da96f9af5ba898e7038d5984a87fee /certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java | |
parent | 459a31e973f55fd97831a9a7cae0dce664259a4e (diff) |
Improve exception flow
Issue-ID: AAF-995
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I4d690fbe27364bc50b97ab42e64e610566d93ca0
Diffstat (limited to 'certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java')
-rw-r--r-- | certService/src/test/java/org/onap/aaf/certservice/certification/CsrModelFactoryTest.java | 24 |
1 files changed, 22 insertions, 2 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 065c7a0e..77594ed7 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 @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.onap.aaf.certservice.certification.CsrModelFactory.StringBase64; import org.onap.aaf.certservice.certification.exceptions.CsrDecryptionException; import org.onap.aaf.certservice.certification.exceptions.DecryptionException; +import org.onap.aaf.certservice.certification.exceptions.KeyDecryptionException; import org.onap.aaf.certservice.certification.model.CsrModel; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.onap.aaf.certservice.certification.TestData.TEST_CSR; import static org.onap.aaf.certservice.certification.TestData.TEST_PK; import static org.onap.aaf.certservice.certification.TestData.TEST_WRONG_CSR; +import static org.onap.aaf.certservice.certification.TestData.TEST_WRONG_PEM; class CsrModelFactoryTest { @@ -66,9 +68,8 @@ class CsrModelFactoryTest { ); } - @Test - void shouldThrowCsrDecryptionExceptionWhenCsrAreIncorrect() { + void shouldThrowCsrDecryptionExceptionWhenCsrIsIncorrect() { // given String encoderPK = new String(Base64.encode(TEST_PK.getBytes())); String wrongCsr = new String(Base64.encode(TEST_WRONG_CSR.getBytes())); @@ -86,4 +87,23 @@ class CsrModelFactoryTest { assertTrue(actualMessage.contains(expectedMessage)); } + @Test + void shouldThrowKeyDecryptionExceptionWhenKeyIsIncorrect() { + // given + String encoderPK = new String(Base64.encode(TEST_WRONG_PEM.getBytes())); + 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)); + } + } |