mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Merge branch 'max-client-id-length' into 'master'
Set max length for client IDs See merge request akwizgran/briar!762
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
package org.briarproject.bramble.api.plugin;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a string that uniquely identifies a transport plugin.
|
||||
* Type-safe wrapper for a namespaced string that uniquely identifies a
|
||||
* transport plugin.
|
||||
*/
|
||||
public class TransportId {
|
||||
|
||||
/**
|
||||
* The maximum length of transport identifier in UTF-8 bytes.
|
||||
* The maximum length of a transport identifier in UTF-8 bytes.
|
||||
*/
|
||||
public static int MAX_TRANSPORT_ID_LENGTH = 64;
|
||||
public static int MAX_TRANSPORT_ID_LENGTH = 100;
|
||||
|
||||
private final String id;
|
||||
|
||||
public TransportId(String id) {
|
||||
byte[] b = id.getBytes(Charset.forName("UTF-8"));
|
||||
if (b.length == 0 || b.length > MAX_TRANSPORT_ID_LENGTH)
|
||||
int length = StringUtils.toUtf8(id).length;
|
||||
if (length == 0 || length > MAX_TRANSPORT_ID_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
package org.briarproject.bramble.api.sync;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* Wrapper for a name-spaced string that uniquely identifies a sync client.
|
||||
* Type-safe wrapper for a namespaced string that uniquely identifies a sync
|
||||
* client.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ClientId implements Comparable<ClientId> {
|
||||
|
||||
/**
|
||||
* The maximum length of a client identifier in UTF-8 bytes.
|
||||
*/
|
||||
public static int MAX_CLIENT_ID_LENGTH = 100;
|
||||
|
||||
private final String id;
|
||||
|
||||
public ClientId(String id) {
|
||||
int length = StringUtils.toUtf8(id).length;
|
||||
if (length == 0 || length > MAX_CLIENT_ID_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -23,6 +24,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
||||
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.plugin.TransportId.MAX_TRANSPORT_ID_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.ClientId.MAX_CLIENT_ID_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
@@ -54,6 +57,14 @@ public class TestUtils {
|
||||
return getRandomBytes(UniqueId.LENGTH);
|
||||
}
|
||||
|
||||
public static ClientId getClientId() {
|
||||
return new ClientId(getRandomString(MAX_CLIENT_ID_LENGTH));
|
||||
}
|
||||
|
||||
public static TransportId getTransportId() {
|
||||
return new TransportId(getRandomString(MAX_TRANSPORT_ID_LENGTH));
|
||||
}
|
||||
|
||||
public static SecretKey getSecretKey() {
|
||||
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -27,7 +28,7 @@ public class KeyDerivationTest extends BrambleTestCase {
|
||||
new CryptoComponentImpl(new TestSecureRandomProvider(), null);
|
||||
private final TransportCrypto transportCrypto =
|
||||
new TransportCryptoImpl(crypto);
|
||||
private final TransportId transportId = new TransportId("id");
|
||||
private final TransportId transportId = getTransportId();
|
||||
private final SecretKey master = getSecretKey();
|
||||
|
||||
@Test
|
||||
@@ -135,7 +136,7 @@ public class KeyDerivationTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testTransportIdAffectsOutput() {
|
||||
TransportId transportId1 = new TransportId("id1");
|
||||
TransportId transportId1 = getTransportId();
|
||||
assertFalse(transportId.getString().equals(transportId1.getString()));
|
||||
TransportKeys k = transportCrypto.deriveTransportKeys(transportId,
|
||||
master, 123, true, true);
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -64,15 +63,17 @@ import static java.util.Collections.singletonList;
|
||||
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.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -104,21 +105,20 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
private final KeySetId keySetId;
|
||||
|
||||
public DatabaseComponentImplTest() {
|
||||
clientId = new ClientId(getRandomString(123));
|
||||
groupId = new GroupId(TestUtils.getRandomId());
|
||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||
group = new Group(groupId, clientId, descriptor);
|
||||
clientId = getClientId();
|
||||
group = getGroup(clientId);
|
||||
groupId = group.getId();
|
||||
author = getAuthor();
|
||||
localAuthor = getLocalAuthor();
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
messageId = new MessageId(getRandomId());
|
||||
messageId1 = new MessageId(getRandomId());
|
||||
long timestamp = System.currentTimeMillis();
|
||||
size = 1234;
|
||||
raw = new byte[size];
|
||||
message = new Message(messageId, groupId, timestamp, raw);
|
||||
metadata = new Metadata();
|
||||
metadata.put("foo", new byte[] {'b', 'a', 'r'});
|
||||
transportId = new TransportId("id");
|
||||
transportId = getTransportId();
|
||||
maxLatency = Integer.MAX_VALUE;
|
||||
contactId = new ContactId(234);
|
||||
contact = new Contact(contactId, author, localAuthor.getId(),
|
||||
@@ -919,7 +919,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateOffer() throws Exception {
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId1 = new MessageId(getRandomId());
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
@@ -950,7 +950,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testGenerateRequest() throws Exception {
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId1 = new MessageId(getRandomId());
|
||||
Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
@@ -1138,9 +1138,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testReceiveOffer() throws Exception {
|
||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId1 = new MessageId(getRandomId());
|
||||
MessageId messageId2 = new MessageId(getRandomId());
|
||||
MessageId messageId3 = new MessageId(getRandomId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
@@ -1508,7 +1508,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMessageDependencies() throws Exception {
|
||||
int shutdownHandle = 12345;
|
||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId2 = new MessageId(getRandomId());
|
||||
context.checking(new Expectations() {{
|
||||
// open()
|
||||
oneOf(database).open(null);
|
||||
|
||||
@@ -52,18 +52,19 @@ import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
||||
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.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.INVALID;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -94,10 +95,9 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
private final KeySetId keySetId, keySetId1;
|
||||
|
||||
JdbcDatabaseTest() throws Exception {
|
||||
groupId = new GroupId(getRandomId());
|
||||
clientId = new ClientId(getRandomString(123));
|
||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||
group = new Group(groupId, clientId, descriptor);
|
||||
clientId = getClientId();
|
||||
group = getGroup(clientId);
|
||||
groupId = group.getId();
|
||||
author = getAuthor();
|
||||
localAuthor = getLocalAuthor();
|
||||
messageId = new MessageId(getRandomId());
|
||||
@@ -105,7 +105,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
size = 1234;
|
||||
raw = getRandomBytes(size);
|
||||
message = new Message(messageId, groupId, timestamp, raw);
|
||||
transportId = new TransportId("id");
|
||||
transportId = getTransportId();
|
||||
contactId = new ContactId(1);
|
||||
keySetId = new KeySetId(1);
|
||||
keySetId1 = new KeySetId(2);
|
||||
@@ -1407,9 +1407,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
db.addMessage(txn, message, PENDING, true, contactId);
|
||||
|
||||
// Add a second group
|
||||
GroupId groupId1 = new GroupId(getRandomId());
|
||||
Group group1 = new Group(groupId1, clientId,
|
||||
getRandomBytes(MAX_GROUP_DESCRIPTOR_LENGTH));
|
||||
Group group1 = getGroup(clientId);
|
||||
GroupId groupId1 = group1.getId();
|
||||
db.addGroup(txn, group1);
|
||||
|
||||
// Add a message to the second group
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.RE
|
||||
import static org.briarproject.bramble.api.keyagreement.RecordTypes.ABORT;
|
||||
import static org.briarproject.bramble.api.keyagreement.RecordTypes.CONFIRM;
|
||||
import static org.briarproject.bramble.api.keyagreement.RecordTypes.KEY;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class KeyAgreementTransportTest extends BrambleMockTestCase {
|
||||
private final TransportConnectionWriter transportConnectionWriter =
|
||||
context.mock(TransportConnectionWriter.class);
|
||||
|
||||
private final TransportId transportId = new TransportId("test");
|
||||
private final TransportId transportId = getTransportId();
|
||||
private final KeyAgreementConnection keyAgreementConnection =
|
||||
new KeyAgreementConnection(duplexTransportConnection, transportId);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -29,8 +30,8 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
|
||||
public ConnectionRegistryImplTest() {
|
||||
contactId = new ContactId(1);
|
||||
contactId1 = new ContactId(2);
|
||||
transportId = new TransportId("id");
|
||||
transportId1 = new TransportId("id1");
|
||||
transportId = getTransportId();
|
||||
transportId1 = getTransportId();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.Arrays;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
|
||||
public class PluginManagerImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
@@ -46,21 +48,21 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
||||
SimplexPluginFactory simplexFactory =
|
||||
context.mock(SimplexPluginFactory.class);
|
||||
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
TransportId simplexId = new TransportId("simplex");
|
||||
TransportId simplexId = getTransportId();
|
||||
SimplexPluginFactory simplexFailFactory =
|
||||
context.mock(SimplexPluginFactory.class, "simplexFailFactory");
|
||||
SimplexPlugin simplexFailPlugin =
|
||||
context.mock(SimplexPlugin.class, "simplexFailPlugin");
|
||||
TransportId simplexFailId = new TransportId("simplex1");
|
||||
TransportId simplexFailId = getTransportId();
|
||||
|
||||
// Two duplex plugin factories: one creates a plugin, the other fails
|
||||
DuplexPluginFactory duplexFactory =
|
||||
context.mock(DuplexPluginFactory.class);
|
||||
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
TransportId duplexId = new TransportId("duplex");
|
||||
TransportId duplexId = getTransportId();
|
||||
DuplexPluginFactory duplexFailFactory =
|
||||
context.mock(DuplexPluginFactory.class, "duplexFailFactory");
|
||||
TransportId duplexFailId = new TransportId("duplex1");
|
||||
TransportId duplexFailId = getTransportId();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(simplexPlugin).getId();
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
|
||||
public class PollerTest extends BrambleMockTestCase {
|
||||
|
||||
@@ -48,7 +49,7 @@ public class PollerTest extends BrambleMockTestCase {
|
||||
private final SecureRandom random;
|
||||
|
||||
private final Executor ioExecutor = new ImmediateExecutor();
|
||||
private final TransportId transportId = new TransportId("id");
|
||||
private final TransportId transportId = getTransportId();
|
||||
private final ContactId contactId = new ContactId(234);
|
||||
private final int pollingInterval = 60 * 1000;
|
||||
private final long now = System.currentTimeMillis();
|
||||
@@ -64,7 +65,7 @@ public class PollerTest extends BrambleMockTestCase {
|
||||
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
SimplexPlugin simplexPlugin1 =
|
||||
context.mock(SimplexPlugin.class, "simplexPlugin1");
|
||||
TransportId simplexId1 = new TransportId("simplex1");
|
||||
TransportId simplexId1 = getTransportId();
|
||||
List<SimplexPlugin> simplexPlugins = Arrays.asList(simplexPlugin,
|
||||
simplexPlugin1);
|
||||
TransportConnectionWriter simplexWriter =
|
||||
@@ -72,7 +73,7 @@ public class PollerTest extends BrambleMockTestCase {
|
||||
|
||||
// Two duplex plugins: one supports polling, the other doesn't
|
||||
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
TransportId duplexId = new TransportId("duplex");
|
||||
TransportId duplexId = getTransportId();
|
||||
DuplexPlugin duplexPlugin1 =
|
||||
context.mock(DuplexPlugin.class, "duplexPlugin1");
|
||||
List<DuplexPlugin> duplexPlugins = Arrays.asList(duplexPlugin,
|
||||
@@ -349,7 +350,6 @@ public class PollerTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testCancelsPollingOnTransportDisabled() throws Exception {
|
||||
Plugin plugin = context.mock(Plugin.class);
|
||||
List<ContactId> connected = Collections.singletonList(contactId);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(plugin).getId();
|
||||
|
||||
@@ -32,9 +32,9 @@ import java.util.Map;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_VERSION;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -51,7 +51,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
context.mock(ContactGroupFactory.class);
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
|
||||
private final Group localGroup = getGroup();
|
||||
private final Group localGroup = getGroup(CLIENT_ID);
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final BdfDictionary fooPropertiesDict = BdfDictionary.of(
|
||||
new BdfEntry("fooKey1", "fooValue1"),
|
||||
@@ -90,7 +90,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
Contact contact1 = getContact(true);
|
||||
Contact contact2 = getContact(true);
|
||||
List<Contact> contacts = Arrays.asList(contact1, contact2);
|
||||
Group contactGroup1 = getGroup(), contactGroup2 = getGroup();
|
||||
Group contactGroup1 = getGroup(CLIENT_ID);
|
||||
Group contactGroup2 = getGroup(CLIENT_ID);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).containsGroup(txn, localGroup.getId());
|
||||
@@ -143,7 +144,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testCreatesContactGroupWhenAddingContact() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
Group contactGroup = getGroup(CLIENT_ID);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Create the group and share it with the contact
|
||||
@@ -171,7 +172,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testRemovesGroupWhenRemovingContact() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
Group contactGroup = getGroup(CLIENT_ID);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
@@ -306,7 +307,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testStoresRemotePropertiesWithVersion0() throws Exception {
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
Group contactGroup = getGroup(CLIENT_ID);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Map<TransportId, TransportProperties> properties =
|
||||
new LinkedHashMap<>();
|
||||
@@ -417,8 +418,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
Contact contact3 = getContact(true);
|
||||
List<Contact> contacts =
|
||||
Arrays.asList(contact1, contact2, contact3);
|
||||
Group contactGroup2 = getGroup();
|
||||
Group contactGroup3 = getGroup();
|
||||
Group contactGroup2 = getGroup(CLIENT_ID);
|
||||
Group contactGroup3 = getGroup(CLIENT_ID);
|
||||
Map<MessageId, BdfDictionary> messageMetadata3 =
|
||||
new LinkedHashMap<>();
|
||||
// A remote update for another transport should be ignored
|
||||
@@ -514,7 +515,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testMergingNewPropertiesCreatesUpdate() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
Group contactGroup = getGroup(CLIENT_ID);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -549,7 +550,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testMergingUpdatedPropertiesCreatesUpdate() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup();
|
||||
Group contactGroup = getGroup(CLIENT_ID);
|
||||
BdfDictionary oldMetadata = BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
@@ -600,12 +601,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
t.mergeLocalProperties(new TransportId("foo"), fooProperties);
|
||||
}
|
||||
|
||||
private Group getGroup() {
|
||||
GroupId g = new GroupId(getRandomId());
|
||||
byte[] descriptor = getRandomBytes(MAX_GROUP_DESCRIPTOR_LENGTH);
|
||||
return new Group(g, CLIENT_ID, descriptor);
|
||||
}
|
||||
|
||||
private Contact getContact(boolean active) {
|
||||
ContactId c = new ContactId(nextContactId++);
|
||||
return new Contact(c, getAuthor(), localAuthor.getId(),
|
||||
|
||||
@@ -6,14 +6,11 @@ import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
@@ -22,6 +19,11 @@ import java.io.IOException;
|
||||
|
||||
import static org.briarproject.bramble.api.plugin.TransportId.MAX_TRANSPORT_ID_LENGTH;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TransportPropertyValidatorTest extends BrambleTestCase {
|
||||
@@ -33,18 +35,14 @@ public class TransportPropertyValidatorTest extends BrambleTestCase {
|
||||
private final TransportPropertyValidator tpv;
|
||||
|
||||
public TransportPropertyValidatorTest() {
|
||||
transportId = new TransportId("test");
|
||||
transportId = getTransportId();
|
||||
bdfDictionary = new BdfDictionary();
|
||||
|
||||
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
ClientId clientId = new ClientId(StringUtils.getRandomString(5));
|
||||
byte[] descriptor = TestUtils.getRandomBytes(12);
|
||||
group = new Group(groupId, clientId, descriptor);
|
||||
|
||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
group = getGroup(getClientId());
|
||||
MessageId messageId = new MessageId(getRandomId());
|
||||
long timestamp = System.currentTimeMillis();
|
||||
byte[] body = TestUtils.getRandomBytes(123);
|
||||
message = new Message(messageId, groupId, timestamp, body);
|
||||
byte[] body = getRandomBytes(123);
|
||||
message = new Message(messageId, group.getId(), timestamp, body);
|
||||
|
||||
Mockery context = new Mockery();
|
||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
@@ -63,7 +61,7 @@ public class TransportPropertyValidatorTest extends BrambleTestCase {
|
||||
BdfDictionary result = tpv.validateMessage(message, group, body)
|
||||
.getDictionary();
|
||||
|
||||
assertEquals("test", result.getString("transportId"));
|
||||
assertEquals(transportId.getString(), result.getString("transportId"));
|
||||
assertEquals(4, result.getLong("version").longValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ import javax.inject.Inject;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -73,13 +74,13 @@ public class SyncIntegrationTest extends BrambleTestCase {
|
||||
component.inject(this);
|
||||
|
||||
contactId = new ContactId(234);
|
||||
transportId = new TransportId("id");
|
||||
transportId = getTransportId();
|
||||
// Create the transport keys
|
||||
tagKey = TestUtils.getSecretKey();
|
||||
headerKey = TestUtils.getSecretKey();
|
||||
streamNumber = 123;
|
||||
// Create a group
|
||||
ClientId clientId = new ClientId(getRandomString(123));
|
||||
ClientId clientId = getClientId();
|
||||
int clientVersion = 1234567890;
|
||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||
Group group = groupFactory.createGroup(clientId, clientVersion,
|
||||
|
||||
@@ -21,9 +21,7 @@ import org.briarproject.bramble.api.sync.ValidationManager.State;
|
||||
import org.briarproject.bramble.api.sync.event.MessageAddedEvent;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.ByteUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -38,6 +36,9 @@ import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERE
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.INVALID;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
|
||||
public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@@ -51,14 +52,12 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final Executor dbExecutor = new ImmediateExecutor();
|
||||
private final Executor validationExecutor = new ImmediateExecutor();
|
||||
private final ClientId clientId =
|
||||
new ClientId(StringUtils.getRandomString(5));
|
||||
private final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
private final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
private final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
private final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
private final byte[] descriptor = new byte[32];
|
||||
private final Group group = new Group(groupId, clientId, descriptor);
|
||||
private final ClientId clientId = getClientId();
|
||||
private final MessageId messageId = new MessageId(getRandomId());
|
||||
private final MessageId messageId1 = new MessageId(getRandomId());
|
||||
private final MessageId messageId2 = new MessageId(getRandomId());
|
||||
private final Group group = getGroup(clientId);
|
||||
private final GroupId groupId = group.getId();
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
private final byte[] raw = new byte[123];
|
||||
private final Message message = new Message(messageId, groupId, timestamp,
|
||||
@@ -716,8 +715,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRecursiveInvalidation() throws Exception {
|
||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId3 = new MessageId(getRandomId());
|
||||
MessageId messageId4 = new MessageId(getRandomId());
|
||||
Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
twoDependents.put(messageId1, PENDING);
|
||||
twoDependents.put(messageId2, PENDING);
|
||||
@@ -819,8 +818,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testPendingDependentsGetDelivered() throws Exception {
|
||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
MessageId messageId3 = new MessageId(getRandomId());
|
||||
MessageId messageId4 = new MessageId(getRandomId());
|
||||
Message message3 = new Message(messageId3, groupId, timestamp,
|
||||
raw);
|
||||
Message message4 = new Message(messageId4, groupId, timestamp,
|
||||
|
||||
@@ -16,10 +16,12 @@ import javax.annotation.Nullable;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
|
||||
@Module
|
||||
public class TestPluginConfigModule {
|
||||
|
||||
public static final TransportId TRANSPORT_ID = new TransportId("id");
|
||||
public static final TransportId TRANSPORT_ID = getTransportId();
|
||||
public static final int MAX_LATENCY = 2 * 60 * 1000; // 2 minutes
|
||||
|
||||
@NotNullByDefault
|
||||
|
||||
@@ -2,17 +2,16 @@ package org.briarproject.bramble.test;
|
||||
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
|
||||
public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
||||
|
||||
@@ -21,17 +20,14 @@ public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
||||
protected final MetadataEncoder metadataEncoder =
|
||||
context.mock(MetadataEncoder.class);
|
||||
protected final Clock clock = context.mock(Clock.class);
|
||||
protected final AuthorFactory authorFactory =
|
||||
context.mock(AuthorFactory.class);
|
||||
|
||||
protected final Group group = getGroup(getClientId());
|
||||
protected final GroupId groupId = group.getId();
|
||||
protected final byte[] descriptor = group.getDescriptor();
|
||||
protected final MessageId messageId = new MessageId(getRandomId());
|
||||
protected final GroupId groupId = new GroupId(getRandomId());
|
||||
protected final long timestamp = 1234567890 * 1000L;
|
||||
protected final byte[] raw = getRandomBytes(123);
|
||||
protected final Message message =
|
||||
new Message(messageId, groupId, timestamp, raw);
|
||||
protected final ClientId clientId = new ClientId(getRandomString(123));
|
||||
protected final byte[] descriptor = getRandomBytes(123);
|
||||
protected final Group group = new Group(groupId, clientId, descriptor);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class KeyManagerImplTest extends BrambleMockTestCase {
|
||||
@@ -47,8 +48,8 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
|
||||
private final ContactId contactId = new ContactId(123);
|
||||
private final ContactId inactiveContactId = new ContactId(234);
|
||||
private final KeySetId keySetId = new KeySetId(345);
|
||||
private final TransportId transportId = new TransportId("known");
|
||||
private final TransportId unknownTransportId = new TransportId("unknown");
|
||||
private final TransportId transportId = getTransportId();
|
||||
private final TransportId unknownTransportId = getTransportId();
|
||||
private final StreamContext streamContext =
|
||||
new StreamContext(contactId, transportId, getSecretKey(),
|
||||
getSecretKey(), 1);
|
||||
|
||||
@@ -36,6 +36,7 @@ import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOC
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -53,7 +54,7 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
|
||||
private final TransportId transportId = new TransportId("id");
|
||||
private final TransportId transportId = getTransportId();
|
||||
private final long maxLatency = 30 * 1000; // 30 seconds
|
||||
private final long rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
||||
private final ContactId contactId = new ContactId(123);
|
||||
|
||||
@@ -14,8 +14,6 @@ import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
@@ -34,6 +32,7 @@ import static org.briarproject.bramble.api.identity.Author.Status.NONE;
|
||||
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
|
||||
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -867,9 +866,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
private Blog createBlog(LocalAuthor localAuthor, boolean rssFeed) {
|
||||
GroupId groupId = new GroupId(getRandomId());
|
||||
Group group = new Group(groupId, CLIENT_ID, getRandomBytes(42));
|
||||
return new Blog(group, localAuthor, rssFeed);
|
||||
return new Blog(getGroup(CLIENT_ID), localAuthor, rssFeed);
|
||||
}
|
||||
|
||||
private BdfList authorToBdfList(Author a) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
@@ -25,6 +24,7 @@ import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -64,9 +64,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
private final String body = getRandomString(42);
|
||||
|
||||
public BlogPostValidatorTest() {
|
||||
GroupId groupId = new GroupId(getRandomId());
|
||||
descriptor = getRandomBytes(42);
|
||||
group = new Group(groupId, CLIENT_ID, descriptor);
|
||||
group = getGroup(CLIENT_ID);
|
||||
descriptor = group.getDescriptor();
|
||||
author = getAuthor();
|
||||
authorList = BdfList.of(
|
||||
author.getFormatVersion(),
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.sync.ValidationManager.MessageValidator;
|
||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.ByteUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager.IncomingQueueMessageHook;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager.QueueMessageValidator;
|
||||
import org.briarproject.briar.api.client.QueueMessage;
|
||||
@@ -35,6 +34,8 @@ import org.junit.Test;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.briar.api.client.MessageQueueManager.QUEUE_STATE_KEY;
|
||||
import static org.briarproject.briar.api.client.QueueMessage.QUEUE_MESSAGE_HEADER_LENGTH;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -44,11 +45,9 @@ import static org.junit.Assert.fail;
|
||||
|
||||
public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
|
||||
private final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||
private final ClientId clientId =
|
||||
new ClientId(StringUtils.getRandomString(5));
|
||||
private final byte[] descriptor = new byte[0];
|
||||
private final Group group = new Group(groupId, clientId, descriptor);
|
||||
private final ClientId clientId = getClientId();
|
||||
private final Group group = getGroup(clientId);
|
||||
private final GroupId groupId = group.getId();
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,6 +37,7 @@ import javax.net.SocketFactory;
|
||||
|
||||
import okhttp3.Dns;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -60,12 +61,10 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
private final Dns noDnsLookups = context.mock(Dns.class);
|
||||
|
||||
private final GroupId localGroupId = new GroupId(getRandomId());
|
||||
private final Group localGroup =
|
||||
new Group(localGroupId, CLIENT_ID, getRandomBytes(42));
|
||||
private final GroupId blogGroupId = new GroupId(getRandomId());
|
||||
private final Group blogGroup =
|
||||
new Group(blogGroupId, BlogManager.CLIENT_ID, getRandomBytes(42));
|
||||
private final Group localGroup = getGroup(CLIENT_ID);
|
||||
private final GroupId localGroupId = localGroup.getId();
|
||||
private final Group blogGroup = getGroup(BlogManager.CLIENT_ID);
|
||||
private final GroupId blogGroupId = blogGroup.getId();
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final Blog blog = new Blog(blogGroup, localAuthor, true);
|
||||
private final Feed feed =
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
@@ -40,6 +39,7 @@ import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
@@ -79,6 +79,7 @@ import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ACK;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
||||
import static org.hamcrest.Matchers.array;
|
||||
import static org.hamcrest.Matchers.samePropertyValuesAs;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -145,11 +146,8 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
introducee2 =
|
||||
new Contact(contactId2, author2, localAuthorId, true, true);
|
||||
|
||||
ClientId clientId = IntroductionManagerImpl.CLIENT_ID;
|
||||
localGroup1 = new Group(new GroupId(getRandomId()),
|
||||
clientId, new byte[0]);
|
||||
introductionGroup1 = new Group(new GroupId(getRandomId()),
|
||||
clientId, new byte[0]);
|
||||
localGroup1 = getGroup(CLIENT_ID);
|
||||
introductionGroup1 = getGroup(CLIENT_ID);
|
||||
|
||||
sessionId = new SessionId(getRandomId());
|
||||
localStateMessage = new Message(
|
||||
|
||||
@@ -12,9 +12,7 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
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.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
@@ -27,6 +25,7 @@ import org.junit.Test;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerProtocolState.AWAIT_RESPONSES;
|
||||
@@ -50,6 +49,7 @@ import static org.briarproject.briar.api.introduction.IntroductionConstants.STAT
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.STORAGE_ID;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class IntroducerManagerTest extends BriarTestCase {
|
||||
@@ -93,12 +93,9 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
introducee2 =
|
||||
new Contact(contactId2, author2, localAuthorId2, true, true);
|
||||
|
||||
localGroup0 = new Group(new GroupId(getRandomId()),
|
||||
getClientId(), new byte[0]);
|
||||
introductionGroup1 = new Group(new GroupId(getRandomId()),
|
||||
getClientId(), new byte[0]);
|
||||
introductionGroup2 = new Group(new GroupId(getRandomId()),
|
||||
getClientId(), new byte[0]);
|
||||
localGroup0 = getGroup(CLIENT_ID);
|
||||
introductionGroup1 = getGroup(CLIENT_ID);
|
||||
introductionGroup2 = getGroup(CLIENT_ID);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -179,8 +176,4 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
assertFalse(txn.isCommitted());
|
||||
}
|
||||
|
||||
private ClientId getClientId() {
|
||||
return IntroductionManagerImpl.CLIENT_ID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -54,6 +53,7 @@ import javax.inject.Inject;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.client.MessageQueueManager.QUEUE_STATE_KEY;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.ALICE_MAC_KEY_LABEL;
|
||||
@@ -372,7 +372,7 @@ public class IntroductionIntegrationTest
|
||||
TransportProperties tp = new TransportProperties(
|
||||
Collections.singletonMap("key", "value"));
|
||||
c0.getTransportPropertyManager()
|
||||
.mergeLocalProperties(new TransportId("fake"), tp);
|
||||
.mergeLocalProperties(getTransportId(), tp);
|
||||
sync0To1(1, true);
|
||||
|
||||
// sync second response
|
||||
|
||||
@@ -13,9 +13,7 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
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.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||
@@ -33,9 +31,9 @@ import java.util.Map;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.GROUP_ID_1;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.GROUP_ID_2;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.ROLE;
|
||||
@@ -44,6 +42,7 @@ import static org.briarproject.briar.api.introduction.IntroductionConstants.SESS
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
@@ -79,11 +78,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
introducee2 =
|
||||
new Contact(contactId2, author2, localAuthorId2, true, true);
|
||||
|
||||
ClientId clientId = new ClientId(getRandomString(5));
|
||||
introductionGroup1 = new Group(new GroupId(getRandomId()),
|
||||
clientId, new byte[0]);
|
||||
introductionGroup2 = new Group(new GroupId(getRandomId()),
|
||||
clientId, new byte[0]);
|
||||
introductionGroup1 = getGroup(CLIENT_ID);
|
||||
introductionGroup2 = getGroup(CLIENT_ID);
|
||||
|
||||
message1 = new Message(
|
||||
new MessageId(getRandomId()),
|
||||
|
||||
@@ -8,9 +8,7 @@ import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
@@ -27,6 +25,8 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -61,11 +61,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
|
||||
private final Clock clock = new SystemClock();
|
||||
|
||||
public IntroductionValidatorTest() {
|
||||
GroupId groupId = new GroupId(getRandomId());
|
||||
ClientId clientId = new ClientId(getRandomString(5));
|
||||
byte[] descriptor = getRandomBytes(12);
|
||||
group = new Group(groupId, clientId, descriptor);
|
||||
|
||||
group = getGroup(getClientId());
|
||||
MessageId messageId = new MessageId(getRandomId());
|
||||
long timestamp = System.currentTimeMillis();
|
||||
byte[] raw = getRandomBytes(123);
|
||||
|
||||
@@ -10,12 +10,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.client.MessageQueueManager;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.test.BriarTestCase;
|
||||
@@ -24,6 +20,10 @@ import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.GROUP_ID;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAC;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.SESSION_ID;
|
||||
@@ -59,13 +59,10 @@ public class MessageSenderTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSendMessage() throws DbException, FormatException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Group privateGroup =
|
||||
new Group(new GroupId(TestUtils.getRandomId()),
|
||||
new ClientId(StringUtils.getRandomString(5)),
|
||||
new byte[0]);
|
||||
SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
||||
byte[] mac = TestUtils.getRandomBytes(42);
|
||||
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
Group privateGroup = getGroup(getClientId());
|
||||
SessionId sessionId = new SessionId(getRandomId());
|
||||
byte[] mac = getRandomBytes(42);
|
||||
byte[] sig = getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||
long time = 42L;
|
||||
BdfDictionary msg = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, TYPE_ACK),
|
||||
@@ -76,7 +73,7 @@ public class MessageSenderTest extends BriarTestCase {
|
||||
);
|
||||
BdfList bodyList =
|
||||
BdfList.of(TYPE_ACK, sessionId.getBytes(), mac, sig);
|
||||
byte[] body = TestUtils.getRandomBytes(8);
|
||||
byte[] body = getRandomBytes(8);
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jmock.Expectations;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -63,9 +64,8 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
|
||||
protected final Transaction txn = new Transaction(null, false);
|
||||
protected final GroupId contactGroupId = new GroupId(getRandomId());
|
||||
protected final GroupId privateGroupId = new GroupId(getRandomId());
|
||||
protected final Group privateGroupGroup =
|
||||
new Group(privateGroupId, CLIENT_ID, getRandomBytes(123));
|
||||
protected final Group privateGroupGroup = getGroup(CLIENT_ID);
|
||||
protected final GroupId privateGroupId = privateGroupGroup.getId();
|
||||
protected final Author author = getAuthor();
|
||||
protected final PrivateGroup privateGroup =
|
||||
new PrivateGroup(privateGroupGroup,
|
||||
|
||||
@@ -854,10 +854,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
Collection<Contact> contacts =
|
||||
Arrays.asList(contact, contact2, contact3);
|
||||
|
||||
Group contactGroup2 = new Group(new GroupId(getRandomId()),
|
||||
CLIENT_ID, getRandomBytes(5));
|
||||
Group contactGroup3 = new Group(new GroupId(getRandomId()),
|
||||
CLIENT_ID, getRandomBytes(5));
|
||||
Group contactGroup2 = getGroup(CLIENT_ID);
|
||||
Group contactGroup3 = getGroup(CLIENT_ID);
|
||||
|
||||
MessageId storageId2 = new MessageId(getRandomId());
|
||||
MessageId storageId3 = new MessageId(getRandomId());
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
@@ -226,8 +225,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
private void expectPreShareShareable(Transaction txn, Contact contact,
|
||||
Blog blog, Map<MessageId, BdfDictionary> sessions)
|
||||
throws Exception {
|
||||
Group contactGroup = new Group(new GroupId(getRandomId()), CLIENT_ID,
|
||||
getRandomBytes(42));
|
||||
Group contactGroup = getGroup(CLIENT_ID);
|
||||
BdfDictionary sessionDict = new BdfDictionary();
|
||||
Message message = new Message(new MessageId(getRandomId()),
|
||||
contactGroup.getId(), 42L, getRandomBytes(1337));
|
||||
|
||||
Reference in New Issue
Block a user