mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
2 Commits
sqlite-jdb
...
2343-mailb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdcacde915 | ||
|
|
e74021f571 |
@@ -1,8 +1,6 @@
|
|||||||
package org.briarproject.bramble.mailbox;
|
package org.briarproject.bramble.mailbox;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.WeakSingletonProvider;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.mailbox.InvalidMailboxIdException;
|
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxFileId;
|
import org.briarproject.bramble.api.mailbox.MailboxFileId;
|
||||||
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
||||||
@@ -13,7 +11,6 @@ import org.briarproject.bramble.mailbox.MailboxApi.MailboxFile;
|
|||||||
import org.briarproject.bramble.mailbox.MailboxApi.TolerableFailureException;
|
import org.briarproject.bramble.mailbox.MailboxApi.TolerableFailureException;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -25,14 +22,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.net.SocketFactory;
|
|
||||||
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static org.briarproject.bramble.mailbox.MailboxIntegrationTestUtils.SETUP_TOKEN;
|
||||||
|
import static org.briarproject.bramble.mailbox.MailboxIntegrationTestUtils.URL_BASE;
|
||||||
|
import static org.briarproject.bramble.mailbox.MailboxIntegrationTestUtils.createMailboxApi;
|
||||||
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.isOptionalTestEnabled;
|
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
||||||
@@ -40,58 +34,31 @@ import static org.briarproject.bramble.test.TestUtils.readBytes;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.writeBytes;
|
import static org.briarproject.bramble.test.TestUtils.writeBytes;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
public class MailboxIntegrationTest extends BrambleTestCase {
|
public class MailboxApiIntegrationTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder folder = new TemporaryFolder();
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
private static final String URL_BASE = "http://127.0.0.1:8000";
|
private static final MailboxApi api = createMailboxApi();
|
||||||
private static final MailboxAuthToken SETUP_TOKEN;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
SETUP_TOKEN = MailboxAuthToken.fromString(
|
|
||||||
"54686973206973206120736574757020746f6b656e20666f722042726961722e");
|
|
||||||
} catch (InvalidMailboxIdException e) {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final OkHttpClient client = new OkHttpClient.Builder()
|
|
||||||
.socketFactory(SocketFactory.getDefault())
|
|
||||||
.connectTimeout(60_000, MILLISECONDS)
|
|
||||||
.build();
|
|
||||||
private static final WeakSingletonProvider<OkHttpClient>
|
|
||||||
httpClientProvider =
|
|
||||||
new WeakSingletonProvider<OkHttpClient>() {
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public OkHttpClient createInstance() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// We aren't using a real onion address, so use the given address verbatim
|
|
||||||
private static final UrlConverter urlConverter = onion -> onion;
|
|
||||||
private static final MailboxApiImpl api =
|
|
||||||
new MailboxApiImpl(httpClientProvider, urlConverter);
|
|
||||||
// needs to be static to keep values across different tests
|
// needs to be static to keep values across different tests
|
||||||
private static MailboxProperties ownerProperties;
|
private static MailboxProperties ownerProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before each test to make sure the mailbox is setup once
|
* Called before each test to make sure the mailbox is setup once
|
||||||
* before starting with individual tests.
|
* before starting with individual tests.
|
||||||
* {@link BeforeClass} needs to be static, so we can't use the API class.
|
|
||||||
*/
|
*/
|
||||||
@Before
|
@BeforeClass
|
||||||
public void ensureSetup() throws IOException, ApiException {
|
public static void setUp() throws IOException, ApiException {
|
||||||
// Skip this test unless it's explicitly enabled in the environment
|
// Skip this test unless it's explicitly enabled in the environment
|
||||||
assumeTrue(isOptionalTestEnabled(MailboxIntegrationTest.class));
|
assumeTrue(isOptionalTestEnabled(MailboxApiIntegrationTest.class));
|
||||||
|
|
||||||
if (ownerProperties != null) return;
|
assertNull(ownerProperties);
|
||||||
MailboxProperties setupProperties = new MailboxProperties(
|
MailboxProperties setupProperties = new MailboxProperties(
|
||||||
URL_BASE, SETUP_TOKEN, new ArrayList<>());
|
URL_BASE, SETUP_TOKEN, new ArrayList<>());
|
||||||
ownerProperties = api.setup(setupProperties);
|
ownerProperties = api.setup(setupProperties);
|
||||||
@@ -100,7 +67,7 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
|||||||
@AfterClass
|
@AfterClass
|
||||||
// we can't test wiping as a regular test as it stops the mailbox
|
// we can't test wiping as a regular test as it stops the mailbox
|
||||||
public static void wipe() throws IOException, ApiException {
|
public static void wipe() throws IOException, ApiException {
|
||||||
if (!isOptionalTestEnabled(MailboxIntegrationTest.class)) return;
|
if (!isOptionalTestEnabled(MailboxApiIntegrationTest.class)) return;
|
||||||
|
|
||||||
api.wipeMailbox(ownerProperties);
|
api.wipeMailbox(ownerProperties);
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.briarproject.bramble.mailbox;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.BrambleCoreModule;
|
||||||
|
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
|
||||||
|
import org.briarproject.bramble.test.BrambleIntegrationTestComponent;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Component(modules = {
|
||||||
|
BrambleCoreIntegrationTestModule.class,
|
||||||
|
BrambleCoreModule.class
|
||||||
|
})
|
||||||
|
interface MailboxIntegrationTestComponent extends
|
||||||
|
BrambleIntegrationTestComponent {
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package org.briarproject.bramble.mailbox;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
||||||
|
import org.briarproject.bramble.api.WeakSingletonProvider;
|
||||||
|
import org.briarproject.bramble.api.mailbox.InvalidMailboxIdException;
|
||||||
|
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||||
|
import org.briarproject.bramble.io.IoModule;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
|
class MailboxIntegrationTestUtils {
|
||||||
|
|
||||||
|
static final String URL_BASE = "http://127.0.0.1:8000";
|
||||||
|
static final MailboxAuthToken SETUP_TOKEN;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
SETUP_TOKEN = MailboxAuthToken.fromString(
|
||||||
|
"54686973206973206120736574757020746f6b656e20666f722042726961722e");
|
||||||
|
} catch (InvalidMailboxIdException e) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static WeakSingletonProvider<OkHttpClient> createHttpClientProvider() {
|
||||||
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
|
.socketFactory(SocketFactory.getDefault())
|
||||||
|
.connectTimeout(60_000, MILLISECONDS)
|
||||||
|
.build();
|
||||||
|
return new WeakSingletonProvider<OkHttpClient>() {
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
public OkHttpClient createInstance() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static MailboxApi createMailboxApi() {
|
||||||
|
return new MailboxApiImpl(createHttpClientProvider(), onion -> onion);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MailboxIntegrationTestComponent createTestComponent() {
|
||||||
|
MailboxIntegrationTestComponent component =
|
||||||
|
DaggerMailboxIntegrationTestComponent
|
||||||
|
.builder()
|
||||||
|
.ioModule(new TestIoModule())
|
||||||
|
.mailboxModule(new TestMailboxModule())
|
||||||
|
.build();
|
||||||
|
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(component);
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Module
|
||||||
|
static class TestIoModule extends IoModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
WeakSingletonProvider<OkHttpClient> provideOkHttpClientProvider() {
|
||||||
|
return createHttpClientProvider();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Module
|
||||||
|
static class TestMailboxModule extends MailboxModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
UrlConverter provideUrlConverter() {
|
||||||
|
return onion -> onion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.mailbox;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.mailbox.MailboxIntegrationTestUtils.createTestComponent;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class OwnMailboxContactListWorkerIntegrationTest
|
||||||
|
extends BrambleTestCase {
|
||||||
|
|
||||||
|
private MailboxIntegrationTestComponent component;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
component = createTestComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just test that we can build the component. TODO: Write actual tests
|
||||||
|
@Test
|
||||||
|
public void testBuild() {
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user