diff --git a/briar-core/src/main/java/org/briarproject/briar/sharing/SharingManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/sharing/SharingManagerImpl.java index 743fe4683603e1e5077c41795442a2817bf441d9..c03ee5eb538154a6ff636e47d4ec607dd1b0cbd1 100644 --- a/briar-core/src/main/java/org/briarproject/briar/sharing/SharingManagerImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/sharing/SharingManagerImpl.java @@ -238,7 +238,8 @@ abstract class SharingManagerImpl<S extends Shareable> try { Contact contact = db.getContact(txn, contactId); if (!canBeShared(txn, shareableId, contact)) - throw new IllegalArgumentException(); + // we might have received an invitation in the meantime + return; // Look up the session, if there is one GroupId contactGroupId = getContactGroup(contact).getId(); StoredSession ss = getSession(txn, contactGroupId, sessionId); 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 b66b98124d5c99b42996344397e104b42420eb69..39db620840a177bf6df759057aae81d9c0b71df7 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 @@ -96,7 +96,7 @@ public class BlogSharingIntegrationTest injectEagerSingletons(c2); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPersonalBlogCannotBeSharedWithOwner() throws Exception { listenToEvents(true); @@ -108,11 +108,6 @@ public class BlogSharingIntegrationTest contact0From1)); assertFalse(blogSharingManager2.canBeShared(blog0.getId(), contact0From2)); - - // create invitation - blogSharingManager0 - .sendInvitation(blog1.getId(), contactId1From0, "Hi!", - clock.currentTimeMillis()); } @Test 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 b33e2b6a7e68735b4248360cecd8f474d7e5a3cd..052d0e69d314505298bb70a8245facd22a67f0e6 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 @@ -9,6 +9,7 @@ import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.EventListener; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; +import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Message; import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.test.TestDatabaseModule; @@ -379,7 +380,7 @@ public class ForumSharingIntegrationTest assertEquals(1, forumManager1.getForums().size()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testSharingSameForumWithEachOther() throws Exception { // initialize and let invitee accept all requests listenToEvents(true); @@ -399,6 +400,13 @@ public class ForumSharingIntegrationTest eventWaiter.await(TIMEOUT, 1); assertTrue(listener0.responseReceived); + // response and invitation got tracked + Group group = contactGroupFactory + .createContactGroup(ForumSharingManager.CLIENT_ID, + contact0From1); + assertEquals(2, c1.getMessageTracker().getGroupCount(group.getId()) + .getMsgCount()); + // forum was added successfully assertEquals(1, forumManager1.getForums().size()); @@ -407,6 +415,40 @@ public class ForumSharingIntegrationTest contactId0From1, "I am re-sharing this forum with you.", clock.currentTimeMillis()); + + // assert that the last invitation wasn't send + assertEquals(2, c1.getMessageTracker().getGroupCount(group.getId()) + .getMsgCount()); + } + + @Test + public void testSharingSameForumWithEachOtherBeforeAccept() + throws Exception { + // send invitation + forumSharingManager0 + .sendInvitation(forum0.getId(), contactId1From0, "Hi!", + clock.currentTimeMillis()); + sync0To1(1, true); + + // ensure that invitee has received the invitations + assertEquals(1, forumSharingManager1.getInvitations().size()); + + // assert that the invitation arrived + Group group = contactGroupFactory + .createContactGroup(ForumSharingManager.CLIENT_ID, + contact0From1); + assertEquals(1, c1.getMessageTracker().getGroupCount(group.getId()) + .getMsgCount()); + + // invitee now shares same forum back + forumSharingManager1.sendInvitation(forum0.getId(), + contactId0From1, + "I am re-sharing this forum with you.", + clock.currentTimeMillis()); + + // assert that the last invitation wasn't send + assertEquals(1, c1.getMessageTracker().getGroupCount(group.getId()) + .getMsgCount()); } @Test