mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 13:02:13 +00:00
SEC-3002: Add JUnit Assume to GCM encryption tests
Not all JDKs have GCM installed on them.
This commit is contained in:
parent
92c23fbbdc
commit
3db01bd9d6
@ -5,12 +5,19 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
|
import org.junit.Assume;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class EncryptorsTests {
|
public class EncryptorsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void stronger() throws Exception {
|
public void stronger() throws Exception {
|
||||||
|
Assume.assumeTrue("GCM must be available for this test", isAesGcmAvailable());
|
||||||
|
|
||||||
BytesEncryptor encryptor = Encryptors.stronger("password", "5c0744940b5c369b");
|
BytesEncryptor encryptor = Encryptors.stronger("password", "5c0744940b5c369b");
|
||||||
byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
|
byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
@ -33,6 +40,8 @@ public class EncryptorsTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void preferred() {
|
public void preferred() {
|
||||||
|
Assume.assumeTrue("GCM must be available for this test", isAesGcmAvailable());
|
||||||
|
|
||||||
TextEncryptor encryptor = Encryptors.delux("password", "5c0744940b5c369b");
|
TextEncryptor encryptor = Encryptors.delux("password", "5c0744940b5c369b");
|
||||||
String result = encryptor.encrypt("text");
|
String result = encryptor.encrypt("text");
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
@ -68,4 +77,13 @@ public class EncryptorsTests {
|
|||||||
assertEquals("text", encryptor.encrypt("text"));
|
assertEquals("text", encryptor.encrypt("text"));
|
||||||
assertEquals("text", encryptor.decrypt("text"));
|
assertEquals("text", encryptor.decrypt("text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAesGcmAvailable() {
|
||||||
|
try {
|
||||||
|
Cipher.getInstance("AES/GCM/NoPadding");
|
||||||
|
return true;
|
||||||
|
} catch (GeneralSecurityException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user