Skip to content

Commit 6a12d6c

Browse files
committed
tst
1 parent e923b37 commit 6a12d6c

File tree

1 file changed

+15
-4
lines changed
  • plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/encryption

1 file changed

+15
-4
lines changed

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/encryption/JwtEncryptionManagerTest.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.encryption
55

6+
import com.nimbusds.jose.JOSEException
67
import org.assertj.core.api.Assertions.assertThat
78
import org.junit.jupiter.api.Test
9+
import org.junit.jupiter.api.assertThrows
810
import java.io.ByteArrayOutputStream
911
import java.util.concurrent.atomic.AtomicBoolean
1012
import javax.crypto.spec.SecretKeySpec
@@ -14,8 +16,13 @@ class JwtEncryptionManagerTest {
1416
@Test
1517
fun `uses a different encryption key for each instance`() {
1618
val blob = Random.Default.nextBytes(256)
17-
assertThat(JwtEncryptionManager().encrypt(blob))
18-
.isNotEqualTo(JwtEncryptionManager().encrypt(blob))
19+
val sut1 = JwtEncryptionManager()
20+
val encrypted = sut1.encrypt(blob)
21+
22+
assertThrows<JOSEException> {
23+
assertThat(sut1.decrypt(encrypted))
24+
.isNotEqualTo(JwtEncryptionManager().decrypt(encrypted))
25+
}
1926
}
2027

2128
@Test
@@ -24,8 +31,12 @@ class JwtEncryptionManagerTest {
2431
val blob = Random.Default.nextBytes(256)
2532
val bytes = "DEADBEEF".repeat(8).hexToByteArray() // 32 bytes
2633
val key = SecretKeySpec(bytes, "HmacSHA256")
27-
assertThat(JwtEncryptionManager(key).encrypt(blob))
28-
.isNotEqualTo(JwtEncryptionManager(key).encrypt(blob))
34+
val sut1 = JwtEncryptionManager(key)
35+
val encrypted = sut1.encrypt(blob)
36+
37+
// each encrypt() call will use a different IV so we can't just directly compare
38+
assertThat(sut1.decrypt(encrypted))
39+
.isEqualTo(JwtEncryptionManager(key).decrypt(encrypted))
2940
}
3041

3142
@Test

0 commit comments

Comments
 (0)