1
0
mirror of synced 2026-08-04 09:17:02 +00:00

Start AssertJ Migration

Issue gh-3175
This commit is contained in:
Rob Winch
2015-12-16 10:38:31 -06:00
parent 6cbb439701
commit bb600a473e
355 changed files with 3036 additions and 3133 deletions
@@ -32,55 +32,55 @@ public class BCryptPasswordEncoderTests {
public void matches() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("password");
assertFalse(result.equals("password"));
assertTrue(encoder.matches("password", result));
assertThat(result.equals("password")).isFalse();
assertThat(encoder.matches("password", result)).isTrue();
}
@Test
public void unicode() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("passw\u9292rd");
assertFalse(encoder.matches("pass\u9292\u9292rd", result));
assertTrue(encoder.matches("passw\u9292rd", result));
assertThat(encoder.matches("pass\u9292\u9292rd", result)).isFalse();
assertThat(encoder.matches("passw\u9292rd", result)).isTrue();
}
@Test
public void notMatches() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String result = encoder.encode("password");
assertFalse(encoder.matches("bogus", result));
assertThat(encoder.matches("bogus", result)).isFalse();
}
@Test
public void customStrength() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(8);
String result = encoder.encode("password");
assertTrue(encoder.matches("password", result));
assertThat(encoder.matches("password", result)).isTrue();
}
@Test
public void customRandom() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(8, new SecureRandom());
String result = encoder.encode("password");
assertTrue(encoder.matches("password", result));
assertThat(encoder.matches("password", result)).isTrue();
}
@Test
public void doesntMatchNullEncodedValue() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
assertFalse(encoder.matches("password", null));
assertThat(encoder.matches("password", null)).isFalse();
}
@Test
public void doesntMatchEmptyEncodedValue() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
assertFalse(encoder.matches("password", ""));
assertThat(encoder.matches("password", "")).isFalse();
}
@Test
public void doesntMatchBogusEncodedValue() {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
assertFalse(encoder.matches("password", "012345678901234567890123456789"));
assertThat(encoder.matches("password", "012345678901234567890123456789")).isFalse();
}
}
+29 -29
View File
@@ -17,7 +17,7 @@ package org.springframework.security.crypto.bcrypt;
import java.util.Arrays;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
/**
* JUnit unit tests for BCrypt routines
@@ -86,7 +86,7 @@ public class BCryptTests {
String salt = test_vectors[i][1];
String expected = test_vectors[i][2];
String hashed = BCrypt.hashpw(plain, salt);
assertEquals(hashed, expected);
assertThat(expected).isEqualTo(hashed);
print(".");
}
println("");
@@ -105,7 +105,7 @@ public class BCryptTests {
String salt = BCrypt.gensalt(i);
String hashed1 = BCrypt.hashpw(plain, salt);
String hashed2 = BCrypt.hashpw(plain, hashed1);
assertEquals(hashed1, hashed2);
assertThat(hashed2).isEqualTo(hashed1);
print(".");
}
}
@@ -123,7 +123,7 @@ public class BCryptTests {
String salt = BCrypt.gensalt();
String hashed1 = BCrypt.hashpw(plain, salt);
String hashed2 = BCrypt.hashpw(plain, hashed1);
assertEquals(hashed1, hashed2);
assertThat(hashed2).isEqualTo(hashed1);
print(".");
}
println("");
@@ -138,7 +138,7 @@ public class BCryptTests {
for (int i = 0; i < test_vectors.length; i++) {
String plain = test_vectors[i][0];
String expected = test_vectors[i][2];
assertTrue(BCrypt.checkpw(plain, expected));
assertThat(BCrypt.checkpw(plain, expected)).isTrue();
print(".");
}
println("");
@@ -154,7 +154,7 @@ public class BCryptTests {
int broken_index = (i + 4) % test_vectors.length;
String plain = test_vectors[i][0];
String expected = test_vectors[broken_index][2];
assertFalse(BCrypt.checkpw(plain, expected));
assertThat(BCrypt.checkpw(plain, expected)).isFalse();
print(".");
}
println("");
@@ -170,19 +170,19 @@ public class BCryptTests {
String pw2 = "????????";
String h1 = BCrypt.hashpw(pw1, BCrypt.gensalt());
assertFalse(BCrypt.checkpw(pw2, h1));
assertThat(BCrypt.checkpw(pw2, h1)).isFalse();
print(".");
String h2 = BCrypt.hashpw(pw2, BCrypt.gensalt());
assertFalse(BCrypt.checkpw(pw1, h2));
assertThat(BCrypt.checkpw(pw1, h2)).isFalse();
print(".");
println("");
}
@Test
public void roundsForDoesNotOverflow() {
assertEquals(1024, BCrypt.roundsForLogRounds(10));
assertEquals(0x80000000L, BCrypt.roundsForLogRounds(31));
assertThat(BCrypt.roundsForLogRounds(10)).isEqualTo(1024);
assertThat(BCrypt.roundsForLogRounds(31)).isEqualTo(0x80000000L);
}
@Test(expected = IllegalArgumentException.class)
@@ -209,29 +209,29 @@ public class BCryptTests {
@Test
public void testBase64EncodeSimpleByteArrays() {
assertEquals("..", encode_base64(new byte[] { 0 }, 1));
assertEquals("...", encode_base64(new byte[] { 0, 0 }, 2));
assertEquals("....", encode_base64(new byte[] { 0, 0, 0 }, 3));
assertThat(1)).as("..").isEqualTo(encode_base64(new byte[] { 0 });
assertThat(0 }).as("...").isCloseTo(encode_base64(new byte[] { 0, within(2)));
assertThat(0 }).as("....").isCloseTo(encode_base64(new byte[] { 0, 0, within(3)));
}
@Test
public void decodingCharsOutsideAsciiGivesNoResults() {
byte[] ba = BCrypt.decode_base64("ππππππππ", 1);
assertEquals(0, ba.length);
assertThat(ba.length).isEqualTo(0);
}
@Test
public void decodingStopsWithFirstInvalidCharacter() {
assertEquals(1, BCrypt.decode_base64("....", 1).length);
assertEquals(0, BCrypt.decode_base64(" ....", 1).length);
assertThat(1).length).isEqualTo(1, BCrypt.decode_base64("....");
assertThat(1).length).isEqualTo(0, BCrypt.decode_base64(" ....");
}
@Test
public void decodingOnlyProvidesAvailableBytes() {
assertEquals(0, BCrypt.decode_base64("", 1).length);
assertEquals(3, BCrypt.decode_base64("......", 3).length);
assertEquals(4, BCrypt.decode_base64("......", 4).length);
assertEquals(4, BCrypt.decode_base64("......", 5).length);
assertThat(1).length).isEqualTo(0, BCrypt.decode_base64("");
assertThat(3).length).isEqualTo(3, BCrypt.decode_base64("......");
assertThat(4).length).isEqualTo(4, BCrypt.decode_base64("......");
assertThat(5).length).isEqualTo(4, BCrypt.decode_base64("......");
}
/**
@@ -247,10 +247,10 @@ public class BCryptTests {
ba[i] = (byte) b;
String s = encode_base64(ba, 3);
assertEquals(4, s.length());
assertThat(s.length()).isEqualTo(4);
byte[] decoded = BCrypt.decode_base64(s, 3);
assertArrayEquals(ba, decoded);
assertThat(decoded).isEqualTo(ba);
}
}
}
@@ -267,8 +267,8 @@ public class BCryptTests {
@Test
public void genSaltGeneratesCorrectSaltPrefix() {
assertTrue(BCrypt.gensalt(4).startsWith("$2a$04$"));
assertTrue(BCrypt.gensalt(31).startsWith("$2a$31$"));
assertThat(BCrypt.gensalt(4).startsWith("$2a$04$")).isTrue();
assertThat(BCrypt.gensalt(31).startsWith("$2a$31$")).isTrue();
}
@Test(expected = IllegalArgumentException.class)
@@ -294,12 +294,12 @@ public class BCryptTests {
@Test
public void equalsOnStringsIsCorrect() {
assertTrue(BCrypt.equalsNoEarlyReturn("", ""));
assertTrue(BCrypt.equalsNoEarlyReturn("test", "test"));
assertThat(BCrypt.equalsNoEarlyReturn("", "")).isTrue();
assertThat(BCrypt.equalsNoEarlyReturn("test", "test")).isTrue();
assertFalse(BCrypt.equalsNoEarlyReturn("test", ""));
assertFalse(BCrypt.equalsNoEarlyReturn("", "test"));
assertThat(BCrypt.equalsNoEarlyReturn("test", "")).isFalse();
assertThat(BCrypt.equalsNoEarlyReturn("", "test")).isFalse();
assertFalse(BCrypt.equalsNoEarlyReturn("test", "pass"));
assertThat(BCrypt.equalsNoEarlyReturn("test", "pass")).isFalse();
}
}
@@ -1,6 +1,6 @@
package org.springframework.security.crypto.codec;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.*;
@@ -13,14 +13,14 @@ public class Base64Tests {
public void isBase64ReturnsTrueForValidBase64() {
new Base64(); // unused
assertTrue(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte).isTrue() 'C',
(byte) 'D' }));
}
@Test
public void isBase64ReturnsFalseForInvalidBase64() throws Exception {
// Include invalid '`' character
assertFalse(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte).isFalse() 'C',
(byte) '`' }));
}
@@ -1,6 +1,6 @@
package org.springframework.security.crypto.codec;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.*;
@@ -15,11 +15,11 @@ public class Utf8Tests {
@Test
public void utf8EncodesAndDecodesCorrectly() throws Exception {
byte[] bytes = Utf8.encode("6048b75ed560785c");
assertEquals(16, bytes.length);
assertTrue(Arrays.equals("6048b75ed560785c".getBytes("UTF-8"), bytes));
assertThat(bytes.length).isEqualTo(16);
assertThat(Arrays.equals("6048b75ed560785c".getBytes("UTF-8"), bytes)).isTrue();
String decoded = Utf8.decode(bytes);
assertEquals("6048b75ed560785c", decoded);
assertThat(decoded).isEqualTo("6048b75ed560785c");
}
}
@@ -1,6 +1,6 @@
package org.springframework.security.crypto.encrypt;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -20,10 +20,10 @@ public class EncryptorsTests {
BytesEncryptor encryptor = Encryptors.stronger("password", "5c0744940b5c369b");
byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
assertNotNull(result);
assertFalse(new String(result).equals("text"));
assertEquals("text", new String(encryptor.decrypt(result)));
assertFalse(new String(result).equals(new String(encryptor.encrypt("text"
assertThat(result).isNotNull();
assertThat(new String(result).equals("text")).isFalse();
assertThat(new String(encryptor.decrypt(result))).isEqualTo("text");
assertThat(new String(result).isFalse().equals(new String(encryptor.encrypt("text"
.getBytes()))));
}
@@ -31,10 +31,10 @@ public class EncryptorsTests {
public void standard() throws Exception {
BytesEncryptor encryptor = Encryptors.standard("password", "5c0744940b5c369b");
byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
assertNotNull(result);
assertFalse(new String(result).equals("text"));
assertEquals("text", new String(encryptor.decrypt(result)));
assertFalse(new String(result).equals(new String(encryptor.encrypt("text"
assertThat(result).isNotNull();
assertThat(new String(result).equals("text")).isFalse();
assertThat(new String(encryptor.decrypt(result))).isEqualTo("text");
assertThat(new String(result).isFalse().equals(new String(encryptor.encrypt("text"
.getBytes()))));
}
@@ -44,20 +44,20 @@ public class EncryptorsTests {
TextEncryptor encryptor = Encryptors.delux("password", "5c0744940b5c369b");
String result = encryptor.encrypt("text");
assertNotNull(result);
assertFalse(result.equals("text"));
assertEquals("text", encryptor.decrypt(result));
assertFalse(result.equals(encryptor.encrypt("text")));
assertThat(result).isNotNull();
assertThat(result.equals("text")).isFalse();
assertThat(encryptor.decrypt(result)).isEqualTo("text");
assertThat(result.equals(encryptor.encrypt("text"))).isFalse();
}
@Test
public void text() {
TextEncryptor encryptor = Encryptors.text("password", "5c0744940b5c369b");
String result = encryptor.encrypt("text");
assertNotNull(result);
assertFalse(result.equals("text"));
assertEquals("text", encryptor.decrypt(result));
assertFalse(result.equals(encryptor.encrypt("text")));
assertThat(result).isNotNull();
assertThat(result.equals("text")).isFalse();
assertThat(encryptor.decrypt(result)).isEqualTo("text");
assertThat(result.equals(encryptor.encrypt("text"))).isFalse();
}
@Test
@@ -65,17 +65,17 @@ public class EncryptorsTests {
TextEncryptor encryptor = Encryptors
.queryableText("password", "5c0744940b5c369b");
String result = encryptor.encrypt("text");
assertNotNull(result);
assertFalse(result.equals("text"));
assertEquals("text", encryptor.decrypt(result));
assertTrue(result.equals(encryptor.encrypt("text")));
assertThat(result).isNotNull();
assertThat(result.equals("text")).isFalse();
assertThat(encryptor.decrypt(result)).isEqualTo("text");
assertThat(result.equals(encryptor.encrypt("text"))).isTrue();
}
@Test
public void noOpText() {
TextEncryptor encryptor = Encryptors.noOpText();
assertEquals("text", encryptor.encrypt("text"));
assertEquals("text", encryptor.decrypt("text"));
assertThat(encryptor.encrypt("text")).isEqualTo("text");
assertThat(encryptor.decrypt("text")).isEqualTo("text");
}
private boolean isAesGcmAvailable() {
@@ -1,6 +1,6 @@
package org.springframework.security.crypto.keygen;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
@@ -12,41 +12,41 @@ public class KeyGeneratorsTests {
@Test
public void secureRandom() {
BytesKeyGenerator keyGenerator = KeyGenerators.secureRandom();
assertEquals(8, keyGenerator.getKeyLength());
assertThat(keyGenerator.getKeyLength()).isEqualTo(8);
byte[] key = keyGenerator.generateKey();
assertEquals(8, key.length);
assertThat(key.length).isEqualTo(8);
byte[] key2 = keyGenerator.generateKey();
assertFalse(Arrays.equals(key, key2));
assertThat(Arrays.equals(key, key2)).isFalse();
}
@Test
public void secureRandomCustomLength() {
BytesKeyGenerator keyGenerator = KeyGenerators.secureRandom(21);
assertEquals(21, keyGenerator.getKeyLength());
assertThat(keyGenerator.getKeyLength()).isEqualTo(21);
byte[] key = keyGenerator.generateKey();
assertEquals(21, key.length);
assertThat(key.length).isEqualTo(21);
byte[] key2 = keyGenerator.generateKey();
assertFalse(Arrays.equals(key, key2));
assertThat(Arrays.equals(key, key2)).isFalse();
}
@Test
public void shared() throws Exception {
BytesKeyGenerator keyGenerator = KeyGenerators.shared(21);
assertEquals(21, keyGenerator.getKeyLength());
assertThat(keyGenerator.getKeyLength()).isEqualTo(21);
byte[] key = keyGenerator.generateKey();
assertEquals(21, key.length);
assertThat(key.length).isEqualTo(21);
byte[] key2 = keyGenerator.generateKey();
assertTrue(Arrays.equals(key, key2));
assertThat(Arrays.equals(key, key2)).isTrue();
}
@Test
public void string() {
StringKeyGenerator keyGenerator = KeyGenerators.string();
String hexStringKey = keyGenerator.generateKey();
assertEquals(16, hexStringKey.length());
assertEquals(8, Hex.decode(hexStringKey).length);
assertThat(hexStringKey.length()).isEqualTo(16);
assertThat(Hex.decode(hexStringKey).length).isEqualTo(8);
String hexStringKey2 = keyGenerator.generateKey();
assertFalse(hexStringKey.equals(hexStringKey2));
assertThat(hexStringKey.equals(hexStringKey2)).isFalse();
}
}
@@ -1,6 +1,6 @@
package org.springframework.security.crypto.password;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import java.security.MessageDigest;
@@ -12,20 +12,20 @@ public class StandardPasswordEncoderTests {
@Test
public void matches() {
String result = encoder.encode("password");
assertFalse(result.equals("password"));
assertTrue(encoder.matches("password", result));
assertThat(result.equals("password")).isFalse();
assertThat(encoder.matches("password", result)).isTrue();
}
@Test
public void matchesLengthChecked() {
String result = encoder.encode("password");
assertFalse(encoder.matches("password", result.substring(0, result.length() - 2)));
assertThat(encoder.matches("password", result.substring(0, result.length() - 2))).isFalse();
}
@Test
public void notMatches() {
String result = encoder.encode("password");
assertFalse(encoder.matches("bogus", result));
assertThat(encoder.matches("bogus", result)).isFalse();
}
}
@@ -1,6 +1,6 @@
package org.springframework.security.crypto.util;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
@@ -15,7 +15,7 @@ public class EncodingUtilsTests {
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
String result = new String(Hex.encode(bytes));
assertEquals("01ff414243c0c1c2", result);
assertThat(result).isEqualTo("01ff414243c0c1c2");
}
@Test
@@ -23,7 +23,7 @@ public class EncodingUtilsTests {
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
byte[] result = Hex.decode("01ff414243c0c1c2");
assertTrue(Arrays.equals(bytes, result));
assertThat(Arrays.equals(bytes, result)).isTrue();
}
@Test
@@ -33,7 +33,7 @@ public class EncodingUtilsTests {
byte[] one = new byte[] { (byte) 0x01 };
byte[] two = new byte[] { (byte) 0xFF, (byte) 65, (byte) 66 };
byte[] three = new byte[] { (byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
assertTrue(Arrays.equals(bytes, EncodingUtils.concatenate(one, two, three)));
assertThat(Arrays.equals(bytes, EncodingUtils.concatenate(one, two, three))).isTrue();
}
@Test
@@ -42,8 +42,8 @@ public class EncodingUtilsTests {
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
byte[] two = new byte[] { (byte) 0xFF, (byte) 65, (byte) 66 };
byte[] subArray = EncodingUtils.subArray(bytes, 1, 4);
assertEquals(3, subArray.length);
assertTrue(Arrays.equals(two, subArray));
assertThat(subArray.length).isEqualTo(3);
assertThat(Arrays.equals(two, subArray)).isTrue();
}
}