mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Refactor MailboxProperties and MailboxUpdateWithMailbox.
This commit is contained in:
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -14,13 +15,36 @@ public class MailboxProperties {
|
|||||||
private final MailboxAuthToken authToken;
|
private final MailboxAuthToken authToken;
|
||||||
private final boolean owner;
|
private final boolean owner;
|
||||||
private final List<MailboxVersion> serverSupports;
|
private final List<MailboxVersion> serverSupports;
|
||||||
|
@Nullable
|
||||||
|
private final MailboxFolderId inboxId; // Null for own mailbox
|
||||||
|
@Nullable
|
||||||
|
private final MailboxFolderId outboxId; // Null for own mailbox
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for properties used by the mailbox's owner.
|
||||||
|
*/
|
||||||
public MailboxProperties(String baseUrl, MailboxAuthToken authToken,
|
public MailboxProperties(String baseUrl, MailboxAuthToken authToken,
|
||||||
boolean owner, List<MailboxVersion> serverSupports) {
|
List<MailboxVersion> serverSupports) {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.authToken = authToken;
|
this.authToken = authToken;
|
||||||
this.owner = owner;
|
this.owner = true;
|
||||||
this.serverSupports = serverSupports;
|
this.serverSupports = serverSupports;
|
||||||
|
this.inboxId = null;
|
||||||
|
this.outboxId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for properties used by a contact of the mailbox's owner.
|
||||||
|
*/
|
||||||
|
public MailboxProperties(String baseUrl, MailboxAuthToken authToken,
|
||||||
|
List<MailboxVersion> serverSupports, MailboxFolderId inboxId,
|
||||||
|
MailboxFolderId outboxId) {
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
this.authToken = authToken;
|
||||||
|
this.owner = false;
|
||||||
|
this.serverSupports = serverSupports;
|
||||||
|
this.inboxId = inboxId;
|
||||||
|
this.outboxId = outboxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBaseUrl() {
|
public String getBaseUrl() {
|
||||||
@@ -43,4 +67,14 @@ public class MailboxProperties {
|
|||||||
public List<MailboxVersion> getServerSupports() {
|
public List<MailboxVersion> getServerSupports() {
|
||||||
return serverSupports;
|
return serverSupports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public MailboxFolderId getInboxId() {
|
||||||
|
return inboxId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public MailboxFolderId getOutboxId() {
|
||||||
|
return outboxId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,48 +9,21 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class MailboxUpdateWithMailbox extends MailboxUpdate {
|
public class MailboxUpdateWithMailbox extends MailboxUpdate {
|
||||||
private final List<MailboxVersion> serverSupports;
|
|
||||||
private final String onion;
|
private final MailboxProperties properties;
|
||||||
private final MailboxAuthToken authToken;
|
|
||||||
private final MailboxFolderId inboxId;
|
|
||||||
private final MailboxFolderId outboxId;
|
|
||||||
|
|
||||||
public MailboxUpdateWithMailbox(List<MailboxVersion> clientSupports,
|
public MailboxUpdateWithMailbox(List<MailboxVersion> clientSupports,
|
||||||
List<MailboxVersion> serverSupports, String onion,
|
MailboxProperties properties) {
|
||||||
MailboxAuthToken authToken, MailboxFolderId inboxId,
|
|
||||||
MailboxFolderId outboxId
|
|
||||||
) {
|
|
||||||
super(clientSupports, true);
|
super(clientSupports, true);
|
||||||
this.serverSupports = serverSupports;
|
this.properties = properties;
|
||||||
this.onion = onion;
|
|
||||||
this.authToken = authToken;
|
|
||||||
this.inboxId = inboxId;
|
|
||||||
this.outboxId = outboxId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MailboxUpdateWithMailbox(MailboxUpdateWithMailbox o,
|
public MailboxUpdateWithMailbox(MailboxUpdateWithMailbox o,
|
||||||
List<MailboxVersion> newClientSupports) {
|
List<MailboxVersion> newClientSupports) {
|
||||||
this(newClientSupports, o.serverSupports, o.onion, o.authToken,
|
this(newClientSupports, o.getMailboxProperties());
|
||||||
o.inboxId, o.outboxId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOnion() {
|
public MailboxProperties getMailboxProperties() {
|
||||||
return onion;
|
return properties;
|
||||||
}
|
|
||||||
|
|
||||||
public MailboxAuthToken getAuthToken() {
|
|
||||||
return authToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MailboxFolderId getInboxId() {
|
|
||||||
return inboxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MailboxFolderId getOutboxId() {
|
|
||||||
return outboxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MailboxVersion> getServerSupports() {
|
|
||||||
return serverSupports;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ import org.briarproject.bramble.api.identity.Author;
|
|||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.bramble.api.identity.Identity;
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.sync.ClientId;
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
@@ -223,6 +226,19 @@ public class TestUtils {
|
|||||||
getAgreementPublicKey(), verified);
|
getAgreementPublicKey(), verified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MailboxProperties getMailboxProperties(boolean owner,
|
||||||
|
List<MailboxVersion> serverSupports) {
|
||||||
|
String baseUrl = "http://" + getRandomString(56) + ".onion"; // TODO
|
||||||
|
MailboxAuthToken authToken = new MailboxAuthToken(getRandomId());
|
||||||
|
if (owner) {
|
||||||
|
return new MailboxProperties(baseUrl, authToken, serverSupports);
|
||||||
|
}
|
||||||
|
MailboxFolderId inboxId = new MailboxFolderId(getRandomId());
|
||||||
|
MailboxFolderId outboxId = new MailboxFolderId(getRandomId());
|
||||||
|
return new MailboxProperties(baseUrl, authToken, serverSupports,
|
||||||
|
inboxId, outboxId);
|
||||||
|
}
|
||||||
|
|
||||||
public static void writeBytes(File file, byte[] bytes)
|
public static void writeBytes(File file, byte[] bytes)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
FileOutputStream outputStream = new FileOutputStream(file);
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
@@ -275,7 +291,7 @@ public class TestUtils {
|
|||||||
return Math.sqrt(getVariance(samples));
|
return Math.sqrt(getVariance(samples));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOptionalTestEnabled(Class testClass) {
|
public static boolean isOptionalTestEnabled(Class<?> testClass) {
|
||||||
String optionalTests = System.getenv("OPTIONAL_TESTS");
|
String optionalTests = System.getenv("OPTIONAL_TESTS");
|
||||||
return optionalTests != null &&
|
return optionalTests != null &&
|
||||||
asList(optionalTests.split(",")).contains(testClass.getName());
|
asList(optionalTests.split(",")).contains(testClass.getName());
|
||||||
@@ -292,11 +308,8 @@ public class TestUtils {
|
|||||||
MailboxUpdateWithMailbox am = (MailboxUpdateWithMailbox) a;
|
MailboxUpdateWithMailbox am = (MailboxUpdateWithMailbox) a;
|
||||||
MailboxUpdateWithMailbox bm = (MailboxUpdateWithMailbox) b;
|
MailboxUpdateWithMailbox bm = (MailboxUpdateWithMailbox) b;
|
||||||
return am.getClientSupports().equals(bm.getClientSupports()) &&
|
return am.getClientSupports().equals(bm.getClientSupports()) &&
|
||||||
am.getServerSupports().equals(bm.getServerSupports()) &&
|
mailboxPropertiesEqual(am.getMailboxProperties(),
|
||||||
am.getOnion().equals(bm.getOnion()) &&
|
bm.getMailboxProperties());
|
||||||
am.getAuthToken().equals(bm.getAuthToken()) &&
|
|
||||||
am.getInboxId().equals(bm.getInboxId()) &&
|
|
||||||
am.getOutboxId().equals(bm.getOutboxId());
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.briarproject.bramble.api.identity.Author;
|
|||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||||
@@ -455,9 +456,11 @@ class ClientHelperImpl implements ClientHelper {
|
|||||||
checkLength(inboxId, UniqueId.LENGTH);
|
checkLength(inboxId, UniqueId.LENGTH);
|
||||||
byte[] outboxId = properties.getRaw(PROP_KEY_OUTBOXID);
|
byte[] outboxId = properties.getRaw(PROP_KEY_OUTBOXID);
|
||||||
checkLength(outboxId, UniqueId.LENGTH);
|
checkLength(outboxId, UniqueId.LENGTH);
|
||||||
return new MailboxUpdateWithMailbox(clientSupportsList,
|
String baseUrl = "http://" + onion + ".onion"; // TODO
|
||||||
serverSupportsList, onion, new MailboxAuthToken(authToken),
|
MailboxProperties props = new MailboxProperties(baseUrl,
|
||||||
|
new MailboxAuthToken(authToken), serverSupportsList,
|
||||||
new MailboxFolderId(inboxId), new MailboxFolderId(outboxId));
|
new MailboxFolderId(inboxId), new MailboxFolderId(outboxId));
|
||||||
|
return new MailboxUpdateWithMailbox(clientSupportsList, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class MailboxApiImpl implements MailboxApi {
|
|||||||
}
|
}
|
||||||
return new MailboxProperties(properties.getBaseUrl(),
|
return new MailboxProperties(properties.getBaseUrl(),
|
||||||
MailboxAuthToken.fromString(tokenNode.textValue()),
|
MailboxAuthToken.fromString(tokenNode.textValue()),
|
||||||
true, parseServerSupports(node));
|
parseServerSupports(node));
|
||||||
} catch (JacksonException | InvalidMailboxIdException e) {
|
} catch (JacksonException | InvalidMailboxIdException e) {
|
||||||
throw new ApiException();
|
throw new ApiException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,11 +177,10 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
|||||||
LOG.info("QR code is valid");
|
LOG.info("QR code is valid");
|
||||||
byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33);
|
byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33);
|
||||||
String onion = crypto.encodeOnion(onionPubKey);
|
String onion = crypto.encodeOnion(onionPubKey);
|
||||||
String baseUrl = "http://" + onion + ".onion";
|
String baseUrl = "http://" + onion + ".onion"; // TODO
|
||||||
byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65);
|
byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65);
|
||||||
MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes);
|
MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes);
|
||||||
return new MailboxProperties(baseUrl, setupToken, true,
|
return new MailboxProperties(baseUrl, setupToken, new ArrayList<>());
|
||||||
new ArrayList<>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
static final String SETTINGS_NAMESPACE = "mailbox";
|
static final String SETTINGS_NAMESPACE = "mailbox";
|
||||||
|
// TODO: This currently stores the base URL, not the 56-char onion address
|
||||||
static final String SETTINGS_KEY_ONION = "onion";
|
static final String SETTINGS_KEY_ONION = "onion";
|
||||||
static final String SETTINGS_KEY_TOKEN = "token";
|
static final String SETTINGS_KEY_TOKEN = "token";
|
||||||
static final String SETTINGS_KEY_SERVER_SUPPORTS = "serverSupports";
|
static final String SETTINGS_KEY_SERVER_SUPPORTS = "serverSupports";
|
||||||
@@ -69,7 +70,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MailboxAuthToken tokenId = MailboxAuthToken.fromString(token);
|
MailboxAuthToken tokenId = MailboxAuthToken.fromString(token);
|
||||||
return new MailboxProperties(onion, tokenId, true, serverSupports);
|
return new MailboxProperties(onion, tokenId, serverSupports);
|
||||||
} catch (InvalidMailboxIdException e) {
|
} catch (InvalidMailboxIdException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,11 +242,14 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
private void createAndSendUpdateWithMailbox(Transaction txn, Contact c,
|
private void createAndSendUpdateWithMailbox(Transaction txn, Contact c,
|
||||||
List<MailboxVersion> serverSupports, String ownOnion)
|
List<MailboxVersion> serverSupports, String ownOnion)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
MailboxUpdate u = new MailboxUpdateWithMailbox(
|
String baseUrl = "http://" + ownOnion + ".onion"; // TODO
|
||||||
clientSupports, serverSupports, ownOnion,
|
MailboxProperties properties = new MailboxProperties(baseUrl,
|
||||||
new MailboxAuthToken(crypto.generateUniqueId().getBytes()),
|
new MailboxAuthToken(crypto.generateUniqueId().getBytes()),
|
||||||
|
serverSupports,
|
||||||
new MailboxFolderId(crypto.generateUniqueId().getBytes()),
|
new MailboxFolderId(crypto.generateUniqueId().getBytes()),
|
||||||
new MailboxFolderId(crypto.generateUniqueId().getBytes()));
|
new MailboxFolderId(crypto.generateUniqueId().getBytes()));
|
||||||
|
MailboxUpdate u =
|
||||||
|
new MailboxUpdateWithMailbox(clientSupports, properties);
|
||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
storeMessageReplaceLatest(txn, g.getId(), u);
|
storeMessageReplaceLatest(txn, g.getId(), u);
|
||||||
}
|
}
|
||||||
@@ -325,11 +328,12 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
BdfList serverSupports = new BdfList();
|
BdfList serverSupports = new BdfList();
|
||||||
if (u.hasMailbox()) {
|
if (u.hasMailbox()) {
|
||||||
MailboxUpdateWithMailbox um = (MailboxUpdateWithMailbox) u;
|
MailboxUpdateWithMailbox um = (MailboxUpdateWithMailbox) u;
|
||||||
serverSupports = encodeSupportsList(um.getServerSupports());
|
MailboxProperties properties = um.getMailboxProperties();
|
||||||
dict.put(PROP_KEY_ONION, um.getOnion());
|
serverSupports = encodeSupportsList(properties.getServerSupports());
|
||||||
dict.put(PROP_KEY_AUTHTOKEN, um.getAuthToken().getBytes());
|
dict.put(PROP_KEY_ONION, properties.getOnion());
|
||||||
dict.put(PROP_KEY_INBOXID, um.getInboxId().getBytes());
|
dict.put(PROP_KEY_AUTHTOKEN, properties.getAuthToken());
|
||||||
dict.put(PROP_KEY_OUTBOXID, um.getOutboxId().getBytes());
|
dict.put(PROP_KEY_INBOXID, properties.getInboxId());
|
||||||
|
dict.put(PROP_KEY_OUTBOXID, properties.getOutboxId());
|
||||||
}
|
}
|
||||||
return BdfList.of(version, encodeSupportsList(u.getClientSupports()),
|
return BdfList.of(version, encodeSupportsList(u.getClientSupports()),
|
||||||
serverSupports, dict);
|
serverSupports, dict);
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ import org.briarproject.bramble.api.db.Metadata;
|
|||||||
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.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||||
@@ -52,6 +51,7 @@ import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY
|
|||||||
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_ONION;
|
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_ONION;
|
||||||
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_OUTBOXID;
|
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY_OUTBOXID;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getMailboxProperties;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
@@ -111,22 +111,18 @@ public class ClientHelperImplTest extends BrambleMockTestCase {
|
|||||||
someServerSupports = BdfList.of(BdfList.of(1, 0));
|
someServerSupports = BdfList.of(BdfList.of(1, 0));
|
||||||
validMailboxUpdateWithMailbox = new MailboxUpdateWithMailbox(
|
validMailboxUpdateWithMailbox = new MailboxUpdateWithMailbox(
|
||||||
singletonList(new MailboxVersion(1, 0)),
|
singletonList(new MailboxVersion(1, 0)),
|
||||||
singletonList(new MailboxVersion(1, 0)),
|
getMailboxProperties(false,
|
||||||
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd",
|
singletonList(new MailboxVersion(1, 0))));
|
||||||
new MailboxAuthToken(getRandomId()),
|
|
||||||
new MailboxFolderId(getRandomId()),
|
|
||||||
new MailboxFolderId(getRandomId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BdfDictionary getValidMailboxUpdateWithMailboxDict() {
|
private BdfDictionary getValidMailboxUpdateWithMailboxDict() {
|
||||||
BdfDictionary dict = new BdfDictionary();
|
BdfDictionary dict = new BdfDictionary();
|
||||||
dict.put(PROP_KEY_ONION, validMailboxUpdateWithMailbox.getOnion());
|
MailboxProperties properties =
|
||||||
dict.put(PROP_KEY_AUTHTOKEN, validMailboxUpdateWithMailbox
|
validMailboxUpdateWithMailbox.getMailboxProperties();
|
||||||
.getAuthToken().getBytes());
|
dict.put(PROP_KEY_ONION, properties.getOnion());
|
||||||
dict.put(PROP_KEY_INBOXID, validMailboxUpdateWithMailbox.getInboxId()
|
dict.put(PROP_KEY_AUTHTOKEN, properties.getAuthToken());
|
||||||
.getBytes());
|
dict.put(PROP_KEY_INBOXID, properties.getInboxId());
|
||||||
dict.put(PROP_KEY_OUTBOXID, validMailboxUpdateWithMailbox.getOutboxId()
|
dict.put(PROP_KEY_OUTBOXID, properties.getOutboxId());
|
||||||
.getBytes());
|
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ import okio.Buffer;
|
|||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static org.briarproject.bramble.mailbox.MailboxApi.CLIENT_SUPPORTS;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getContactId;
|
import static org.briarproject.bramble.test.TestUtils.getContactId;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getMailboxProperties;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.mailboxPropertiesEqual;
|
import static org.briarproject.bramble.test.TestUtils.mailboxPropertiesEqual;
|
||||||
@@ -102,9 +104,9 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
List<MailboxVersion> versions = singletonList(new MailboxVersion(1, 0));
|
List<MailboxVersion> versions = singletonList(new MailboxVersion(1, 0));
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
MailboxProperties properties2 =
|
MailboxProperties properties2 =
|
||||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token2, new ArrayList<>());
|
||||||
|
|
||||||
RecordedRequest request;
|
RecordedRequest request;
|
||||||
|
|
||||||
@@ -199,9 +201,9 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
MailboxProperties properties2 =
|
MailboxProperties properties2 =
|
||||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token2, new ArrayList<>());
|
||||||
|
|
||||||
// valid response with valid token
|
// valid response with valid token
|
||||||
mailboxPropertiesEqual(properties2, api.setup(properties));
|
mailboxPropertiesEqual(properties2, api.setup(properties));
|
||||||
@@ -282,7 +284,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testSetupOnlyForOwner() {
|
public void testSetupOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> api.setup(properties)
|
() -> api.setup(properties)
|
||||||
@@ -298,9 +300,9 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
MailboxProperties properties2 =
|
MailboxProperties properties2 =
|
||||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token2, new ArrayList<>());
|
||||||
|
|
||||||
assertTrue(api.checkStatus(properties));
|
assertTrue(api.checkStatus(properties));
|
||||||
RecordedRequest request1 = server.takeRequest();
|
RecordedRequest request1 = server.takeRequest();
|
||||||
@@ -321,7 +323,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testStatusOnlyForOwner() {
|
public void testStatusOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> api.checkStatus(properties)
|
() -> api.checkStatus(properties)
|
||||||
@@ -338,9 +340,9 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
MailboxProperties properties2 =
|
MailboxProperties properties2 =
|
||||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token2, new ArrayList<>());
|
||||||
|
|
||||||
api.wipeMailbox(properties);
|
api.wipeMailbox(properties);
|
||||||
RecordedRequest request1 = server.takeRequest();
|
RecordedRequest request1 = server.takeRequest();
|
||||||
@@ -370,7 +372,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testWipeOnlyForOwner() {
|
public void testWipeOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
api.wipeMailbox(properties));
|
api.wipeMailbox(properties));
|
||||||
}
|
}
|
||||||
@@ -384,7 +386,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// contact gets added as expected
|
// contact gets added as expected
|
||||||
api.addContact(properties, mailboxContact);
|
api.addContact(properties, mailboxContact);
|
||||||
@@ -416,7 +418,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testAddContactOnlyForOwner() {
|
public void testAddContactOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
api.addContact(properties, mailboxContact));
|
api.addContact(properties, mailboxContact));
|
||||||
}
|
}
|
||||||
@@ -431,7 +433,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// contact gets deleted as expected
|
// contact gets deleted as expected
|
||||||
api.deleteContact(properties, contactId);
|
api.deleteContact(properties, contactId);
|
||||||
@@ -468,7 +470,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeleteContactOnlyForOwner() {
|
public void testDeleteContactOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
api.deleteContact(properties, contactId));
|
api.deleteContact(properties, contactId));
|
||||||
}
|
}
|
||||||
@@ -495,7 +497,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// valid response with two contacts
|
// valid response with two contacts
|
||||||
assertEquals(singletonList(contactId), api.getContacts(properties));
|
assertEquals(singletonList(contactId), api.getContacts(properties));
|
||||||
@@ -560,7 +562,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetContactsOnlyForOwner() {
|
public void testGetContactsOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
() -> api.getContacts(properties)
|
() -> api.getContacts(properties)
|
||||||
@@ -580,7 +582,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// file gets uploaded as expected
|
// file gets uploaded as expected
|
||||||
api.addFile(properties, contactInboxId, file);
|
api.addFile(properties, contactInboxId, file);
|
||||||
@@ -639,7 +641,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// valid response with one file
|
// valid response with one file
|
||||||
List<MailboxFile> received1 = api.getFiles(properties, contactInboxId);
|
List<MailboxFile> received1 = api.getFiles(properties, contactInboxId);
|
||||||
@@ -735,7 +737,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// file gets downloaded as expected
|
// file gets downloaded as expected
|
||||||
api.getFile(properties, contactOutboxId, name, file1);
|
api.getFile(properties, contactOutboxId, name, file1);
|
||||||
@@ -779,7 +781,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// file gets deleted as expected
|
// file gets deleted as expected
|
||||||
api.deleteFile(properties, contactInboxId, name);
|
api.deleteFile(properties, contactInboxId, name);
|
||||||
@@ -843,7 +845,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
server.start();
|
server.start();
|
||||||
String baseUrl = getBaseUrl(server);
|
String baseUrl = getBaseUrl(server);
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
new MailboxProperties(baseUrl, token, new ArrayList<>());
|
||||||
|
|
||||||
// valid response with one folders
|
// valid response with one folders
|
||||||
assertEquals(singletonList(id1), api.getFolders(properties));
|
assertEquals(singletonList(id1), api.getFolders(properties));
|
||||||
@@ -912,7 +914,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetFoldersOnlyForOwner() {
|
public void testGetFoldersOnlyForOwner() {
|
||||||
MailboxProperties properties =
|
MailboxProperties properties =
|
||||||
new MailboxProperties("", token, false, new ArrayList<>());
|
getMailboxProperties(false, CLIENT_SUPPORTS);
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
api.getFolders(properties));
|
api.getFolders(properties));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
|||||||
|
|
||||||
if (ownerProperties != null) return;
|
if (ownerProperties != null) return;
|
||||||
MailboxProperties setupProperties = new MailboxProperties(
|
MailboxProperties setupProperties = new MailboxProperties(
|
||||||
URL_BASE, SETUP_TOKEN, true, new ArrayList<>());
|
URL_BASE, SETUP_TOKEN, new ArrayList<>());
|
||||||
ownerProperties = api.setup(setupProperties);
|
ownerProperties = api.setup(setupProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// new setup doesn't work as mailbox is stopping
|
// new setup doesn't work as mailbox is stopping
|
||||||
MailboxProperties setupProperties = new MailboxProperties(
|
MailboxProperties setupProperties = new MailboxProperties(
|
||||||
URL_BASE, SETUP_TOKEN, true, new ArrayList<>());
|
URL_BASE, SETUP_TOKEN, new ArrayList<>());
|
||||||
assertThrows(ApiException.class, () -> api.setup(setupProperties));
|
assertThrows(ApiException.class, () -> api.setup(setupProperties));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,8 +151,8 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
|||||||
ContactId contactId = new ContactId(1);
|
ContactId contactId = new ContactId(1);
|
||||||
MailboxContact contact = getMailboxContact(contactId);
|
MailboxContact contact = getMailboxContact(contactId);
|
||||||
MailboxProperties contactProperties = new MailboxProperties(
|
MailboxProperties contactProperties = new MailboxProperties(
|
||||||
ownerProperties.getBaseUrl(), contact.token, false,
|
ownerProperties.getBaseUrl(), contact.token,
|
||||||
new ArrayList<>());
|
new ArrayList<>(), contact.inboxId, contact.outboxId);
|
||||||
api.addContact(ownerProperties, contact);
|
api.addContact(ownerProperties, contact);
|
||||||
|
|
||||||
// upload a file for our contact
|
// upload a file for our contact
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private final String onion = getRandomString(56);
|
private final String onion = getRandomString(56);
|
||||||
private final byte[] onionBytes = getRandomBytes(32);
|
private final byte[] onionBytes = getRandomBytes(32);
|
||||||
private final String onionAddress = "http://" + onion + ".onion";
|
private final String baseUrl = "http://" + onion + ".onion"; // TODO
|
||||||
private final MailboxAuthToken setupToken =
|
private final MailboxAuthToken setupToken =
|
||||||
new MailboxAuthToken(getRandomId());
|
new MailboxAuthToken(getRandomId());
|
||||||
private final MailboxAuthToken ownerToken =
|
private final MailboxAuthToken ownerToken =
|
||||||
@@ -65,9 +65,9 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
private final String validPayload = getValidPayload();
|
private final String validPayload = getValidPayload();
|
||||||
private final long time = System.currentTimeMillis();
|
private final long time = System.currentTimeMillis();
|
||||||
private final MailboxProperties setupProperties = new MailboxProperties(
|
private final MailboxProperties setupProperties = new MailboxProperties(
|
||||||
onionAddress, setupToken, true, new ArrayList<>());
|
baseUrl, setupToken, new ArrayList<>());
|
||||||
private final MailboxProperties ownerProperties = new MailboxProperties(
|
private final MailboxProperties ownerProperties = new MailboxProperties(
|
||||||
onionAddress, ownerToken, true, new ArrayList<>());
|
baseUrl, ownerToken, new ArrayList<>());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitialQrCodeReceivedState() {
|
public void testInitialQrCodeReceivedState() {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString());
|
expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString());
|
||||||
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
|
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
|
||||||
serverSupportsInts);
|
serverSupportsInts);
|
||||||
MailboxProperties properties = new MailboxProperties(onion, token, true,
|
MailboxProperties properties = new MailboxProperties(onion, token,
|
||||||
serverSupports);
|
serverSupports);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ 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.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
||||||
@@ -48,6 +46,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
|||||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getMailboxProperties;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.hasEvent;
|
import static org.briarproject.bramble.test.TestUtils.hasEvent;
|
||||||
@@ -82,6 +81,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final List<MailboxVersion> someServerSupportsList;
|
private final List<MailboxVersion> someServerSupportsList;
|
||||||
private final BdfList someServerSupports;
|
private final BdfList someServerSupports;
|
||||||
private final BdfList emptyServerSupports = new BdfList();
|
private final BdfList emptyServerSupports = new BdfList();
|
||||||
|
private final MailboxProperties updateProps;
|
||||||
private final MailboxUpdateWithMailbox updateWithMailbox;
|
private final MailboxUpdateWithMailbox updateWithMailbox;
|
||||||
private final MailboxUpdate updateNoMailbox;
|
private final MailboxUpdate updateNoMailbox;
|
||||||
private final MailboxProperties ownProps;
|
private final MailboxProperties ownProps;
|
||||||
@@ -108,22 +108,16 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
updateNoMailbox = new MailboxUpdate(someClientSupportsList);
|
updateNoMailbox = new MailboxUpdate(someClientSupportsList);
|
||||||
|
|
||||||
ownProps = new MailboxProperties("http://bar.onion",
|
updateProps = getMailboxProperties(false, someServerSupportsList);
|
||||||
new MailboxAuthToken(getRandomId()), true,
|
ownProps = new MailboxProperties(updateProps.getBaseUrl(),
|
||||||
someServerSupportsList);
|
updateProps.getAuthToken(), someServerSupportsList);
|
||||||
updateWithMailbox = new MailboxUpdateWithMailbox(someClientSupportsList,
|
updateWithMailbox = new MailboxUpdateWithMailbox(someClientSupportsList,
|
||||||
someServerSupportsList, ownProps.getOnion(),
|
updateProps);
|
||||||
new MailboxAuthToken(getRandomId()),
|
|
||||||
new MailboxFolderId(getRandomId()),
|
|
||||||
new MailboxFolderId(getRandomId()));
|
|
||||||
propsDict = new BdfDictionary();
|
propsDict = new BdfDictionary();
|
||||||
propsDict.put(PROP_KEY_ONION, updateWithMailbox.getOnion());
|
propsDict.put(PROP_KEY_ONION, updateProps.getOnion());
|
||||||
propsDict.put(PROP_KEY_AUTHTOKEN, updateWithMailbox.getAuthToken()
|
propsDict.put(PROP_KEY_AUTHTOKEN, updateProps.getAuthToken());
|
||||||
.getBytes());
|
propsDict.put(PROP_KEY_INBOXID, updateProps.getInboxId());
|
||||||
propsDict.put(PROP_KEY_INBOXID, updateWithMailbox.getInboxId()
|
propsDict.put(PROP_KEY_OUTBOXID, updateProps.getOutboxId());
|
||||||
.getBytes());
|
|
||||||
propsDict.put(PROP_KEY_OUTBOXID, updateWithMailbox.getOutboxId()
|
|
||||||
.getBytes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MailboxUpdateManagerImpl createInstance(
|
private MailboxUpdateManagerImpl createInstance(
|
||||||
@@ -219,11 +213,11 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
|
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
|
||||||
will(returnValue(ownProps));
|
will(returnValue(ownProps));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getAuthToken()));
|
will(returnValue(updateProps.getAuthToken()));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getInboxId()));
|
will(returnValue(updateProps.getInboxId()));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getOutboxId()));
|
will(returnValue(updateProps.getOutboxId()));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, contact);
|
MAJOR_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
@@ -478,11 +472,11 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
|
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
|
||||||
will(returnValue(ownProps));
|
will(returnValue(ownProps));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getAuthToken()));
|
will(returnValue(updateProps.getAuthToken()));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getInboxId()));
|
will(returnValue(updateProps.getInboxId()));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getOutboxId()));
|
will(returnValue(updateProps.getOutboxId()));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, contact);
|
MAJOR_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
@@ -668,11 +662,11 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(contacts));
|
will(returnValue(contacts));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getAuthToken()));
|
will(returnValue(updateProps.getAuthToken()));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getInboxId()));
|
will(returnValue(updateProps.getInboxId()));
|
||||||
oneOf(crypto).generateUniqueId();
|
oneOf(crypto).generateUniqueId();
|
||||||
will(returnValue(updateWithMailbox.getOutboxId()));
|
will(returnValue(updateProps.getOutboxId()));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
MAJOR_VERSION, contact);
|
MAJOR_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import org.briarproject.bramble.api.data.BdfDictionary;
|
|||||||
import org.briarproject.bramble.api.data.BdfEntry;
|
import org.briarproject.bramble.api.data.BdfEntry;
|
||||||
import org.briarproject.bramble.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdateManager;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdateManager;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
|
||||||
@@ -24,8 +23,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getMailboxProperties;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class MailboxUpdateValidatorTest extends BrambleMockTestCase {
|
public class MailboxUpdateValidatorTest extends BrambleMockTestCase {
|
||||||
@@ -35,7 +34,6 @@ public class MailboxUpdateValidatorTest extends BrambleMockTestCase {
|
|||||||
private final BdfDictionary bdfDict;
|
private final BdfDictionary bdfDict;
|
||||||
private final BdfList emptyServerSupports;
|
private final BdfList emptyServerSupports;
|
||||||
private final BdfList someClientSupports;
|
private final BdfList someClientSupports;
|
||||||
private final List<MailboxVersion> someClientSupportsList;
|
|
||||||
private final BdfList someServerSupports;
|
private final BdfList someServerSupports;
|
||||||
private final MailboxUpdateWithMailbox updateMailbox;
|
private final MailboxUpdateWithMailbox updateMailbox;
|
||||||
private final MailboxUpdate updateNoMailbox;
|
private final MailboxUpdate updateNoMailbox;
|
||||||
@@ -49,17 +47,15 @@ public class MailboxUpdateValidatorTest extends BrambleMockTestCase {
|
|||||||
// {@link ClientHelper#parseAndValidateMailboxUpdate(BdfList, BdfList, BdfDictionary)}
|
// {@link ClientHelper#parseAndValidateMailboxUpdate(BdfList, BdfList, BdfDictionary)}
|
||||||
emptyServerSupports = new BdfList();
|
emptyServerSupports = new BdfList();
|
||||||
someClientSupports = BdfList.of(BdfList.of(1, 0));
|
someClientSupports = BdfList.of(BdfList.of(1, 0));
|
||||||
someClientSupportsList = singletonList(new MailboxVersion(1, 0));
|
List<MailboxVersion> someClientSupportsList =
|
||||||
|
singletonList(new MailboxVersion(1, 0));
|
||||||
someServerSupports = BdfList.of(BdfList.of(1, 0));
|
someServerSupports = BdfList.of(BdfList.of(1, 0));
|
||||||
bdfDict = BdfDictionary.of(new BdfEntry("foo", "bar"));
|
bdfDict = BdfDictionary.of(new BdfEntry("foo", "bar"));
|
||||||
|
|
||||||
|
MailboxProperties props = getMailboxProperties(false,
|
||||||
|
singletonList(new MailboxVersion(1, 0)));
|
||||||
updateMailbox = new MailboxUpdateWithMailbox(
|
updateMailbox = new MailboxUpdateWithMailbox(
|
||||||
singletonList(new MailboxVersion(1, 0)),
|
singletonList(new MailboxVersion(1, 0)), props);
|
||||||
singletonList(new MailboxVersion(1, 0)),
|
|
||||||
"baz",
|
|
||||||
new MailboxAuthToken(getRandomId()),
|
|
||||||
new MailboxFolderId(getRandomId()),
|
|
||||||
new MailboxFolderId(getRandomId()));
|
|
||||||
updateNoMailbox = new MailboxUpdate(someClientSupportsList);
|
updateNoMailbox = new MailboxUpdate(someClientSupportsList);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user