diff --git a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java index bbf2434ce..2c2eacf21 100644 --- a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java @@ -50,6 +50,7 @@ import static org.briarproject.bramble.test.TestUtils.getAgreementPublicKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getTransportProperties; import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap; +import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER; import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID; import static org.briarproject.briar.api.introduction.IntroductionManager.MAJOR_VERSION; @@ -257,6 +258,71 @@ public class IntroductionIntegrationTest assertGroupCount(messageTracker2, g2.getId(), 2, 1); } + @Test + public void testIntroductionSessionWithAutoDelete() throws Exception { + addListeners(true, true); + + // 0 and 1 set an auto-delete timer for their conversation + setAutoDeleteTimer(c0, contactId1From0); + setAutoDeleteTimer(c1, contactId0From1); + + // Make introduction + introductionManager0 + .makeIntroduction(contact1From0, contact2From0, "Hi!"); + + // Sync first REQUEST message + sync0To1(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Sync second REQUEST message + sync0To2(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Sync first ACCEPT message + sync1To0(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Sync second ACCEPT message + sync2To0(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Sync forwarded ACCEPT messages to introducees + sync0To1(1, true); + sync0To2(1, true); + + // Sync first AUTH and its forward + sync1To0(1, true); + sync0To2(1, true); + + // Sync second AUTH and its forward as well as the following ACTIVATE + sync2To0(2, true); + sync0To1(2, true); + + // Sync second ACTIVATE and its forward + sync1To0(1, true); + sync0To2(1, true); + + // Wait for introduction to succeed + eventWaiter.await(TIMEOUT, 2); + assertTrue(listener1.succeeded); + assertTrue(listener2.succeeded); + + // All visible messages between 0 and 1 should have auto-delete timers + for (ConversationMessageHeader h : getMessages1From0()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + for (ConversationMessageHeader h : getMessages0From1()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + // No visible messages between 0 and 2 should have auto-delete timers + for (ConversationMessageHeader h : getMessages2From0()) { + assertEquals(NO_AUTO_DELETE_TIMER, h.getAutoDeleteTimer()); + } + for (ConversationMessageHeader h : getMessages0From2()) { + assertEquals(NO_AUTO_DELETE_TIMER, h.getAutoDeleteTimer()); + } + } + @Test public void testIntroductionSessionFirstDecline() throws Exception { addListeners(false, true); diff --git a/briar-core/src/test/java/org/briarproject/briar/messaging/SimplexMessagingIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/messaging/SimplexMessagingIntegrationTest.java index faa27b3f3..16e540e95 100644 --- a/briar-core/src/test/java/org/briarproject/briar/messaging/SimplexMessagingIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/messaging/SimplexMessagingIntegrationTest.java @@ -39,7 +39,7 @@ import static org.briarproject.bramble.test.TestPluginConfigModule.SIMPLEX_TRANS import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory; import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getTestDirectory; -import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER; +import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.junit.Assert.assertTrue; public class SimplexMessagingIntegrationTest extends BriarTestCase { @@ -125,7 +125,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { device.getPrivateMessageFactory(); PrivateMessage message = privateMessageFactory.createPrivateMessage( groupId, timestamp, "Hi!", singletonList(attachmentHeader), - NO_AUTO_DELETE_TIMER); + MIN_AUTO_DELETE_TIMER_MS); messagingManager.addLocalMessage(message); } diff --git a/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java index 9535b81f8..5a9064f28 100644 --- a/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationIntegrationTest.java @@ -27,7 +27,7 @@ import java.util.Set; import javax.annotation.Nullable; import static java.util.Collections.emptySet; -import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER; +import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -165,6 +165,33 @@ public class GroupInvitationIntegrationTest assertEquals(0, groupManager1.getPrivateGroups().size()); } + @Test + public void testInvitationDeclineWithAutoDelete() throws Exception { + // 0 and 1 set an auto-delete timer for their conversation + setAutoDeleteTimer(c0, contactId1From0); + setAutoDeleteTimer(c1, contactId0From1); + + // Send invitation + sendInvitation(clock.currentTimeMillis(), null); + sync0To1(1, true); + + // Decline invitation + groupInvitationManager1 + .respondToInvitation(contactId0From1, privateGroup, false); + sync1To0(1, true); + + // Group was not added + assertTrue(groupManager1.getPrivateGroups().isEmpty()); + + // All visible messages between 0 and 1 should have auto-delete timers + for (ConversationMessageHeader h : getMessages1From0()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + for (ConversationMessageHeader h : getMessages0From1()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + } + @Test public void testInvitationAccept() throws Exception { long timestamp = clock.currentTimeMillis(); @@ -223,6 +250,35 @@ public class GroupInvitationIntegrationTest assertEquals(privateGroup, groups.iterator().next()); } + @Test + public void testInvitationAcceptWithAutoDelete() throws Exception { + // 0 and 1 set an auto-delete timer for their conversation + setAutoDeleteTimer(c0, contactId1From0); + setAutoDeleteTimer(c1, contactId0From1); + + // Send invitation + sendInvitation(clock.currentTimeMillis(), null); + sync0To1(1, true); + + // Accept invitation + groupInvitationManager1 + .respondToInvitation(contactId0From1, privateGroup, true); + sync1To0(1, true); + + // Group was added + Collection groups = groupManager1.getPrivateGroups(); + assertEquals(1, groups.size()); + assertEquals(privateGroup, groups.iterator().next()); + + // All visible messages between 0 and 1 should have auto-delete timers + for (ConversationMessageHeader h : getMessages1From0()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + for (ConversationMessageHeader h : getMessages0From1()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + } + @Test public void testGroupCount() throws Exception { long timestamp = clock.currentTimeMillis(); @@ -687,9 +743,9 @@ public class GroupInvitationIntegrationTest throws DbException { byte[] signature = groupInvitationFactory.signInvitation(contact1From0, privateGroup.getId(), timestamp, author0.getPrivateKey()); + long timer = getAutoDeleteTimer(c0, contactId1From0); groupInvitationManager0.sendInvitation(privateGroup.getId(), - contactId1From0, text, timestamp, signature, - NO_AUTO_DELETE_TIMER); + contactId1From0, text, timestamp, signature, timer); } } diff --git a/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java index b2deb691c..b8454c72d 100644 --- a/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java @@ -30,6 +30,7 @@ import org.junit.rules.ExpectedException; import java.util.Collection; +import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID; import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION; import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount; @@ -203,6 +204,41 @@ public class BlogSharingIntegrationTest assertGroupCount(messageTracker1, g, 2, 1); } + @Test + public void testSuccessfulSharingWithAutoDelete() throws Exception { + // Initialize and let invitee accept all requests + listenToEvents(true); + + // Set an auto-delete timer for the conversation + setAutoDeleteTimer(c0, contactId1From0); + setAutoDeleteTimer(c1, contactId0From1); + + // Send invitation + blogSharingManager0 + .sendInvitation(blog2.getId(), contactId1From0, "Hi!"); + + // Sync first request message + sync0To1(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Sync response back + sync1To0(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Blog was added successfully + assertEquals(0, blogSharingManager0.getInvitations().size()); + assertEquals(3, blogManager1.getBlogs().size()); + assertTrue(blogManager1.getBlogs().contains(blog2)); + + // All visible messages should have auto-delete timers + for (ConversationMessageHeader h : getMessages1From0()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + for (ConversationMessageHeader h : getMessages0From1()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + } + @Test public void testSuccessfulSharingWithRssBlog() throws Exception { // initialize and let invitee accept all requests @@ -647,4 +683,15 @@ public class BlogSharingIntegrationTest c2.getEventBus().addListener(listener2); } + private Collection getMessages1From0() + throws DbException { + return db0.transactionWithResult(true, txn -> + blogSharingManager0.getMessageHeaders(txn, contactId1From0)); + } + + private Collection getMessages0From1() + throws DbException { + return db1.transactionWithResult(true, txn -> + blogSharingManager1.getMessageHeaders(txn, contactId0From1)); + } } diff --git a/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java index 82efda25a..999e9c022 100644 --- a/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java @@ -44,6 +44,7 @@ import javax.annotation.Nullable; import static java.util.Collections.emptySet; import static junit.framework.Assert.assertNotNull; import static org.briarproject.bramble.util.StringUtils.getRandomString; +import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_ID; import static org.briarproject.briar.api.forum.ForumSharingManager.MAJOR_VERSION; import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount; @@ -187,6 +188,41 @@ public class ForumSharingIntegrationTest assertFalse(forumSharingManager1.canBeShared(forum.getId(), c0)); } + @Test + public void testSuccessfulSharingWithAutoDelete() throws Exception { + // Set an auto-delete timer for the conversation + setAutoDeleteTimer(c0, contactId1From0); + setAutoDeleteTimer(c1, contactId0From1); + + // Send invitation + forumSharingManager0 + .sendInvitation(forum.getId(), contactId1From0, "Hi!"); + + // Sync request message + sync0To1(1, true); + eventWaiter.await(TIMEOUT, 1); + + // Invitee accepts + respondToRequest(contactId0From1, true); + + // Sync response back + sync1To0(1, true); + eventWaiter.await(TIMEOUT, 1); + assertResponseReceived(listener0, contactId1From0, true); + + // Forum was added successfully + assertEquals(0, forumSharingManager0.getInvitations().size()); + assertEquals(1, forumManager1.getForums().size()); + + // All visible messages should have auto-delete timers + for (ConversationMessageHeader h : getMessages1From0()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + for (ConversationMessageHeader h : getMessages0From1()) { + assertEquals(MIN_AUTO_DELETE_TIMER_MS, h.getAutoDeleteTimer()); + } + } + @Test public void testDeclinedSharing() throws Exception { // send invitation diff --git a/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java index 30ce6dbb1..79cee06da 100644 --- a/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java @@ -63,6 +63,7 @@ import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING; import static org.briarproject.bramble.test.TestPluginConfigModule.SIMPLEX_TRANSPORT_ID; import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.util.LogUtils.logException; +import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -94,9 +95,6 @@ public abstract class BriarIntegrationTest + component.getAutoDeleteManager().setAutoDeleteTimer(txn, + contactId, MIN_AUTO_DELETE_TIMER_MS)); + } + + protected long getAutoDeleteTimer(BriarIntegrationTestComponent component, + ContactId contactId) throws DbException { + return component.getDatabaseComponent().transactionWithResult(true, + txn -> component.getAutoDeleteManager().getAutoDeleteTimer(txn, + contactId)); + } } diff --git a/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTestComponent.java b/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTestComponent.java index 750275f78..9bee9e573 100644 --- a/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTestComponent.java +++ b/briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTestComponent.java @@ -13,6 +13,7 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager; import org.briarproject.bramble.api.properties.TransportPropertyManager; import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule; import org.briarproject.briar.api.attachment.AttachmentReader; +import org.briarproject.briar.api.autodelete.AutoDeleteManager; import org.briarproject.briar.api.avatar.AvatarManager; import org.briarproject.briar.api.blog.BlogFactory; import org.briarproject.briar.api.blog.BlogManager; @@ -131,6 +132,8 @@ public interface BriarIntegrationTestComponent ConnectionManager getConnectionManager(); + AutoDeleteManager getAutoDeleteManager(); + class Helper { public static void injectEagerSingletons(