Skip to content

Commit 63f28a7

Browse files
committed
Merge branch '6.5.x'
2 parents 571bd60 + f988272 commit 63f28a7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

crypto/src/test/java/org/springframework/security/crypto/bcrypt/BCryptPasswordEncoderTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.crypto.bcrypt;
1818

19+
import java.nio.charset.StandardCharsets;
1920
import java.security.SecureRandom;
2021

2122
import org.junit.jupiter.api.BeforeEach;
@@ -25,6 +26,7 @@
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
2728
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
29+
import static org.assertj.core.api.Assertions.assertThatNoException;
2830

2931
/**
3032
* @author Dave Syer
@@ -236,4 +238,23 @@ public void matchesWhenPasswordOverMaxLengthThenAllowToMatch() {
236238
assertThat(getEncoder().matches(password73chars, encodedPassword73chars)).isTrue();
237239
}
238240

241+
/**
242+
* Fixes gh-18133
243+
* @author StringManolo
244+
*/
245+
@Test
246+
void passwordLargerThan72BytesShouldThrowIllegalArgumentException() {
247+
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
248+
String singleByteChars = "a".repeat(68);
249+
String password72Bytes = singleByteChars + "😀";
250+
assertThat(password72Bytes.length()).isEqualTo(70);
251+
assertThat(password72Bytes.getBytes(StandardCharsets.UTF_8).length).isEqualTo(72);
252+
assertThatNoException().isThrownBy(() -> encoder.encode(password72Bytes));
253+
String singleByteCharsTooLong = "a".repeat(69);
254+
String password73Bytes = singleByteCharsTooLong + "😀";
255+
assertThat(password73Bytes.getBytes(StandardCharsets.UTF_8).length).isEqualTo(73);
256+
assertThatIllegalArgumentException().isThrownBy(() -> encoder.encode(password73Bytes))
257+
.withMessageContaining("password cannot be more than 72 bytes");
258+
}
259+
239260
}

0 commit comments

Comments
 (0)