#364 Add tests for more encryption algorithms

This commit is contained in:
ljacqu 2015-12-20 14:08:22 +01:00
parent acfc4dba3e
commit 51d1705b1f
5 changed files with 89 additions and 7 deletions

View File

@ -66,17 +66,28 @@ public abstract class AbstractEncryptionMethodTest {
} }
} }
static void generateHashes(EncryptionMethod method) { // @org.junit.Test public void a() { AbstractEncryptionMethodTest.generateTest(); }
System.out.println("AbstractEncryptionMethodTest.testGivenPasswords(method,"); // TODO #364: Remove this method
static void generateTest(EncryptionMethod method) {
String className = method.getClass().getSimpleName();
System.out.println("public class " + className + "Test extends AbstractEncryptionMethodTest {");
System.out.println("\tpublic " + className + "Test() {");
System.out.println("\t\tsuper(new " + className + "(),");
String delim = ", ";
for (String password : GIVEN_PASSWORDS) { for (String password : GIVEN_PASSWORDS) {
if (password.equals(GIVEN_PASSWORDS[GIVEN_PASSWORDS.length - 1])) {
delim = "); ";
}
try { try {
System.out.println("\t\"" + method.getHash(password, getSalt(method), "USERNAME") System.out.println("\t\t\"" + method.getHash(password, getSalt(method), "USERNAME")
+ "\", // " + password); + "\"" + delim + "// " + password);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Could not generate hash", e); throw new RuntimeException("Could not generate hash", e);
} }
} }
System.out.println(");"); System.out.println("\t}");
System.out.println("}");
} }
// TODO #358: Remove this method and use the new salt method on the interface // TODO #358: Remove this method and use the new salt method on the interface
@ -84,12 +95,16 @@ public abstract class AbstractEncryptionMethodTest {
try { try {
if (method instanceof BCRYPT) { if (method instanceof BCRYPT) {
return BCRYPT.gensalt(); return BCRYPT.gensalt();
} else if (method instanceof MD5) { } else if (method instanceof MD5 || method instanceof WORDPRESS) {
return ""; return "";
} else if (method instanceof JOOMLA) { } else if (method instanceof JOOMLA) {
return PasswordSecurity.createSalt(32); return PasswordSecurity.createSalt(32);
} else if (method instanceof SHA256) { } else if (method instanceof SHA256 || method instanceof PHPBB) {
return PasswordSecurity.createSalt(16); return PasswordSecurity.createSalt(16);
} else if (method instanceof WBB3) {
return PasswordSecurity.createSalt(40);
} else if (method instanceof XAUTH) {
return PasswordSecurity.createSalt(12);
} }
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -0,0 +1,16 @@
package fr.xephi.authme.security.crypts;
/**
* Test for {@link PHPBB}.
*/
public class PHPBBTest extends AbstractEncryptionMethodTest {
public PHPBBTest() {
super(new PHPBB(),
"$H$7MaSGQb0xe3Fp/a.Q.Ewpw.UKfCv.t0", // password
"$H$7ESfAVjzqajC7fJFcZKZIhyds41MuW.", // PassWord1
"$H$7G65SXRPbR69jLg.qZTjtqsw36Ciw7.", // &^%te$t?Pw@_
"$H$7Brcg8zO9amr2SHVgz.pFxprDu40v4/"); // âË_3(íù*
}
}

View File

@ -0,0 +1,20 @@
package fr.xephi.authme.security.crypts;
import org.junit.Ignore;
/**
* Test for {@link WBB3}.
*/
@Ignore
// TODO #364 ljacqu 20151220: Unignore test after fixing closely coupled DB dependency
public class WBB3Test extends AbstractEncryptionMethodTest {
public WBB3Test() {
super(new WBB3(),
"ca426c4d20a82cd24c7bb07d94d69f3757e3d07d", // password
"72d59d27674a3cace2600ff152ba8b46274e27e9", // PassWord1
"23daf26602e52591156968a14c2a6592b5be4743", // &^%te$t?Pw@_
"d3908efe4a15314066391dd8572883c70b16fd8a"); // âË_3(íù*
}
}

View File

@ -0,0 +1,15 @@
package fr.xephi.authme.security.crypts;
/**
* Test for {@link WORDPRESS}.
*/
public class WORDPRESSTest extends AbstractEncryptionMethodTest {
public WORDPRESSTest() {
super(new WORDPRESS(),
"$P$B9wyjxuU4yrfjnnHNGSzH9ti9CC0Os1", // password
"$P$BjzPjjzPjjkRzvGGRTyYu0sNqcz6Ci0", // PassWord1
"$P$BjzPjjzPjrAOyB1V0WFdpisgCTFx.N/", // &^%te$t?Pw@_
"$P$BjzPjxxyjp2QdKcab/oTW8l/W0AgE21"); // âË_3(íù*
}
}

View File

@ -0,0 +1,16 @@
package fr.xephi.authme.security.crypts;
/**
* Test for {@link XAUTH}.
*/
public class XAUTHTest extends AbstractEncryptionMethodTest {
public XAUTHTest() {
super(new XAUTH(),
"e54d4916577410d26d2f6e9362445463dab9ffdff9a67ed3b74d3f2312bc8fab84f653fcb88ad8338793ef8a6d0a1162105e46ec24f0dcb52355c634e3e6439f45444b09c715", // password
"d54489a4fd4732ee03d56810ab92944096e3d49335266adeecfbc12567abb3ff744761b33a1fcc4d04739e377775c788e4baace3caf35c7b9176b82b1fe3472e4cbdc5a43214", // PassWord1
"ce6404c1092fb5abf0a72f9c4327bfe8f4cdc4b8dc90ee6ca35c42b8ae9481b89c2559bb60b99ff2b57a102cfced40b8e2f5ef481400c9e6f79445017fc763b1cc27f4c2df36", // &^%te$t?Pw@_
"73074fe3f5503677ab9c5a1885b46a8b6fb249453317da08d86312c20e7b326e84f615e1b594c71129d2d1020400a89838e44653dc02d1799886e522a2789fbe1df6e70b7ffb"); // âË_3(íù*
}
}