Optionally create a Tor plugin without a hidden service. Should speed up

tests.
This commit is contained in:
akwizgran
2012-05-04 17:46:29 +01:00
parent 4338bd9a8b
commit a82ae82108
2 changed files with 33 additions and 20 deletions

View File

@@ -30,20 +30,23 @@ public class TorPluginTest extends BriarTestCase {
TorPlugin serverPlugin = new TorPlugin(e, serverCallback, 0L);
serverPlugin.start();
// The plugin should create a hidden service... eventually
serverCallback.latch.await(10, TimeUnit.MINUTES);
assertTrue(serverCallback.latch.await(10, TimeUnit.MINUTES));
String onion = serverCallback.local.get("onion");
assertNotNull(onion);
assertTrue(onion.endsWith(".onion"));
// Create another plugin instance for the client
Callback clientCallback = new Callback();
clientCallback.config.put("noHiddenService", "");
TransportProperties p = new TransportProperties();
p.put("onion", onion);
clientCallback.remote.put(contactId, p);
TorPlugin clientPlugin = new TorPlugin(e, clientCallback, 0L);
clientPlugin.start();
// The plugin should start without creating a hidden service
assertTrue(clientCallback.latch.await(10, TimeUnit.MINUTES));
// Connect to the server's hidden service
DuplexTransportConnection clientEnd =
clientPlugin.createConnection(contactId);
clientPlugin.createConnection(contactId);
assertNotNull(clientEnd);
DuplexTransportConnection serverEnd = serverCallback.incomingConnection;
assertNotNull(serverEnd);
@@ -69,13 +72,14 @@ public class TorPluginTest extends BriarTestCase {
TorPlugin plugin = new TorPlugin(e, callback, 0L);
plugin.start();
// The plugin should create a hidden service... eventually
callback.latch.await(10, TimeUnit.MINUTES);
assertTrue(callback.latch.await(10, TimeUnit.MINUTES));
String onion = callback.local.get("onion");
assertNotNull(onion);
assertTrue(onion.endsWith(".onion"));
// Get the PEM-encoded private key and stop the plugin
// Get the PEM-encoded private key
String privateKey = callback.config.get("privateKey");
assertNotNull(privateKey);
// Stop the plugin
plugin.stop();
// Start another instance, reusing the private key
callback = new Callback();
@@ -83,7 +87,7 @@ public class TorPluginTest extends BriarTestCase {
plugin = new TorPlugin(e, callback, 0L);
plugin.start();
// The plugin should create a hidden service... eventually
callback.latch.await(10, TimeUnit.MINUTES);
assertTrue(callback.latch.await(10, TimeUnit.MINUTES));
// The onion URL should be the same
assertEquals(onion, callback.local.get("onion"));
// The private key should be the same
@@ -95,7 +99,7 @@ public class TorPluginTest extends BriarTestCase {
private static class Callback implements DuplexPluginCallback {
private final Map<ContactId, TransportProperties> remote =
new Hashtable<ContactId, TransportProperties>();
new Hashtable<ContactId, TransportProperties>();
private final CountDownLatch latch = new CountDownLatch(1);
private TransportConfig config = new TransportConfig();