Migrated BAEL-7190 to a new module (#16518)

* BAEL-7190 implementation

* Migrated BAEL-7190 to a new module

* Revert "BAEL-7190 implementation"

This reverts commit dd947aefda7b12a0eb06030b5d89f2ada77834a5.
This commit is contained in:
Mikhail Polivakha
2024-04-28 22:05:04 +03:00
committed by GitHub
parent ba73008ee9
commit bb0116b5d5
7 changed files with 0 additions and 23 deletions
@@ -0,0 +1,45 @@
package com.baeldung.unrecoverablekeyexception;
import java.security.UnrecoverableKeyException;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.Test;
public class KeyManagerInitializerUnitTest {
@Test
public void givenPasswordIsCorrect_whenInitializingTheKeyManager_thenNoExceptionIsThrown() {
// Given.
String privateKeyPassword = "privateKeyPassword";
// When.
ThrowingCallable initializeKeyManager = () -> KeyManagerInitializer.initializeKeyManager(privateKeyPassword);
// Then.
Assertions.assertThatCode(initializeKeyManager).doesNotThrowAnyException();;
}
@Test
public void givenPasswordIsWrong_whenInitializingTheKeyManager_thenUnrecoverableKeyExceptionExceptionIsThrown() {
// Given.
String privateKeyPassword = "wrongPassword";
// When.
ThrowingCallable initializeKeyManager = () -> KeyManagerInitializer.initializeKeyManager(privateKeyPassword);
// Then.
Assertions.assertThatThrownBy(initializeKeyManager).isInstanceOf(UnrecoverableKeyException.class);
}
@Test
public void givenMultipleKeysWithDifferentPasswordsInKeystore_whenInitializingTheKeyManager_thenUnrecoverableKeyExceptionIsThrown() {
// Given.
String firstPrivateKeyPassword = "abc123";
// When.
ThrowingCallable initializeKeyManager = () -> KeyManagerInitializer.initializeKeyManager(firstPrivateKeyPassword, "multi_entry_keystore.jks");
// Then.
Assertions.assertThatThrownBy(initializeKeyManager).isInstanceOf(UnrecoverableKeyException.class);
}
}