Rename to Mailbox update

This commit is contained in:
Daniel Lublin
2022-05-16 09:59:38 +02:00
parent d2728dd29b
commit 3f7aed7886
21 changed files with 348 additions and 387 deletions

View File

@@ -23,8 +23,8 @@ import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdate;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdateMailbox;
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.mailbox.MailboxVersion;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
@@ -47,17 +47,17 @@ import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSignaturePrivateKey;
import static org.briarproject.bramble.test.TestUtils.getSignaturePublicKey;
import static org.briarproject.bramble.test.TestUtils.mailboxPropertiesUpdateEqual;
import static org.briarproject.bramble.test.TestUtils.mailboxUpdateEqual;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -98,7 +98,7 @@ public class ClientHelperImplTest extends BrambleMockTestCase {
messageFactory, bdfReaderFactory, bdfWriterFactory, metadataParser,
metadataEncoder, cryptoComponent, authorFactory);
private final MailboxPropertiesUpdateMailbox validMailboxPropsUpdate;
private final MailboxUpdateWithMailbox validMailboxUpdateWithMailbox;
private final BdfList emptyClientSupports;
private final BdfList someClientSupports;
private final BdfList emptyServerSupports;
@@ -109,7 +109,7 @@ public class ClientHelperImplTest extends BrambleMockTestCase {
someClientSupports = BdfList.of(BdfList.of(1, 0));
emptyServerSupports = new BdfList();
someServerSupports = BdfList.of(BdfList.of(1, 0));
validMailboxPropsUpdate = new MailboxPropertiesUpdateMailbox(
validMailboxUpdateWithMailbox = new MailboxUpdateWithMailbox(
singletonList(new MailboxVersion(1, 0)),
singletonList(new MailboxVersion(1, 0)),
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd",
@@ -118,14 +118,14 @@ public class ClientHelperImplTest extends BrambleMockTestCase {
new MailboxFolderId(getRandomId()));
}
private BdfDictionary getValidMailboxPropsUpdateDict() {
private BdfDictionary getValidMailboxUpdateWithMailboxDict() {
BdfDictionary dict = new BdfDictionary();
dict.put(PROP_KEY_ONION, validMailboxPropsUpdate.getOnion());
dict.put(PROP_KEY_AUTHTOKEN, validMailboxPropsUpdate.getAuthToken()
dict.put(PROP_KEY_ONION, validMailboxUpdateWithMailbox.getOnion());
dict.put(PROP_KEY_AUTHTOKEN, validMailboxUpdateWithMailbox
.getAuthToken().getBytes());
dict.put(PROP_KEY_INBOXID, validMailboxUpdateWithMailbox.getInboxId()
.getBytes());
dict.put(PROP_KEY_INBOXID, validMailboxPropsUpdate.getInboxId()
.getBytes());
dict.put(PROP_KEY_OUTBOXID, validMailboxPropsUpdate.getOutboxId()
dict.put(PROP_KEY_OUTBOXID, validMailboxUpdateWithMailbox.getOutboxId()
.getBytes());
return dict;
}
@@ -560,172 +560,150 @@ public class ClientHelperImplTest extends BrambleMockTestCase {
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsWithEmptyClientSupports()
public void testRejectsMailboxUpdateWithEmptyClientSupports()
throws Exception {
BdfDictionary emptyPropsDict = new BdfDictionary();
clientHelper.parseAndValidateMailboxPropertiesUpdate(
emptyClientSupports, emptyServerSupports, emptyPropsDict
clientHelper.parseAndValidateMailboxUpdate(emptyClientSupports,
emptyServerSupports, emptyPropsDict
);
}
@Test
public void testParseEmptyMailboxPropsUpdate() throws Exception {
public void testParseMailboxUpdateNoMailbox() throws Exception {
BdfDictionary emptyPropsDict = new BdfDictionary();
MailboxPropertiesUpdate parsedProps = clientHelper
.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
emptyServerSupports, emptyPropsDict
);
assertFalse(parsedProps.hasMailbox());
MailboxUpdate parsedUpdate = clientHelper.parseAndValidateMailboxUpdate(
someClientSupports, emptyServerSupports, emptyPropsDict);
assertFalse(parsedUpdate.hasMailbox());
}
@Test(expected = FormatException.class)
public void testRejectsEmptyMailboxPropsWithSomeServerSupports()
public void testRejectsMailboxUpdateNoMailboxWithSomeServerSupports()
throws Exception {
BdfDictionary emptyPropsDict = new BdfDictionary();
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, emptyPropsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, emptyPropsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsShortSupports() throws Exception {
clientHelper.parseAndValidateMailboxPropertiesUpdate(
BdfList.of(BdfList.of(1)), emptyServerSupports,
new BdfDictionary()
);
public void testRejectsMailboxUpdateShortSupports() throws Exception {
clientHelper.parseAndValidateMailboxUpdate(BdfList.of(BdfList.of(1)),
emptyServerSupports, new BdfDictionary());
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsLongSupports() throws Exception {
clientHelper.parseAndValidateMailboxPropertiesUpdate(
public void testRejectsMailboxUpdateLongSupports() throws Exception {
clientHelper.parseAndValidateMailboxUpdate(
BdfList.of(BdfList.of(1, 0, 0)), emptyServerSupports,
new BdfDictionary()
);
new BdfDictionary());
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsNonIntSupports() throws Exception {
clientHelper.parseAndValidateMailboxPropertiesUpdate(
public void testRejectsMailboxUpdateNonIntSupports() throws Exception {
clientHelper.parseAndValidateMailboxUpdate(
BdfList.of(BdfList.of(1, "0")), emptyServerSupports,
new BdfDictionary()
);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsNonListSupports() throws Exception {
clientHelper.parseAndValidateMailboxPropertiesUpdate(
BdfList.of("non-list"), emptyServerSupports, new BdfDictionary()
);
public void testRejectsMailboxUpdateNonListSupports() throws Exception {
clientHelper.parseAndValidateMailboxUpdate(
BdfList.of("non-list"), emptyServerSupports,
new BdfDictionary());
}
@Test
public void testParseValidMailboxPropsUpdate() throws Exception {
MailboxPropertiesUpdate parsedProps = clientHelper
.parseAndValidateMailboxPropertiesUpdate(
someClientSupports, someServerSupports,
getValidMailboxPropsUpdateDict()
);
assertTrue(mailboxPropertiesUpdateEqual(validMailboxPropsUpdate,
parsedProps));
public void testParseValidMailboxUpdateWithMailbox() throws Exception {
MailboxUpdate parsedUpdate = clientHelper.parseAndValidateMailboxUpdate(
someClientSupports, someServerSupports,
getValidMailboxUpdateWithMailboxDict());
assertTrue(
mailboxUpdateEqual(validMailboxUpdateWithMailbox,
parsedUpdate));
}
@Test(expected = FormatException.class)
public void rejectsMailboxPropsWithEmptyServerSupports() throws Exception {
clientHelper.parseAndValidateMailboxPropertiesUpdate(
someClientSupports, emptyServerSupports,
getValidMailboxPropsUpdateDict()
);
public void rejectsMailboxUpdateWithEmptyServerSupports() throws Exception {
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
emptyServerSupports, getValidMailboxUpdateWithMailboxDict());
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateOnionNotDecodable()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateOnionNotDecodable() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
String badOnion = "!" + propsDict.getString(PROP_KEY_ONION)
.substring(1);
propsDict.put(PROP_KEY_ONION, badOnion);
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
emptyServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
emptyServerSupports, propsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateOnionWrongLength()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateOnionWrongLength() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
String tooLongOnion = propsDict.getString(PROP_KEY_ONION) + "!";
propsDict.put(PROP_KEY_ONION, tooLongOnion);
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
emptyServerSupports, propsDict
);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateInboxIdWrongLength()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateInboxIdWrongLength() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.put(PROP_KEY_INBOXID, getRandomBytes(UniqueId.LENGTH + 1));
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateOutboxIdWrongLength()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateOutboxIdWrongLength() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.put(PROP_KEY_OUTBOXID, getRandomBytes(UniqueId.LENGTH + 1));
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateAuthTokenWrongLength()
public void testRejectsMailboxUpdateAuthTokenWrongLength()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.put(PROP_KEY_AUTHTOKEN, getRandomBytes(UniqueId.LENGTH + 1));
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateMissingOnion() throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateMissingOnion() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.remove(PROP_KEY_ONION);
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict
);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateMissingAuthToken()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateMissingAuthToken() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.remove(PROP_KEY_AUTHTOKEN);
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateMissingInboxId() throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateMissingInboxId() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.remove(PROP_KEY_INBOXID);
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict);
}
@Test(expected = FormatException.class)
public void testRejectsMailboxPropsUpdateMissingOutboxId()
throws Exception {
BdfDictionary propsDict = getValidMailboxPropsUpdateDict();
public void testRejectsMailboxUpdateMissingOutboxId() throws Exception {
BdfDictionary propsDict = getValidMailboxUpdateWithMailboxDict();
propsDict.remove(PROP_KEY_OUTBOXID);
clientHelper.parseAndValidateMailboxPropertiesUpdate(someClientSupports,
someServerSupports, propsDict
);
clientHelper.parseAndValidateMailboxUpdate(someClientSupports,
someServerSupports, propsDict);
}
}

View File

@@ -9,9 +9,9 @@ import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxPairingState;
import org.briarproject.bramble.api.mailbox.MailboxPairingTask;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdate;
import org.briarproject.bramble.api.mailbox.MailboxPropertyManager;
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateManager;
import org.briarproject.bramble.api.mailbox.OwnMailboxConnectionStatusEvent;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.test.BrambleMockTestCase;
@@ -49,11 +49,11 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
private final MailboxApi api = context.mock(MailboxApi.class);
private final MailboxSettingsManager mailboxSettingsManager =
context.mock(MailboxSettingsManager.class);
private final MailboxPropertyManager mailboxPropertyManager =
context.mock(MailboxPropertyManager.class);
private final MailboxUpdateManager mailboxUpdateManager =
context.mock(MailboxUpdateManager.class);
private final MailboxPairingTaskFactory factory =
new MailboxPairingTaskFactoryImpl(executor, db, crypto, clock, api,
mailboxSettingsManager, mailboxPropertyManager);
mailboxSettingsManager, mailboxUpdateManager);
private final String onion = getRandomString(56);
private final byte[] onionBytes = getRandomBytes(32);
@@ -107,8 +107,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
}});
Contact contact1 = getContact();
Transaction txn = new Transaction(null, false);
MailboxPropertiesUpdate emptyProps = new MailboxPropertiesUpdate(
CLIENT_SUPPORTS);
MailboxUpdate updateNoMailbox = new MailboxUpdate(CLIENT_SUPPORTS);
context.checking(new DbExpectations() {{
oneOf(db).transaction(with(false), withDbRunnable(txn));
oneOf(mailboxSettingsManager).setOwnMailboxProperties(
@@ -116,9 +115,9 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time);
oneOf(db).getContacts(txn);
will(returnValue(singletonList(contact1)));
oneOf(mailboxPropertyManager).getRemoteProperties(txn,
oneOf(mailboxUpdateManager).getRemoteUpdate(txn,
contact1.getId());
will(returnValue(emptyProps));
will(returnValue(updateNoMailbox));
oneOf(db).resetUnackedMessagesToSend(txn, contact1.getId());
}});

View File

@@ -14,11 +14,11 @@ import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdate;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdateMailbox;
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.mailbox.MailboxVersion;
import org.briarproject.bramble.api.mailbox.RemoteMailboxPropertiesUpdateEvent;
import org.briarproject.bramble.api.mailbox.RemoteMailboxUpdateEvent;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
@@ -34,14 +34,14 @@ import java.util.List;
import java.util.Map;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.CLIENT_ID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.MAJOR_VERSION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.MSG_KEY_LOCAL;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.MSG_KEY_VERSION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.CLIENT_ID;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.MAJOR_VERSION;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.MSG_KEY_LOCAL;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.MSG_KEY_VERSION;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
import static org.briarproject.bramble.mailbox.MailboxApi.CLIENT_SUPPORTS;
@@ -50,13 +50,13 @@ import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.hasEvent;
import static org.briarproject.bramble.test.TestUtils.mailboxPropertiesUpdateEqual;
import static org.briarproject.bramble.test.TestUtils.mailboxUpdateEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
@@ -80,11 +80,11 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
private final BdfList emptyServerSupports;
private final BdfList someServerSupports;
private final List<MailboxVersion> someServerSupportsList;
private final MailboxPropertiesUpdateMailbox updateMailbox;
private final MailboxPropertiesUpdate updateNoMailbox;
private final MailboxUpdateWithMailbox updateWithMailbox;
private final MailboxUpdate updateNoMailbox;
private final MailboxProperties ownProps;
public MailboxPropertyManagerImplTest() {
public MailboxUpdateManagerImplTest() {
someClientSupports = BdfList.of(BdfList.of(1, 0));
someClientSupportsList = singletonList(new MailboxVersion(1, 0));
emptyServerSupports = new BdfList();
@@ -97,7 +97,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
ownProps = new MailboxProperties("http://bar.onion",
new MailboxAuthToken(getRandomId()), true,
someServerSupportsList);
updateMailbox = new MailboxPropertiesUpdateMailbox(
updateWithMailbox = new MailboxUpdateWithMailbox(
singletonList(new MailboxVersion(1, 0)),
singletonList(new MailboxVersion(1, 0)),
ownProps.getOnion(),
@@ -105,22 +105,23 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
new MailboxFolderId(getRandomId()),
new MailboxFolderId(getRandomId()));
propsDict = new BdfDictionary();
propsDict.put(PROP_KEY_ONION, updateMailbox.getOnion());
propsDict.put(PROP_KEY_AUTHTOKEN,
updateMailbox.getAuthToken().getBytes());
propsDict.put(PROP_KEY_INBOXID, updateMailbox.getInboxId().getBytes());
propsDict.put(PROP_KEY_OUTBOXID,
updateMailbox.getOutboxId().getBytes());
updateNoMailbox = new MailboxPropertiesUpdate(someClientSupportsList);
propsDict.put(PROP_KEY_ONION, updateWithMailbox.getOnion());
propsDict.put(PROP_KEY_AUTHTOKEN, updateWithMailbox.getAuthToken()
.getBytes());
propsDict.put(PROP_KEY_INBOXID, updateWithMailbox.getInboxId()
.getBytes());
propsDict.put(PROP_KEY_OUTBOXID, updateWithMailbox.getOutboxId()
.getBytes());
updateNoMailbox = new MailboxUpdate(someClientSupportsList);
}
private MailboxPropertyManagerImpl createInstance() {
private MailboxUpdateManagerImpl createInstance() {
context.checking(new Expectations() {{
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID,
MAJOR_VERSION);
will(returnValue(localGroup));
}});
return new MailboxPropertyManagerImpl(db, clientHelper,
return new MailboxUpdateManagerImpl(db, clientHelper,
clientVersioningManager, metadataParser, contactGroupFactory,
clock, mailboxSettingsManager, crypto);
}
@@ -161,7 +162,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
emptyServerSupports, emptyPropsDict, true);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.onDatabaseOpened(txn);
}
@@ -193,11 +194,11 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(ownProps));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getAuthToken()));
will(returnValue(updateWithMailbox.getAuthToken()));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getInboxId()));
will(returnValue(updateWithMailbox.getInboxId()));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getOutboxId()));
will(returnValue(updateWithMailbox.getOutboxId()));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact);
will(returnValue(contactGroup));
@@ -208,7 +209,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
someServerSupports, propsDict, true);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.onDatabaseOpened(txn);
}
@@ -222,7 +223,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(true));
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.onDatabaseOpened(txn);
}
@@ -259,7 +260,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
emptyServerSupports, emptyPropsDict, true);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.addingContact(txn, contact);
}
@@ -287,11 +288,11 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(ownProps));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getAuthToken()));
will(returnValue(updateWithMailbox.getAuthToken()));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getInboxId()));
will(returnValue(updateWithMailbox.getInboxId()));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getOutboxId()));
will(returnValue(updateWithMailbox.getOutboxId()));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact);
will(returnValue(contactGroup));
@@ -302,7 +303,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
someServerSupports, propsDict, true);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.addingContact(txn, contact);
}
@@ -319,7 +320,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(db).removeGroup(txn, contactGroup);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.removingContact(txn, contact);
}
@@ -355,16 +356,16 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(contact.getId()));
oneOf(clientHelper).getMessageAsList(txn, message.getId());
will(returnValue(body));
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, someServerSupports, propsDict);
will(returnValue(updateMailbox));
will(returnValue(updateWithMailbox));
oneOf(db).resetUnackedMessagesToSend(txn, contact.getId());
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
assertEquals(ACCEPT_DO_NOT_SHARE,
t.incomingMessage(txn, message, meta));
assertTrue(hasEvent(txn, RemoteMailboxPropertiesUpdateEvent.class));
assertTrue(hasEvent(txn, RemoteMailboxUpdateEvent.class));
}
@Test
@@ -407,16 +408,16 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(contact.getId()));
oneOf(clientHelper).getMessageAsList(txn, message.getId());
will(returnValue(body));
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, someServerSupports, propsDict);
will(returnValue(updateMailbox));
will(returnValue(updateWithMailbox));
oneOf(db).resetUnackedMessagesToSend(txn, contact.getId());
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
assertEquals(ACCEPT_DO_NOT_SHARE,
t.incomingMessage(txn, message, meta));
assertTrue(hasEvent(txn, RemoteMailboxPropertiesUpdateEvent.class));
assertTrue(hasEvent(txn, RemoteMailboxUpdateEvent.class));
}
@Test
@@ -447,14 +448,14 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessageMetadata(txn, message.getId());
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
assertEquals(ACCEPT_DO_NOT_SHARE,
t.incomingMessage(txn, message, meta));
assertFalse(hasEvent(txn, RemoteMailboxPropertiesUpdateEvent.class));
assertFalse(hasEvent(txn, RemoteMailboxUpdateEvent.class));
}
@Test
public void testCreatesAndStoresLocalPropertiesWithNewVersionOnPairing()
public void testCreatesAndStoresLocalUpdateWithNewVersionOnPairing()
throws Exception {
Contact contact = getContact();
List<Contact> contacts = singletonList(contact);
@@ -477,11 +478,11 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(db).getContacts(txn);
will(returnValue(contacts));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getAuthToken()));
will(returnValue(updateWithMailbox.getAuthToken()));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getInboxId()));
will(returnValue(updateWithMailbox.getInboxId()));
oneOf(crypto).generateUniqueId();
will(returnValue(updateMailbox.getOutboxId()));
will(returnValue(updateWithMailbox.getOutboxId()));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact);
will(returnValue(contactGroup));
@@ -493,12 +494,12 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(db).removeMessage(txn, latestId);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.mailboxPaired(txn, ownProps.getOnion(), someServerSupportsList);
}
@Test
public void testStoresEmptyLocalPropertiesWithNewVersionOnUnpairing()
public void testStoresLocalUpdateNoMailboxWithNewVersionOnUnpairing()
throws Exception {
Contact contact = getContact();
List<Contact> contacts = singletonList(contact);
@@ -531,13 +532,12 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(db).removeMessage(txn, latestId);
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxUpdateManagerImpl t = createInstance();
t.mailboxUnpaired(txn);
}
@Test
public void testGetRemoteProperties()
throws Exception {
public void testGetRemoteUpdate() throws Exception {
Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -554,27 +554,26 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
context.checking(new Expectations() {{
oneOf(db).getContact(txn, contact.getId());
will(returnValue(contact));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact);
oneOf(contactGroupFactory)
.createContactGroup(CLIENT_ID, MAJOR_VERSION, contact);
will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId());
will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body));
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, someServerSupports, propsDict);
will(returnValue(updateMailbox));
will(returnValue(updateWithMailbox));
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxPropertiesUpdate remote =
t.getRemoteProperties(txn, contact.getId());
assertTrue(mailboxPropertiesUpdateEqual(remote, updateMailbox));
MailboxUpdateManagerImpl t = createInstance();
MailboxUpdate remote = t.getRemoteUpdate(txn, contact.getId());
assertTrue(mailboxUpdateEqual(remote, updateWithMailbox));
}
@Test
public void testGetRemotePropertiesReturnsNullBecauseNoUpdate()
public void testGetRemoteUpdateReturnsNullBecauseNoUpdate()
throws Exception {
Transaction txn = new Transaction(null, false);
Contact contact = getContact();
@@ -593,13 +592,12 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(emptyMessageMetadata));
}});
MailboxPropertyManagerImpl t = createInstance();
assertNull(t.getRemoteProperties(txn, contact.getId()));
MailboxUpdateManagerImpl t = createInstance();
assertNull(t.getRemoteUpdate(txn, contact.getId()));
}
@Test
public void testGetRemotePropertiesNoMailbox()
throws Exception {
public void testGetRemoteUpdateNoMailbox() throws Exception {
Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -624,20 +622,18 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body));
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, emptyServerSupports, emptyPropsDict);
will(returnValue(updateNoMailbox));
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxPropertiesUpdate remote =
t.getRemoteProperties(txn, contact.getId());
assertTrue(mailboxPropertiesUpdateEqual(remote, updateNoMailbox));
MailboxUpdateManagerImpl t = createInstance();
MailboxUpdate remote = t.getRemoteUpdate(txn, contact.getId());
assertTrue(mailboxUpdateEqual(remote, updateNoMailbox));
}
@Test
public void testGetLocalProperties()
throws Exception {
public void testGetLocalUpdate() throws Exception {
Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -662,20 +658,18 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body));
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, someServerSupports, propsDict);
will(returnValue(updateMailbox));
will(returnValue(updateWithMailbox));
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxPropertiesUpdate local =
t.getLocalProperties(txn, contact.getId());
assertTrue(mailboxPropertiesUpdateEqual(local, updateMailbox));
MailboxUpdateManagerImpl t = createInstance();
MailboxUpdate local = t.getLocalUpdate(txn, contact.getId());
assertTrue(mailboxUpdateEqual(local, updateWithMailbox));
}
@Test
public void testGetLocalPropertiesNoMailbox()
throws Exception {
public void testGetLocalUpdateNoMailbox() throws Exception {
Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -700,15 +694,14 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body));
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, emptyServerSupports, emptyPropsDict);
will(returnValue(updateNoMailbox));
}});
MailboxPropertyManagerImpl t = createInstance();
MailboxPropertiesUpdate local =
t.getLocalProperties(txn, contact.getId());
assertTrue(mailboxPropertiesUpdateEqual(local, updateNoMailbox));
MailboxUpdateManagerImpl t = createInstance();
MailboxUpdate local = t.getLocalUpdate(txn, contact.getId());
assertTrue(mailboxUpdateEqual(local, updateNoMailbox));
}
private void expectStoreMessage(Transaction txn, GroupId g,

View File

@@ -8,9 +8,9 @@ import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.MetadataEncoder;
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdate;
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdateMailbox;
import org.briarproject.bramble.api.mailbox.MailboxPropertyManager;
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateManager;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.mailbox.MailboxVersion;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.Message;
@@ -28,7 +28,7 @@ import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.junit.Assert.assertEquals;
public class MailboxPropertyValidatorTest extends BrambleMockTestCase {
public class MailboxUpdateValidatorTest extends BrambleMockTestCase {
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
@@ -37,39 +37,39 @@ public class MailboxPropertyValidatorTest extends BrambleMockTestCase {
private final BdfList someClientSupports;
private final List<MailboxVersion> someClientSupportsList;
private final BdfList someServerSupports;
private final MailboxPropertiesUpdateMailbox updateMailbox;
private final MailboxPropertiesUpdate updateNoMailbox;
private final MailboxUpdateWithMailbox updateMailbox;
private final MailboxUpdate updateNoMailbox;
private final Group group;
private final Message message;
private final MailboxPropertyValidator mpv;
private final MailboxUpdateValidator muv;
public MailboxPropertyValidatorTest() {
public MailboxUpdateValidatorTest() {
// Just dummies, clientHelper is mocked so our test is a bit shallow;
// not testing
// {@link ClientHelper#parseAndValidateMailboxPropertiesUpdate(BdfDictionary)}
// {@link ClientHelper#parseAndValidateMailboxUpdate(BdfList, BdfList, BdfDictionary)}
emptyServerSupports = new BdfList();
someClientSupports = BdfList.of(BdfList.of(1, 0));
someClientSupportsList = singletonList(new MailboxVersion(1, 0));
someServerSupports = BdfList.of(BdfList.of(1, 0));
bdfDict = BdfDictionary.of(new BdfEntry("foo", "bar"));
updateMailbox = new MailboxPropertiesUpdateMailbox(
updateMailbox = new MailboxUpdateWithMailbox(
singletonList(new MailboxVersion(1, 0)),
singletonList(new MailboxVersion(1, 0)),
"baz",
new MailboxAuthToken(getRandomId()),
new MailboxFolderId(getRandomId()),
new MailboxFolderId(getRandomId()));
updateNoMailbox = new MailboxPropertiesUpdate(someClientSupportsList);
updateNoMailbox = new MailboxUpdate(someClientSupportsList);
group = getGroup(MailboxPropertyManager.CLIENT_ID,
MailboxPropertyManager.MAJOR_VERSION);
group = getGroup(MailboxUpdateManager.CLIENT_ID,
MailboxUpdateManager.MAJOR_VERSION);
message = getMessage(group.getId());
MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class);
Clock clock = context.mock(Clock.class);
mpv = new MailboxPropertyValidator(clientHelper, metadataEncoder,
muv = new MailboxUpdateValidator(clientHelper, metadataEncoder,
clock);
}
@@ -79,26 +79,26 @@ public class MailboxPropertyValidatorTest extends BrambleMockTestCase {
BdfList.of(4, someClientSupports, someServerSupports, bdfDict);
context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, someServerSupports, bdfDict);
will(returnValue(updateMailbox));
}});
BdfDictionary result =
mpv.validateMessage(message, group, body).getDictionary();
muv.validateMessage(message, group, body).getDictionary();
assertEquals(4, result.getLong("version").longValue());
}
@Test(expected = FormatException.class)
public void testValidateWrongVersionValue() throws IOException {
BdfList body = BdfList.of(-1, bdfDict);
mpv.validateMessage(message, group, body);
muv.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testValidateWrongVersionType() throws IOException {
BdfList body = BdfList.of(bdfDict, bdfDict);
mpv.validateMessage(message, group, body);
muv.validateMessage(message, group, body);
}
@Test
@@ -108,13 +108,13 @@ public class MailboxPropertyValidatorTest extends BrambleMockTestCase {
emptyBdfDict);
context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateMailboxPropertiesUpdate(
oneOf(clientHelper).parseAndValidateMailboxUpdate(
someClientSupports, emptyServerSupports, emptyBdfDict);
will(returnValue(updateNoMailbox));
}});
BdfDictionary result =
mpv.validateMessage(message, group, body).getDictionary();
muv.validateMessage(message, group, body).getDictionary();
assertEquals(42, result.getLong("version").longValue());
}
}

View File

@@ -345,7 +345,7 @@ public class TransportKeyAgreementIntegrationTest
.canSendOutgoingStreams(aliceId, DUPLEX_TRANSPORT_ID));
}
// Sync initial client versioning updates and mailbox properties updates
// Sync initial client versioning updates and mailbox updates
syncMessage(alice, bob, bobId, 1, true);
syncMessage(bob, alice, aliceId, 1, true);
syncMessage(alice, bob, bobId, 2, true);