mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Add handshake key pairs to DB, remove inactive contacts.
This commit is contained in:
@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
@@ -37,6 +36,7 @@ import org.junit.Test;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
@@ -90,7 +90,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
public BlogManagerImplTest() {
|
||||
MetadataParser metadataParser = context.mock(MetadataParser.class);
|
||||
blogManager = new BlogManagerImpl(db, contactManager, identityManager, clientHelper,
|
||||
blogManager = new BlogManagerImpl(db, contactManager, identityManager,
|
||||
clientHelper,
|
||||
metadataParser, blogFactory, blogPostFactory);
|
||||
|
||||
localAuthor1 = getLocalAuthor();
|
||||
@@ -130,10 +131,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testRemovingContact() throws DbException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
ContactId contactId = new ContactId(0);
|
||||
Contact contact = new Contact(contactId, blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), getRandomString(5), true, true);
|
||||
Contact contact = getContact(blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
@@ -152,10 +151,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testRemovingContactAfterRemovingBlog() throws DbException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
ContactId contactId = new ContactId(0);
|
||||
Contact contact = new Contact(contactId, blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), getRandomString(5), true, true);
|
||||
Contact contact = getContact(blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
|
||||
@@ -234,12 +234,12 @@ public class IntroductionIntegrationTest
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
|
||||
// make sure that introduced contacts are not verified
|
||||
for (Contact c : contactManager1.getActiveContacts()) {
|
||||
for (Contact c : contactManager1.getContacts()) {
|
||||
if (c.getAuthor().equals(author2)) {
|
||||
assertFalse(c.isVerified());
|
||||
}
|
||||
}
|
||||
for (Contact c : contactManager2.getActiveContacts()) {
|
||||
for (Contact c : contactManager2.getContacts()) {
|
||||
if (c.getAuthor().equals(author1)) {
|
||||
assertFalse(c.isVerified());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.Group.Visibility;
|
||||
@@ -27,7 +26,7 @@ import org.jmock.Expectations;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
@@ -64,10 +63,12 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Contact contact = getContact();
|
||||
final ContactId contactId = contact.getId();
|
||||
final Author author = contact.getAuthor();
|
||||
final GroupId contactGroupId = new GroupId(getRandomId());
|
||||
final Group privateGroupGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
final GroupId privateGroupId = privateGroupGroup.getId();
|
||||
final Author author = getAuthor();
|
||||
final PrivateGroup privateGroup = new PrivateGroup(privateGroupGroup,
|
||||
getRandomString(MAX_GROUP_NAME_LENGTH), author,
|
||||
getRandomBytes(GROUP_SALT_LENGTH));
|
||||
@@ -79,11 +80,6 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
final long messageTimestamp = message.getTimestamp();
|
||||
final long inviteTimestamp = messageTimestamp - 1;
|
||||
final long localTimestamp = inviteTimestamp - 1;
|
||||
private final BdfDictionary meta =
|
||||
BdfDictionary.of(new BdfEntry("me", "ta"));
|
||||
final ContactId contactId = new ContactId(5);
|
||||
final Contact contact = new Contact(contactId, author,
|
||||
new AuthorId(getRandomId()), getRandomString(5), true, true);
|
||||
|
||||
final InviteMessage inviteMessage =
|
||||
new InviteMessage(new MessageId(getRandomId()), contactGroupId,
|
||||
@@ -168,6 +164,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
|
||||
private void expectSendMessage(MessageType type, boolean visible)
|
||||
throws Exception {
|
||||
BdfDictionary meta = BdfDictionary.of(new BdfEntry("me", "ta"));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(type, privateGroupId,
|
||||
message.getTimestamp(), true, true, visible, false, false);
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.jmock.Expectations;
|
||||
import org.jmock.lib.legacy.ClassImposteriser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -44,9 +43,11 @@ import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
@@ -97,10 +98,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
private final GroupInvitationManagerImpl groupInvitationManager;
|
||||
|
||||
private final Transaction txn = new Transaction(null, false);
|
||||
private final ContactId contactId = new ContactId(0);
|
||||
private final Author author = getAuthor();
|
||||
private final Contact contact = new Contact(contactId, author,
|
||||
new AuthorId(getRandomId()), getRandomString(5), true, true);
|
||||
private final Contact contact = getContact(author,
|
||||
new AuthorId(getRandomId()), true);
|
||||
private final ContactId contactId = contact.getId();
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final Group privateGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
@@ -844,12 +845,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingGroupEndsSessions() throws Exception {
|
||||
Contact contact2 = new Contact(new ContactId(2), author,
|
||||
author.getId(), getRandomString(5), true, true);
|
||||
Contact contact3 = new Contact(new ContactId(3), author,
|
||||
author.getId(), getRandomString(5), true, true);
|
||||
Collection<Contact> contacts =
|
||||
Arrays.asList(contact, contact2, contact3);
|
||||
Contact contact2 = getContact();
|
||||
Contact contact3 = getContact();
|
||||
Collection<Contact> contacts = asList(contact, contact2, contact3);
|
||||
|
||||
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.privategroup.invitation;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
@@ -18,6 +17,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -31,6 +31,7 @@ import static org.briarproject.briar.privategroup.invitation.InviteeState.LEFT;
|
||||
import static org.briarproject.briar.privategroup.invitation.InviteeState.START;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -53,43 +54,43 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
// onInviteAction
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromStart() throws Exception {
|
||||
public void testOnInviteActionFromStart() {
|
||||
engine.onInviteAction(txn, getDefaultSession(START), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromLeft() throws Exception {
|
||||
public void testOnInviteActionFromLeft() {
|
||||
engine.onInviteAction(txn, getDefaultSession(ACCEPTED), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromInvited() throws Exception {
|
||||
public void testOnInviteActionFromInvited() {
|
||||
engine.onInviteAction(txn, getDefaultSession(INVITED), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromDissolved() throws Exception {
|
||||
public void testOnInviteActionFromDissolved() {
|
||||
engine.onInviteAction(txn, getDefaultSession(DISSOLVED), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromAccepted() throws Exception {
|
||||
public void testOnInviteActionFromAccepted() {
|
||||
engine.onInviteAction(txn, getDefaultSession(ACCEPTED), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromJoined() throws Exception {
|
||||
public void testOnInviteActionFromJoined() {
|
||||
engine.onInviteAction(txn, getDefaultSession(JOINED), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testOnInviteActionFromError() throws Exception {
|
||||
public void testOnInviteActionFromError() {
|
||||
engine.onInviteAction(txn, getDefaultSession(ERROR), null,
|
||||
messageTimestamp, signature);
|
||||
}
|
||||
@@ -263,43 +264,43 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
// onMemberAddedAction
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromStart() throws Exception {
|
||||
public void testOnMemberAddedFromStart() {
|
||||
InviteeSession session = getDefaultSession(START);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromInvited() throws Exception {
|
||||
public void testOnMemberAddedFromInvited() {
|
||||
InviteeSession session = getDefaultSession(INVITED);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromAccepted() throws Exception {
|
||||
public void testOnMemberAddedFromAccepted() {
|
||||
InviteeSession session = getDefaultSession(ACCEPTED);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromJoined() throws Exception {
|
||||
public void testOnMemberAddedFromJoined() {
|
||||
InviteeSession session = getDefaultSession(JOINED);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromLeft() throws Exception {
|
||||
public void testOnMemberAddedFromLeft() {
|
||||
InviteeSession session = getDefaultSession(LEFT);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromDissolved() throws Exception {
|
||||
public void testOnMemberAddedFromDissolved() {
|
||||
InviteeSession session = getDefaultSession(DISSOLVED);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMemberAddedFromError() throws Exception {
|
||||
public void testOnMemberAddedFromError() {
|
||||
InviteeSession session = getDefaultSession(ERROR);
|
||||
assertEquals(session, engine.onMemberAddedAction(txn, session));
|
||||
}
|
||||
@@ -329,9 +330,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
privateGroup.getSalt(),
|
||||
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH),
|
||||
signature);
|
||||
Author notCreator = getAuthor();
|
||||
Contact notCreatorContact = new Contact(contactId, notCreator,
|
||||
localAuthor.getId(), getRandomString(5), true, true);
|
||||
Contact notCreatorContact = getContact(contactId, getAuthor(),
|
||||
localAuthor.getId(), true);
|
||||
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
@@ -510,8 +510,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
session.getInviteTimestamp());
|
||||
assertNotNull(session.getLastRemoteMessageId());
|
||||
assertNotNull(invalidJoinMessage.getPreviousMessageId());
|
||||
assertFalse(session.getLastRemoteMessageId()
|
||||
.equals(invalidJoinMessage.getPreviousMessageId()));
|
||||
assertNotEquals(session.getLastRemoteMessageId(),
|
||||
invalidJoinMessage.getPreviousMessageId());
|
||||
|
||||
expectAbortWhenSubscribedToGroup();
|
||||
InviteeSession newSession =
|
||||
@@ -530,8 +530,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
session.getInviteTimestamp());
|
||||
assertNotNull(session.getLastRemoteMessageId());
|
||||
assertNotNull(properJoinMessage.getPreviousMessageId());
|
||||
assertTrue(session.getLastRemoteMessageId()
|
||||
.equals(properJoinMessage.getPreviousMessageId()));
|
||||
assertEquals(session.getLastRemoteMessageId(),
|
||||
properJoinMessage.getPreviousMessageId());
|
||||
|
||||
expectSetPrivateGroupVisibility(SHARED);
|
||||
|
||||
@@ -646,8 +646,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
session.getInviteTimestamp());
|
||||
assertNotNull(session.getLastRemoteMessageId());
|
||||
assertNotNull(properLeaveMessage.getPreviousMessageId());
|
||||
assertTrue(session.getLastRemoteMessageId()
|
||||
.equals(properLeaveMessage.getPreviousMessageId()));
|
||||
assertEquals(session.getLastRemoteMessageId(),
|
||||
properLeaveMessage.getPreviousMessageId());
|
||||
|
||||
expectMarkInvitesUnavailableToAnswer();
|
||||
InviteeSession newSession =
|
||||
@@ -676,8 +676,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
session.getInviteTimestamp());
|
||||
assertNotNull(session.getLastRemoteMessageId());
|
||||
assertNotNull(properLeaveMessage.getPreviousMessageId());
|
||||
assertTrue(session.getLastRemoteMessageId()
|
||||
.equals(properLeaveMessage.getPreviousMessageId()));
|
||||
assertEquals(session.getLastRemoteMessageId(),
|
||||
properLeaveMessage.getPreviousMessageId());
|
||||
|
||||
expectMarkInvitesUnavailableToAnswer();
|
||||
InviteeSession newSession =
|
||||
|
||||
@@ -34,11 +34,11 @@ import java.util.Map;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID;
|
||||
@@ -61,11 +61,10 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
private final BlogManager blogManager = context.mock(BlogManager.class);
|
||||
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final ContactId contactId = new ContactId(0);
|
||||
private final Author author = getAuthor();
|
||||
private final Contact contact =
|
||||
new Contact(contactId, author, localAuthor.getId(),
|
||||
getRandomString(5), true, true);
|
||||
getContact(author, localAuthor.getId(), true);
|
||||
private final ContactId contactId = contact.getId();
|
||||
private final Collection<Contact> contacts =
|
||||
Collections.singletonList(contact);
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
Reference in New Issue
Block a user