mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Add test for invitee responding after sharer deleted invitation
This commit is contained in:
@@ -1,13 +1,20 @@
|
|||||||
package org.briarproject.briar.sharing;
|
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.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.api.autodelete.event.ConversationMessagesDeletedEvent;
|
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.conversation.event.ConversationMessageReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||||
import org.briarproject.briar.api.sharing.Shareable;
|
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.api.sharing.SharingManager;
|
||||||
import org.briarproject.briar.autodelete.AbstractAutoDeleteTest;
|
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.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.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
|
||||||
import static org.briarproject.briar.test.TestEventListener.assertEvent;
|
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.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public abstract class AbstractAutoDeleteIntegrationTest
|
public abstract class AbstractAutoDeleteIntegrationTest
|
||||||
extends AbstractAutoDeleteTest {
|
extends AbstractAutoDeleteTest {
|
||||||
|
|
||||||
protected abstract SharingManager<? extends Shareable> getSharingManager0();
|
protected abstract SharingManager<? extends Shareable> getSharingManager0();
|
||||||
|
|
||||||
|
protected abstract SharingManager<? extends Shareable> getSharingManager1();
|
||||||
|
|
||||||
protected abstract Shareable getShareable();
|
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 abstract Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass();
|
||||||
|
|
||||||
protected void testAutoDeclinedSharing() throws Exception {
|
protected void testAutoDeclinedSharing() throws Exception {
|
||||||
@@ -173,4 +189,83 @@ public abstract class AbstractAutoDeleteIntegrationTest
|
|||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
assertGroupCount(c1, contactId0From1, 1, 1);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.briarproject.briar.sharing;
|
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.blog.event.BlogInvitationResponseReceivedEvent;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class AutoDeleteBlogIntegrationTest
|
public class AutoDeleteBlogIntegrationTest
|
||||||
extends AbstractAutoDeleteIntegrationTest {
|
extends AbstractAutoDeleteIntegrationTest {
|
||||||
|
|
||||||
private SharingManager<? extends Shareable> sharingManager0;
|
private SharingManager<Blog> sharingManager0;
|
||||||
private Shareable shareable;
|
private SharingManager<Blog> sharingManager1;
|
||||||
private Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>>
|
private Blog shareable;
|
||||||
|
private BlogManager manager0;
|
||||||
|
private BlogManager manager1;
|
||||||
|
private Class<BlogInvitationResponseReceivedEvent>
|
||||||
responseReceivedEventClass;
|
responseReceivedEventClass;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
manager0 = c0.getBlogManager();
|
||||||
|
manager1 = c1.getBlogManager();
|
||||||
// personalBlog(author0) is already shared with c1
|
// personalBlog(author0) is already shared with c1
|
||||||
shareable = c0.getBlogManager().getPersonalBlog(author2);
|
shareable = manager0.getPersonalBlog(author2);
|
||||||
sharingManager0 = c0.getBlogSharingManager();
|
sharingManager0 = c0.getBlogSharingManager();
|
||||||
addContacts1And2();
|
sharingManager1 = c1.getBlogSharingManager();
|
||||||
responseReceivedEventClass = BlogInvitationResponseReceivedEvent.class;
|
responseReceivedEventClass = BlogInvitationResponseReceivedEvent.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +50,26 @@ public class AutoDeleteBlogIntegrationTest
|
|||||||
return sharingManager0;
|
return sharingManager0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SharingManager<? extends Shareable> getSharingManager1() {
|
||||||
|
return sharingManager1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Shareable getShareable() {
|
protected Shareable getShareable() {
|
||||||
return shareable;
|
return shareable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Blog> subscriptions0() throws DbException {
|
||||||
|
return manager0.getBlogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Blog> subscriptions1() throws DbException {
|
||||||
|
return manager1.getBlogs();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass() {
|
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass() {
|
||||||
return responseReceivedEventClass;
|
return responseReceivedEventClass;
|
||||||
@@ -54,4 +79,9 @@ public class AutoDeleteBlogIntegrationTest
|
|||||||
public void testAutoDeclinedBlogSharing() throws Exception {
|
public void testAutoDeclinedBlogSharing() throws Exception {
|
||||||
testAutoDeclinedSharing();
|
testAutoDeclinedSharing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRespondAfterSenderDeletedBlogInvitation() throws Exception {
|
||||||
|
testRespondAfterSenderDeletedInvitation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.briar.sharing;
|
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.ConversationManager;
|
||||||
import org.briarproject.briar.api.conversation.event.ConversationMessageReceivedEvent;
|
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.forum.event.ForumInvitationResponseReceivedEvent;
|
||||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||||
import org.briarproject.briar.api.sharing.Shareable;
|
import org.briarproject.briar.api.sharing.Shareable;
|
||||||
@@ -10,21 +13,28 @@ import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class AutoDeleteForumIntegrationTest
|
public class AutoDeleteForumIntegrationTest
|
||||||
extends AbstractAutoDeleteIntegrationTest {
|
extends AbstractAutoDeleteIntegrationTest {
|
||||||
|
|
||||||
private SharingManager<? extends Shareable> sharingManager0;
|
private SharingManager<Forum> sharingManager0;
|
||||||
protected Shareable shareable;
|
private SharingManager<Forum> sharingManager1;
|
||||||
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>>
|
protected Forum shareable;
|
||||||
|
private ForumManager manager0;
|
||||||
|
private ForumManager manager1;
|
||||||
|
protected Class<ForumInvitationResponseReceivedEvent>
|
||||||
responseReceivedEventClass;
|
responseReceivedEventClass;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
shareable = c0.getForumManager().addForum("Test Forum");
|
manager0 = c0.getForumManager();
|
||||||
|
manager1 = c1.getForumManager();
|
||||||
|
shareable = manager0.addForum("Test Forum");
|
||||||
sharingManager0 = c0.getForumSharingManager();
|
sharingManager0 = c0.getForumSharingManager();
|
||||||
addContacts1And2();
|
sharingManager1 = c1.getForumSharingManager();
|
||||||
responseReceivedEventClass = ForumInvitationResponseReceivedEvent.class;
|
responseReceivedEventClass = ForumInvitationResponseReceivedEvent.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,11 +49,26 @@ public class AutoDeleteForumIntegrationTest
|
|||||||
return sharingManager0;
|
return sharingManager0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SharingManager<? extends Shareable> getSharingManager1() {
|
||||||
|
return sharingManager1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Shareable getShareable() {
|
protected Shareable getShareable() {
|
||||||
return shareable;
|
return shareable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Forum> subscriptions0() throws DbException {
|
||||||
|
return manager0.getForums();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Forum> subscriptions1() throws DbException {
|
||||||
|
return manager1.getForums();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass() {
|
protected Class<? extends ConversationMessageReceivedEvent<? extends InvitationResponse>> getResponseReceivedEventClass() {
|
||||||
return responseReceivedEventClass;
|
return responseReceivedEventClass;
|
||||||
@@ -53,4 +78,10 @@ public class AutoDeleteForumIntegrationTest
|
|||||||
public void testAutoDeclinedForumSharing() throws Exception {
|
public void testAutoDeclinedForumSharing() throws Exception {
|
||||||
testAutoDeclinedSharing();
|
testAutoDeclinedSharing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRespondAfterSenderDeletedForumInvitation()
|
||||||
|
throws Exception {
|
||||||
|
testRespondAfterSenderDeletedInvitation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user