Add test for invitee responding after sharer deleted invitation

This commit is contained in:
Daniel Lublin
2021-03-10 11:17:37 +01:00
parent 45e3c56eb8
commit 37d8a34c69
3 changed files with 166 additions and 10 deletions

View File

@@ -1,13 +1,20 @@
package org.briarproject.briar.sharing;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.autodelete.event.ConversationMessagesDeletedEvent;
import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
import org.briarproject.briar.api.forum.Forum;
import org.briarproject.briar.api.sharing.InvitationResponse;
import org.briarproject.briar.api.sharing.Shareable;
import org.briarproject.briar.api.sharing.SharingInvitationItem;
import org.briarproject.briar.api.sharing.SharingManager;
import org.briarproject.briar.autodelete.AbstractAutoDeleteTest;
import java.util.Collection;
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.briar.test.TestEventListener.assertEvent;
@@ -15,14 +22,23 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public abstract class AbstractAutoDeleteIntegrationTest
extends AbstractAutoDeleteTest {
protected abstract SharingManager<? extends Shareable> getSharingManager0();
protected abstract SharingManager<? extends Shareable> getSharingManager1();
protected abstract Shareable getShareable();
protected abstract Collection<? extends Shareable> subscriptions0()
throws DbException;
protected abstract Collection<? extends Shareable> subscriptions1()
throws DbException;
protected abstract Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass();
protected void testAutoDeclinedSharing() throws Exception {
@@ -173,4 +189,83 @@ public abstract class AbstractAutoDeleteIntegrationTest
sync0To1(1, true);
assertGroupCount(c1, contactId0From1, 1, 1);
}
protected void testRespondAfterSenderDeletedInvitation() throws Exception {
setAutoDeleteTimer(c0, contactId1From0, MIN_AUTO_DELETE_TIMER_MS);
assertTrue(subscriptions0().contains(getShareable()));
assertFalse(subscriptions1().contains(getShareable()));
// what we expect after 1 accepts
int expectedSubscriptions1 = subscriptions1().size() + 1;
getSharingManager0().sendInvitation(
getShareable().getId(), contactId1From0, "This shareable!");
sync0To1(1, true);
// 0's timer starts when it gets the ACK of the invitation
ack1To0(1);
waitForEvents(c0);
assertGroupCount(c1, contactId0From1, 1, 1);
// When 0's timer has elapsed, the message should be deleted from 0's
// view of the conversation but 1 should still see the message
long timerLatency = MIN_AUTO_DELETE_TIMER_MS + BATCH_DELAY_MS;
c0.getTimeTravel().addCurrentTimeMillis(timerLatency);
c1.getTimeTravel().addCurrentTimeMillis(timerLatency);
assertGroupCount(c0, contactId1From0, 0, 0);
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
assertGroupCount(c1, contactId0From1, 1, 1);
assertEquals(1, getMessageHeaders(c1, contactId0From1).size());
// 1 marks as read, timer starting
markMessageRead(c1, contact0From1,
getMessageHeaders(c1, contactId0From1).get(0).getId());
assertGroupCount(c1, contactId0From1, 1, 0);
// 1 accepts the invitation that 0 has already deleted
assertEquals(1, getSharingManager1().getInvitations().size());
SharingInvitationItem invitation =
getSharingManager1().getInvitations().iterator().next();
assertEquals(getShareable(), invitation.getShareable());
Contact c = contactManager1.getContact(contactId0From1);
if (getShareable() instanceof Blog) {
//noinspection unchecked
((SharingManager<Blog>) getSharingManager1()).respondToInvitation(
(Blog) getShareable(), c, true);
} else if (getShareable() instanceof Forum) {
//noinspection unchecked
((SharingManager<Forum>) getSharingManager1()).respondToInvitation(
(Forum) getShareable(), c, true);
} else {
fail();
}
// Sync the invitation response message to 0
sync1To0(1, true);
// 1's timer starts when it gets the ACK
ack0To1(1);
waitForEvents(c1);
assertGroupCount(c0, contactId1From0, 1, 1);
assertGroupCount(c1, contactId0From1, 2, 0);
// 0 marks as read, timer starting
markMessageRead(c0, contact1From0,
getMessageHeaders(c0, contactId1From0).get(0).getId());
assertGroupCount(c0, contactId1From0, 1, 0);
assertGroupCount(c1, contactId0From1, 2, 0);
// both peers delete all messages after their timers expire
c0.getTimeTravel().addCurrentTimeMillis(timerLatency);
c1.getTimeTravel().addCurrentTimeMillis(timerLatency);
assertGroupCount(c0, contactId1From0, 0, 0);
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
assertGroupCount(c1, contactId0From1, 0, 0);
assertEquals(0, getMessageHeaders(c1, contactId0From1).size());
// there are no invitations hanging around
assertEquals(0, getSharingManager0().getInvitations().size());
assertEquals(0, getSharingManager1().getInvitations().size());
assertEquals(expectedSubscriptions1, subscriptions1().size());
}
}

View File

@@ -1,5 +1,8 @@
package org.briarproject.briar.sharing;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.blog.BlogManager;
import org.briarproject.briar.api.blog.event.BlogInvitationResponseReceivedEvent;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
@@ -10,22 +13,29 @@ import org.briarproject.briar.test.BriarIntegrationTestComponent;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
public class AutoDeleteBlogIntegrationTest
extends AbstractAutoDeleteIntegrationTest {
private SharingManager<? extends Shareable> sharingManager0;
private Shareable shareable;
private Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>>
private SharingManager<Blog> sharingManager0;
private SharingManager<Blog> sharingManager1;
private Blog shareable;
private BlogManager manager0;
private BlogManager manager1;
private Class<BlogInvitationResponseReceivedEvent>
responseReceivedEventClass;
@Before
@Override
public void setUp() throws Exception {
super.setUp();
manager0 = c0.getBlogManager();
manager1 = c1.getBlogManager();
// personalBlog(author0) is already shared with c1
shareable = c0.getBlogManager().getPersonalBlog(author2);
shareable = manager0.getPersonalBlog(author2);
sharingManager0 = c0.getBlogSharingManager();
addContacts1And2();
sharingManager1 = c1.getBlogSharingManager();
responseReceivedEventClass = BlogInvitationResponseReceivedEvent.class;
}
@@ -40,11 +50,26 @@ public class AutoDeleteBlogIntegrationTest
return sharingManager0;
}
@Override
protected SharingManager<? extends Shareable> getSharingManager1() {
return sharingManager1;
}
@Override
protected Shareable getShareable() {
return shareable;
}
@Override
protected Collection<Blog> subscriptions0() throws DbException {
return manager0.getBlogs();
}
@Override
protected Collection<Blog> subscriptions1() throws DbException {
return manager1.getBlogs();
}
@Override
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass() {
return responseReceivedEventClass;
@@ -54,4 +79,9 @@ public class AutoDeleteBlogIntegrationTest
public void testAutoDeclinedBlogSharing() throws Exception {
testAutoDeclinedSharing();
}
@Test
public void testRespondAfterSenderDeletedBlogInvitation() throws Exception {
testRespondAfterSenderDeletedInvitation();
}
}

View File

@@ -1,7 +1,10 @@
package org.briarproject.briar.sharing;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
import org.briarproject.briar.api.forum.Forum;
import org.briarproject.briar.api.forum.ForumManager;
import org.briarproject.briar.api.forum.event.ForumInvitationResponseReceivedEvent;
import org.briarproject.briar.api.sharing.InvitationResponse;
import org.briarproject.briar.api.sharing.Shareable;
@@ -10,21 +13,28 @@ import org.briarproject.briar.test.BriarIntegrationTestComponent;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
public class AutoDeleteForumIntegrationTest
extends AbstractAutoDeleteIntegrationTest {
private SharingManager<? extends Shareable> sharingManager0;
protected Shareable shareable;
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>>
private SharingManager<Forum> sharingManager0;
private SharingManager<Forum> sharingManager1;
protected Forum shareable;
private ForumManager manager0;
private ForumManager manager1;
protected Class<ForumInvitationResponseReceivedEvent>
responseReceivedEventClass;
@Before
@Override
public void setUp() throws Exception {
super.setUp();
shareable = c0.getForumManager().addForum("Test Forum");
manager0 = c0.getForumManager();
manager1 = c1.getForumManager();
shareable = manager0.addForum("Test Forum");
sharingManager0 = c0.getForumSharingManager();
addContacts1And2();
sharingManager1 = c1.getForumSharingManager();
responseReceivedEventClass = ForumInvitationResponseReceivedEvent.class;
}
@@ -39,11 +49,26 @@ public class AutoDeleteForumIntegrationTest
return sharingManager0;
}
@Override
protected SharingManager<? extends Shareable> getSharingManager1() {
return sharingManager1;
}
@Override
protected Shareable getShareable() {
return shareable;
}
@Override
protected Collection<Forum> subscriptions0() throws DbException {
return manager0.getForums();
}
@Override
protected Collection<Forum> subscriptions1() throws DbException {
return manager1.getForums();
}
@Override
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass() {
return responseReceivedEventClass;
@@ -53,4 +78,10 @@ public class AutoDeleteForumIntegrationTest
public void testAutoDeclinedForumSharing() throws Exception {
testAutoDeclinedSharing();
}
@Test
public void testRespondAfterSenderDeletedForumInvitation()
throws Exception {
testRespondAfterSenderDeletedInvitation();
}
}