Replace expected @Test attributes with AssertJ
Replace JUnit expected @Test attributes with AssertJ calls.
This commit is contained in:
committed by
Josh Cummings
parent
20baa7d409
commit
c502312719
+34
-32
@@ -22,6 +22,7 @@ import org.bouncycastle.crypto.params.Argon2Parameters;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Simeon Macke
|
||||
@@ -66,69 +67,70 @@ public class Argon2EncodingUtilsTests {
|
||||
this.testDataEntry2.decoded.getParameters())).isEqualTo(this.testDataEntry2.encoded);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void encodeWhenNonexistingAlgorithmThenThrowException() {
|
||||
Argon2EncodingUtils.encode(new byte[] { 0, 1, 2, 3 }, (new Argon2Parameters.Builder(3)).withVersion(19)
|
||||
.withMemoryAsKB(333).withIterations(5).withParallelism(2).build());
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> Argon2EncodingUtils.encode(new byte[] { 0, 1, 2, 3 }, (new Argon2Parameters.Builder(3))
|
||||
.withVersion(19).withMemoryAsKB(333).withIterations(5).withParallelism(2).build()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenNotAnArgon2HashThenThrowException() {
|
||||
Argon2EncodingUtils.decode("notahash");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils.decode("notahash"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenNonexistingAlgorithmThenThrowException() {
|
||||
Argon2EncodingUtils.decode(
|
||||
"$argon2x$v=19$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils.decode(
|
||||
"$argon2x$v=19$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenIllegalVersionParameterThenThrowException() {
|
||||
Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=x$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=x$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenIllegalMemoryParameterThenThrowException() {
|
||||
Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=x,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=19$m=x,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenIllegalIterationsParameterThenThrowException() {
|
||||
Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=19$m=1024,t=x,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=19$m=1024,t=x,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenIllegalParallelityParameterThenThrowException() {
|
||||
Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=19$m=1024,t=3,p=x$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils.decode(
|
||||
"$argon2i$v=19$m=1024,t=3,p=x$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenMissingVersionParameterThenThrowException() {
|
||||
Argon2EncodingUtils
|
||||
.decode("$argon2i$m=1024,t=3,p=x$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$m=1024,t=3,p=x$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenMissingMemoryParameterThenThrowException() {
|
||||
Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenMissingIterationsParameterThenThrowException() {
|
||||
Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=1024,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=1024,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodeWhenMissingParallelityParameterThenThrowException() {
|
||||
Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=1024,t=3$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=1024,t=3$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
private void assertArgon2HashEquals(Argon2EncodingUtils.Argon2Hash expected,
|
||||
|
||||
+3
-2
@@ -28,6 +28,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.security.crypto.keygen.BytesKeyGenerator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Simeon Macke
|
||||
@@ -181,9 +182,9 @@ public class Argon2PasswordEncoderTests {
|
||||
assertThat(this.encoder.upgradeEncoding("")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void upgradeEncodingWhenEncodedPassIsBogusThenThrowException() {
|
||||
this.encoder.upgradeEncoding("thisIsNoValidHash");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.encoder.upgradeEncoding("thisIsNoValidHash"));
|
||||
}
|
||||
|
||||
private void injectPredictableSaltGen() throws Exception {
|
||||
|
||||
+11
-10
@@ -21,6 +21,7 @@ import java.security.SecureRandom;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -129,14 +130,14 @@ public class BCryptPasswordEncoderTests {
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void badLowCustomStrength() {
|
||||
new BCryptPasswordEncoder(3);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new BCryptPasswordEncoder(3));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void badHighCustomStrength() {
|
||||
new BCryptPasswordEncoder(32);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new BCryptPasswordEncoder(32));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,22 +190,22 @@ public class BCryptPasswordEncoderTests {
|
||||
* @see <a href=
|
||||
* "https://github.com/spring-projects/spring-security/pull/7042#issuecomment-506755496">https://github.com/spring-projects/spring-security/pull/7042#issuecomment-506755496</a>
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void upgradeFromNonBCrypt() {
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
encoder.upgradeEncoding("not-a-bcrypt-password");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> encoder.upgradeEncoding("not-a-bcrypt-password"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void encodeNullRawPassword() {
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
encoder.encode(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> encoder.encode(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void matchNullRawPassword() {
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
encoder.matches(null, "does-not-matter");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> encoder.matches(null, "does-not-matter"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* JUnit unit tests for BCrypt routines
|
||||
@@ -328,19 +329,21 @@ public class BCryptTests {
|
||||
assertThat(BCrypt.roundsForLogRounds(31)).isEqualTo(0x80000000L);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void emptyByteArrayCannotBeEncoded() {
|
||||
BCrypt.encode_base64(new byte[0], 0, new StringBuilder());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.encode_base64(new byte[0], 0, new StringBuilder()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void moreBytesThanInTheArrayCannotBeEncoded() {
|
||||
BCrypt.encode_base64(new byte[1], 2, new StringBuilder());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.encode_base64(new byte[1], 2, new StringBuilder()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void decodingMustRequestMoreThanZeroBytes() {
|
||||
BCrypt.decode_base64("", 0);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> BCrypt.decode_base64("", 0));
|
||||
}
|
||||
|
||||
private static String encode_base64(byte d[], int len) throws IllegalArgumentException {
|
||||
@@ -394,14 +397,14 @@ public class BCryptTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void genSaltFailsWithTooFewRounds() {
|
||||
BCrypt.gensalt(3);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> BCrypt.gensalt(3));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void genSaltFailsWithTooManyRounds() {
|
||||
BCrypt.gensalt(32);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> BCrypt.gensalt(32));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -410,24 +413,26 @@ public class BCryptTests {
|
||||
assertThat(BCrypt.gensalt(31)).startsWith("$2a$31$");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltIsNull() {
|
||||
BCrypt.hashpw("password", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> BCrypt.hashpw("password", null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltSpecifiesTooFewRounds() {
|
||||
BCrypt.hashpw("password", "$2a$03$......................");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$03$......................"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltSpecifiesTooManyRounds() {
|
||||
BCrypt.hashpw("password", "$2a$32$......................");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$32$......................"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void saltLengthIsChecked() {
|
||||
BCrypt.hashpw("", "");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> BCrypt.hashpw("", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -436,9 +441,10 @@ public class BCryptTests {
|
||||
.isEqualTo("$2$05$......................bvpG2UfzdyW/S0ny/4YyEZrmczoJfVm");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltIsTooShort() {
|
||||
BCrypt.hashpw("password", "$2a$10$123456789012345678901");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$10$123456789012345678901"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.security.crypto.codec;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
@@ -37,14 +39,14 @@ public class Base64Tests {
|
||||
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C', (byte) '`' })).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
@Test
|
||||
public void isBase64RejectsNull() {
|
||||
Base64.isBase64(null);
|
||||
assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> Base64.isBase64(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void isBase64RejectsInvalidLength() {
|
||||
Base64.isBase64(new byte[] { (byte) 'A' });
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Base64.isBase64(new byte[] { (byte) 'A' }));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-4
@@ -27,6 +27,8 @@ import org.junit.Test;
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
public class BouncyCastleAesBytesEncryptorTests {
|
||||
|
||||
private byte[] testData;
|
||||
@@ -69,14 +71,16 @@ public class BouncyCastleAesBytesEncryptorTests {
|
||||
Assert.assertArrayEquals(this.testData, decrypted2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void bcCbcWithWrongLengthIv() {
|
||||
new BouncyCastleAesCbcBytesEncryptor(this.password, this.salt, KeyGenerators.secureRandom(8));
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new BouncyCastleAesCbcBytesEncryptor(this.password, this.salt, KeyGenerators.secureRandom(8)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void bcGcmWithWrongLengthIv() {
|
||||
new BouncyCastleAesGcmBytesEncryptor(this.password, this.salt, KeyGenerators.secureRandom(8));
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new BouncyCastleAesGcmBytesEncryptor(this.password, this.salt, KeyGenerators.secureRandom(8)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -21,6 +21,7 @@ import java.util.Base64;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -28,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class Base64StringKeyGeneratorTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void constructorIntWhenLessThan32ThenIllegalArgumentException() {
|
||||
new Base64StringKeyGenerator(31);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Base64StringKeyGenerator(31));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void constructorEncoderWhenEncoderNullThenThrowsIllegalArgumentException() {
|
||||
Base64.Encoder encoder = null;
|
||||
new Base64StringKeyGenerator(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Base64StringKeyGenerator(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+10
-8
@@ -72,19 +72,21 @@ public class DelegatingPasswordEncoderTests {
|
||||
this.passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void constructorWhenIdForEncodeNullThenIllegalArgumentException() {
|
||||
new DelegatingPasswordEncoder(null, this.delegates);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new DelegatingPasswordEncoder(null, this.delegates));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void constructorWhenIdForEncodeDoesNotExistThenIllegalArgumentException() {
|
||||
new DelegatingPasswordEncoder(this.bcryptId + "INVALID", this.delegates);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId + "INVALID", this.delegates));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void setDefaultPasswordEncoderForMatchesWhenNullThenIllegalArgumentException() {
|
||||
this.passwordEncoder.setDefaultPasswordEncoderForMatches(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.passwordEncoder.setDefaultPasswordEncoderForMatches(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,9 +182,9 @@ public class DelegatingPasswordEncoderTests {
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void matchesWhenRawPasswordNotNullAndEncodedPasswordNullThenThrowsIllegalArgumentException() {
|
||||
this.passwordEncoder.matches(this.rawPassword, null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-4
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests {@link LdapShaPasswordEncoder}.
|
||||
@@ -92,15 +93,16 @@ public class LdapShaPasswordEncoderTests {
|
||||
assertThat(this.sha.encode("somepassword").startsWith("{SSHA}"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidPrefixIsRejected() {
|
||||
this.sha.matches("somepassword", "{MD9}xxxxxxxxxx");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.sha.matches("somepassword", "{MD9}xxxxxxxxxx"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void malformedPrefixIsRejected() {
|
||||
// No right brace
|
||||
this.sha.matches("somepassword", "{SSHA25ro4PKC8jhQZ26jVsozhX/xaP0suHgX");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.sha.matches("somepassword", "{SSHA25ro4PKC8jhQZ26jVsozhX/xaP0suHgX"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@ package org.springframework.security.crypto.password;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -112,9 +113,9 @@ public class MessageDigestPasswordEncoderTests {
|
||||
assertThat(pe.matches(raw, "{THIS_IS_A_SALT}4b79b7de23eb23b78cc5ede227d532b8a51f89b2ec166f808af76b0dbedc47d7"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testInvalidStrength() {
|
||||
new MessageDigestPasswordEncoder("SHA-666");
|
||||
assertThatIllegalStateException().isThrownBy(() -> new MessageDigestPasswordEncoder("SHA-666"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-12
@@ -19,6 +19,7 @@ package org.springframework.security.crypto.scrypt;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Shazin Sadakath
|
||||
@@ -91,29 +92,32 @@ public class SCryptPasswordEncoderTests {
|
||||
assertThat(encoder.matches("password", "012345678901234567890123456789")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidCpuCostParameter() {
|
||||
new SCryptPasswordEncoder(Integer.MIN_VALUE, 16, 2, 32, 16);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(Integer.MIN_VALUE, 16, 2, 32, 16));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidMemoryCostParameter() {
|
||||
new SCryptPasswordEncoder(2, Integer.MAX_VALUE, 2, 32, 16);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(2, Integer.MAX_VALUE, 2, 32, 16));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidParallelizationParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, Integer.MAX_VALUE, 32, 16);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(2, 8, Integer.MAX_VALUE, 32, 16));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidSaltLengthParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, 1, 16, -1);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new SCryptPasswordEncoder(2, 8, 1, 16, -1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidKeyLengthParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, 1, -1, 16);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new SCryptPasswordEncoder(2, 8, 1, -1, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,9 +157,10 @@ public class SCryptPasswordEncoderTests {
|
||||
assertThat(strongEncoder.upgradeEncoding(weakPassword)).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void upgradeEncodingWhenInvalidInputThenException() {
|
||||
new SCryptPasswordEncoder().upgradeEncoding("not-a-scrypt-password");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder().upgradeEncoding("not-a-scrypt-password"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user