mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Refactor integration tests to allow clock to be replaced.
This commit is contained in:
@@ -21,7 +21,6 @@ import org.briarproject.bramble.rendezvous.RendezvousModule;
|
||||
import org.briarproject.bramble.settings.SettingsModule;
|
||||
import org.briarproject.bramble.sync.SyncModule;
|
||||
import org.briarproject.bramble.sync.validation.ValidationModule;
|
||||
import org.briarproject.bramble.system.ClockModule;
|
||||
import org.briarproject.bramble.transport.TransportModule;
|
||||
import org.briarproject.bramble.versioning.VersioningModule;
|
||||
|
||||
@@ -29,7 +28,6 @@ import dagger.Module;
|
||||
|
||||
@Module(includes = {
|
||||
ClientModule.class,
|
||||
ClockModule.class,
|
||||
ConnectionModule.class,
|
||||
ContactModule.class,
|
||||
CryptoModule.class,
|
||||
|
||||
@@ -14,6 +14,7 @@ import dagger.Provides;
|
||||
DefaultEventExecutorModule.class,
|
||||
DefaultTaskSchedulerModule.class,
|
||||
DefaultWakefulIoExecutorModule.class,
|
||||
TestClockModule.class,
|
||||
TestDatabaseConfigModule.class,
|
||||
TestPluginConfigModule.class,
|
||||
TestSecureRandomModule.class
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.briarproject.bramble.test;
|
||||
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.system.SystemClock;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class TestClockModule {
|
||||
|
||||
private final Clock clock;
|
||||
|
||||
public TestClockModule() {
|
||||
clock = new SystemClock();
|
||||
}
|
||||
|
||||
public TestClockModule(AtomicLong time) {
|
||||
clock = new SettableClock(time);
|
||||
}
|
||||
|
||||
@Provides
|
||||
Clock provideClock() {
|
||||
return clock;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@ import org.briarproject.bramble.system.JavaSystemModule;
|
||||
import dagger.Module;
|
||||
|
||||
@Module(includes = {
|
||||
CircumventionModule.class,
|
||||
JavaNetworkModule.class,
|
||||
JavaSystemModule.class,
|
||||
CircumventionModule.class,
|
||||
SocksModule.class
|
||||
})
|
||||
public class BrambleJavaModule {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.api.system.LocationUtils;
|
||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||
import org.briarproject.bramble.system.ClockModule;
|
||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||
import org.briarproject.briar.BriarCoreModule;
|
||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||
@@ -76,6 +77,7 @@ import dagger.Component;
|
||||
BriarAccountModule.class,
|
||||
AppModule.class,
|
||||
AttachmentModule.class,
|
||||
ClockModule.class,
|
||||
MediaModule.class
|
||||
})
|
||||
public interface AndroidComponent
|
||||
|
||||
@@ -127,7 +127,7 @@ public class BlogManagerIntegrationTest
|
||||
|
||||
// add a post to blog0
|
||||
BlogPost p = blogPostFactory.createBlogPost(blog0.getId(),
|
||||
clock.currentTimeMillis(), null, author0, text);
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// check that post is now in blog0
|
||||
@@ -158,9 +158,8 @@ public class BlogManagerIntegrationTest
|
||||
public void testBlogPostInWrongBlog() throws Exception {
|
||||
// add a post to blog1
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog1.getId(), clock.currentTimeMillis(), null,
|
||||
author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(blog1.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// check that post is now in blog1
|
||||
@@ -197,9 +196,8 @@ public class BlogManagerIntegrationTest
|
||||
public void testBlogComment() throws Exception {
|
||||
// add a post to blog0
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(blog0.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// sync the post over
|
||||
@@ -242,9 +240,8 @@ public class BlogManagerIntegrationTest
|
||||
public void testBlogCommentOnOwnPost() throws Exception {
|
||||
// add a post to blog0
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(blog0.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// get header of own post
|
||||
@@ -278,9 +275,8 @@ public class BlogManagerIntegrationTest
|
||||
public void testCommentOnComment() throws Exception {
|
||||
// add a post to blog0
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(blog0.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// sync the post over
|
||||
@@ -366,9 +362,8 @@ public class BlogManagerIntegrationTest
|
||||
public void testCommentOnOwnComment() throws Exception {
|
||||
// add a post to blog0
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(blog0.getId(), clock.currentTimeMillis(), null,
|
||||
author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(blog0.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// sync the post over
|
||||
@@ -411,9 +406,8 @@ public class BlogManagerIntegrationTest
|
||||
|
||||
// add a feed post to rssBlog
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(rssBlog.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// make sure it got saved as an RSS feed post
|
||||
@@ -430,9 +424,8 @@ public class BlogManagerIntegrationTest
|
||||
public void testFeedReblog() throws Exception {
|
||||
// add a feed post to rssBlog
|
||||
String text = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, text);
|
||||
BlogPost p = blogPostFactory.createBlogPost(rssBlog.getId(),
|
||||
c0.getClock().currentTimeMillis(), null, author0, text);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// reblog feed post to own blog
|
||||
|
||||
@@ -84,9 +84,9 @@ public class ForumManagerTest
|
||||
@Test
|
||||
public void testForumPost() throws Exception {
|
||||
assertEquals(1, forumManager0.getForums().size());
|
||||
long ms1 = clock.currentTimeMillis() - 1000L;
|
||||
long ms1 = c0.getClock().currentTimeMillis() - 1000L;
|
||||
String text1 = "some forum text";
|
||||
long ms2 = clock.currentTimeMillis();
|
||||
long ms2 = c0.getClock().currentTimeMillis();
|
||||
String text2 = "some other forum text";
|
||||
ForumPost post1 =
|
||||
createForumPost(forum0.getGroup().getId(), null, text1, ms1);
|
||||
@@ -136,7 +136,7 @@ public class ForumManagerTest
|
||||
@Test
|
||||
public void testForumPostDelivery() throws Exception {
|
||||
// add one forum post
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c0.getClock().currentTimeMillis();
|
||||
ForumPost post1 = createForumPost(groupId0, null, "a", time);
|
||||
forumManager0.addLocalPost(post1);
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
@@ -150,7 +150,7 @@ public class ForumManagerTest
|
||||
assertGroupCount(messageTracker1, groupId0, 1, 1, time);
|
||||
|
||||
// add another forum post
|
||||
long time2 = clock.currentTimeMillis();
|
||||
long time2 = c0.getClock().currentTimeMillis();
|
||||
ForumPost post2 = createForumPost(groupId0, null, "b", time2);
|
||||
forumManager1.addLocalPost(post2);
|
||||
assertEquals(1, forumManager0.getPostHeaders(groupId0).size());
|
||||
@@ -167,7 +167,7 @@ public class ForumManagerTest
|
||||
@Test
|
||||
public void testForumPostDeliveredAfterParent() throws Exception {
|
||||
// add one forum post without the parent
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c0.getClock().currentTimeMillis();
|
||||
ForumPost post1 = createForumPost(groupId0, null, "a", time);
|
||||
ForumPost post2 = createForumPost(groupId0, post1, "a", time);
|
||||
forumManager0.addLocalPost(post2);
|
||||
@@ -199,7 +199,7 @@ public class ForumManagerTest
|
||||
sync1To0(1, true);
|
||||
|
||||
// add one forum post with a parent in another forum
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c0.getClock().currentTimeMillis();
|
||||
ForumPost post1 = createForumPost(g1, null, "a", time);
|
||||
ForumPost post = createForumPost(groupId0, post1, "b", time);
|
||||
forumManager0.addLocalPost(post);
|
||||
|
||||
@@ -1042,10 +1042,12 @@ public class IntroductionIntegrationTest
|
||||
contactManager1.removeContact(contactId0From1);
|
||||
SecretKey rootKey0_1 = getSecretKey();
|
||||
contactId1From0 = contactManager0.addContact(author1, author0.getId(),
|
||||
rootKey0_1, clock.currentTimeMillis(), true, true, true);
|
||||
rootKey0_1, c0.getClock().currentTimeMillis(), true, true,
|
||||
true);
|
||||
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||
contactId0From1 = contactManager1.addContact(author0, author1.getId(),
|
||||
rootKey0_1, clock.currentTimeMillis(), false, true, true);
|
||||
rootKey0_1, c1.getClock().currentTimeMillis(), false, true,
|
||||
true);
|
||||
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||
|
||||
// Sync initial client versioning updates and transport properties
|
||||
@@ -1169,7 +1171,7 @@ public class IntroductionIntegrationTest
|
||||
m -> new AcceptMessage(m.getMessageId(), m.getGroupId(),
|
||||
m.getTimestamp(), m.getPreviousMessageId(),
|
||||
m.getSessionId(), m.getEphemeralPublicKey(),
|
||||
clock.currentTimeMillis(),
|
||||
c0.getClock().currentTimeMillis(),
|
||||
m.getTransportProperties(), NO_AUTO_DELETE_TIMER)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ public class MessagingManagerIntegrationTest
|
||||
// send legacy message
|
||||
GroupId g = c0.getMessagingManager().getConversationId(contactId);
|
||||
PrivateMessage m0 = messageFactory.createLegacyPrivateMessage(g,
|
||||
clock.currentTimeMillis(), getRandomString(42));
|
||||
c0.getClock().currentTimeMillis(), getRandomString(42));
|
||||
c0.getMessagingManager().addLocalMessage(m0);
|
||||
syncMessage(c0, c1, contactId, 1, true);
|
||||
|
||||
@@ -384,7 +384,8 @@ public class MessagingManagerIntegrationTest
|
||||
throws Exception {
|
||||
GroupId g = from.getMessagingManager().getConversationId(contactId);
|
||||
PrivateMessage m = messageFactory.createPrivateMessage(g,
|
||||
clock.currentTimeMillis(), text, attachments, autoDeleteTimer);
|
||||
from.getClock().currentTimeMillis(), text, attachments,
|
||||
autoDeleteTimer);
|
||||
from.getMessagingManager().addLocalMessage(m);
|
||||
syncMessage(from, to, contactId, 1 + attachments.size(), true);
|
||||
return m;
|
||||
@@ -395,7 +396,7 @@ public class MessagingManagerIntegrationTest
|
||||
GroupId g = c.getMessagingManager().getConversationId(contactId);
|
||||
InputStream stream = new ByteArrayInputStream(getRandomBytes(42));
|
||||
return c.getMessagingManager().addLocalAttachment(g,
|
||||
clock.currentTimeMillis(), "image/jpeg", stream);
|
||||
c.getClock().currentTimeMillis(), "image/jpeg", stream);
|
||||
}
|
||||
|
||||
private Collection<ConversationMessageHeader> getMessages(
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PrivateGroupIntegrationTest
|
||||
privateGroup0 =
|
||||
privateGroupFactory.createPrivateGroup("Test Group", author0);
|
||||
groupId0 = privateGroup0.getId();
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
long joinTime = c0.getClock().currentTimeMillis();
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(groupId0, joinTime, author0);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true);
|
||||
@@ -92,7 +92,8 @@ public class PrivateGroupIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testMembership() throws Exception {
|
||||
sendInvitation(contactId1From0, clock.currentTimeMillis(), "Hi!");
|
||||
sendInvitation(contactId1From0, c0.getClock().currentTimeMillis(),
|
||||
"Hi!");
|
||||
|
||||
// our group has only one member (ourselves)
|
||||
Collection<GroupMember> members = groupManager0.getMembers(groupId0);
|
||||
@@ -135,8 +136,10 @@ public class PrivateGroupIntegrationTest
|
||||
@Test
|
||||
public void testRevealContacts() throws Exception {
|
||||
// invite two contacts
|
||||
sendInvitation(contactId1From0, clock.currentTimeMillis(), "Hi 1!");
|
||||
sendInvitation(contactId2From0, clock.currentTimeMillis(), "Hi 2!");
|
||||
sendInvitation(contactId1From0, c0.getClock().currentTimeMillis(),
|
||||
"Hi 1!");
|
||||
sendInvitation(contactId2From0, c0.getClock().currentTimeMillis(),
|
||||
"Hi 2!");
|
||||
sync0To1(1, true);
|
||||
sync0To2(1, true);
|
||||
|
||||
@@ -182,7 +185,7 @@ public class PrivateGroupIntegrationTest
|
||||
getGroupMember(groupManager2, author1.getId()).getVisibility());
|
||||
|
||||
// 2 sends a message to the group
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c2.getClock().currentTimeMillis();
|
||||
String text = "This is a test message!";
|
||||
MessageId previousMsgId = groupManager2.getPreviousMsgId(groupId0);
|
||||
GroupMessage msg = groupMessageFactory
|
||||
|
||||
@@ -83,7 +83,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
addGroup();
|
||||
|
||||
// create and add test message
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c0.getClock().currentTimeMillis();
|
||||
String text = "This is a test message!";
|
||||
MessageId previousMsgId =
|
||||
groupManager0.getPreviousMsgId(groupId0);
|
||||
@@ -125,7 +125,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
|
||||
// create and add test message with no previousMsgId
|
||||
GroupMessage msg = groupMessageFactory.createGroupMessage(groupId0,
|
||||
clock.currentTimeMillis(), null, author0, "test", null);
|
||||
c0.getClock().currentTimeMillis(), null, author0, "test", null);
|
||||
groupManager0.addLocalMessage(msg);
|
||||
|
||||
// sync test message
|
||||
@@ -136,9 +136,9 @@ public class PrivateGroupManagerIntegrationTest
|
||||
|
||||
// create and add test message with random previousMsgId
|
||||
MessageId previousMsgId = new MessageId(getRandomId());
|
||||
msg = groupMessageFactory
|
||||
.createGroupMessage(groupId0, clock.currentTimeMillis(), null,
|
||||
author0, "test", previousMsgId);
|
||||
msg = groupMessageFactory.createGroupMessage(groupId0,
|
||||
c0.getClock().currentTimeMillis(), null, author0, "test",
|
||||
previousMsgId);
|
||||
groupManager0.addLocalMessage(msg);
|
||||
|
||||
// sync test message
|
||||
@@ -149,9 +149,9 @@ public class PrivateGroupManagerIntegrationTest
|
||||
|
||||
// create and add test message with wrong previousMsgId
|
||||
previousMsgId = groupManager1.getPreviousMsgId(groupId0);
|
||||
msg = groupMessageFactory
|
||||
.createGroupMessage(groupId0, clock.currentTimeMillis(), null,
|
||||
author0, "test", previousMsgId);
|
||||
msg = groupMessageFactory.createGroupMessage(groupId0,
|
||||
c0.getClock().currentTimeMillis(), null, author0, "test",
|
||||
previousMsgId);
|
||||
groupManager0.addLocalMessage(msg);
|
||||
|
||||
// sync test message
|
||||
@@ -168,9 +168,9 @@ public class PrivateGroupManagerIntegrationTest
|
||||
// create and add test message with random parentMsgId
|
||||
MessageId parentMsgId = new MessageId(getRandomId());
|
||||
MessageId previousMsgId = groupManager0.getPreviousMsgId(groupId0);
|
||||
GroupMessage msg = groupMessageFactory
|
||||
.createGroupMessage(groupId0, clock.currentTimeMillis(),
|
||||
parentMsgId, author0, "test", previousMsgId);
|
||||
GroupMessage msg = groupMessageFactory.createGroupMessage(groupId0,
|
||||
c0.getClock().currentTimeMillis(), parentMsgId, author0, "test",
|
||||
previousMsgId);
|
||||
groupManager0.addLocalMessage(msg);
|
||||
|
||||
// sync test message
|
||||
@@ -181,9 +181,9 @@ public class PrivateGroupManagerIntegrationTest
|
||||
|
||||
// create and add test message with wrong parentMsgId
|
||||
parentMsgId = previousMsgId;
|
||||
msg = groupMessageFactory
|
||||
.createGroupMessage(groupId0, clock.currentTimeMillis(),
|
||||
parentMsgId, author0, "test", previousMsgId);
|
||||
msg = groupMessageFactory.createGroupMessage(groupId0,
|
||||
c0.getClock().currentTimeMillis(), parentMsgId, author0, "test",
|
||||
previousMsgId);
|
||||
groupManager0.addLocalMessage(msg);
|
||||
|
||||
// sync test message
|
||||
@@ -211,7 +211,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
||||
|
||||
// create and add test message with good timestamp
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c0.getClock().currentTimeMillis();
|
||||
msg = groupMessageFactory
|
||||
.createGroupMessage(groupId0, time, null, author0, "test",
|
||||
previousMsgId);
|
||||
@@ -238,7 +238,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
@Test
|
||||
public void testWrongJoinMessages1() throws Exception {
|
||||
// author0 joins privateGroup0 with wrong join message
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
long joinTime = c0.getClock().currentTimeMillis();
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author0,
|
||||
joinTime, getRandomBytes(12));
|
||||
@@ -251,7 +251,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
contactId1From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author1 joins privateGroup0 with wrong timestamp
|
||||
joinTime = clock.currentTimeMillis();
|
||||
joinTime = c1.getClock().currentTimeMillis();
|
||||
long inviteTime = joinTime;
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
@@ -283,7 +283,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
@Test
|
||||
public void testWrongJoinMessages2() throws Exception {
|
||||
// author0 joins privateGroup0 with wrong member's join message
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
long joinTime = c0.getClock().currentTimeMillis();
|
||||
long inviteTime = joinTime - 1;
|
||||
BdfList toSign = groupInvitationFactory
|
||||
.createInviteToken(author0.getId(), author0.getId(),
|
||||
@@ -303,7 +303,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
contactId1From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author1 joins privateGroup0 with wrong signature in join message
|
||||
joinTime = clock.currentTimeMillis();
|
||||
joinTime = c1.getClock().currentTimeMillis();
|
||||
inviteTime = joinTime - 1;
|
||||
// signature uses joiner's key, not creator's key
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
@@ -365,7 +365,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
contactId2From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author2 joins privateGroup0
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
long joinTime = c2.getClock().currentTimeMillis();
|
||||
long inviteTime = joinTime - 1;
|
||||
Contact c2 = contactManager0.getContact(contactId2From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
@@ -447,7 +447,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
|
||||
private void addGroup() throws Exception {
|
||||
// author0 joins privateGroup0
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
long joinTime = c0.getClock().currentTimeMillis();
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author0);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true);
|
||||
@@ -459,7 +459,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
contactId1From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author1 joins privateGroup0
|
||||
joinTime = clock.currentTimeMillis();
|
||||
joinTime = c1.getClock().currentTimeMillis();
|
||||
long inviteTime = joinTime - 1;
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
|
||||
@@ -57,7 +57,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
privateGroup =
|
||||
privateGroupFactory.createPrivateGroup("Testgroup", author0);
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
long joinTime = c0.getClock().currentTimeMillis();
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup.getId(), joinTime, author0);
|
||||
groupManager0.addPrivateGroup(privateGroup, joinMsg0, true);
|
||||
@@ -88,7 +88,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testSendInvitation() throws Exception {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
long timestamp = c0.getClock().currentTimeMillis();
|
||||
String text = "Hi!";
|
||||
sendInvitation(timestamp, text);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testInvitationDecline() throws Exception {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
long timestamp = c0.getClock().currentTimeMillis();
|
||||
sendInvitation(timestamp, null);
|
||||
|
||||
sync0To1(1, true);
|
||||
@@ -172,7 +172,7 @@ public class GroupInvitationIntegrationTest
|
||||
setAutoDeleteTimer(c1, contactId0From1, MIN_AUTO_DELETE_TIMER_MS);
|
||||
|
||||
// Send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// Decline invitation
|
||||
@@ -194,7 +194,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testInvitationAccept() throws Exception {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
long timestamp = c0.getClock().currentTimeMillis();
|
||||
sendInvitation(timestamp, null);
|
||||
|
||||
// check that invitation message state is correct
|
||||
@@ -257,7 +257,7 @@ public class GroupInvitationIntegrationTest
|
||||
setAutoDeleteTimer(c1, contactId0From1, MIN_AUTO_DELETE_TIMER_MS);
|
||||
|
||||
// Send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// Accept invitation
|
||||
@@ -281,7 +281,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testGroupCount() throws Exception {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
long timestamp = c0.getClock().currentTimeMillis();
|
||||
sendInvitation(timestamp, null);
|
||||
|
||||
// 0 has one read outgoing message
|
||||
@@ -313,7 +313,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testMultipleInvitations() throws Exception {
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
|
||||
// invitation is not allowed before the first hasn't been answered
|
||||
assertFalse(groupInvitationManager0
|
||||
@@ -330,7 +330,7 @@ public class GroupInvitationIntegrationTest
|
||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
||||
|
||||
// send and accept the second invitation
|
||||
sendInvitation(clock.currentTimeMillis(), "Second Invitation");
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), "Second Invitation");
|
||||
sync0To1(1, true);
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup, true);
|
||||
@@ -342,7 +342,8 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
// don't allow another invitation request
|
||||
try {
|
||||
sendInvitation(clock.currentTimeMillis(), "Third Invitation");
|
||||
sendInvitation(c0.getClock().currentTimeMillis(),
|
||||
"Third Invitation");
|
||||
fail();
|
||||
} catch (ProtocolStateException e) {
|
||||
// expected
|
||||
@@ -351,7 +352,7 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
@Test(expected = ProtocolStateException.class)
|
||||
public void testInvitationsWithSameTimestamp() throws Exception {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
long timestamp = c0.getClock().currentTimeMillis();
|
||||
sendInvitation(timestamp, null);
|
||||
sync0To1(1, true);
|
||||
|
||||
@@ -369,7 +370,7 @@ public class GroupInvitationIntegrationTest
|
||||
@Test(expected = ProtocolStateException.class)
|
||||
public void testCreatorLeavesBeforeInvitationAccepted() throws Exception {
|
||||
// Creator invites invitee to join group
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
|
||||
// Creator's invite message is delivered to invitee
|
||||
sync0To1(1, true);
|
||||
@@ -392,7 +393,7 @@ public class GroupInvitationIntegrationTest
|
||||
@Test
|
||||
public void testCreatorLeavesBeforeInvitationDeclined() throws Exception {
|
||||
// Creator invites invitee to join group
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
|
||||
// Creator's invite message is delivered to invitee
|
||||
sync0To1(1, true);
|
||||
@@ -419,7 +420,7 @@ public class GroupInvitationIntegrationTest
|
||||
public void testCreatorLeavesConcurrentlyWithInvitationAccepted()
|
||||
throws Exception {
|
||||
// Creator invites invitee to join group
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
|
||||
// Creator's invite message is delivered to invitee
|
||||
sync0To1(1, true);
|
||||
@@ -450,7 +451,7 @@ public class GroupInvitationIntegrationTest
|
||||
public void testCreatorLeavesConcurrentlyWithInvitationDeclined()
|
||||
throws Exception {
|
||||
// Creator invites invitee to join group
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
|
||||
// Creator's invite message is delivered to invitee
|
||||
sync0To1(1, true);
|
||||
@@ -477,7 +478,7 @@ public class GroupInvitationIntegrationTest
|
||||
public void testCreatorLeavesConcurrentlyWithMemberLeaving()
|
||||
throws Exception {
|
||||
// Creator invites invitee to join group
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
|
||||
// Creator's invite message is delivered to invitee
|
||||
sync0To1(1, true);
|
||||
@@ -517,7 +518,7 @@ public class GroupInvitationIntegrationTest
|
||||
public void testDeletingAllMessagesWhenCompletingSession()
|
||||
throws Exception {
|
||||
// send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// messages can not be deleted
|
||||
@@ -572,7 +573,7 @@ public class GroupInvitationIntegrationTest
|
||||
@Test
|
||||
public void testDeletingAllMessagesWhenDeclining() throws Exception {
|
||||
// send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// respond
|
||||
@@ -608,7 +609,7 @@ public class GroupInvitationIntegrationTest
|
||||
assertGroupCount(messageTracker1, g0From1.getId(), 0, 0);
|
||||
|
||||
// creator can re-invite
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// now new messages can not be deleted anymore
|
||||
@@ -639,7 +640,7 @@ public class GroupInvitationIntegrationTest
|
||||
@Test
|
||||
public void testDeletingSomeMessages() throws Exception {
|
||||
// send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sendInvitation(c0.getClock().currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// deleting the invitation will fail for both
|
||||
|
||||
@@ -725,7 +725,7 @@ public class ForumSharingIntegrationTest
|
||||
assertResponseReceived(listener0, contactId1From0, true);
|
||||
|
||||
// sharer posts into the forum
|
||||
long time = clock.currentTimeMillis();
|
||||
long time = c0.getClock().currentTimeMillis();
|
||||
String text = getRandomString(42);
|
||||
ForumPost p = forumPostFactory
|
||||
.createPost(forum.getId(), time, null, author0, text);
|
||||
@@ -743,7 +743,7 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(author0, header.getAuthor());
|
||||
|
||||
// now invitee creates a post
|
||||
time = clock.currentTimeMillis();
|
||||
time = c1.getClock().currentTimeMillis();
|
||||
text = getRandomString(42);
|
||||
p = forumPostFactory
|
||||
.createPost(forum.getId(), time, null, author1, text);
|
||||
@@ -789,7 +789,7 @@ public class ForumSharingIntegrationTest
|
||||
assertResponseReceived(listener0, contactId1From0, true);
|
||||
|
||||
// now invitee creates a post
|
||||
time = clock.currentTimeMillis();
|
||||
time = c1.getClock().currentTimeMillis();
|
||||
text = getRandomString(42);
|
||||
p = forumPostFactory
|
||||
.createPost(forum.getId(), time, null, author1, text);
|
||||
@@ -848,7 +848,7 @@ public class ForumSharingIntegrationTest
|
||||
// send an accept message for the same forum
|
||||
Message m = messageEncoder.encodeAcceptMessage(
|
||||
forumSharingManager0.getContactGroup(contact1From0).getId(),
|
||||
forum.getId(), clock.currentTimeMillis(), invitationId);
|
||||
forum.getId(), c0.getClock().currentTimeMillis(), invitationId);
|
||||
c0.getClientHelper().addLocalMessage(m, new BdfDictionary(), true);
|
||||
|
||||
// sync unexpected message and the expected abort message back
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.briarproject.bramble.api.sync.MessageFactory;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.event.MessageStateChangedEvent;
|
||||
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.TestTransportConnectionReader;
|
||||
import org.briarproject.bramble.test.TestTransportConnectionWriter;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
@@ -96,8 +95,6 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
private LifecycleManager lifecycleManager0, lifecycleManager1,
|
||||
lifecycleManager2;
|
||||
|
||||
@Inject
|
||||
protected Clock clock;
|
||||
@Inject
|
||||
protected CryptoComponent crypto;
|
||||
@Inject
|
||||
@@ -139,9 +136,9 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
private final SecretKey rootKey0_2 = getSecretKey();
|
||||
private final SecretKey rootKey1_2 = getSecretKey();
|
||||
|
||||
protected File t0Dir = new File(testDir, AUTHOR0);
|
||||
protected File t1Dir = new File(testDir, AUTHOR1);
|
||||
protected File t2Dir = new File(testDir, AUTHOR2);
|
||||
protected final File t0Dir = new File(testDir, AUTHOR0);
|
||||
protected final File t1Dir = new File(testDir, AUTHOR1);
|
||||
protected final File t2Dir = new File(testDir, AUTHOR2);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -269,16 +266,20 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
|
||||
protected void addDefaultContacts() throws Exception {
|
||||
contactId1From0 = contactManager0.addContact(author1, author0.getId(),
|
||||
rootKey0_1, clock.currentTimeMillis(), true, true, true);
|
||||
rootKey0_1, c0.getClock().currentTimeMillis(), true, true,
|
||||
true);
|
||||
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||
contactId0From1 = contactManager1.addContact(author0, author1.getId(),
|
||||
rootKey0_1, clock.currentTimeMillis(), false, true, true);
|
||||
rootKey0_1, c1.getClock().currentTimeMillis(), false, true,
|
||||
true);
|
||||
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||
contactId2From0 = contactManager0.addContact(author2, author0.getId(),
|
||||
rootKey0_2, clock.currentTimeMillis(), true, true, true);
|
||||
rootKey0_2, c0.getClock().currentTimeMillis(), true, true,
|
||||
true);
|
||||
contact2From0 = contactManager0.getContact(contactId2From0);
|
||||
contactId0From2 = contactManager2.addContact(author0, author2.getId(),
|
||||
rootKey0_2, clock.currentTimeMillis(), false, true, true);
|
||||
rootKey0_2, c2.getClock().currentTimeMillis(), false, true,
|
||||
true);
|
||||
contact0From2 = contactManager2.getContact(contactId0From2);
|
||||
|
||||
// Sync initial client versioning updates
|
||||
@@ -297,9 +298,11 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
protected void addContacts1And2(boolean haveTransportProperties)
|
||||
throws Exception {
|
||||
contactId2From1 = contactManager1.addContact(author2, author1.getId(),
|
||||
rootKey1_2, clock.currentTimeMillis(), true, true, true);
|
||||
rootKey1_2, c1.getClock().currentTimeMillis(), true, true,
|
||||
true);
|
||||
contactId1From2 = contactManager2.addContact(author1, author2.getId(),
|
||||
rootKey1_2, clock.currentTimeMillis(), false, true, true);
|
||||
rootKey1_2, c2.getClock().currentTimeMillis(), false, true,
|
||||
true);
|
||||
|
||||
// Sync initial client versioning updates
|
||||
sync1To2(1, true);
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
|
||||
import org.briarproject.briar.api.attachment.AttachmentReader;
|
||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||
@@ -134,6 +135,8 @@ public interface BriarIntegrationTestComponent
|
||||
|
||||
AutoDeleteManager getAutoDeleteManager();
|
||||
|
||||
Clock getClock();
|
||||
|
||||
class Helper {
|
||||
|
||||
public static void injectEagerSingletons(
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.briarproject.bramble.network.JavaNetworkModule
|
||||
import org.briarproject.bramble.plugin.tor.CircumventionModule
|
||||
import org.briarproject.bramble.plugin.tor.UnixTorPluginFactory
|
||||
import org.briarproject.bramble.socks.SocksModule
|
||||
import org.briarproject.bramble.system.ClockModule
|
||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule
|
||||
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule
|
||||
import org.briarproject.bramble.system.DesktopSecureRandomModule
|
||||
@@ -36,6 +37,7 @@ import javax.inject.Singleton
|
||||
includes = [
|
||||
AccountModule::class,
|
||||
CircumventionModule::class,
|
||||
ClockModule::class,
|
||||
DefaultBatteryManagerModule::class,
|
||||
DefaultEventExecutorModule::class,
|
||||
DefaultTaskSchedulerModule::class,
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.briarproject.bramble.event.DefaultEventExecutorModule
|
||||
import org.briarproject.bramble.network.JavaNetworkModule
|
||||
import org.briarproject.bramble.plugin.tor.CircumventionModule
|
||||
import org.briarproject.bramble.socks.SocksModule
|
||||
import org.briarproject.bramble.system.ClockModule
|
||||
import org.briarproject.bramble.system.DefaultTaskSchedulerModule
|
||||
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule
|
||||
import org.briarproject.bramble.system.JavaSystemModule
|
||||
@@ -34,6 +35,7 @@ import javax.inject.Singleton
|
||||
JavaSystemModule::class,
|
||||
AccountModule::class,
|
||||
CircumventionModule::class,
|
||||
ClockModule::class,
|
||||
DefaultEventExecutorModule::class,
|
||||
DefaultTaskSchedulerModule::class,
|
||||
DefaultWakefulIoExecutorModule::class,
|
||||
|
||||
Reference in New Issue
Block a user