Add integration tests for auto-delete timer.

This commit is contained in:
akwizgran
2020-12-03 17:58:10 +00:00
committed by Torsten Grote
parent 0328aa0630
commit d7a2de5817
7 changed files with 230 additions and 8 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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<PrivateGroup> 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);
}
}

View File

@@ -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<ConversationMessageHeader> getMessages1From0()
throws DbException {
return db0.transactionWithResult(true, txn ->
blogSharingManager0.getMessageHeaders(txn, contactId1From0));
}
private Collection<ConversationMessageHeader> getMessages0From1()
throws DbException {
return db1.transactionWithResult(true, txn ->
blogSharingManager1.getMessageHeaders(txn, contactId0From1));
}
}

View File

@@ -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

View File

@@ -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<C extends BriarIntegrationTestCompone
private LifecycleManager lifecycleManager0, lifecycleManager1,
lifecycleManager2;
private SecretKey rootKey0_1 = getSecretKey();
private SecretKey rootKey0_2 = getSecretKey();
private SecretKey rootKey1_2 = getSecretKey();
@Inject
protected Clock clock;
@@ -137,6 +135,9 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
private final String AUTHOR0 = "Author 0";
private final String AUTHOR1 = "Author 1";
private final String AUTHOR2 = "Author 2";
private final SecretKey rootKey0_1 = getSecretKey();
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);
@@ -451,4 +452,17 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
contactManager2.removeContact(contactId1From2);
}
protected void setAutoDeleteTimer(BriarIntegrationTestComponent component,
ContactId contactId) throws DbException {
component.getDatabaseComponent().transaction(false, txn ->
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));
}
}

View File

@@ -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(