mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Set max length for client IDs.
This commit is contained in:
@@ -1,22 +1,23 @@
|
|||||||
package org.briarproject.bramble.api.plugin;
|
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 {
|
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;
|
private final String id;
|
||||||
|
|
||||||
public TransportId(String id) {
|
public TransportId(String id) {
|
||||||
byte[] b = id.getBytes(Charset.forName("UTF-8"));
|
int length = StringUtils.toUtf8(id).length;
|
||||||
if (b.length == 0 || b.length > MAX_TRANSPORT_ID_LENGTH)
|
if (length == 0 || length > MAX_TRANSPORT_ID_LENGTH)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
package org.briarproject.bramble.api.sync;
|
package org.briarproject.bramble.api.sync;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
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
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ClientId implements Comparable<ClientId> {
|
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;
|
private final String id;
|
||||||
|
|
||||||
public ClientId(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;
|
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.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
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.ClientId;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
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.Author.FORMAT_VERSION;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
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_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_GROUP_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
@@ -54,6 +57,14 @@ public class TestUtils {
|
|||||||
return getRandomBytes(UniqueId.LENGTH);
|
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() {
|
public static SecretKey getSecretKey() {
|
||||||
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
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.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -27,7 +28,7 @@ public class KeyDerivationTest extends BrambleTestCase {
|
|||||||
new CryptoComponentImpl(new TestSecureRandomProvider(), null);
|
new CryptoComponentImpl(new TestSecureRandomProvider(), null);
|
||||||
private final TransportCrypto transportCrypto =
|
private final TransportCrypto transportCrypto =
|
||||||
new TransportCryptoImpl(crypto);
|
new TransportCryptoImpl(crypto);
|
||||||
private final TransportId transportId = new TransportId("id");
|
private final TransportId transportId = getTransportId();
|
||||||
private final SecretKey master = getSecretKey();
|
private final SecretKey master = getSecretKey();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -135,7 +136,7 @@ public class KeyDerivationTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransportIdAffectsOutput() {
|
public void testTransportIdAffectsOutput() {
|
||||||
TransportId transportId1 = new TransportId("id1");
|
TransportId transportId1 = getTransportId();
|
||||||
assertFalse(transportId.getString().equals(transportId1.getString()));
|
assertFalse(transportId.getString().equals(transportId1.getString()));
|
||||||
TransportKeys k = transportCrypto.deriveTransportKeys(transportId,
|
TransportKeys k = transportCrypto.deriveTransportKeys(transportId,
|
||||||
master, 123, true, true);
|
master, 123, true, true);
|
||||||
|
|||||||
@@ -70,9 +70,10 @@ 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.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
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.getAuthor;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@@ -104,7 +105,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
private final KeySetId keySetId;
|
private final KeySetId keySetId;
|
||||||
|
|
||||||
public DatabaseComponentImplTest() {
|
public DatabaseComponentImplTest() {
|
||||||
clientId = new ClientId(getRandomString(123));
|
clientId = getClientId();
|
||||||
groupId = new GroupId(TestUtils.getRandomId());
|
groupId = new GroupId(TestUtils.getRandomId());
|
||||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||||
group = new Group(groupId, clientId, descriptor);
|
group = new Group(groupId, clientId, descriptor);
|
||||||
@@ -118,7 +119,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
message = new Message(messageId, groupId, timestamp, raw);
|
message = new Message(messageId, groupId, timestamp, raw);
|
||||||
metadata = new Metadata();
|
metadata = new Metadata();
|
||||||
metadata.put("foo", new byte[] {'b', 'a', 'r'});
|
metadata.put("foo", new byte[] {'b', 'a', 'r'});
|
||||||
transportId = new TransportId("id");
|
transportId = getTransportId();
|
||||||
maxLatency = Integer.MAX_VALUE;
|
maxLatency = Integer.MAX_VALUE;
|
||||||
contactId = new ContactId(234);
|
contactId = new ContactId(234);
|
||||||
contact = new Contact(contactId, author, localAuthor.getId(),
|
contact = new Contact(contactId, author, localAuthor.getId(),
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ 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.PENDING;
|
||||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
|
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.getAuthor;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
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.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -95,7 +96,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
|
|
||||||
JdbcDatabaseTest() throws Exception {
|
JdbcDatabaseTest() throws Exception {
|
||||||
groupId = new GroupId(getRandomId());
|
groupId = new GroupId(getRandomId());
|
||||||
clientId = new ClientId(getRandomString(123));
|
clientId = getClientId();
|
||||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||||
group = new Group(groupId, clientId, descriptor);
|
group = new Group(groupId, clientId, descriptor);
|
||||||
author = getAuthor();
|
author = getAuthor();
|
||||||
@@ -105,7 +106,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
size = 1234;
|
size = 1234;
|
||||||
raw = getRandomBytes(size);
|
raw = getRandomBytes(size);
|
||||||
message = new Message(messageId, groupId, timestamp, raw);
|
message = new Message(messageId, groupId, timestamp, raw);
|
||||||
transportId = new TransportId("id");
|
transportId = getTransportId();
|
||||||
contactId = new ContactId(1);
|
contactId = new ContactId(1);
|
||||||
keySetId = new KeySetId(1);
|
keySetId = new KeySetId(1);
|
||||||
keySetId1 = new KeySetId(2);
|
keySetId1 = new KeySetId(2);
|
||||||
|
|||||||
@@ -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.ABORT;
|
||||||
import static org.briarproject.bramble.api.keyagreement.RecordTypes.CONFIRM;
|
import static org.briarproject.bramble.api.keyagreement.RecordTypes.CONFIRM;
|
||||||
import static org.briarproject.bramble.api.keyagreement.RecordTypes.KEY;
|
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.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ public class KeyAgreementTransportTest extends BrambleMockTestCase {
|
|||||||
private final TransportConnectionWriter transportConnectionWriter =
|
private final TransportConnectionWriter transportConnectionWriter =
|
||||||
context.mock(TransportConnectionWriter.class);
|
context.mock(TransportConnectionWriter.class);
|
||||||
|
|
||||||
private final TransportId transportId = new TransportId("test");
|
private final TransportId transportId = getTransportId();
|
||||||
private final KeyAgreementConnection keyAgreementConnection =
|
private final KeyAgreementConnection keyAgreementConnection =
|
||||||
new KeyAgreementConnection(duplexTransportConnection, transportId);
|
new KeyAgreementConnection(duplexTransportConnection, transportId);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@@ -29,8 +30,8 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
|
|||||||
public ConnectionRegistryImplTest() {
|
public ConnectionRegistryImplTest() {
|
||||||
contactId = new ContactId(1);
|
contactId = new ContactId(1);
|
||||||
contactId1 = new ContactId(2);
|
contactId1 = new ContactId(2);
|
||||||
transportId = new TransportId("id");
|
transportId = getTransportId();
|
||||||
transportId1 = new TransportId("id1");
|
transportId1 = getTransportId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import java.util.Arrays;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
|
|
||||||
public class PluginManagerImplTest extends BrambleTestCase {
|
public class PluginManagerImplTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -46,21 +48,21 @@ public class PluginManagerImplTest extends BrambleTestCase {
|
|||||||
SimplexPluginFactory simplexFactory =
|
SimplexPluginFactory simplexFactory =
|
||||||
context.mock(SimplexPluginFactory.class);
|
context.mock(SimplexPluginFactory.class);
|
||||||
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||||
TransportId simplexId = new TransportId("simplex");
|
TransportId simplexId = getTransportId();
|
||||||
SimplexPluginFactory simplexFailFactory =
|
SimplexPluginFactory simplexFailFactory =
|
||||||
context.mock(SimplexPluginFactory.class, "simplexFailFactory");
|
context.mock(SimplexPluginFactory.class, "simplexFailFactory");
|
||||||
SimplexPlugin simplexFailPlugin =
|
SimplexPlugin simplexFailPlugin =
|
||||||
context.mock(SimplexPlugin.class, "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
|
// Two duplex plugin factories: one creates a plugin, the other fails
|
||||||
DuplexPluginFactory duplexFactory =
|
DuplexPluginFactory duplexFactory =
|
||||||
context.mock(DuplexPluginFactory.class);
|
context.mock(DuplexPluginFactory.class);
|
||||||
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||||
TransportId duplexId = new TransportId("duplex");
|
TransportId duplexId = getTransportId();
|
||||||
DuplexPluginFactory duplexFailFactory =
|
DuplexPluginFactory duplexFailFactory =
|
||||||
context.mock(DuplexPluginFactory.class, "duplexFailFactory");
|
context.mock(DuplexPluginFactory.class, "duplexFailFactory");
|
||||||
TransportId duplexFailId = new TransportId("duplex1");
|
TransportId duplexFailId = getTransportId();
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
allowing(simplexPlugin).getId();
|
allowing(simplexPlugin).getId();
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
|
|
||||||
public class PollerTest extends BrambleMockTestCase {
|
public class PollerTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ public class PollerTest extends BrambleMockTestCase {
|
|||||||
private final SecureRandom random;
|
private final SecureRandom random;
|
||||||
|
|
||||||
private final Executor ioExecutor = new ImmediateExecutor();
|
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 ContactId contactId = new ContactId(234);
|
||||||
private final int pollingInterval = 60 * 1000;
|
private final int pollingInterval = 60 * 1000;
|
||||||
private final long now = System.currentTimeMillis();
|
private final long now = System.currentTimeMillis();
|
||||||
@@ -64,7 +65,7 @@ public class PollerTest extends BrambleMockTestCase {
|
|||||||
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||||
SimplexPlugin simplexPlugin1 =
|
SimplexPlugin simplexPlugin1 =
|
||||||
context.mock(SimplexPlugin.class, "simplexPlugin1");
|
context.mock(SimplexPlugin.class, "simplexPlugin1");
|
||||||
TransportId simplexId1 = new TransportId("simplex1");
|
TransportId simplexId1 = getTransportId();
|
||||||
List<SimplexPlugin> simplexPlugins = Arrays.asList(simplexPlugin,
|
List<SimplexPlugin> simplexPlugins = Arrays.asList(simplexPlugin,
|
||||||
simplexPlugin1);
|
simplexPlugin1);
|
||||||
TransportConnectionWriter simplexWriter =
|
TransportConnectionWriter simplexWriter =
|
||||||
@@ -72,7 +73,7 @@ public class PollerTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
// Two duplex plugins: one supports polling, the other doesn't
|
// Two duplex plugins: one supports polling, the other doesn't
|
||||||
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||||
TransportId duplexId = new TransportId("duplex");
|
TransportId duplexId = getTransportId();
|
||||||
DuplexPlugin duplexPlugin1 =
|
DuplexPlugin duplexPlugin1 =
|
||||||
context.mock(DuplexPlugin.class, "duplexPlugin1");
|
context.mock(DuplexPlugin.class, "duplexPlugin1");
|
||||||
List<DuplexPlugin> duplexPlugins = Arrays.asList(duplexPlugin,
|
List<DuplexPlugin> duplexPlugins = Arrays.asList(duplexPlugin,
|
||||||
@@ -349,7 +350,6 @@ public class PollerTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testCancelsPollingOnTransportDisabled() throws Exception {
|
public void testCancelsPollingOnTransportDisabled() throws Exception {
|
||||||
Plugin plugin = context.mock(Plugin.class);
|
Plugin plugin = context.mock(Plugin.class);
|
||||||
List<ContactId> connected = Collections.singletonList(contactId);
|
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
allowing(plugin).getId();
|
allowing(plugin).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.BdfList;
|
||||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
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.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.junit.Test;
|
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.plugin.TransportId.MAX_TRANSPORT_ID_LENGTH;
|
||||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT;
|
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;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class TransportPropertyValidatorTest extends BrambleTestCase {
|
public class TransportPropertyValidatorTest extends BrambleTestCase {
|
||||||
@@ -33,18 +35,14 @@ public class TransportPropertyValidatorTest extends BrambleTestCase {
|
|||||||
private final TransportPropertyValidator tpv;
|
private final TransportPropertyValidator tpv;
|
||||||
|
|
||||||
public TransportPropertyValidatorTest() {
|
public TransportPropertyValidatorTest() {
|
||||||
transportId = new TransportId("test");
|
transportId = getTransportId();
|
||||||
bdfDictionary = new BdfDictionary();
|
bdfDictionary = new BdfDictionary();
|
||||||
|
|
||||||
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
group = getGroup(getClientId());
|
||||||
ClientId clientId = new ClientId(StringUtils.getRandomString(5));
|
MessageId messageId = new MessageId(getRandomId());
|
||||||
byte[] descriptor = TestUtils.getRandomBytes(12);
|
|
||||||
group = new Group(groupId, clientId, descriptor);
|
|
||||||
|
|
||||||
MessageId messageId = new MessageId(TestUtils.getRandomId());
|
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
byte[] body = TestUtils.getRandomBytes(123);
|
byte[] body = getRandomBytes(123);
|
||||||
message = new Message(messageId, groupId, timestamp, body);
|
message = new Message(messageId, group.getId(), timestamp, body);
|
||||||
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||||
@@ -63,7 +61,7 @@ public class TransportPropertyValidatorTest extends BrambleTestCase {
|
|||||||
BdfDictionary result = tpv.validateMessage(message, group, body)
|
BdfDictionary result = tpv.validateMessage(message, group, body)
|
||||||
.getDictionary();
|
.getDictionary();
|
||||||
|
|
||||||
assertEquals("test", result.getString("transportId"));
|
assertEquals(transportId.getString(), result.getString("transportId"));
|
||||||
assertEquals(4, result.getLong("version").longValue());
|
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.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
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.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.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -73,13 +74,13 @@ public class SyncIntegrationTest extends BrambleTestCase {
|
|||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
|
||||||
contactId = new ContactId(234);
|
contactId = new ContactId(234);
|
||||||
transportId = new TransportId("id");
|
transportId = getTransportId();
|
||||||
// Create the transport keys
|
// Create the transport keys
|
||||||
tagKey = TestUtils.getSecretKey();
|
tagKey = TestUtils.getSecretKey();
|
||||||
headerKey = TestUtils.getSecretKey();
|
headerKey = TestUtils.getSecretKey();
|
||||||
streamNumber = 123;
|
streamNumber = 123;
|
||||||
// Create a group
|
// Create a group
|
||||||
ClientId clientId = new ClientId(getRandomString(123));
|
ClientId clientId = getClientId();
|
||||||
int clientVersion = 1234567890;
|
int clientVersion = 1234567890;
|
||||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||||
Group group = groupFactory.createGroup(clientId, clientVersion,
|
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.api.sync.event.MessageAddedEvent;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
|
||||||
import org.briarproject.bramble.util.ByteUtils;
|
import org.briarproject.bramble.util.ByteUtils;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -38,6 +36,8 @@ 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.INVALID;
|
||||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING;
|
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.api.sync.ValidationManager.State.UNKNOWN;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
|
|
||||||
public class ValidationManagerImplTest extends BrambleMockTestCase {
|
public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
@@ -51,12 +51,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private final Executor dbExecutor = new ImmediateExecutor();
|
private final Executor dbExecutor = new ImmediateExecutor();
|
||||||
private final Executor validationExecutor = new ImmediateExecutor();
|
private final Executor validationExecutor = new ImmediateExecutor();
|
||||||
private final ClientId clientId =
|
private final ClientId clientId = getClientId();
|
||||||
new ClientId(StringUtils.getRandomString(5));
|
private final MessageId messageId = new MessageId(getRandomId());
|
||||||
private final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
private final MessageId messageId1 = new MessageId(getRandomId());
|
||||||
private final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
private final MessageId messageId2 = new MessageId(getRandomId());
|
||||||
private final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
private final GroupId groupId = new GroupId(getRandomId());
|
||||||
private final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
|
||||||
private final byte[] descriptor = new byte[32];
|
private final byte[] descriptor = new byte[32];
|
||||||
private final Group group = new Group(groupId, clientId, descriptor);
|
private final Group group = new Group(groupId, clientId, descriptor);
|
||||||
private final long timestamp = System.currentTimeMillis();
|
private final long timestamp = System.currentTimeMillis();
|
||||||
@@ -716,8 +715,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecursiveInvalidation() throws Exception {
|
public void testRecursiveInvalidation() throws Exception {
|
||||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId3 = new MessageId(getRandomId());
|
||||||
MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId4 = new MessageId(getRandomId());
|
||||||
Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||||
twoDependents.put(messageId1, PENDING);
|
twoDependents.put(messageId1, PENDING);
|
||||||
twoDependents.put(messageId2, PENDING);
|
twoDependents.put(messageId2, PENDING);
|
||||||
@@ -819,8 +818,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPendingDependentsGetDelivered() throws Exception {
|
public void testPendingDependentsGetDelivered() throws Exception {
|
||||||
MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId3 = new MessageId(getRandomId());
|
||||||
MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId4 = new MessageId(getRandomId());
|
||||||
Message message3 = new Message(messageId3, groupId, timestamp,
|
Message message3 = new Message(messageId3, groupId, timestamp,
|
||||||
raw);
|
raw);
|
||||||
Message message4 = new Message(messageId4, groupId, timestamp,
|
Message message4 = new Message(messageId4, groupId, timestamp,
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ import javax.annotation.Nullable;
|
|||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class TestPluginConfigModule {
|
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
|
public static final int MAX_LATENCY = 2 * 60 * 1000; // 2 minutes
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import org.briarproject.bramble.api.sync.Message;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
|
||||||
|
|
||||||
public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ public abstract class ValidatorTestCase extends BrambleMockTestCase {
|
|||||||
protected final byte[] raw = getRandomBytes(123);
|
protected final byte[] raw = getRandomBytes(123);
|
||||||
protected final Message message =
|
protected final Message message =
|
||||||
new Message(messageId, groupId, timestamp, raw);
|
new Message(messageId, groupId, timestamp, raw);
|
||||||
protected final ClientId clientId = new ClientId(getRandomString(123));
|
protected final ClientId clientId = getClientId();
|
||||||
protected final byte[] descriptor = getRandomBytes(123);
|
protected final byte[] descriptor = getRandomBytes(123);
|
||||||
protected final Group group = new Group(groupId, clientId, descriptor);
|
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.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class KeyManagerImplTest extends BrambleMockTestCase {
|
public class KeyManagerImplTest extends BrambleMockTestCase {
|
||||||
@@ -47,8 +48,8 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final ContactId contactId = new ContactId(123);
|
private final ContactId contactId = new ContactId(123);
|
||||||
private final ContactId inactiveContactId = new ContactId(234);
|
private final ContactId inactiveContactId = new ContactId(234);
|
||||||
private final KeySetId keySetId = new KeySetId(345);
|
private final KeySetId keySetId = new KeySetId(345);
|
||||||
private final TransportId transportId = new TransportId("known");
|
private final TransportId transportId = getTransportId();
|
||||||
private final TransportId unknownTransportId = new TransportId("unknown");
|
private final TransportId unknownTransportId = getTransportId();
|
||||||
private final StreamContext streamContext =
|
private final StreamContext streamContext =
|
||||||
new StreamContext(contactId, transportId, getSecretKey(),
|
new StreamContext(contactId, transportId, getSecretKey(),
|
||||||
getSecretKey(), 1);
|
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.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
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.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.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -53,7 +54,7 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
context.mock(ScheduledExecutorService.class);
|
context.mock(ScheduledExecutorService.class);
|
||||||
private final Clock clock = context.mock(Clock.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 maxLatency = 30 * 1000; // 30 seconds
|
||||||
private final long rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
private final long rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
||||||
private final ContactId contactId = new ContactId(123);
|
private final ContactId contactId = new ContactId(123);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.sync.ValidationManager.MessageValidator;
|
|||||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
import org.briarproject.bramble.util.ByteUtils;
|
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.IncomingQueueMessageHook;
|
||||||
import org.briarproject.briar.api.client.MessageQueueManager.QueueMessageValidator;
|
import org.briarproject.briar.api.client.MessageQueueManager.QueueMessageValidator;
|
||||||
import org.briarproject.briar.api.client.QueueMessage;
|
import org.briarproject.briar.api.client.QueueMessage;
|
||||||
@@ -35,6 +34,7 @@ import org.junit.Test;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.briar.api.client.MessageQueueManager.QUEUE_STATE_KEY;
|
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.briarproject.briar.api.client.QueueMessage.QUEUE_MESSAGE_HEADER_LENGTH;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -45,8 +45,7 @@ import static org.junit.Assert.fail;
|
|||||||
public class MessageQueueManagerImplTest extends BriarTestCase {
|
public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||||
|
|
||||||
private final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
private final GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||||
private final ClientId clientId =
|
private final ClientId clientId = getClientId();
|
||||||
new ClientId(StringUtils.getRandomString(5));
|
|
||||||
private final byte[] descriptor = new byte[0];
|
private final byte[] descriptor = new byte[0];
|
||||||
private final Group group = new Group(groupId, clientId, descriptor);
|
private final Group group = new Group(groupId, clientId, descriptor);
|
||||||
private final long timestamp = System.currentTimeMillis();
|
private final long timestamp = System.currentTimeMillis();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import org.briarproject.bramble.api.event.EventListener;
|
|||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
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.TransportProperties;
|
||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
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.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID;
|
import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
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.bramble.util.StringUtils.getRandomString;
|
||||||
import static org.briarproject.briar.api.client.MessageQueueManager.QUEUE_STATE_KEY;
|
import static org.briarproject.briar.api.client.MessageQueueManager.QUEUE_STATE_KEY;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.ALICE_MAC_KEY_LABEL;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.ALICE_MAC_KEY_LABEL;
|
||||||
@@ -372,7 +372,7 @@ public class IntroductionIntegrationTest
|
|||||||
TransportProperties tp = new TransportProperties(
|
TransportProperties tp = new TransportProperties(
|
||||||
Collections.singletonMap("key", "value"));
|
Collections.singletonMap("key", "value"));
|
||||||
c0.getTransportPropertyManager()
|
c0.getTransportPropertyManager()
|
||||||
.mergeLocalProperties(new TransportId("fake"), tp);
|
.mergeLocalProperties(getTransportId(), tp);
|
||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
|
|
||||||
// sync second response
|
// sync second response
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_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.getAuthor;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
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_1;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.GROUP_ID_2;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.GROUP_ID_2;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.ROLE;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.ROLE;
|
||||||
@@ -79,7 +79,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
|||||||
introducee2 =
|
introducee2 =
|
||||||
new Contact(contactId2, author2, localAuthorId2, true, true);
|
new Contact(contactId2, author2, localAuthorId2, true, true);
|
||||||
|
|
||||||
ClientId clientId = new ClientId(getRandomString(5));
|
ClientId clientId = getClientId();
|
||||||
introductionGroup1 = new Group(new GroupId(getRandomId()),
|
introductionGroup1 = new Group(new GroupId(getRandomId()),
|
||||||
clientId, new byte[0]);
|
clientId, new byte[0]);
|
||||||
introductionGroup2 = new Group(new GroupId(getRandomId()),
|
introductionGroup2 = new Group(new GroupId(getRandomId()),
|
||||||
|
|||||||
@@ -10,12 +10,9 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
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.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
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.MessageQueueManager;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.test.BriarTestCase;
|
import org.briarproject.briar.test.BriarTestCase;
|
||||||
@@ -24,6 +21,9 @@ import org.jmock.Mockery;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
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.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.GROUP_ID;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAC;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAC;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.SESSION_ID;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.SESSION_ID;
|
||||||
@@ -59,13 +59,11 @@ public class MessageSenderTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSendMessage() throws DbException, FormatException {
|
public void testSendMessage() throws DbException, FormatException {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
Group privateGroup =
|
Group privateGroup = new Group(new GroupId(getRandomId()),
|
||||||
new Group(new GroupId(TestUtils.getRandomId()),
|
getClientId(), new byte[0]);
|
||||||
new ClientId(StringUtils.getRandomString(5)),
|
SessionId sessionId = new SessionId(getRandomId());
|
||||||
new byte[0]);
|
byte[] mac = getRandomBytes(42);
|
||||||
SessionId sessionId = new SessionId(TestUtils.getRandomId());
|
byte[] sig = getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||||
byte[] mac = TestUtils.getRandomBytes(42);
|
|
||||||
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);
|
|
||||||
long time = 42L;
|
long time = 42L;
|
||||||
BdfDictionary msg = BdfDictionary.of(
|
BdfDictionary msg = BdfDictionary.of(
|
||||||
new BdfEntry(TYPE, TYPE_ACK),
|
new BdfEntry(TYPE, TYPE_ACK),
|
||||||
@@ -76,7 +74,7 @@ public class MessageSenderTest extends BriarTestCase {
|
|||||||
);
|
);
|
||||||
BdfList bodyList =
|
BdfList bodyList =
|
||||||
BdfList.of(TYPE_ACK, sessionId.getBytes(), mac, sig);
|
BdfList.of(TYPE_ACK, sessionId.getBytes(), mac, sig);
|
||||||
byte[] body = TestUtils.getRandomBytes(8);
|
byte[] body = getRandomBytes(8);
|
||||||
Metadata metadata = new Metadata();
|
Metadata metadata = new Metadata();
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
|||||||
Reference in New Issue
Block a user