Convert to assertj
Fixes gh-3175
This commit is contained in:
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.security.crypto.bcrypt;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -209,9 +209,9 @@ public class BCryptTests {
|
||||
|
||||
@Test
|
||||
public void testBase64EncodeSimpleByteArrays() {
|
||||
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)));
|
||||
assertThat(encode_base64(new byte[] { 0 }, 1)).isEqualTo("..");
|
||||
assertThat(encode_base64(new byte[] { 0, 0 }, 2)).isEqualTo("...");
|
||||
assertThat(encode_base64(new byte[] { 0, 0 , 0 }, 3)).isEqualTo("....");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -222,16 +222,16 @@ public class BCryptTests {
|
||||
|
||||
@Test
|
||||
public void decodingStopsWithFirstInvalidCharacter() {
|
||||
assertThat(1).length).isEqualTo(1, BCrypt.decode_base64("....");
|
||||
assertThat(1).length).isEqualTo(0, BCrypt.decode_base64(" ....");
|
||||
assertThat(BCrypt.decode_base64("....", 1).length).isEqualTo(1);
|
||||
assertThat(BCrypt.decode_base64(" ....", 1).length).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodingOnlyProvidesAvailableBytes() {
|
||||
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("......");
|
||||
assertThat(BCrypt.decode_base64("", 1).length).isEqualTo(0);
|
||||
assertThat(BCrypt.decode_base64("......", 3).length).isEqualTo(3);
|
||||
assertThat(BCrypt.decode_base64("......", 4).length).isEqualTo(4);
|
||||
assertThat(BCrypt.decode_base64("......", 5).length).isEqualTo(4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,8 +288,8 @@ public class BCryptTests {
|
||||
|
||||
@Test
|
||||
public void hashpwWorksWithOldRevision() {
|
||||
assertEquals("$2$05$......................bvpG2UfzdyW/S0ny/4YyEZrmczoJfVm",
|
||||
BCrypt.hashpw("password", "$2$05$......................"));
|
||||
assertThat(BCrypt.hashpw("password", "$2$05$......................")).isEqualTo(
|
||||
"$2$05$......................bvpG2UfzdyW/S0ny/4YyEZrmczoJfVm");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -13,15 +13,15 @@ public class Base64Tests {
|
||||
public void isBase64ReturnsTrueForValidBase64() {
|
||||
new Base64(); // unused
|
||||
|
||||
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte).isTrue() 'C',
|
||||
(byte) 'D' }));
|
||||
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
|
||||
(byte) 'D' })).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isBase64ReturnsFalseForInvalidBase64() throws Exception {
|
||||
// Include invalid '`' character
|
||||
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte).isFalse() 'C',
|
||||
(byte) '`' }));
|
||||
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
|
||||
(byte) '`' })).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
|
||||
package org.springframework.security.crypto.encrypt;
|
||||
|
||||
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;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
@@ -23,8 +21,8 @@ public class EncryptorsTests {
|
||||
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()))));
|
||||
assertThat(new String(result)).isNotEqualTo(
|
||||
new String(encryptor.encrypt("text".getBytes())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,8 +32,8 @@ public class EncryptorsTests {
|
||||
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()))));
|
||||
assertThat(new String(result)).isNotEqualTo(
|
||||
new String(encryptor.encrypt("text".getBytes())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,8 +60,8 @@ public class EncryptorsTests {
|
||||
|
||||
@Test
|
||||
public void queryableText() {
|
||||
TextEncryptor encryptor = Encryptors
|
||||
.queryableText("password", "5c0744940b5c369b");
|
||||
TextEncryptor encryptor = Encryptors.queryableText("password",
|
||||
"5c0744940b5c369b");
|
||||
String result = encryptor.encrypt("text");
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.equals("text")).isFalse();
|
||||
@@ -82,7 +80,8 @@ public class EncryptorsTests {
|
||||
try {
|
||||
Cipher.getInstance("AES/GCM/NoPadding");
|
||||
return true;
|
||||
} catch (GeneralSecurityException e) {
|
||||
}
|
||||
catch (GeneralSecurityException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package org.springframework.security.crypto.password;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.crypto.codec.Hex;
|
||||
@@ -18,8 +14,7 @@ public class DigesterTests {
|
||||
Digester digester = new Digester("SHA-1", 3);
|
||||
byte[] result = digester.digest(Utf8.encode("text"));
|
||||
// echo -n text | openssl sha1 -binary | openssl sha1 -binary | openssl sha1
|
||||
assertEquals("3cfa28da425eca5b894f0af2b158adf7001e000f",
|
||||
new String(Hex.encode(result)));
|
||||
assertThat(new String(Hex.encode(result))).isEqualTo("3cfa28da425eca5b894f0af2b158adf7001e000f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.springframework.security.crypto.password;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -12,7 +11,7 @@ public class StandardPasswordEncoderTests {
|
||||
@Test
|
||||
public void matches() {
|
||||
String result = encoder.encode("password");
|
||||
assertThat(result.equals("password")).isFalse();
|
||||
assertThat(result).isNotEqualTo("password");
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
package org.springframework.security.crypto.util;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class EncodingUtilsTests {
|
||||
@Test
|
||||
public void hexEncode() {
|
||||
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
String result = new String(Hex.encode(bytes));
|
||||
assertThat(result).isEqualTo("01ff414243c0c1c2");
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class EncodingUtilsTests {
|
||||
@Test
|
||||
public void hexDecode() {
|
||||
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
byte[] result = Hex.decode("01ff414243c0c1c2");
|
||||
assertThat(Arrays.equals(bytes, result)).isTrue();
|
||||
}
|
||||
@@ -29,17 +29,18 @@ public class EncodingUtilsTests {
|
||||
@Test
|
||||
public void concatenate() {
|
||||
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
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 };
|
||||
assertThat(Arrays.equals(bytes, EncodingUtils.concatenate(one, two, three))).isTrue();
|
||||
assertThat(Arrays.equals(bytes,
|
||||
EncodingUtils.concatenate(one, two, three))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subArray() {
|
||||
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
|
||||
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
|
||||
(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);
|
||||
assertThat(subArray.length).isEqualTo(3);
|
||||
|
||||
Reference in New Issue
Block a user