Skip to content

Commit f159452

Browse files
author
Christian Hammers
committed
added test for invalid argument
1 parent 704e046 commit f159452

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

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

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

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
21-
2219
import java.security.NoSuchAlgorithmException;
2320

2421
import org.apache.commons.codec.Charsets;
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertTrue;
2524
import org.junit.Test;
2625

2726
public class UnixCryptTest {
@@ -59,6 +58,16 @@ public void testUnixCryptExplicitCall() {
5958
assertTrue(UnixCrypt.crypt("secret".getBytes(), null).matches("^[a-zA-Z0-9./]{13}$"));
6059
}
6160

61+
/**
62+
* Single character salts are illegal!
63+
* E.g. with glibc 2.13, crypt("secret", "x") = "xxZREZpkHZpkI" but
64+
* crypt("secret", "xx") = "xxWAum7tHdIUw" which makes it unverifyable.
65+
*/
66+
@Test(expected = IllegalArgumentException.class)
67+
public void testUnixCryptWithHalfSalt() {
68+
UnixCrypt.crypt("secret", "x");
69+
}
70+
6271
/**
6372
* Unimplemented "$foo$" salt prefixes would be threated as UnixCrypt salt.
6473
*/

0 commit comments

Comments
 (0)