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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user