Apply updated Code Style
Closes gh-13881
This commit is contained in:
@@ -59,20 +59,26 @@ final class Argon2EncodingUtils {
|
||||
static String encode(byte[] hash, Argon2Parameters parameters) throws IllegalArgumentException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
switch (parameters.getType()) {
|
||||
case Argon2Parameters.ARGON2_d:
|
||||
stringBuilder.append("$argon2d");
|
||||
break;
|
||||
case Argon2Parameters.ARGON2_i:
|
||||
stringBuilder.append("$argon2i");
|
||||
break;
|
||||
case Argon2Parameters.ARGON2_id:
|
||||
stringBuilder.append("$argon2id");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid algorithm type: " + parameters.getType());
|
||||
case Argon2Parameters.ARGON2_d:
|
||||
stringBuilder.append("$argon2d");
|
||||
break;
|
||||
case Argon2Parameters.ARGON2_i:
|
||||
stringBuilder.append("$argon2i");
|
||||
break;
|
||||
case Argon2Parameters.ARGON2_id:
|
||||
stringBuilder.append("$argon2id");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid algorithm type: " + parameters.getType());
|
||||
}
|
||||
stringBuilder.append("$v=").append(parameters.getVersion()).append("$m=").append(parameters.getMemory())
|
||||
.append(",t=").append(parameters.getIterations()).append(",p=").append(parameters.getLanes());
|
||||
stringBuilder.append("$v=")
|
||||
.append(parameters.getVersion())
|
||||
.append("$m=")
|
||||
.append(parameters.getMemory())
|
||||
.append(",t=")
|
||||
.append(parameters.getIterations())
|
||||
.append(",p=")
|
||||
.append(parameters.getLanes());
|
||||
if (parameters.getSalt() != null) {
|
||||
stringBuilder.append("$").append(b64encoder.encodeToString(parameters.getSalt()));
|
||||
}
|
||||
@@ -108,17 +114,17 @@ final class Argon2EncodingUtils {
|
||||
}
|
||||
int currentPart = 1;
|
||||
switch (parts[currentPart++]) {
|
||||
case "argon2d":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_d);
|
||||
break;
|
||||
case "argon2i":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i);
|
||||
break;
|
||||
case "argon2id":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid algorithm type: " + parts[0]);
|
||||
case "argon2d":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_d);
|
||||
break;
|
||||
case "argon2i":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i);
|
||||
break;
|
||||
case "argon2id":
|
||||
paramsBuilder = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid algorithm type: " + parts[0]);
|
||||
}
|
||||
if (parts[currentPart].startsWith("v=")) {
|
||||
paramsBuilder.withVersion(Integer.parseInt(parts[currentPart].substring(2)));
|
||||
|
||||
@@ -338,29 +338,29 @@ public final class Base64 {
|
||||
| ((numSigBytes > 2) ? ((source[srcOffset + 2] << 24) >>> 24) : 0);
|
||||
|
||||
switch (numSigBytes) {
|
||||
case 3:
|
||||
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
|
||||
destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
|
||||
destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f];
|
||||
destination[destOffset + 3] = ALPHABET[(inBuff) & 0x3f];
|
||||
return destination;
|
||||
case 3:
|
||||
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
|
||||
destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
|
||||
destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f];
|
||||
destination[destOffset + 3] = ALPHABET[(inBuff) & 0x3f];
|
||||
return destination;
|
||||
|
||||
case 2:
|
||||
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
|
||||
destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
|
||||
destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f];
|
||||
destination[destOffset + 3] = EQUALS_SIGN;
|
||||
return destination;
|
||||
case 2:
|
||||
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
|
||||
destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
|
||||
destination[destOffset + 2] = ALPHABET[(inBuff >>> 6) & 0x3f];
|
||||
destination[destOffset + 3] = EQUALS_SIGN;
|
||||
return destination;
|
||||
|
||||
case 1:
|
||||
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
|
||||
destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
|
||||
destination[destOffset + 2] = EQUALS_SIGN;
|
||||
destination[destOffset + 3] = EQUALS_SIGN;
|
||||
return destination;
|
||||
case 1:
|
||||
destination[destOffset] = ALPHABET[(inBuff >>> 18)];
|
||||
destination[destOffset + 1] = ALPHABET[(inBuff >>> 12) & 0x3f];
|
||||
destination[destOffset + 2] = EQUALS_SIGN;
|
||||
destination[destOffset + 3] = EQUALS_SIGN;
|
||||
return destination;
|
||||
|
||||
default:
|
||||
return destination;
|
||||
default:
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,8 +391,8 @@ public final class Base64 {
|
||||
} // end if: len < 0
|
||||
|
||||
if (off + len > source.length) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Cannot have offset of %d and length of %d with array of length %d", off, len, source.length));
|
||||
throw new IllegalArgumentException(String
|
||||
.format("Cannot have offset of %d and length of %d with array of length %d", off, len, source.length));
|
||||
} // end if: off < 0
|
||||
|
||||
boolean breakLines = (options & DO_BREAK_LINES) > 0;
|
||||
@@ -608,7 +608,7 @@ public final class Base64 {
|
||||
else {
|
||||
// There's a bad input character in the Base64 stream.
|
||||
throw new InvalidBase64CharacterException(String
|
||||
.format("Bad Base64 input character decimal %d in array position %d", (source[i]) & 0xFF, i));
|
||||
.format("Bad Base64 input character decimal %d in array position %d", (source[i]) & 0xFF, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,16 +34,24 @@ public class Argon2EncodingUtilsTests {
|
||||
private TestDataEntry testDataEntry1 = new TestDataEntry(
|
||||
"$argon2i$v=19$m=1024,t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs",
|
||||
new Argon2EncodingUtils.Argon2Hash(this.decoder.decode("cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"),
|
||||
(new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i)).withVersion(19).withMemoryAsKB(1024)
|
||||
.withIterations(3).withParallelism(2).withSalt("cRdFbCw23gz2Mlxk".getBytes()).build()));
|
||||
(new Argon2Parameters.Builder(Argon2Parameters.ARGON2_i)).withVersion(19)
|
||||
.withMemoryAsKB(1024)
|
||||
.withIterations(3)
|
||||
.withParallelism(2)
|
||||
.withSalt("cRdFbCw23gz2Mlxk".getBytes())
|
||||
.build()));
|
||||
|
||||
private TestDataEntry testDataEntry2 = new TestDataEntry(
|
||||
"$argon2id$v=19$m=333,t=5,p=2$JDR8N3k1QWx0$+PrEoHOHsWkU9lnsxqnOFrWTVEuOh7ZRIUIbe2yUG8FgTYNCWJfHQI09JAAFKzr2JAvoejEpTMghUt0WsntQYA",
|
||||
new Argon2EncodingUtils.Argon2Hash(
|
||||
this.decoder.decode(
|
||||
"+PrEoHOHsWkU9lnsxqnOFrWTVEuOh7ZRIUIbe2yUG8FgTYNCWJfHQI09JAAFKzr2JAvoejEpTMghUt0WsntQYA"),
|
||||
(new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id)).withVersion(19).withMemoryAsKB(333)
|
||||
.withIterations(5).withParallelism(2).withSalt("$4|7y5Alt".getBytes()).build()));
|
||||
(new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id)).withVersion(19)
|
||||
.withMemoryAsKB(333)
|
||||
.withIterations(5)
|
||||
.withParallelism(2)
|
||||
.withSalt("$4|7y5Alt".getBytes())
|
||||
.build()));
|
||||
|
||||
@Test
|
||||
public void decodeWhenValidEncodedHashWithIThenDecodeCorrectly() {
|
||||
@@ -58,20 +66,25 @@ public class Argon2EncodingUtilsTests {
|
||||
@Test
|
||||
public void encodeWhenValidArgumentsWithIThenEncodeToCorrectHash() {
|
||||
assertThat(Argon2EncodingUtils.encode(this.testDataEntry1.decoded.getHash(),
|
||||
this.testDataEntry1.decoded.getParameters())).isEqualTo(this.testDataEntry1.encoded);
|
||||
this.testDataEntry1.decoded.getParameters()))
|
||||
.isEqualTo(this.testDataEntry1.encoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeWhenValidArgumentsWithID2ThenEncodeToCorrectHash() {
|
||||
assertThat(Argon2EncodingUtils.encode(this.testDataEntry2.decoded.getHash(),
|
||||
this.testDataEntry2.decoded.getParameters())).isEqualTo(this.testDataEntry2.encoded);
|
||||
this.testDataEntry2.decoded.getParameters()))
|
||||
.isEqualTo(this.testDataEntry2.encoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeWhenNonexistingAlgorithmThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> 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
|
||||
@@ -81,56 +94,56 @@ public class Argon2EncodingUtilsTests {
|
||||
|
||||
@Test
|
||||
public void decodeWhenNonexistingAlgorithmThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> 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
|
||||
public void decodeWhenIllegalVersionParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> 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
|
||||
public void decodeWhenIllegalMemoryParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> 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
|
||||
public void decodeWhenIllegalIterationsParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> 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
|
||||
public void decodeWhenIllegalParallelityParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> 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
|
||||
public void decodeWhenMissingVersionParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$m=1024,t=3,p=x$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
.decode("$argon2i$m=1024,t=3,p=x$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeWhenMissingMemoryParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
.decode("$argon2i$v=19$t=3,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeWhenMissingIterationsParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=1024,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
.decode("$argon2i$v=19$m=1024,p=2$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeWhenMissingParallelityParameterThenThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Argon2EncodingUtils
|
||||
.decode("$argon2i$v=19$m=1024,t=3$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
.decode("$argon2i$v=19$m=1024,t=3$Y1JkRmJDdzIzZ3oyTWx4aw$cGE5Cbd/cx7micVhXVBdH5qTr66JI1iUyuNNVAnErXs"));
|
||||
}
|
||||
|
||||
private void assertArgon2HashEquals(Argon2EncodingUtils.Argon2Hash expected,
|
||||
|
||||
@@ -218,7 +218,7 @@ public class BCryptPasswordEncoderTests {
|
||||
public void checkWhenNoRoundsThenTrue() {
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", "$2a$00$9N8N35BVs5TLqGL3pspAte5OWWA2a2aZIs.EGp7At7txYakFERMue"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(encoder.matches("wrong", "$2a$00$9N8N35BVs5TLqGL3pspAte5OWWA2a2aZIs.EGp7At7txYakFERMue")).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -332,13 +332,13 @@ public class BCryptTests {
|
||||
@Test
|
||||
public void emptyByteArrayCannotBeEncoded() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.encode_base64(new byte[0], 0, new StringBuilder()));
|
||||
.isThrownBy(() -> BCrypt.encode_base64(new byte[0], 0, new StringBuilder()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreBytesThanInTheArrayCannotBeEncoded() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.encode_base64(new byte[1], 2, new StringBuilder()));
|
||||
.isThrownBy(() -> BCrypt.encode_base64(new byte[1], 2, new StringBuilder()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -421,13 +421,13 @@ public class BCryptTests {
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltSpecifiesTooFewRounds() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$03$......................"));
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$03$......................"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltSpecifiesTooManyRounds() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$32$......................"));
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$32$......................"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -438,13 +438,13 @@ public class BCryptTests {
|
||||
@Test
|
||||
public void hashpwWorksWithOldRevision() {
|
||||
assertThat(BCrypt.hashpw("password", "$2$05$......................"))
|
||||
.isEqualTo("$2$05$......................bvpG2UfzdyW/S0ny/4YyEZrmczoJfVm");
|
||||
.isEqualTo("$2$05$......................bvpG2UfzdyW/S0ny/4YyEZrmczoJfVm");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashpwFailsWhenSaltIsTooShort() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$10$123456789012345678901"));
|
||||
.isThrownBy(() -> BCrypt.hashpw("password", "$2a$10$123456789012345678901"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -31,7 +31,7 @@ public class HexTests {
|
||||
@Test
|
||||
public void encode() {
|
||||
assertThat(Hex.encode(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D' }))
|
||||
.isEqualTo(new char[] { '4', '1', '4', '2', '4', '3', '4', '4' });
|
||||
.isEqualTo(new char[] { '4', '1', '4', '2', '4', '3', '4', '4' });
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,25 +52,25 @@ public class HexTests {
|
||||
@Test
|
||||
public void decodeNotEven() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Hex.decode("414243444"))
|
||||
.withMessage("Hex-encoded string must have an even number of characters");
|
||||
.withMessage("Hex-encoded string must have an even number of characters");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeExistNonHexCharAtFirst() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Hex.decode("G0"))
|
||||
.withMessage("Detected a Non-hex character at 1 or 2 position");
|
||||
.withMessage("Detected a Non-hex character at 1 or 2 position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeExistNonHexCharAtSecond() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Hex.decode("410G"))
|
||||
.withMessage("Detected a Non-hex character at 3 or 4 position");
|
||||
.withMessage("Detected a Non-hex character at 3 or 4 position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeExistNonHexCharAtBoth() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> Hex.decode("4142GG"))
|
||||
.withMessage("Detected a Non-hex character at 5 or 6 position");
|
||||
.withMessage("Detected a Non-hex character at 5 or 6 position");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class AesBytesEncryptorTests {
|
||||
AesBytesEncryptor encryptor = new AesBytesEncryptor(this.password, this.hexSalt, this.generator);
|
||||
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
|
||||
assertThat(new String(Hex.encode(encryption)))
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3b7232ac29355d07869433f1ecf55fe94");
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3b7232ac29355d07869433f1ecf55fe94");
|
||||
byte[] decryption = encryptor.decrypt(encryption);
|
||||
assertThat(new String(decryption)).isEqualTo(this.secret);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class AesBytesEncryptorTests {
|
||||
CipherAlgorithm.GCM);
|
||||
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
|
||||
assertThat(new String(Hex.encode(encryption)))
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
|
||||
byte[] decryption = encryptor.decrypt(encryption);
|
||||
assertThat(new String(decryption)).isEqualTo(this.secret);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class AesBytesEncryptorTests {
|
||||
AesBytesEncryptor encryptor = new AesBytesEncryptor(secretKey, this.generator, CipherAlgorithm.GCM);
|
||||
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
|
||||
assertThat(new String(Hex.encode(encryption)))
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
|
||||
byte[] decryption = encryptor.decrypt(encryption);
|
||||
assertThat(new String(decryption)).isEqualTo(this.secret);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class PasswordEncoderFactoriesTests {
|
||||
void constructWhenAlgorithmNotAvailableThenSkip() {
|
||||
try (MockedStatic<Pbkdf2PasswordEncoder> pbkdf2PasswordEncoderMock = mockStatic(Pbkdf2PasswordEncoder.class)) {
|
||||
pbkdf2PasswordEncoderMock.when(Pbkdf2PasswordEncoder::defaultsForSpringSecurity_v5_8)
|
||||
.thenThrow(new IllegalArgumentException(new NoSuchAlgorithmException()));
|
||||
.thenThrow(new IllegalArgumentException(new NoSuchAlgorithmException()));
|
||||
|
||||
assertThatNoException().isThrownBy(PasswordEncoderFactories::createDelegatingPasswordEncoder);
|
||||
}
|
||||
|
||||
@@ -86,19 +86,19 @@ public class DelegatingPasswordEncoderTests {
|
||||
@Test
|
||||
public void constructorWhenIdForEncodeDoesNotExistThenIllegalArgumentException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId + "INVALID", this.delegates));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId + "INVALID", this.delegates));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenPrefixIsNull() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, null, "$"));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, null, "$"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenSuffixIsNull() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "$", null));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "$", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,39 +109,39 @@ public class DelegatingPasswordEncoderTests {
|
||||
@Test
|
||||
public void constructorWhenSuffixIsEmpty() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "$", ""));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "$", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenPrefixAndSuffixAreEmpty() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "", ""));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenIdContainsPrefixThenIllegalArgumentException() {
|
||||
this.delegates.put('{' + this.bcryptId, this.bcrypt);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenIdContainsSuffixThenIllegalArgumentException() {
|
||||
this.delegates.put(this.bcryptId + '$', this.bcrypt);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "", "$"));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "", "$"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenPrefixContainsSuffixThenIllegalArgumentException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "$", "$"));
|
||||
.isThrownBy(() -> new DelegatingPasswordEncoder(this.bcryptId, this.delegates, "$", "$"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultPasswordEncoderForMatchesWhenNullThenIllegalArgumentException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.passwordEncoder.setDefaultPasswordEncoderForMatches(null));
|
||||
.isThrownBy(() -> this.passwordEncoder.setDefaultPasswordEncoderForMatches(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,42 +192,41 @@ public class DelegatingPasswordEncoderTests {
|
||||
@Test
|
||||
public void matchesWhenUnMappedThenIllegalArgumentException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{unmapped}" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"unmapped\"");
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{unmapped}" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"unmapped\"");
|
||||
verifyNoMoreInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenNoClosingPrefixStringThenIllegalArgumentException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{bcrypt" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{bcrypt" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
verifyNoMoreInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenNoStartingPrefixStringThenFalse() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "bcrypt}" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "bcrypt}" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
verifyNoMoreInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenNoIdStringThenFalse() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{}" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"\"");
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{}" + this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"\"");
|
||||
verifyNoMoreInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenPrefixInMiddleThenFalse() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(
|
||||
() -> this.passwordEncoder.matches(this.rawPassword, "invalid" + this.bcryptEncodedPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
.isThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "invalid" + this.bcryptEncodedPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
verifyNoMoreInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@@ -236,8 +235,8 @@ public class DelegatingPasswordEncoderTests {
|
||||
this.delegates = new Hashtable<>(this.delegates);
|
||||
DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> passwordEncoder.matches(this.rawPassword, this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
.isThrownBy(() -> passwordEncoder.matches(this.rawPassword, this.rawPassword))
|
||||
.withMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
verifyNoMoreInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class LdapShaPasswordEncoderTests {
|
||||
public void malformedPrefixIsRejected() {
|
||||
// No right brace
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.sha.matches("somepassword", "{SSHA25ro4PKC8jhQZ26jVsozhX/xaP0suHgX"));
|
||||
.isThrownBy(() -> this.sha.matches("somepassword", "{SSHA25ro4PKC8jhQZ26jVsozhX/xaP0suHgX"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,19 +95,19 @@ public class SCryptPasswordEncoderTests {
|
||||
@Test
|
||||
public void invalidCpuCostParameter() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(Integer.MIN_VALUE, 16, 2, 32, 16));
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(Integer.MIN_VALUE, 16, 2, 32, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidMemoryCostParameter() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(2, Integer.MAX_VALUE, 2, 32, 16));
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(2, Integer.MAX_VALUE, 2, 32, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidParallelizationParameter() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(2, 8, Integer.MAX_VALUE, 32, 16));
|
||||
.isThrownBy(() -> new SCryptPasswordEncoder(2, 8, Integer.MAX_VALUE, 32, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user