Use RandomString for IPB4 implementation; minor documentation
- Improve RandomString and create new generateLowerUpper method - Add documentation to the IPB4 class to explain why the salt is stored twice
This commit is contained in:
@@ -44,6 +44,22 @@ public class RandomStringTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateRandomLowerUpperString() {
|
||||
// given
|
||||
int[] lengths = {0, 1, 17, 143, 1808};
|
||||
Pattern badChars = Pattern.compile(".*[^0-9a-zA-Z].*");
|
||||
|
||||
// when / then
|
||||
for (int length : lengths) {
|
||||
String result = RandomString.generateHex(length);
|
||||
assertThat("Result '" + result + "' should have length " + length,
|
||||
result.length(), equalTo(length));
|
||||
assertThat("Result '" + result + "' should only have characters a-z, A-Z, 0-9",
|
||||
badChars.matcher(result).matches(), equalTo(false));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowForInvalidLength() {
|
||||
// given/when
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.ConsoleLoggerTestInitializer;
|
||||
import fr.xephi.authme.util.WrapperMock;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Test for {@link IPB4}.
|
||||
*/
|
||||
public class IPB4Test extends AbstractEncryptionMethodTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpSettings() {
|
||||
WrapperMock.createInstance();
|
||||
ConsoleLoggerTestInitializer.setupLogger();
|
||||
}
|
||||
|
||||
public IPB4Test() {
|
||||
|
||||
Reference in New Issue
Block a user