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