massive changes

- Changed NoCore to a non-static object
- Cut out all spheres in favour of a NoAdapter interface
- Added basic NoDefaultAdapter object, should be overridden in prod uses
This commit is contained in:
Dave
2015-07-03 22:44:08 +02:00
parent 1e543bafc1
commit c0b2c1c82d
18 changed files with 732 additions and 693 deletions

View File

@@ -0,0 +1,142 @@
package nodash.test;
import static org.junit.Assert.*;
import java.util.Arrays;
import nodash.core.NoAdapter;
import nodash.core.NoCore;
import nodash.core.NoDefaultAdapter;
import nodash.core.NoRegister;
import nodash.exceptions.NoDashSessionBadUuidException;
import nodash.exceptions.NoSessionAlreadyAwaitingConfirmationException;
import nodash.exceptions.NoSessionConfirmedException;
import nodash.exceptions.NoSessionExpiredException;
import nodash.exceptions.NoSessionNotAwaitingConfirmationException;
import nodash.exceptions.NoSessionNotChangedException;
import nodash.exceptions.NoUserAlreadyOnlineException;
import nodash.exceptions.NoUserNotValidException;
import nodash.models.NoSession;
import nodash.models.NoUser;
import org.junit.Test;
public class NoCoreTest {
@Test
public void testLogin() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented");
}
@Test
public void testRegister() {
NoCore core = new NoCore(new NoDefaultAdapter());
NoUser user1 = new NoUser();
NoRegister registration1 = core.register(user1, "password".toCharArray());
assertNotNull(registration1.cookie);
assertNotNull(registration1.data);
NoUser user2 = new NoUser();
NoRegister registration2 = core.register(user2, "password".toCharArray());
assertFalse(Arrays.equals(registration1.cookie, registration2.cookie));
assertFalse(Arrays.equals(registration2.data, registration2.data));
NoUser user3 = new NoUser();
try {
core.register(null, "password".toCharArray());
fail("Did not throw NullPointerException.");
} catch (NullPointerException e) {
// Do nothing, correct
}
try {
core.register(user3, null);
fail("Did not throw NullPointerException.");
} catch (NullPointerException e) {
// Do nothing, correct
}
try {
core.register(null, null);
fail("Did not throw NullPointerException.");
} catch (NullPointerException e) {
// Do nothing, correct
}
}
@Test
public void testSaveAndConfirm() throws NoSessionExpiredException, NoSessionConfirmedException,
NoSessionNotAwaitingConfirmationException, NoUserNotValidException,
NoDashSessionBadUuidException, NoUserAlreadyOnlineException, NoSessionNotChangedException, NoSessionAlreadyAwaitingConfirmationException {
NoAdapter adapter = new NoDefaultAdapter();
NoCore core = new NoCore(adapter);
NoUser newUser = new NoUser();
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();
assertTrue(adapter.checkHash(newUserHash));
NoUser newUserBadPass = new NoUser();
registration = core.register(newUserBadPass, "password".toCharArray());
byte[] newUserBadPassFile = Arrays.copyOf(registration.data, registration.data.length);
try {
core.confirm(registration.cookie, "badpassword".toCharArray(), newUserBadPassFile);
fail("Confirmed with a bad password without throwing an exception.");
} catch (NoUserNotValidException e) {
// Do nothing, true
}
try {
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) {
// 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.getUser(oldUserCookie);
byte[] currentHash = oldUserRevisited.createHash();
oldUserRevisited.createFile("password".toCharArray());
byte[] oldCreatedFile = core.save(oldUserCookie, "new-password".toCharArray());
byte[] oldUserHash = oldUserRevisited.createHash();
core.confirm(oldUserCookie, "new-password".toCharArray(), oldCreatedFile);
assertFalse(adapter.containsNoSession(oldUserCookie));
assertTrue(adapter.checkHash(oldUserHash));
assertFalse(adapter.checkHash(currentHash));
}
@Test
public void testGetUser() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented");
}
@Test
public void testGetSessionState() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented");
}
@Test
public void testShred() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented");
}
}

View File

@@ -0,0 +1,72 @@
package nodash.test;
import static org.junit.Assert.*;
import nodash.core.NoCore;
import nodash.exceptions.NoSessionConfirmedException;
import nodash.exceptions.NoSessionExpiredException;
import nodash.models.NoSession;
import org.junit.Before;
import org.junit.Test;
public class NoSessionTest {
@Before
public void setup() {
NoCore.setup();
}
@Test
public void testNoSession() throws NoSessionConfirmedException, NoSessionExpiredException {
NoSession session = new NoSession();
assertNotNull(session.getUuid());
assertNull(session.getNoUser());
}
@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");
}
}