mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 01:27:35 +01:00
Merge pull request #138 from AuthMe-Team/565-skip-long-hash-tests
#565 Allow to skip extended encryption methods
This commit is contained in:
commit
ee23f7242b
15
pom.xml
15
pom.xml
@ -56,6 +56,7 @@
|
||||
<!-- Output properties -->
|
||||
<project.outputName>AuthMe</project.outputName>
|
||||
<project.buildNumber>CUSTOM</project.buildNumber>
|
||||
<project.skipExtendedHashTests>false</project.skipExtendedHashTests>
|
||||
<project.versionCode>${project.version}-b${project.buildNumber}</project.versionCode>
|
||||
<project.finalName>${project.outputName}-${project.version}</project.finalName>
|
||||
|
||||
@ -81,6 +82,17 @@
|
||||
<project.buildNumber>${env.BUILD_NUMBER}</project.buildNumber>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>skipLongHashTests</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>skipLongHashTests</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<project.skipExtendedHashTests>true</project.skipExtendedHashTests>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
@ -124,6 +136,9 @@
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<argLine>-Dfile.encoding=${project.build.sourceEncoding} @{argLine}</argLine>
|
||||
<systemPropertyVariables>
|
||||
<project.skipExtendedHashTests>${project.skipExtendedHashTests}</project.skipExtendedHashTests>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Libs Shading and Relocation -->
|
||||
|
@ -12,6 +12,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
|
||||
/**
|
||||
* Test for implementations of {@link EncryptionMethod}.
|
||||
@ -36,6 +37,14 @@ public abstract class AbstractEncryptionMethodTest {
|
||||
"asdfg:hjkl", "::test", "~#$#~~~#$#~", "d41d8cd98f00b204e9800998ecf427e",
|
||||
"$2y$7a$da641e404b982ed" };
|
||||
|
||||
/**
|
||||
* Certain hash algorithms are slow by design, which has a considerable effect on these unit tests.
|
||||
* Setting the property below to "true" will reduce the checks in these unit tests as to offer fast,
|
||||
* partial tests during development.
|
||||
*/
|
||||
private static final boolean SKIP_LONG_TESTS =
|
||||
"true".equals(System.getProperty("project.skipExtendedHashTests"));
|
||||
|
||||
/** The encryption method to test. */
|
||||
private EncryptionMethod method;
|
||||
/** Map with the hashes against which the entries in GIVEN_PASSWORDS are tested. */
|
||||
@ -79,8 +88,10 @@ public abstract class AbstractEncryptionMethodTest {
|
||||
|
||||
@Test
|
||||
public void testGivenPasswords() {
|
||||
// Test all entries in GIVEN_PASSWORDS except the last one
|
||||
for (int i = 0; i < GIVEN_PASSWORDS.length - 1; ++i) {
|
||||
// Start with the 2nd to last password if we skip long tests
|
||||
int start = SKIP_LONG_TESTS ? GIVEN_PASSWORDS.length - 2 : 0;
|
||||
// Test entries in GIVEN_PASSWORDS except the last one
|
||||
for (int i = start; i < GIVEN_PASSWORDS.length - 1; ++i) {
|
||||
String password = GIVEN_PASSWORDS[i];
|
||||
assertTrue("Hash for password '" + password + "' should match",
|
||||
doesGivenHashMatch(password, method));
|
||||
@ -124,12 +135,14 @@ public abstract class AbstractEncryptionMethodTest {
|
||||
assertFalse("Upper-case of '" + password + "' should not match generated hash '" + hash + "'",
|
||||
method.comparePassword(password.toUpperCase(), hashedPassword, USERNAME));
|
||||
}
|
||||
assumeThat(SKIP_LONG_TESTS, equalTo(false));
|
||||
}
|
||||
}
|
||||
|
||||
/** Tests various strings to ensure that encryption methods don't rely on the hash's format too much. */
|
||||
@Test
|
||||
public void testMalformedHashes() {
|
||||
assumeThat(SKIP_LONG_TESTS, equalTo(false));
|
||||
String salt = method.hasSeparateSalt() ? "testSalt" : null;
|
||||
for (String bogusHash : BOGUS_HASHES) {
|
||||
HashedPassword hashedPwd = new HashedPassword(bogusHash, salt);
|
||||
|
Loading…
Reference in New Issue
Block a user