mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Only allow one private group (the inbox) to be shared with each contact.
This commit is contained in:
@@ -83,7 +83,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
|
||||
public DatabaseComponentTest() {
|
||||
groupId = new GroupId(TestUtils.getRandomId());
|
||||
group = new Group(groupId, "Group", new byte[GROUP_SALT_LENGTH], true);
|
||||
group = new Group(groupId, "Group", new byte[GROUP_SALT_LENGTH], false);
|
||||
authorId = new AuthorId(TestUtils.getRandomId());
|
||||
author = new Author(authorId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
||||
@@ -465,7 +465,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.setInboxGroup(contactId, group);
|
||||
Group privateGroup = new Group(groupId, "Group",
|
||||
new byte[GROUP_SALT_LENGTH], true);
|
||||
db.setInboxGroup(contactId, privateGroup);
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
@@ -557,7 +559,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchSubscriptionException expected) {}
|
||||
|
||||
try {
|
||||
db.setVisibility(groupId, Collections.<ContactId>emptyList());
|
||||
db.setVisibility(group, Collections.<ContactId>emptyList());
|
||||
fail();
|
||||
} catch(NoSuchSubscriptionException expected) {}
|
||||
|
||||
@@ -1337,8 +1339,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(both));
|
||||
oneOf(database).getContactIds(txn);
|
||||
will(returnValue(both));
|
||||
oneOf(database).removeVisibility(txn, contactId1, groupId);
|
||||
oneOf(database).setVisibleToAll(txn, groupId, false);
|
||||
oneOf(database).removeVisibility(txn, contactId1, group);
|
||||
oneOf(database).setVisibleToAll(txn, group, false);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
LocalSubscriptionsUpdatedEvent.class)));
|
||||
@@ -1347,7 +1349,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
shutdown);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setVisibility(groupId, Arrays.asList(contactId));
|
||||
db.setVisibility(group, Arrays.asList(contactId));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -1372,14 +1374,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(both));
|
||||
oneOf(database).getContactIds(txn);
|
||||
will(returnValue(both));
|
||||
oneOf(database).setVisibleToAll(txn, groupId, false);
|
||||
oneOf(database).setVisibleToAll(txn, group, false);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setVisibility(groupId, both);
|
||||
db.setVisibility(group, both);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -1405,8 +1407,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(Collections.emptyList()));
|
||||
oneOf(database).getContactIds(txn);
|
||||
will(returnValue(both));
|
||||
oneOf(database).addVisibility(txn, contactId, groupId);
|
||||
oneOf(database).setVisibleToAll(txn, groupId, false);
|
||||
oneOf(database).addVisibility(txn, contactId, group);
|
||||
oneOf(database).setVisibleToAll(txn, group, false);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
LocalSubscriptionsUpdatedEvent.class)));
|
||||
@@ -1415,12 +1417,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsGroup(txn, groupId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setVisibleToAll(txn, groupId, true);
|
||||
oneOf(database).setVisibleToAll(txn, group, true);
|
||||
oneOf(database).getVisibility(txn, groupId);
|
||||
will(returnValue(Arrays.asList(contactId)));
|
||||
oneOf(database).getContactIds(txn);
|
||||
will(returnValue(both));
|
||||
oneOf(database).addVisibility(txn, contactId1, groupId);
|
||||
oneOf(database).addVisibility(txn, contactId1, group);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
oneOf(listener).eventOccurred(with(any(
|
||||
LocalSubscriptionsUpdatedEvent.class)));
|
||||
@@ -1429,8 +1431,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
shutdown);
|
||||
|
||||
db.addListener(listener);
|
||||
db.setVisibility(groupId, Arrays.asList(contactId));
|
||||
db.setVisibleToAll(groupId, true);
|
||||
db.setVisibility(group, Arrays.asList(contactId));
|
||||
db.setVisibleToAll(group, true);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
@@ -203,7 +203,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
@@ -240,7 +240,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
@@ -283,7 +283,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertFalse(it.hasNext());
|
||||
|
||||
// Making the subscription visible should make the message sendable
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
assertTrue(it.hasNext());
|
||||
@@ -356,7 +356,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
@@ -654,7 +654,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
// The message is not in the database
|
||||
@@ -673,7 +673,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
@@ -697,7 +697,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.setRetentionTime(txn, contactId, timestamp + 1, 1);
|
||||
db.addMessage(txn, message, false);
|
||||
@@ -721,7 +721,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
@@ -746,7 +746,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
// The message is not in the database
|
||||
@@ -784,7 +784,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.addMessage(txn, message, false);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
|
||||
@@ -826,7 +826,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
@@ -849,7 +849,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addMessage(txn, message, false);
|
||||
|
||||
@@ -876,11 +876,11 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||
|
||||
// Make the group visible to the contact
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addVisibility(txn, contactId, group);
|
||||
assertEquals(Arrays.asList(contactId), db.getVisibility(txn, groupId));
|
||||
|
||||
// Make the group invisible again
|
||||
db.removeVisibility(txn, contactId, groupId);
|
||||
db.removeVisibility(txn, contactId, group);
|
||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
@@ -1201,13 +1201,12 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Make the groups visible to the contact
|
||||
Collections.shuffle(groups);
|
||||
for(Group g : groups) db.addVisibility(txn, contactId, g.getId());
|
||||
for(Group g : groups) db.addVisibility(txn, contactId, g);
|
||||
|
||||
// Make some of the groups invisible to the contact and remove them all
|
||||
Collections.shuffle(groups);
|
||||
for(Group g : groups) {
|
||||
if(Math.random() < 0.5)
|
||||
db.removeVisibility(txn, contactId, g.getId());
|
||||
if(Math.random() < 0.5) db.removeVisibility(txn, contactId, g);
|
||||
db.removeGroup(txn, g.getId());
|
||||
}
|
||||
|
||||
@@ -1572,7 +1571,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Make the group visible to all contacts - it should be available,
|
||||
// subscribed, visible to all
|
||||
db.setVisibleToAll(txn, groupId, true);
|
||||
db.setVisibleToAll(txn, group, true);
|
||||
assertEquals(Arrays.asList(group), db.getGroups(txn));
|
||||
it = db.getAvailableGroups(txn).iterator();
|
||||
assertTrue(it.hasNext());
|
||||
|
||||
Reference in New Issue
Block a user