mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Check metadata for wipers in test
This commit is contained in:
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
@@ -124,6 +125,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
// message.getGroupId turn into contactid
|
// message.getGroupId turn into contactid
|
||||||
// txn.attach event
|
// txn.attach event
|
||||||
} else if (type == WIPE) {
|
} else if (type == WIPE) {
|
||||||
|
if (!remoteWipeIsSetup(txn)) return false;
|
||||||
ContactId contactId = getContactId(txn, m.getGroupId());
|
ContactId contactId = getContactId(txn, m.getGroupId());
|
||||||
// Check if contact is in list of wipers
|
// Check if contact is in list of wipers
|
||||||
if (findMessage(txn, m.getGroupId(), SETUP, true) != null) {
|
if (findMessage(txn, m.getGroupId(), SETUP, true) != null) {
|
||||||
@@ -170,7 +172,10 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
|
|
||||||
public void setup(Transaction txn, List<ContactId> wipers)
|
public void setup(Transaction txn, List<ContactId> wipers)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
// TODO if (we already have a set of wipers?) do something
|
// If we already have a set of wipers do nothing
|
||||||
|
// TODO revoke existing wipers
|
||||||
|
if (remoteWipeIsSetup(txn)) throw new FormatException();
|
||||||
|
|
||||||
if (wipers.size() < 2) throw new FormatException();
|
if (wipers.size() < 2) throw new FormatException();
|
||||||
|
|
||||||
BdfList wipersMetadata = new BdfList();
|
BdfList wipersMetadata = new BdfList();
|
||||||
@@ -388,4 +393,30 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
results.entrySet().iterator().next();
|
results.entrySet().iterator().next();
|
||||||
return new Pair<>(e.getKey(), e.getValue());
|
return new Pair<>(e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remoteWipeIsSetup(Transaction txn) {
|
||||||
|
try {
|
||||||
|
return !db.getGroupMetadata(txn, localGroup.getId()).isEmpty();
|
||||||
|
} catch (DbException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Author> getWipers(Transaction txn) throws DbException {
|
||||||
|
try {
|
||||||
|
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn,
|
||||||
|
localGroup.getId());
|
||||||
|
BdfList bdfWipers = meta.getList(GROUP_KEY_WIPERS);
|
||||||
|
|
||||||
|
List<Author> wipers = new ArrayList<>(bdfWipers.size());
|
||||||
|
for (int i = 0; i < bdfWipers.size(); i++) {
|
||||||
|
BdfList author = bdfWipers.getList(i);
|
||||||
|
wipers.add(clientHelper.parseAndValidateAuthor(author));
|
||||||
|
}
|
||||||
|
return wipers;
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
try {
|
try {
|
||||||
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn,
|
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn,
|
||||||
localGroup.getId());
|
localGroup.getId());
|
||||||
|
|
||||||
return backupMetadataParser.parseBackupMetadata(meta);
|
return backupMetadataParser.parseBackupMetadata(meta);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
|
|||||||
@@ -74,16 +74,16 @@ public class RemoteWipeIntegrationTest extends BriarIntegrationTest<BriarIntegra
|
|||||||
BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
|
BriarIntegrationTestComponent.Helper.injectEagerSingletons(c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoteWipe() throws Exception {
|
public void testRemoteWipe() throws Exception {
|
||||||
remoteWipeManager0.listenForPanic(this);
|
remoteWipeManager0.listenForPanic(this);
|
||||||
db0.transaction(false, txn -> {
|
db0.transaction(false, txn -> {
|
||||||
// TODO assert that we do not already have a wipe setup
|
// Assert that we do not already have a wipe setup
|
||||||
// assertNull(socialBackupManager0.getBackupMetadata(txn));
|
assertFalse(remoteWipeManager0.remoteWipeIsSetup(txn));
|
||||||
remoteWipeManager0.setup(txn,
|
remoteWipeManager0.setup(txn,
|
||||||
asList(contactId1From0, contactId2From0));
|
asList(contactId1From0, contactId2From0));
|
||||||
// TODO now check that we do have a wipe setup
|
// Now check that we do have a wipe setup
|
||||||
|
assertTrue(remoteWipeManager0.remoteWipeIsSetup(txn));
|
||||||
});
|
});
|
||||||
// Sync the setup messages to the contacts
|
// Sync the setup messages to the contacts
|
||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user