all basic tests pass!
This commit is contained in:
@@ -9,6 +9,7 @@ import nodash.core.NoCore;
|
||||
import nodash.core.NoDefaultAdapter;
|
||||
import nodash.core.NoRegister;
|
||||
import nodash.exceptions.NoAdapterException;
|
||||
import nodash.exceptions.NoDashFatalException;
|
||||
import nodash.exceptions.NoDashSessionBadUuidException;
|
||||
import nodash.exceptions.NoSessionAlreadyAwaitingConfirmationException;
|
||||
import nodash.exceptions.NoSessionConfirmedException;
|
||||
@@ -18,7 +19,9 @@ import nodash.exceptions.NoSessionNotChangedException;
|
||||
import nodash.exceptions.NoUserAlreadyOnlineException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoUser;
|
||||
import nodash.models.NoSession.NoState;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NoCoreTest {
|
||||
@@ -36,7 +39,7 @@ public class NoCoreTest {
|
||||
NoRegister registration2 = core.register(user2, "password".toCharArray());
|
||||
|
||||
assertFalse(Arrays.equals(registration1.cookie, registration2.cookie));
|
||||
assertFalse(Arrays.equals(registration2.data, registration2.data));
|
||||
assertFalse(Arrays.equals(registration1.data, registration2.data));
|
||||
|
||||
NoUser user3 = new NoUser();
|
||||
try {
|
||||
@@ -64,7 +67,8 @@ public class NoCoreTest {
|
||||
@Test
|
||||
public void testSaveAndConfirm() throws NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException,
|
||||
NoDashSessionBadUuidException, NoUserAlreadyOnlineException, NoSessionNotChangedException, NoSessionAlreadyAwaitingConfirmationException, NoAdapterException {
|
||||
NoDashSessionBadUuidException, NoUserAlreadyOnlineException, NoSessionNotChangedException,
|
||||
NoSessionAlreadyAwaitingConfirmationException, NoAdapterException {
|
||||
NoAdapter adapter = new NoDefaultAdapter();
|
||||
NoCore core = new NoCore(adapter);
|
||||
|
||||
@@ -74,7 +78,7 @@ public class NoCoreTest {
|
||||
core.confirm(registration.cookie, "password".toCharArray(), newUserFile);
|
||||
byte[] newUserHash = newUser.createHash();
|
||||
adapter.checkHash(newUserHash);
|
||||
|
||||
|
||||
NoUser newUserBadPass = new NoUser();
|
||||
registration = core.register(newUserBadPass, "password".toCharArray());
|
||||
byte[] newUserBadPassFile = Arrays.copyOf(registration.data, registration.data.length);
|
||||
@@ -82,27 +86,36 @@ public class NoCoreTest {
|
||||
core.confirm(registration.cookie, "badpassword".toCharArray(), newUserBadPassFile);
|
||||
fail("Confirmed with a bad password without throwing an exception.");
|
||||
} catch (NoUserNotValidException e) {
|
||||
// Do nothing, true
|
||||
// Do nothing, true
|
||||
}
|
||||
|
||||
byte[] badCookie = Arrays.copyOf(registration.cookie, registration.cookie.length);
|
||||
badCookie[0] = (byte) (badCookie[0] == 'A' ? 'B' : 'A');
|
||||
try {
|
||||
core.confirm(badCookie, "password".toCharArray(), newUserBadPassFile);
|
||||
fail("Confirmed on bad cookie without throwing fatal exception.");
|
||||
} catch (NoSessionExpiredException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
|
||||
try {
|
||||
core.confirm(new byte[] {'b', 'a', 'd', 'c', 'o', 'o', 'k', 'i', 'e'}, "password".toCharArray(),
|
||||
newUserBadPassFile);
|
||||
core.confirm(new byte[] {'b', 'a', 'd', 'c', 'o', 'o', 'k', 'i', 'e'},
|
||||
"password".toCharArray(), newUserBadPassFile);
|
||||
fail("Confirmed on bad cookie without throwing exception.");
|
||||
} catch (NoSessionExpiredException e) {
|
||||
} catch (NoDashFatalException e) {
|
||||
// Do nothing, true
|
||||
}
|
||||
|
||||
|
||||
NoUser oldUser = new NoUser();
|
||||
registration = core.register(oldUser, "password".toCharArray());
|
||||
byte[] oldUserFile = Arrays.copyOf(registration.data, registration.data.length);
|
||||
core.confirm(registration.cookie, "password".toCharArray(), oldUserFile);
|
||||
|
||||
|
||||
oldUserFile = Arrays.copyOf(registration.data, registration.data.length);
|
||||
byte[] oldUserCookie = core.login(oldUserFile, "password".toCharArray());
|
||||
assertNotNull(adapter.getNoSession(oldUserCookie));
|
||||
oldUser.createFile("password".toCharArray()); // Touch the randomizer
|
||||
|
||||
|
||||
NoUser oldUserRevisited = core.getNoUser(oldUserCookie);
|
||||
byte[] currentHash = oldUserRevisited.createHash();
|
||||
oldUserRevisited.createFile("password".toCharArray());
|
||||
@@ -121,18 +134,79 @@ public class NoCoreTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetUser() {
|
||||
fail("Not yet implemented");
|
||||
public void testGetUser() throws NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException,
|
||||
NoUserAlreadyOnlineException {
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
NoUser user = new NoUser();
|
||||
NoRegister registration = core.register(user, "password".toCharArray());
|
||||
byte[] file = Arrays.copyOf(registration.data, registration.data.length);
|
||||
core.confirm(registration.cookie, "password".toCharArray(), file);
|
||||
|
||||
file = Arrays.copyOf(registration.data, registration.data.length);
|
||||
byte[] cookie = core.login(file, "password".toCharArray());
|
||||
byte[] badCookie = Arrays.copyOf(cookie, cookie.length);
|
||||
badCookie[0] = (byte) (badCookie[0] == 'A' ? 'B' : 'A');
|
||||
NoUser user2 = core.getNoUser(cookie);
|
||||
assertNotNull(user2);
|
||||
assertEquals(user, user2);
|
||||
|
||||
try {
|
||||
core.getNoUser(badCookie);
|
||||
fail("Did not fail when given a bad cookie.");
|
||||
} catch (NoSessionExpiredException e) {
|
||||
// Correct, do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSessionState() {
|
||||
fail("Not yet implemented");
|
||||
public void testGetSessionState() throws NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException,
|
||||
NoUserAlreadyOnlineException, NoSessionNotChangedException, NoSessionAlreadyAwaitingConfirmationException {
|
||||
NoCore core = new NoCore(new NoDefaultAdapter());
|
||||
NoUser user = new NoUser();
|
||||
NoRegister registration = core.register(user, "password".toCharArray());
|
||||
assertEquals(core.getSessionState(registration.cookie), NoState.AWAITING_CONFIRMATION);
|
||||
byte[] file = Arrays.copyOf(registration.data, registration.data.length);
|
||||
core.confirm(registration.cookie, "password".toCharArray(), file);
|
||||
|
||||
file = Arrays.copyOf(registration.data, registration.data.length);
|
||||
byte[] cookie = core.login(file, "password".toCharArray());
|
||||
assertEquals(core.getSessionState(cookie), NoState.IDLE);
|
||||
user = core.getNoUser(cookie);
|
||||
user.createFile("password".toCharArray()); // touch randomizer
|
||||
assertEquals(core.getSessionState(cookie), NoState.MODIFIED);
|
||||
|
||||
file = core.save(cookie, "password".toCharArray());
|
||||
assertEquals(core.getSessionState(cookie), NoState.AWAITING_CONFIRMATION);
|
||||
|
||||
core.confirm(cookie, "password".toCharArray(), file);
|
||||
try {
|
||||
core.getSessionState(cookie);
|
||||
fail("Didn't fail on getting session after confirm.");
|
||||
} catch (NoSessionExpiredException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShred() {
|
||||
fail("Not yet implemented");
|
||||
public void testShred() throws NoAdapterException, NoSessionConfirmedException, NoSessionExpiredException {
|
||||
NoAdapter adapter = new NoDefaultAdapter();
|
||||
NoCore core = new NoCore(adapter);
|
||||
NoUser user = new NoUser();
|
||||
NoRegister registration = core.register(user, "password".toCharArray());
|
||||
assertTrue(adapter.isOnline(user.createHash()));
|
||||
assertEquals(core.getSessionState(registration.cookie), NoState.AWAITING_CONFIRMATION);
|
||||
|
||||
core.shred(registration.cookie);
|
||||
|
||||
assertFalse(adapter.isOnline(user.createHash()));
|
||||
try {
|
||||
core.getNoUser(registration.cookie);
|
||||
fail("Returned a user object after shredding.");
|
||||
} catch (NoSessionExpiredException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
11
src/nodash/test/NoDashBasicTests.java
Normal file
11
src/nodash/test/NoDashBasicTests.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package nodash.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({NoCoreTest.class, NoSessionTest.class, NoUserTest.class, NoUtilTest.class})
|
||||
public class NoDashBasicTests {
|
||||
|
||||
}
|
||||
@@ -1,65 +1,71 @@
|
||||
package nodash.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import nodash.exceptions.NoSessionConfirmedException;
|
||||
import nodash.exceptions.NoSessionExpiredException;
|
||||
import nodash.exceptions.NoUserNotValidException;
|
||||
import nodash.models.NoSession;
|
||||
import nodash.models.NoSession.NoState;
|
||||
import nodash.models.NoUser;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class NoSessionTest {
|
||||
|
||||
@Test
|
||||
public void testNoSession() throws NoSessionConfirmedException, NoSessionExpiredException {
|
||||
NoSession session = new NoSession();
|
||||
public void testNoSessionNoUser() throws NoSessionConfirmedException, NoSessionExpiredException {
|
||||
NoUser user = new NoUser();
|
||||
NoSession session = new NoSession(user);
|
||||
assertNotNull(session.getNoUser());
|
||||
assertNotNull(session.getUuid());
|
||||
assertNull(session.getNoUser());
|
||||
assertNotNull(session.getEncryptedUuid());
|
||||
assertNull(session.getIncoming());
|
||||
assertNull(session.getOriginalHash());
|
||||
assertEquals(session.getNoUser(), user);
|
||||
assertEquals(session.getNoState(), NoState.MODIFIED);
|
||||
|
||||
try {
|
||||
new NoSession(null);
|
||||
fail("Did not throw NullPointerException when given a null user.");
|
||||
} catch (NullPointerException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSessionNoUser() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSessionByteArrayCharArray() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheck() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTouchState() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitiateSaveAttempt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfirmSave() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptUuid() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsume() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClose() {
|
||||
fail("Not yet implemented");
|
||||
public void testNoSessionByteArrayCharArray() throws NoUserNotValidException,
|
||||
NoSessionExpiredException, NoSessionConfirmedException {
|
||||
NoUser user = new NoUser();
|
||||
final byte[] userFile1 = user.createFile("password".toCharArray());
|
||||
byte[] userFile2 = Arrays.copyOf(userFile1, userFile1.length);
|
||||
char[] userPassword = "password".toCharArray();
|
||||
NoSession session = new NoSession(userFile2, userPassword);
|
||||
assertFalse(Arrays.equals(userFile1, userFile2));
|
||||
assertFalse(Arrays.equals("password".toCharArray(), userPassword));
|
||||
assertNotNull(session.getNoUser());
|
||||
assertNotNull(session.getOriginalHash());
|
||||
assertNotNull(session.getUuid());
|
||||
assertNull(session.getIncoming());
|
||||
assertEquals(session.getNoUser(), user);
|
||||
assertEquals(session.getNoState(), NoState.IDLE);
|
||||
|
||||
byte[] badUserFile = Arrays.copyOf(userFile1, userFile1.length);
|
||||
badUserFile[0] = (byte) (badUserFile[0] == 'A' ? 'B' : 'A');
|
||||
try {
|
||||
new NoSession(badUserFile, "password".toCharArray());
|
||||
fail("Did not throw NoUserNotValidException when given bad file.");
|
||||
} catch (NoUserNotValidException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
|
||||
try {
|
||||
new NoSession(Arrays.copyOf(userFile2, userFile2.length), "badpassword".toCharArray());
|
||||
fail("Did not throw NoUserNotValidException when given bad password.");
|
||||
} catch (NoUserNotValidException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class NoUserTest {
|
||||
byte[] hash = user.createHash();
|
||||
String hashString = user.createHashString();
|
||||
|
||||
assertEquals(Base64.encodeBase64String(hash), hashString);
|
||||
assertEquals(Base64.encodeBase64URLSafeString(hash), hashString);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user