add PrivateKeyProvider
This commit is contained in:
51
src/test/kotlin/ltd/hlaeja/util/PrivateKeyProviderTest.kt
Normal file
51
src/test/kotlin/ltd/hlaeja/util/PrivateKeyProviderTest.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
package ltd.hlaeja.util
|
||||
|
||||
import java.security.interfaces.RSAPrivateKey
|
||||
import ltd.hlaeja.exception.KeyProviderException
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
||||
class PrivateKeyProviderTest {
|
||||
|
||||
@Test
|
||||
fun `load private key - success`() {
|
||||
// given
|
||||
val pemFilePath = "keys/valid-private-key.pem"
|
||||
|
||||
// when
|
||||
val privateKey: RSAPrivateKey = PrivateKeyProvider.load(pemFilePath)
|
||||
|
||||
// then
|
||||
assertThat(privateKey).isNotNull
|
||||
assertThat(privateKey.algorithm).isEqualTo("RSA")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `load private key - file does not exist`() {
|
||||
// given
|
||||
val nonExistentPemFilePath = "keys/non-existent.pem"
|
||||
|
||||
// when exception
|
||||
val exception = assertThrows<KeyProviderException> {
|
||||
PrivateKeyProvider.load(nonExistentPemFilePath)
|
||||
}
|
||||
|
||||
// then
|
||||
assertThat(exception.message).isEqualTo("Could not load private key")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `load private key - file is invalid`() {
|
||||
// given
|
||||
val invalidPemFilePath = "keys/invalid-private-key.pem"
|
||||
|
||||
// when exception
|
||||
val exception = assertThrows<IllegalArgumentException> {
|
||||
PrivateKeyProvider.load(invalidPemFilePath)
|
||||
}
|
||||
|
||||
// then
|
||||
assertThat(exception.message).contains("Input byte array has wrong 4-byte ending unit")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user