@@ -4,6 +4,7 @@ import org.junit.Assert.assertEquals
44import org.junit.Assert.assertNotEquals
55import org.junit.Assert.assertThrows
66import org.junit.Test
7+ import javax.crypto.BadPaddingException
78import javax.crypto.KeyGenerator
89import javax.crypto.SecretKey
910
@@ -51,16 +52,24 @@ class CryptoTest {
5152 }
5253
5354 @Test
54- fun `잘못된 데이터로 복호화를 시도하면 예외가 발생해야 한다` () {
55+ fun `입력값이 너무 짧은 경우 IllegalArgumentException이 발생해야 한다` () {
5556 // given
5657 val invalid = ByteArray (4 ) { 0x00 }
5758
5859 // when & then
59- assertThrows(Exception ::class .java) {
60+ assertThrows(IllegalArgumentException ::class .java) {
6061 crypto.decrypt(invalid)
6162 }
6263 }
6364
65+ @Test
66+ fun `빈 바이트 배열 암호화 시 예외가 발생하지 않아야 한다` () {
67+ val input = ByteArray (0 )
68+ val encrypted = crypto.encrypt(input)
69+ val decrypted = crypto.decrypt(encrypted)
70+ assertEquals(String (input), String (decrypted))
71+ }
72+
6473 @Test
6574 fun `IV 일부가 조작된 경우 복호화하면 원래 데이터와 달라야 한다` () {
6675 // given
@@ -83,7 +92,7 @@ class CryptoTest {
8392 encrypted[encrypted.lastIndex] = encrypted.last().inc()
8493
8594 // when & then
86- assertThrows(Exception ::class .java) {
95+ assertThrows(BadPaddingException ::class .java) {
8796 crypto.decrypt(encrypted)
8897 }
8998 }
@@ -106,7 +115,7 @@ class CryptoTest {
106115 val otherCrypto = Crypto (otherKeyProvider, " AES/CBC/PKCS5Padding" )
107116
108117 // when & then
109- assertThrows(Exception ::class .java) {
118+ assertThrows(BadPaddingException ::class .java) {
110119 otherCrypto.decrypt(encrypted)
111120 }
112121 }
0 commit comments