diff --git a/src/nodash/models/NoUser.java b/src/nodash/models/NoUser.java index 3a4179e..4ed6511 100644 --- a/src/nodash/models/NoUser.java +++ b/src/nodash/models/NoUser.java @@ -41,8 +41,6 @@ import javax.crypto.IllegalBlockSizeException; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; -import org.apache.commons.codec.binary.Base64; - import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -53,7 +51,7 @@ import nodash.exceptions.NoByteSetBadDecryptionException; import nodash.exceptions.NoDashFatalException; import nodash.exceptions.NoUserNotValidException; -public class NoUser implements Serializable { +public abstract class NoUser implements Serializable { private static final long serialVersionUID = 7132405837081692211L; @NoHash private RSAPublicKeyImpl publicKey; @@ -244,8 +242,8 @@ public class NoUser implements Serializable { } } - public String createHashString() { - return Base64.encodeBase64URLSafeString(createHash()); + public final String createHashString() { + return NoUtil.fromBytes(createHash()); } @Override @@ -258,8 +256,7 @@ public class NoUser implements Serializable { return false; } - return this.privateKey.getModulus().equals(((NoUser) otherUser).privateKey.getModulus()); + return privateKey.getModulus().equals(((NoUser) otherUser).privateKey.getModulus()); } - } diff --git a/src/nodash/test/NoCoreTest.java b/src/nodash/test/NoCoreTest.java index 65a099e..b7ddd94 100644 --- a/src/nodash/test/NoCoreTest.java +++ b/src/nodash/test/NoCoreTest.java @@ -38,6 +38,7 @@ import nodash.exceptions.NoUserAlreadyOnlineException; import nodash.exceptions.NoUserNotValidException; import nodash.models.NoRegister; import nodash.models.NoUser; +import nodash.test.functional.implementations.TestNoUser; import nodash.models.NoSession.NoState; import org.junit.Test; @@ -48,18 +49,18 @@ public class NoCoreTest { public void testRegister() { NoCore core = new NoCore(new NoDefaultAdapter()); - NoUser user1 = new NoUser(); + NoUser user1 = new TestNoUser("Test"); NoRegister registration1 = core.register(user1, "password".toCharArray()); assertNotNull(registration1.cookie); assertNotNull(registration1.data); - NoUser user2 = new NoUser(); + NoUser user2 = new TestNoUser("Test"); NoRegister registration2 = core.register(user2, "password".toCharArray()); assertFalse(Arrays.equals(registration1.cookie, registration2.cookie)); assertFalse(Arrays.equals(registration1.data, registration2.data)); - NoUser user3 = new NoUser(); + NoUser user3 = new TestNoUser("Test"); try { core.register(null, "password".toCharArray()); fail("Did not throw NullPointerException."); @@ -91,14 +92,14 @@ public class NoCoreTest { NoAdapter adapter = new NoDefaultAdapter(); NoCore core = new NoCore(adapter); - NoUser newUser = new NoUser(); + NoUser newUser = new TestNoUser("Test"); NoRegister registration = core.register(newUser, "password".toCharArray()); byte[] newUserFile = Arrays.copyOf(registration.data, registration.data.length); core.confirm(registration.cookie, "password".toCharArray(), newUserFile); byte[] newUserHash = newUser.createHash(); adapter.checkHash(newUserHash); - NoUser newUserBadPass = new NoUser(); + NoUser newUserBadPass = new TestNoUser("Test"); registration = core.register(newUserBadPass, "password".toCharArray()); byte[] newUserBadPassFile = Arrays.copyOf(registration.data, registration.data.length); try { @@ -125,7 +126,7 @@ public class NoCoreTest { // Do nothing, true } - NoUser oldUser = new NoUser(); + NoUser oldUser = new TestNoUser("Test"); registration = core.register(oldUser, "password".toCharArray()); byte[] oldUserFile = Arrays.copyOf(registration.data, registration.data.length); core.confirm(registration.cookie, "password".toCharArray(), oldUserFile); @@ -162,7 +163,7 @@ public class NoCoreTest { NoSessionNotAwaitingConfirmationException, NoUserNotValidException, NoUserAlreadyOnlineException { NoCore core = new NoCore(new NoDefaultAdapter()); - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); NoRegister registration = core.register(user, "password".toCharArray()); byte[] file = Arrays.copyOf(registration.data, registration.data.length); core.confirm(registration.cookie, "password".toCharArray(), file); @@ -188,7 +189,7 @@ public class NoCoreTest { NoSessionNotAwaitingConfirmationException, NoUserNotValidException, NoUserAlreadyOnlineException, NoSessionNotChangedException, NoSessionAlreadyAwaitingConfirmationException { NoCore core = new NoCore(new NoDefaultAdapter()); - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); NoRegister registration = core.register(user, "password".toCharArray()); assertEquals(core.getSessionState(registration.cookie), NoState.AWAITING_CONFIRMATION); byte[] file = Arrays.copyOf(registration.data, registration.data.length); @@ -217,7 +218,7 @@ public class NoCoreTest { public void testShred() throws NoAdapterException, NoSessionConfirmedException, NoSessionExpiredException { NoAdapter adapter = new NoDefaultAdapter(); NoCore core = new NoCore(adapter); - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); NoRegister registration = core.register(user, "password".toCharArray()); assertTrue(adapter.isOnline(user.createHash())); assertEquals(core.getSessionState(registration.cookie), NoState.AWAITING_CONFIRMATION); diff --git a/src/nodash/test/NoSessionTest.java b/src/nodash/test/NoSessionTest.java index 9602fd2..c427665 100644 --- a/src/nodash/test/NoSessionTest.java +++ b/src/nodash/test/NoSessionTest.java @@ -27,6 +27,7 @@ import nodash.exceptions.NoUserNotValidException; import nodash.models.NoSession; import nodash.models.NoSession.NoState; import nodash.models.NoUser; +import nodash.test.functional.implementations.TestNoUser; import org.junit.Test; @@ -34,7 +35,7 @@ public class NoSessionTest { @Test public void testNoSessionNoUser() throws NoSessionConfirmedException, NoSessionExpiredException { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); NoSession session = new NoSession(user); assertNotNull(session.getNoUser()); assertNotNull(session.getUuid()); @@ -54,7 +55,7 @@ public class NoSessionTest { @Test public void testNoSessionByteArrayCharArray() throws NoUserNotValidException, NoSessionExpiredException, NoSessionConfirmedException { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); final byte[] userFile1 = user.createFile("password".toCharArray()); byte[] userFile2 = Arrays.copyOf(userFile1, userFile1.length); char[] userPassword = "password".toCharArray(); diff --git a/src/nodash/test/NoUserTest.java b/src/nodash/test/NoUserTest.java index 7df4d46..a335b1a 100644 --- a/src/nodash/test/NoUserTest.java +++ b/src/nodash/test/NoUserTest.java @@ -28,15 +28,15 @@ import javax.crypto.IllegalBlockSizeException; import nodash.core.NoUtil; import nodash.exceptions.NoUserNotValidException; import nodash.models.NoUser; +import nodash.test.functional.implementations.TestNoUser; -import org.apache.commons.codec.binary.Base64; import org.junit.Test; public class NoUserTest { @Test public void testNoUser() { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); assertNotNull(user.getNoActions()); assertEquals(user.getNoActions().size(), 0); @@ -48,7 +48,7 @@ public class NoUserTest { @Test public void testCreateFile() { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); byte[] file = user.createFile("password".toCharArray()); assertNotNull(file); @@ -61,7 +61,7 @@ public class NoUserTest { @Test public void testCreateHash() { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); byte[] hash = user.createHash(); assertNotNull(hash); @@ -74,18 +74,18 @@ public class NoUserTest { @Test public void testCreateHashString() { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); byte[] hash = user.createHash(); String hashString = user.createHashString(); - assertEquals(Base64.encodeBase64URLSafeString(hash), hashString); + assertEquals(NoUtil.fromBytes(hash), hashString); } @Test public void testCreateUserFromFile() throws IllegalBlockSizeException, BadPaddingException, ClassNotFoundException, IOException, NoUserNotValidException { - NoUser user = new NoUser(); + NoUser user = new TestNoUser("Test"); final byte[] originalFile = user.createFile("password".toCharArray()); byte[] file = Arrays.copyOf(originalFile, originalFile.length); byte[] hash = user.createHash();