Mark invitation unavailable to answer when creator dissolved the group

after the invitation.

Closes #876
This commit is contained in:
Torsten Grote
2016-12-20 17:15:00 -02:00
parent 79fc41477c
commit 6a94785d9a
3 changed files with 21 additions and 10 deletions

View File

@@ -269,6 +269,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (!isValidDependency(s, m.getPreviousMessageId()))
return abort(txn, s); return abort(txn, s);
// Mark any invite messages in the session unavailable to answer
markInvitesUnavailableToAnswer(txn, s);
// Move to the DISSOLVED state // Move to the DISSOLVED state
return new InviteeSession(s.getContactGroupId(), s.getPrivateGroupId(), return new InviteeSession(s.getContactGroupId(), s.getPrivateGroupId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(), s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),

View File

@@ -1,4 +1,4 @@
package org.briarproject.briar.privategroup; package org.briarproject.briar.privategroup.invitation;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
@@ -329,6 +329,9 @@ public class GroupInvitationIntegrationTest
// Creator's leave message is delivered to invitee // Creator's leave message is delivered to invitee
sync0To1(1, true); sync0To1(1, true);
// invitee should have no more open invitations
assertTrue(groupInvitationManager1.getInvitations().isEmpty());
// Invitee declines invitation, but it's no longer open - no exception // Invitee declines invitation, but it's no longer open - no exception
// as the action has succeeded // as the action has succeeded
assertEquals(0, groupManager1.getPrivateGroups().size()); assertEquals(0, groupManager1.getPrivateGroups().size());

View File

@@ -651,6 +651,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
assertTrue(session.getLastRemoteMessageId() assertTrue(session.getLastRemoteMessageId()
.equals(properLeaveMessage.getPreviousMessageId())); .equals(properLeaveMessage.getPreviousMessageId()));
expectMarkInvitesUnavailableToAnswer();
InviteeSession newSession = InviteeSession newSession =
engine.onLeaveMessage(txn, session, properLeaveMessage); engine.onLeaveMessage(txn, session, properLeaveMessage);
@@ -680,6 +681,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
assertTrue(session.getLastRemoteMessageId() assertTrue(session.getLastRemoteMessageId()
.equals(properLeaveMessage.getPreviousMessageId())); .equals(properLeaveMessage.getPreviousMessageId()));
expectMarkInvitesUnavailableToAnswer();
InviteeSession newSession = InviteeSession newSession =
engine.onLeaveMessage(txn, session, properLeaveMessage); engine.onLeaveMessage(txn, session, properLeaveMessage);
@@ -701,7 +703,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
public void testOnAbortMessageWhenNotSubscribed() throws Exception { public void testOnAbortMessageWhenNotSubscribed() throws Exception {
InviteeSession session = getDefaultSession(START); InviteeSession session = getDefaultSession(START);
expectAbortWhenSubscribedToGroup(); expectAbortWhenNotSubscribedToGroup();
InviteeSession newSession = InviteeSession newSession =
engine.onAbortMessage(txn, session, abortMessage); engine.onAbortMessage(txn, session, abortMessage);
assertSessionAborted(session, newSession); assertSessionAborted(session, newSession);
@@ -711,7 +713,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
public void testOnAbortMessageWhenSubscribed() throws Exception { public void testOnAbortMessageWhenSubscribed() throws Exception {
InviteeSession session = getDefaultSession(START); InviteeSession session = getDefaultSession(START);
expectAbortWhenNotSubscribedToGroup(); expectAbortWhenSubscribedToGroup();
InviteeSession newSession = InviteeSession newSession =
engine.onAbortMessage(txn, session, abortMessage); engine.onAbortMessage(txn, session, abortMessage);
assertSessionAborted(session, newSession); assertSessionAborted(session, newSession);
@@ -739,6 +741,17 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
} }
private void expectAbort(boolean subscribed) throws Exception { private void expectAbort(boolean subscribed) throws Exception {
expectMarkInvitesUnavailableToAnswer();
if (subscribed) {
expectIsSubscribedPrivateGroup();
expectSetPrivateGroupVisibility(INVISIBLE);
} else {
expectIsNotSubscribedPrivateGroup();
}
expectSendAbortMessage();
}
private void expectMarkInvitesUnavailableToAnswer() throws Exception {
final BdfDictionary query = BdfDictionary.of(new BdfEntry("query", "")); final BdfDictionary query = BdfDictionary.of(new BdfEntry("query", ""));
final BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", "")); final BdfDictionary meta = BdfDictionary.of(new BdfEntry("meta", ""));
final Map<MessageId, BdfDictionary> invites = final Map<MessageId, BdfDictionary> invites =
@@ -752,13 +765,6 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
will(returnValue(invites)); will(returnValue(invites));
}}); }});
expectMarkMessageAvailableToAnswer(lastRemoteMessageId, false); expectMarkMessageAvailableToAnswer(lastRemoteMessageId, false);
if (subscribed) {
expectIsSubscribedPrivateGroup();
expectSetPrivateGroupVisibility(INVISIBLE);
} else {
expectIsNotSubscribedPrivateGroup();
}
expectSendAbortMessage();
} }
private void assertSessionAborted(InviteeSession oldSession, private void assertSessionAborted(InviteeSession oldSession,