diff options
author | Steve Marion <steve.marion@sonarsource.com> | 2024-06-05 16:19:43 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-06-18 20:02:40 +0000 |
commit | c5a79c9f7724e1a7699bb3053fbabcfdaa14a1a9 (patch) | |
tree | ddeb970b4c0748f8c265be064cfc472785400475 /sonar-plugin-api-impl | |
parent | 18a6df458ab6c808402f4e379cf439f011206730 (diff) | |
download | sonarqube-c5a79c9f7724e1a7699bb3053fbabcfdaa14a1a9.tar.gz sonarqube-c5a79c9f7724e1a7699bb3053fbabcfdaa14a1a9.zip |
SONAR-22352 fix test AES GCM/ECB assertions to comply with different underlying implementation of encryption algorithm.
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r-- | sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java | 24 | ||||
-rw-r--r-- | sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java | 8 |
2 files changed, 10 insertions, 22 deletions
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java index cf57bcf914a..6be6c5b4b26 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesECBCipherTest.java @@ -30,7 +30,6 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.fail; public class AesECBCipherTest { @@ -61,7 +60,7 @@ public class AesECBCipherTest { assertThatThrownBy(() -> cipher.encrypt("this is a secret")) .isInstanceOf(RuntimeException.class) - .hasMessageContaining("Invalid AES key"); + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -79,13 +78,9 @@ public class AesECBCipherTest { URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/bad_secret_key.txt"); AesECBCipher cipher = new AesECBCipher(new File(resource.toURI()).getCanonicalPath()); - try { - cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY="); - fail(); - - } catch (RuntimeException e) { - assertThat(e.getCause()).isInstanceOf(InvalidKeyException.class); - } + assertThatThrownBy(() -> cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=")) + .isInstanceOf(RuntimeException.class) + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -93,14 +88,9 @@ public class AesECBCipherTest { URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/other_secret_key.txt"); AesECBCipher cipher = new AesECBCipher(new File(resource.toURI()).getCanonicalPath()); - try { - // text encrypted with another key - cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY="); - fail(); - - } catch (RuntimeException e) { - assertThat(e.getCause()).isInstanceOf(BadPaddingException.class); - } + assertThatThrownBy(() -> cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=")) + .isInstanceOf(RuntimeException.class) + .hasCauseInstanceOf(BadPaddingException.class); } @Test diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java index e402d11efd0..bda1d4cac0c 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/AesGCMCipherTest.java @@ -49,8 +49,7 @@ public class AesGCMCipherTest { AesGCMCipher cipher = new AesGCMCipher(new File(resource.toURI()).getCanonicalPath()); assertThatThrownBy(() -> cipher.encrypt("this is a secret")) - .hasRootCauseInstanceOf(InvalidKeyException.class) - .hasMessageContaining("Invalid AES key"); + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -71,8 +70,7 @@ public class AesGCMCipherTest { AesGCMCipher cipher = new AesGCMCipher(new File(resource.toURI()).getCanonicalPath()); assertThatThrownBy(() -> cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=")) - .hasRootCauseInstanceOf(InvalidKeyException.class) - .hasMessageContaining("Invalid AES key"); + .hasCauseInstanceOf(InvalidKeyException.class); } @Test @@ -82,7 +80,7 @@ public class AesGCMCipherTest { AesGCMCipher cipher = new AesGCMCipher(new File(resource.toURI()).getCanonicalPath()); assertThatThrownBy(() -> cipher.decrypt(originalCipher.encrypt("this is a secret"))) - .hasRootCauseInstanceOf(BadPaddingException.class); + .hasCauseInstanceOf(BadPaddingException.class); } private String pathToSecretKey() throws Exception { |