Remove blank lines from all tests
Remove all blank lines from test code so that test methods are visually grouped together. This generally helps to make the test classes easer to scan, however, the "given" / "when" / "then" blocks used by some tests are now not as easy to discern. Issue gh-8945
This commit is contained in:
-16
@@ -89,7 +89,6 @@ public class Argon2PasswordEncoderTests {
|
||||
public void matchesWhenGeneratedWithDifferentEncoderThenTrue() {
|
||||
Argon2PasswordEncoder oldEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
|
||||
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder();
|
||||
|
||||
String password = "secret";
|
||||
String oldEncodedPassword = oldEncoder.encode(password);
|
||||
assertThat(newEncoder.matches(password, oldEncodedPassword)).isTrue();
|
||||
@@ -113,9 +112,7 @@ public class Argon2PasswordEncoderTests {
|
||||
@Test
|
||||
public void encodeWhenUsingPredictableSaltThenEqualTestHash() throws Exception {
|
||||
injectPredictableSaltGen();
|
||||
|
||||
String hash = this.encoder.encode("sometestpassword");
|
||||
|
||||
assertThat(hash).isEqualTo(
|
||||
"$argon2id$v=19$m=4096,t=3,p=1$QUFBQUFBQUFBQUFBQUFBQQ$hmmTNyJlwbb6HAvFoHFWF+u03fdb0F2qA+39oPlcAqo");
|
||||
}
|
||||
@@ -125,7 +122,6 @@ public class Argon2PasswordEncoderTests {
|
||||
this.encoder = new Argon2PasswordEncoder(16, 32, 4, 512, 5);
|
||||
injectPredictableSaltGen();
|
||||
String hash = this.encoder.encode("sometestpassword");
|
||||
|
||||
assertThat(hash).isEqualTo(
|
||||
"$argon2id$v=19$m=512,t=5,p=4$QUFBQUFBQUFBQUFBQUFBQQ$PNv4C3K50bz3rmON+LtFpdisD7ePieLNq+l5iUHgc1k");
|
||||
}
|
||||
@@ -133,16 +129,13 @@ public class Argon2PasswordEncoderTests {
|
||||
@Test
|
||||
public void upgradeEncodingWhenSameEncodingThenFalse() {
|
||||
String hash = this.encoder.encode("password");
|
||||
|
||||
assertThat(this.encoder.upgradeEncoding(hash)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upgradeEncodingWhenSameStandardParamsThenFalse() {
|
||||
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder();
|
||||
|
||||
String hash = this.encoder.encode("password");
|
||||
|
||||
assertThat(newEncoder.upgradeEncoding(hash)).isFalse();
|
||||
}
|
||||
|
||||
@@ -150,9 +143,7 @@ public class Argon2PasswordEncoderTests {
|
||||
public void upgradeEncodingWhenSameCustomParamsThenFalse() {
|
||||
Argon2PasswordEncoder oldEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
|
||||
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
|
||||
|
||||
String hash = oldEncoder.encode("password");
|
||||
|
||||
assertThat(newEncoder.upgradeEncoding(hash)).isFalse();
|
||||
}
|
||||
|
||||
@@ -160,9 +151,7 @@ public class Argon2PasswordEncoderTests {
|
||||
public void upgradeEncodingWhenHashHasLowerMemoryThenTrue() {
|
||||
Argon2PasswordEncoder oldEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
|
||||
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder(20, 64, 4, 512, 4);
|
||||
|
||||
String hash = oldEncoder.encode("password");
|
||||
|
||||
assertThat(newEncoder.upgradeEncoding(hash)).isTrue();
|
||||
}
|
||||
|
||||
@@ -170,9 +159,7 @@ public class Argon2PasswordEncoderTests {
|
||||
public void upgradeEncodingWhenHashHasLowerIterationsThenTrue() {
|
||||
Argon2PasswordEncoder oldEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
|
||||
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 5);
|
||||
|
||||
String hash = oldEncoder.encode("password");
|
||||
|
||||
assertThat(newEncoder.upgradeEncoding(hash)).isTrue();
|
||||
}
|
||||
|
||||
@@ -180,9 +167,7 @@ public class Argon2PasswordEncoderTests {
|
||||
public void upgradeEncodingWhenHashHasHigherParamsThenFalse() {
|
||||
Argon2PasswordEncoder oldEncoder = new Argon2PasswordEncoder(20, 64, 4, 256, 4);
|
||||
Argon2PasswordEncoder newEncoder = new Argon2PasswordEncoder(20, 64, 4, 128, 3);
|
||||
|
||||
String hash = oldEncoder.encode("password");
|
||||
|
||||
assertThat(newEncoder.upgradeEncoding(hash)).isFalse();
|
||||
}
|
||||
|
||||
@@ -205,7 +190,6 @@ public class Argon2PasswordEncoderTests {
|
||||
byte[] bytes = new byte[16];
|
||||
Arrays.fill(bytes, (byte) 0x41);
|
||||
Mockito.when(this.keyGeneratorMock.generateKey()).thenReturn(bytes);
|
||||
|
||||
// we can't use the @InjectMock-annotation because the salt-generator is set in
|
||||
// the constructor
|
||||
// and Mockito will only inject mocks if they are null
|
||||
|
||||
-3
@@ -113,7 +113,6 @@ public class BCryptPasswordEncoderTests {
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(8);
|
||||
String result = encoder.encode("password");
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,10 +168,8 @@ public class BCryptPasswordEncoderTests {
|
||||
public void upgradeFromLowerStrength() {
|
||||
BCryptPasswordEncoder weakEncoder = new BCryptPasswordEncoder(5);
|
||||
BCryptPasswordEncoder strongEncoder = new BCryptPasswordEncoder(15);
|
||||
|
||||
String weakPassword = weakEncoder.encode("password");
|
||||
String strongPassword = strongEncoder.encode("password");
|
||||
|
||||
assertThat(weakEncoder.upgradeEncoding(strongPassword)).isFalse();
|
||||
assertThat(strongEncoder.upgradeEncoding(weakPassword)).isTrue();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package org.springframework.security.crypto.bcrypt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -141,7 +140,6 @@ public class BCryptTests {
|
||||
"$2y$06$sYDFHqOcXTjBgOsqC0WCKeMd3T1UhHuWQSxncLGtXDLMrcE6vFDti"));
|
||||
testObjectsString.add(new TestObject<>("~!@#$%^&*() ~!@#$%^&*()PNBFRD", "$2y$06$6Xm0gCw4g7ZNDCEp4yTise",
|
||||
"$2y$06$6Xm0gCw4g7ZNDCEp4yTisez0kSdpXEl66MvdxGidnmChIe8dFmMnq"));
|
||||
|
||||
testObjectsByteArray = new ArrayList<>();
|
||||
testObjectsByteArray.add(new TestObject<>(new byte[] {}, "$2a$06$fPIsBO8qRqkjj273rfaOI.",
|
||||
"$2a$06$fPIsBO8qRqkjj273rfaOI.uiVGfgi6Z1Iz.vZr11mi/38o09TUVCy"));
|
||||
@@ -315,11 +313,9 @@ public class BCryptTests {
|
||||
print("BCrypt.hashpw w/ international chars: ");
|
||||
String pw1 = "ππππππππ";
|
||||
String pw2 = "????????";
|
||||
|
||||
String h1 = BCrypt.hashpw(pw1, BCrypt.gensalt());
|
||||
assertThat(BCrypt.checkpw(pw2, h1)).isFalse();
|
||||
print(".");
|
||||
|
||||
String h2 = BCrypt.hashpw(pw2, BCrypt.gensalt());
|
||||
assertThat(BCrypt.checkpw(pw1, h2)).isFalse();
|
||||
print(".");
|
||||
@@ -386,15 +382,12 @@ public class BCryptTests {
|
||||
@Test
|
||||
public void testBase64EncodeDecode() {
|
||||
byte[] ba = new byte[3];
|
||||
|
||||
for (int b = 0; b <= 0xFF; b++) {
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
Arrays.fill(ba, (byte) 0);
|
||||
ba[i] = (byte) b;
|
||||
|
||||
String s = encode_base64(ba, 3);
|
||||
assertThat(s.length()).isEqualTo(4);
|
||||
|
||||
byte[] decoded = BCrypt.decode_base64(s, 3);
|
||||
assertThat(decoded).isEqualTo(ba);
|
||||
}
|
||||
@@ -452,10 +445,8 @@ public class BCryptTests {
|
||||
public void equalsOnStringsIsCorrect() {
|
||||
assertThat(BCrypt.equalsNoEarlyReturn("", "")).isTrue();
|
||||
assertThat(BCrypt.equalsNoEarlyReturn("test", "test")).isTrue();
|
||||
|
||||
assertThat(BCrypt.equalsNoEarlyReturn("test", "")).isFalse();
|
||||
assertThat(BCrypt.equalsNoEarlyReturn("", "test")).isFalse();
|
||||
|
||||
assertThat(BCrypt.equalsNoEarlyReturn("test", "pass")).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,7 @@ public class Utf8Tests {
|
||||
byte[] bytes = Utf8.encode("6048b75ed560785c");
|
||||
assertThat(bytes).hasSize(16);
|
||||
assertThat(Arrays.equals("6048b75ed560785c".getBytes("UTF-8"), bytes)).isTrue();
|
||||
|
||||
String decoded = Utf8.decode(bytes);
|
||||
|
||||
assertThat(decoded).isEqualTo("6048b75ed560785c");
|
||||
}
|
||||
|
||||
|
||||
-5
@@ -67,7 +67,6 @@ public class AesBytesEncryptorTests {
|
||||
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
|
||||
assertThat(new String(Hex.encode(encryption)))
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3b7232ac29355d07869433f1ecf55fe94");
|
||||
|
||||
byte[] decryption = encryptor.decrypt(encryption);
|
||||
assertThat(new String(decryption)).isEqualTo(this.secret);
|
||||
}
|
||||
@@ -77,11 +76,9 @@ public class AesBytesEncryptorTests {
|
||||
CryptoAssumptions.assumeGCMJCE();
|
||||
AesBytesEncryptor encryptor = new AesBytesEncryptor(this.password, this.hexSalt, this.generator,
|
||||
CipherAlgorithm.GCM);
|
||||
|
||||
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
|
||||
assertThat(new String(Hex.encode(encryption)))
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
|
||||
|
||||
byte[] decryption = encryptor.decrypt(encryption);
|
||||
assertThat(new String(decryption)).isEqualTo(this.secret);
|
||||
}
|
||||
@@ -92,11 +89,9 @@ public class AesBytesEncryptorTests {
|
||||
PBEKeySpec keySpec = new PBEKeySpec(this.password.toCharArray(), Hex.decode(this.hexSalt), 1024, 256);
|
||||
SecretKey secretKey = CipherUtils.newSecretKey(SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA1.name(), keySpec);
|
||||
AesBytesEncryptor encryptor = new AesBytesEncryptor(secretKey, this.generator, CipherAlgorithm.GCM);
|
||||
|
||||
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
|
||||
assertThat(new String(Hex.encode(encryption)))
|
||||
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
|
||||
|
||||
byte[] decryption = encryptor.decrypt(encryption);
|
||||
assertThat(new String(decryption)).isEqualTo(this.secret);
|
||||
}
|
||||
|
||||
-1
@@ -102,7 +102,6 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||
Assert.assertArrayEquals(this.testData, leftDecrypted);
|
||||
Assert.assertArrayEquals(this.testData, rightDecrypted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void testCompatibility(BytesEncryptor left, BytesEncryptor right) {
|
||||
|
||||
-1
@@ -52,7 +52,6 @@ public final class CryptoAssumptions {
|
||||
throw new AssumptionViolatedException(cipherAlgorithm + " padding not available, skipping test", ex);
|
||||
}
|
||||
Assume.assumeTrue("AES key length of 256 not allowed, skipping test", aes256Available);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -35,7 +35,6 @@ public class PasswordEncoderFactoriesTests {
|
||||
@Test
|
||||
public void encodeWhenDefaultThenBCryptUsed() {
|
||||
String encodedPassword = this.encoder.encode(this.rawPassword);
|
||||
|
||||
assertThat(encodedPassword).startsWith("{bcrypt}");
|
||||
assertThat(this.encoder.matches(this.rawPassword, encodedPassword)).isTrue();
|
||||
}
|
||||
|
||||
-22
@@ -69,7 +69,6 @@ public class DelegatingPasswordEncoderTests {
|
||||
this.delegates = new HashMap<>();
|
||||
this.delegates.put(this.bcryptId, this.bcrypt);
|
||||
this.delegates.put("noop", this.noop);
|
||||
|
||||
this.passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates);
|
||||
}
|
||||
|
||||
@@ -92,9 +91,7 @@ public class DelegatingPasswordEncoderTests {
|
||||
public void matchesWhenCustomDefaultPasswordEncoderForMatchesThenDelegates() {
|
||||
String encodedPassword = "{unmapped}" + this.rawPassword;
|
||||
this.passwordEncoder.setDefaultPasswordEncoderForMatches(this.invalidId);
|
||||
|
||||
assertThat(this.passwordEncoder.matches(this.rawPassword, encodedPassword)).isFalse();
|
||||
|
||||
verify(this.invalidId).matches(this.rawPassword, encodedPassword);
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
@@ -102,16 +99,13 @@ public class DelegatingPasswordEncoderTests {
|
||||
@Test
|
||||
public void encodeWhenValidThenUsesIdForEncode() {
|
||||
given(this.bcrypt.encode(this.rawPassword)).willReturn(this.encodedPassword);
|
||||
|
||||
assertThat(this.passwordEncoder.encode(this.rawPassword)).isEqualTo(this.bcryptEncodedPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenBCryptThenDelegatesToBCrypt() {
|
||||
given(this.bcrypt.matches(this.rawPassword, this.encodedPassword)).willReturn(true);
|
||||
|
||||
assertThat(this.passwordEncoder.matches(this.rawPassword, this.bcryptEncodedPassword)).isTrue();
|
||||
|
||||
verify(this.bcrypt).matches(this.rawPassword, this.encodedPassword);
|
||||
verifyZeroInteractions(this.noop);
|
||||
}
|
||||
@@ -119,9 +113,7 @@ public class DelegatingPasswordEncoderTests {
|
||||
@Test
|
||||
public void matchesWhenNoopThenDelegatesToNoop() {
|
||||
given(this.noop.matches(this.rawPassword, this.encodedPassword)).willReturn(true);
|
||||
|
||||
assertThat(this.passwordEncoder.matches(this.rawPassword, this.noopEncodedPassword)).isTrue();
|
||||
|
||||
verify(this.noop).matches(this.rawPassword, this.encodedPassword);
|
||||
verifyZeroInteractions(this.bcrypt);
|
||||
}
|
||||
@@ -131,7 +123,6 @@ public class DelegatingPasswordEncoderTests {
|
||||
assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{unmapped}" + this.rawPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("There is no PasswordEncoder mapped for the id \"unmapped\"");
|
||||
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@@ -140,7 +131,6 @@ public class DelegatingPasswordEncoderTests {
|
||||
assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{bcrypt" + this.rawPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@@ -149,7 +139,6 @@ public class DelegatingPasswordEncoderTests {
|
||||
assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "bcrypt}" + this.rawPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@@ -158,7 +147,6 @@ public class DelegatingPasswordEncoderTests {
|
||||
assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "{}" + this.rawPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("There is no PasswordEncoder mapped for the id \"\"");
|
||||
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@@ -167,20 +155,16 @@ public class DelegatingPasswordEncoderTests {
|
||||
assertThatThrownBy(() -> this.passwordEncoder.matches(this.rawPassword, "invalid" + this.bcryptEncodedPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenIdIsNullThenFalse() {
|
||||
this.delegates = new Hashtable<>(this.delegates);
|
||||
|
||||
DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates);
|
||||
|
||||
assertThatThrownBy(() -> passwordEncoder.matches(this.rawPassword, this.rawPassword))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("There is no PasswordEncoder mapped for the id \"null\"");
|
||||
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
|
||||
@@ -189,9 +173,7 @@ public class DelegatingPasswordEncoderTests {
|
||||
this.delegates.put(null, this.invalidId);
|
||||
this.passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates);
|
||||
given(this.invalidId.matches(this.rawPassword, this.encodedPassword)).willReturn(true);
|
||||
|
||||
assertThat(this.passwordEncoder.matches(this.rawPassword, this.encodedPassword)).isTrue();
|
||||
|
||||
verify(this.invalidId).matches(this.rawPassword, this.encodedPassword);
|
||||
verifyZeroInteractions(this.bcrypt, this.noop);
|
||||
}
|
||||
@@ -219,23 +201,19 @@ public class DelegatingPasswordEncoderTests {
|
||||
@Test
|
||||
public void upgradeEncodingWhenSameIdAndEncoderFalseThenEncoderDecidesFalse() {
|
||||
assertThat(this.passwordEncoder.upgradeEncoding(this.bcryptEncodedPassword)).isFalse();
|
||||
|
||||
verify(this.bcrypt).upgradeEncoding(this.encodedPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upgradeEncodingWhenSameIdAndEncoderTrueThenEncoderDecidesTrue() {
|
||||
given(this.bcrypt.upgradeEncoding(any())).willReturn(true);
|
||||
|
||||
assertThat(this.passwordEncoder.upgradeEncoding(this.bcryptEncodedPassword)).isTrue();
|
||||
|
||||
verify(this.bcrypt).upgradeEncoding(this.encodedPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upgradeEncodingWhenDifferentIdThenTrue() {
|
||||
assertThat(this.passwordEncoder.upgradeEncoding(this.noopEncodedPassword)).isTrue();
|
||||
|
||||
verifyZeroInteractions(this.bcrypt);
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -83,14 +83,11 @@ public class LdapShaPasswordEncoderTests {
|
||||
public void correctPrefixCaseIsUsed() {
|
||||
this.sha.setForceLowerCasePrefix(false);
|
||||
assertThat(this.sha.encode("somepassword").startsWith("{SSHA}"));
|
||||
|
||||
this.sha.setForceLowerCasePrefix(true);
|
||||
assertThat(this.sha.encode("somepassword").startsWith("{ssha}"));
|
||||
|
||||
this.sha = new LdapShaPasswordEncoder(KeyGenerators.shared(0));
|
||||
this.sha.setForceLowerCasePrefix(false);
|
||||
assertThat(this.sha.encode("somepassword").startsWith("{SHA}"));
|
||||
|
||||
this.sha.setForceLowerCasePrefix(true);
|
||||
assertThat(this.sha.encode("somepassword").startsWith("{SSHA}"));
|
||||
}
|
||||
|
||||
-1
@@ -62,7 +62,6 @@ public class Md4PasswordEncoderTests {
|
||||
String rawPassword = "password";
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
String encodedPassword = md4.encode(rawPassword);
|
||||
|
||||
assertThat(md4.matches(rawPassword, encodedPassword)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -95,7 +95,6 @@ public class MessageDigestPasswordEncoderTests {
|
||||
MessageDigestPasswordEncoder pe = new MessageDigestPasswordEncoder("SHA-1");
|
||||
String raw = "abc123";
|
||||
assertThat(pe.matches(raw, "{THIS_IS_A_SALT}b2f50ffcbd3407fe9415c062d55f54731f340d32"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
-5
@@ -71,14 +71,12 @@ public class Pbkdf2PasswordEncoderTests {
|
||||
byte[] originalBytes = Hex.decode(originalEncodedPassword);
|
||||
byte[] fixedBytes = Arrays.copyOfRange(originalBytes, saltLength, originalBytes.length);
|
||||
String fixedHex = String.valueOf(Hex.encode(fixedBytes));
|
||||
|
||||
assertThat(fixedHex).isEqualTo(encodedPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAndMatchWhenBase64ThenSuccess() {
|
||||
this.encoder.setEncodeHashAsBase64(true);
|
||||
|
||||
String rawPassword = "password";
|
||||
String encodedPassword = this.encoder.encode(rawPassword);
|
||||
assertThat(this.encoder.matches(rawPassword, encodedPassword)).isTrue();
|
||||
@@ -89,7 +87,6 @@ public class Pbkdf2PasswordEncoderTests {
|
||||
this.encoder.setEncodeHashAsBase64(true);
|
||||
String rawPassword = "password";
|
||||
String encodedPassword = "3FOwOMcDgxP+z1x/sv184LFY2WVD+ZGMgYP3LPOSmCcDmk1XPYvcCQ==";
|
||||
|
||||
assertThat(this.encoder.matches(rawPassword, encodedPassword)).isTrue();
|
||||
java.util.Base64.getDecoder().decode(encodedPassword); // validate can decode as
|
||||
// Base64
|
||||
@@ -98,7 +95,6 @@ public class Pbkdf2PasswordEncoderTests {
|
||||
@Test
|
||||
public void encodeAndMatchWhenSha256ThenSuccess() {
|
||||
this.encoder.setAlgorithm(Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256);
|
||||
|
||||
String rawPassword = "password";
|
||||
String encodedPassword = this.encoder.encode(rawPassword);
|
||||
assertThat(this.encoder.matches(rawPassword, encodedPassword)).isTrue();
|
||||
@@ -107,7 +103,6 @@ public class Pbkdf2PasswordEncoderTests {
|
||||
@Test
|
||||
public void matchWhenSha256ThenSuccess() {
|
||||
this.encoder.setAlgorithm(Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256);
|
||||
|
||||
String rawPassword = "password";
|
||||
String encodedPassword = "821447f994e2b04c5014e31fa9fca4ae1cc9f2188c4ed53d3ddb5ba7980982b51a0ecebfc0b81a79";
|
||||
assertThat(this.encoder.matches(rawPassword, encodedPassword)).isTrue();
|
||||
|
||||
-5
@@ -68,7 +68,6 @@ public class SCryptPasswordEncoderTests {
|
||||
public void samePasswordWithDifferentParams() {
|
||||
SCryptPasswordEncoder oldEncoder = new SCryptPasswordEncoder(16384, 8, 1, 32, 64);
|
||||
SCryptPasswordEncoder newEncoder = new SCryptPasswordEncoder();
|
||||
|
||||
String password = "secret";
|
||||
String oldEncodedPassword = oldEncoder.encode(password);
|
||||
assertThat(newEncoder.matches(password, oldEncodedPassword)).isTrue();
|
||||
@@ -140,10 +139,8 @@ public class SCryptPasswordEncoderTests {
|
||||
public void upgradeEncodingWhenWeakerToStrongerThenFalse() {
|
||||
SCryptPasswordEncoder weakEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 10), 4, 1, 32, 64);
|
||||
SCryptPasswordEncoder strongEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 16), 8, 1, 32, 64);
|
||||
|
||||
String weakPassword = weakEncoder.encode("password");
|
||||
String strongPassword = strongEncoder.encode("password");
|
||||
|
||||
assertThat(weakEncoder.upgradeEncoding(strongPassword)).isFalse();
|
||||
}
|
||||
|
||||
@@ -151,10 +148,8 @@ public class SCryptPasswordEncoderTests {
|
||||
public void upgradeEncodingWhenStrongerToWeakerThenTrue() {
|
||||
SCryptPasswordEncoder weakEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 10), 4, 1, 32, 64);
|
||||
SCryptPasswordEncoder strongEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 16), 8, 1, 32, 64);
|
||||
|
||||
String weakPassword = weakEncoder.encode("password");
|
||||
String strongPassword = strongEncoder.encode("password");
|
||||
|
||||
assertThat(strongEncoder.upgradeEncoding(weakPassword)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user