Skip to content

Commit 9470956

Browse files
committed
Assert current behavior
1 parent 572e020 commit 9470956

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
*/
1717
package org.apache.commons.codec.digest;
1818

19+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertNotNull;
2122
import static org.junit.jupiter.api.Assertions.assertThrows;
2223
import static org.junit.jupiter.api.Assertions.assertTrue;
2324

2425
import java.nio.charset.StandardCharsets;
26+
import java.util.Arrays;
2527
import java.util.concurrent.ThreadLocalRandom;
2628

2729
import org.junit.jupiter.api.Test;
@@ -83,4 +85,14 @@ public void testMd5CryptNullData() {
8385
public void testMd5CryptWithEmptySalt() {
8486
assertThrows(IllegalArgumentException.class, () -> Md5Crypt.md5Crypt("secret".getBytes(), ""));
8587
}
88+
89+
@Test
90+
public void testZeroOutInput() {
91+
final byte[] buffer = new byte[200];
92+
Arrays.fill(buffer, (byte) 'A');
93+
Md5Crypt.md5Crypt(buffer);
94+
// input password is 0-filled on return
95+
assertArrayEquals(new byte[buffer.length], buffer);
96+
}
97+
8698
}

src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,14 @@ public void testSha256LargestThanBlocksize() {
9393
// input password is 0-filled on return
9494
assertArrayEquals(new byte[buffer.length], buffer);
9595
}
96+
97+
@Test
98+
public void testZeroOutInput() {
99+
final byte[] buffer = new byte[200];
100+
Arrays.fill(buffer, (byte) 'A');
101+
Sha2Crypt.sha256Crypt(buffer);
102+
// input password is 0-filled on return
103+
assertArrayEquals(new byte[buffer.length], buffer);
104+
}
105+
96106
}

src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,14 @@ public void testSha256LargetThanBlocksize() {
102102
// input password is 0-filled on return
103103
assertArrayEquals(new byte[buffer.length], buffer);
104104
}
105+
106+
@Test
107+
public void testZeroOutInput() {
108+
final byte[] buffer = new byte[200];
109+
Arrays.fill(buffer, (byte) 'A');
110+
Sha2Crypt.sha512Crypt(buffer);
111+
// input password is 0-filled on return
112+
assertArrayEquals(new byte[buffer.length], buffer);
113+
}
114+
105115
}

0 commit comments

Comments
 (0)