Re-introduce InvitationResponse

This was done, so private responses don't need to include a Nameable already.
Retreiving a nameable is tricky and requires a data migration,
so we just don't do it now.
This commit is contained in:
Torsten Grote
2018-09-07 16:03:20 -03:00
parent d430b4fd2d
commit 86f650503b
27 changed files with 144 additions and 215 deletions

View File

@@ -159,7 +159,7 @@ public class IntroductionIntegrationTest
eventWaiter.await(TIMEOUT, 1);
assertTrue(listener0.response1Received);
assertEquals(introducee2.getAuthor().getName(),
listener0.getResponse().getNameable().getName());
listener0.getResponse().getIntroducedAuthor().getName());
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
// sync second ACCEPT message
@@ -167,7 +167,7 @@ public class IntroductionIntegrationTest
eventWaiter.await(TIMEOUT, 1);
assertTrue(listener0.response2Received);
assertEquals(introducee1.getAuthor().getName(),
listener0.getResponse().getNameable().getName());
listener0.getResponse().getIntroducedAuthor().getName());
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
// sync forwarded ACCEPT messages to introducees
@@ -265,7 +265,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct
assertEquals(introducee2.getAuthor().getName(),
listener0.getResponse().getNameable().getName());
listener0.getResponse().getIntroducedAuthor().getName());
// sync second response
sync2To0(1, true);
@@ -282,7 +282,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct
eventWaiter.await(TIMEOUT, 1);
assertEquals(introducee1.getAuthor().getName(),
listener2.getResponse().getNameable().getName());
listener2.getResponse().getIntroducedAuthor().getName());
// note how the introducer does not forward the second response,
// because after the first decline the protocol finished
@@ -356,7 +356,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct
eventWaiter.await(TIMEOUT, 1);
assertEquals(contact2From0.getAuthor().getName(),
listener1.getResponse().getNameable().getName());
listener1.getResponse().getIntroducedAuthor().getName());
assertFalse(contactManager1
.contactExists(author2.getId(), author1.getId()));
@@ -484,7 +484,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct
eventWaiter.await(TIMEOUT, 1);
assertEquals(introducee1.getAuthor().getName(),
listener2.getResponse().getNameable().getName());
listener2.getResponse().getIntroducedAuthor().getName());
// assert that introducee2 is in correct state
introduceeSession = getIntroduceeSession(c2);

View File

@@ -310,8 +310,6 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
false);
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
will(returnValue(privateGroup));
}});
expectGetContactId();
expectSetPrivateGroupVisibility(SHARED);
@@ -401,8 +399,6 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
false);
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
will(returnValue(privateGroup));
}});
expectGetContactId();
CreatorSession newSession =

View File

@@ -2,7 +2,6 @@ package org.briarproject.briar.privategroup.invitation;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.TestDatabaseModule;
import org.briarproject.briar.api.client.ProtocolStateException;
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
@@ -127,7 +126,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) {
foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable());
assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.isLocal());
assertFalse(response.wasAccepted());
}
@@ -144,7 +143,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) {
foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable());
assertEquals(privateGroup0.getId(), response.getShareableId());
assertFalse(response.isLocal());
assertFalse(response.wasAccepted());
}
@@ -177,7 +176,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) {
foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable());
assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.wasAccepted());
} else {
GroupInvitationRequest request = (GroupInvitationRequest) m;
@@ -197,7 +196,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) {
foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable());
assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.wasAccepted());
}
}
@@ -441,38 +440,6 @@ public class GroupInvitationIntegrationTest
sync1To0(1, true);
}
@Test(expected = AssertionError.class)
public void testDeleteOnlyInvitationFails() throws Exception {
// send invitation
sendInvitation(clock.currentTimeMillis(), null);
sync0To1(1, true);
// save MessageId of invitation
Collection<PrivateMessageHeader> messages =
withinTransactionReturns(db1, txn -> groupInvitationManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(1, messages.size());
MessageId inviteId = messages.iterator().next().getId();
// decline invitation
groupInvitationManager1
.respondToInvitation(contactId0From1, privateGroup0, false);
// we should have an invitation and a decline message
messages = withinTransactionReturns(db1, txn -> groupInvitationManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(2, messages.size());
// delete only invitation
withinTransaction(db1, txn -> {
db1.deleteMessage(txn, inviteId);
db1.deleteMessageMetadata(txn, inviteId);
// This should fail
groupInvitationManager1.getMessageHeaders(txn, contactId0From1);
});
}
private void sendInvitation(long timestamp, @Nullable String msg) throws
DbException {
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,

View File

@@ -680,8 +680,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
contactGroup.getId(), query);
will(returnValue(results));
// first message
oneOf(messageParser).parseMetadata(meta2);
will(returnValue(messageMetadata2));
oneOf(messageParser).parseMetadata(meta);
will(returnValue(messageMetadata1));
oneOf(db).getMessageStatus(txn, contactId, message.getId());
@@ -695,8 +693,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
// second message
oneOf(messageParser).parseMetadata(meta2);
will(returnValue(messageMetadata2));
oneOf(messageParser).parseMetadata(meta);
will(returnValue(messageMetadata1));
oneOf(db).getMessageStatus(txn, contactId, messageId2);
}});
@@ -712,7 +708,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
} else if (m.getId().equals(messageId2)) {
assertTrue(m instanceof GroupInvitationResponse);
assertEquals(time2, m.getTimestamp());
assertEquals(pg, ((GroupInvitationResponse) m).getNameable());
assertEquals(pg.getId(),
((GroupInvitationResponse) m).getShareableId());
} else {
throw new AssertionError();
}

View File

@@ -160,7 +160,7 @@ public class BlogSharingIntegrationTest
assertEquals("Hi!", invitation.getMessage());
} else {
BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(blog2, response.getNameable());
assertEquals(blog2.getId(), response.getShareableId());
assertTrue(response.wasAccepted());
assertTrue(response.isLocal());
}
@@ -233,7 +233,7 @@ public class BlogSharingIntegrationTest
assertEquals("Hi!", invitation.getMessage());
} else {
BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(rssBlog, response.getNameable());
assertEquals(rssBlog.getId(), response.getShareableId());
assertTrue(response.wasAccepted());
assertTrue(response.isLocal());
}
@@ -294,7 +294,7 @@ public class BlogSharingIntegrationTest
assertEquals(null, invitation.getMessage());
} else {
BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(blog2, response.getNameable());
assertEquals(blog2.getId(), response.getShareableId());
assertFalse(response.wasAccepted());
assertTrue(response.isLocal());
}

View File

@@ -142,7 +142,7 @@ public class ForumSharingIntegrationTest
assertTrue(invitation.canBeOpened());
} else {
ForumInvitationResponse response = (ForumInvitationResponse) m;
assertEquals(forum0, response.getNameable());
assertEquals(forum0.getId(), response.getShareableId());
assertTrue(response.wasAccepted());
assertTrue(response.isLocal());
}
@@ -198,7 +198,7 @@ public class ForumSharingIntegrationTest
assertFalse(invitation.canBeOpened());
} else {
ForumInvitationResponse response = (ForumInvitationResponse) m;
assertEquals(forum0, response.getNameable());
assertEquals(forum0.getId(), response.getShareableId());
assertFalse(response.wasAccepted());
assertTrue(response.isLocal());
}