[Pkg-privacy-commits] [pyptlib] 91/136: add tests for the new API

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:14 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository pyptlib.

commit c1502aeee151e3261506b8d038d350fa5bc23a7d
Author: Ximin Luo <infinity0 at gmx.com>
Date:   Tue Aug 20 12:28:16 2013 +0100

    add tests for the new API
---
 ChangeLog                   |   2 +-
 pyptlib/test/test_client.py |  42 +++----
 pyptlib/test/test_core.py   |  96 ++++++++++++++++
 pyptlib/test/test_server.py | 264 +++++++++++++++++---------------------------
 4 files changed, 214 insertions(+), 190 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index af0e837..d72aca5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,7 +3,7 @@ Changes in version 0.0.4 - UNRELEASED
    write composed plugins such as obfs-flash, and the 2-INT termination
    behaviour specified in the PT spec.
  - Present a more object-oriented public API, and refactor internals to
-   have better separation of concerns,
+   have better separation of concerns. Add a more complete set of tests.
 
 
 Changes in version 0.0.3 - 2013-02-18
diff --git a/pyptlib/test/test_client.py b/pyptlib/test/test_client.py
index 4fa9af2..ebb6ca2 100644
--- a/pyptlib/test/test_client.py
+++ b/pyptlib/test/test_client.py
@@ -1,53 +1,41 @@
 import os
 import unittest
 
-import pyptlib
-import pyptlib.client
+from pyptlib.client import ClientTransportPlugin
+from pyptlib.config import EnvError, Config
+from pyptlib.test.test_core import PluginCoreTest
 
-class testClient(unittest.TestCase):
-    def test_legit_environment(self):
+class testClient(PluginCoreTest, unittest.TestCase):
+    pluginType = ClientTransportPlugin
+
+    def test_fromEnv_legit(self):
         """Legit environment"""
         TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
                          "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
                          "TOR_PT_CLIENT_TRANSPORTS" : "dummy" }
 
         os.environ = TEST_ENVIRON
-        pyptlib.client.init(["dummy"])
+        self.plugin._loadConfigFromEnv()
+        self.assertOutputLinesEmpty()
 
-    def test_bad_environment(self):
+    def test_fromEnv_bad(self):
         """Missing TOR_PT_MANAGED_TRANSPORT_VER."""
         TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
                          "TOR_PT_CLIENT_TRANSPORTS" : "dummy" }
 
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.client.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_2(self):
+    def test_fromEnv_bad2(self):
         """Missing TOR_PT_CLIENT_TRANSPORTS."""
         TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
                          "TOR_PT_MANAGED_TRANSPORT_VER" : "1" }
 
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.client.init, ["dummy"])
-
-    def test_unknown_transports(self):
-        """Unknown transports"""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_CLIENT_TRANSPORTS" : "are,you,a,badfish,too?" }
-
-        os.environ = TEST_ENVIRON
-        retval = pyptlib.client.init(["dummy"])
-        self.assertEqual(len(retval['transports']), 0)
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_protocol_version(self):
-        """Unsupported managed-proxy configuration protocol version."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "666",
-                         "TOR_PT_CLIENT_TRANSPORTS" : "dummy" }
-
-        os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.client.init, ["dummy"])
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/pyptlib/test/test_core.py b/pyptlib/test/test_core.py
new file mode 100644
index 0000000..ad84ae4
--- /dev/null
+++ b/pyptlib/test/test_core.py
@@ -0,0 +1,96 @@
+import os
+import unittest
+
+from cStringIO import StringIO
+
+from pyptlib.config import EnvError, Config
+
+class PluginCoreTest(object):
+    """
+    This class is not a TestCase but is meant to be mixed-into tests
+    for subclasses of TransportPlugin.
+    """
+    pluginType = None
+    origEnv = os.environ
+
+    def setUp(self):
+        if not self.pluginType:
+            raise ValueError("pluginType not defined")
+        self.plugin = self.pluginType(stdout=StringIO())
+        os.environ = self.origEnv
+
+    def getOutputLines(self):
+        fp = self.plugin.stdout
+        fp.seek(0)
+        return fp.readlines()
+
+    def installTestConfig(self, stateLocation="/pt_stat", **kwargs):
+        """
+        Install a base test config into the plugin.
+
+        If this is not called, will try to get config from environment.
+        """
+        self.plugin.config = self.pluginType.configType(
+            stateLocation, **kwargs)
+
+    def assertEmpty(self, c, msg=None):
+        """Assert that a container has length 0."""
+        self.assertEqual(len(c), 0, "not empty: %s" % (msg or c))
+
+    def assertOutputLinesEmpty(self):
+        """Assert that the output is empty."""
+        self.assertEmpty(self.getOutputLines())
+
+    def assertOutputLinesStartWith(self, *prefixes):
+        """Assert that the output lines each start with the respective prefix."""
+        lines = self.getOutputLines()
+        for p in prefixes:
+            self.assertTrue(lines.pop(0).startswith(p))
+        self.assertEmpty(lines)
+
+    def test_declareSupports_bad_protocol_version(self):
+        """Unsupported managed-proxy configuration protocol version."""
+        self.installTestConfig(managedTransportVer=["666"])
+        self.assertRaises(EnvError, self.plugin._declareSupports, [])
+        self.assertOutputLinesStartWith("VERSION-ERROR ")
+
+    def test_declareSupports_unknown_transports(self):
+        """Unknown transports"""
+        self.installTestConfig(transports="are,you,a,badfish,too?".split(","))
+        self.plugin._declareSupports(["not_any_of_above"])
+        self.assertEmpty(self.plugin.getServedTransports())
+        self.assertOutputLinesStartWith("VERSION ")
+
+    def test_declareSupports_partial(self):
+        """Partial transports"""
+        self.installTestConfig(transports="are,you,a,badfish,too?".split(","))
+        self.plugin._declareSupports(["badfish", "not_any_of_above"])
+        self.assertEquals(self.plugin.getServedTransports(), ["badfish"])
+        self.assertOutputLinesStartWith("VERSION ")
+
+    def test_getServedTransports_noinit(self):
+        """getServerTransports raises correctly."""
+        self.assertRaises(ValueError, self.plugin.getServedTransports)
+
+    def test_init_passthru_loadConfigFromEnv_error(self):
+        """init passes-through errors from loadConfigFromEnv."""
+        self.plugin.configType = DummyConfig
+        self.assertRaises(EnvError, self.plugin.init, [])
+        self.assertOutputLinesStartWith("ENV-ERROR ")
+
+    def test_init_correct_servedTransports(self):
+        """init results in correct getServerTransports."""
+        self.installTestConfig(transports=["yeayeayea"])
+        self.plugin.init(["yeayeayea"])
+        self.assertEquals(["yeayeayea"], self.plugin.getServedTransports())
+        self.assertOutputLinesStartWith("VERSION ")
+
+class DummyConfig(Config):
+
+    @classmethod
+    def fromEnv(cls, *args, **kwargs):
+        """Dummy parser that always fails."""
+        raise EnvError("test")
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/pyptlib/test/test_server.py b/pyptlib/test/test_server.py
index a73fb8c..bdeb923 100644
--- a/pyptlib/test/test_server.py
+++ b/pyptlib/test/test_server.py
@@ -1,206 +1,146 @@
 import os
 import unittest
 
-import pyptlib
-import pyptlib.server
-
-class testServer(unittest.TestCase):
-    def test_legit_environment(self):
+from pyptlib.config import EnvError, Config
+from pyptlib.server import ServerTransportPlugin
+from pyptlib.test.test_core import PluginCoreTest
+from pyptlib.core import SUPPORTED_TRANSPORT_VERSIONS
+
+# a good valid environment to base modifications from
+# so it's clearer to see exactly why an environment fails
+BASE_ENVIRON = {
+    "TOR_PT_STATE_LOCATION" : "/pt_stat",
+    "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
+    "TOR_PT_EXTENDED_SERVER_PORT" : "",
+    "TOR_PT_ORPORT" : "127.0.0.1:43210",
+    "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
+    "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom"
+}
+
+class testServer(PluginCoreTest, unittest.TestCase):
+    pluginType = ServerTransportPlugin
+
+    def test_fromEnv_legit(self):
         """Legit environment."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
-        os.environ = TEST_ENVIRON
-        pyptlib.server.init(["dummy"])
+        os.environ = BASE_ENVIRON
+        self.plugin._loadConfigFromEnv()
+        self.assertOutputLinesEmpty()
 
-    def test_bad_environment(self):
+    def test_fromEnv_bad(self):
         """Missing TOR_PT_MANAGED_TRANSPORT_VER."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON.pop("TOR_PT_MANAGED_TRANSPORT_VER")
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_2(self):
+    def test_fromEnv_bad2(self):
         """Missing TOR_PT_ORPORT."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON.pop("TOR_PT_ORPORT")
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_3(self):
+    def test_fromEnv_bad3(self):
         """Missing TOR_PT_EXTENDED_SERVER_PORT."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON.pop("TOR_PT_EXTENDED_SERVER_PORT")
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_4(self):
+    def test_fromEnv_bad4(self):
         """TOR_PT_EXTENDED_SERVER_PORT not an addport."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "cakez",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_EXTENDED_SERVER_PORT"] = "cakez"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_5(self):
+    def test_fromEnv_bad5(self):
         """TOR_PT_ORPORT not an addport."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "lulz",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_ORPORT"] = "lulz"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_6(self):
+    def test_fromEnv_bad6(self):
         """TOR_PT_SERVER_BINDADDR not an addport."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-lyrical_content,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_SERVER_BINDADDR"] = "dummy-lyrical_content,boom-127.0.0.1:6666"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_7(self):
+    def test_fromEnv_bad7(self):
         """Assymetric TOR_PT_SERVER_TRANSPORTS and TOR_PT_SERVER_BINDADDR."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,laughs-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_SERVER_BINDADDR"] = "dummy-127.0.0.1:5556,laughs-127.0.0.1:6666"
+        TEST_ENVIRON["TOR_PT_SERVER_TRANSPORTS"] = "dummy,boom"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_8(self):
+    def test_fromEnv_bad8(self):
         """Assymetric TOR_PT_SERVER_TRANSPORTS and TOR_PT_SERVER_BINDADDR."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,laughs-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_SERVER_BINDADDR"] = "dummy-127.0.0.1:5556,laughs-127.0.0.1:6666"
+        TEST_ENVIRON["TOR_PT_SERVER_TRANSPORTS"] = "dummy"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_bad_environment_9(self):
+    def test_fromEnv_bad9(self):
         """Assymetric TOR_PT_SERVER_TRANSPORTS and TOR_PT_SERVER_BINDADDR."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,laughs" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_SERVER_BINDADDR"] = "dummy-127.0.0.1:5556"
+        TEST_ENVIRON["TOR_PT_SERVER_TRANSPORTS"] = "dummy,laughs"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["dummy"])
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
+        self.assertOutputLinesStartWith("ENV-ERROR ")
 
-    def test_disabled_extorport(self):
+    def test_fromEnv_disabled_extorport(self):
         """Disabled TOR_PT_EXTENDED_SERVER_PORT."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
-
-        os.environ = TEST_ENVIRON
-        retval = pyptlib.server.init(["dummy"])
-        self.assertIsNone(retval['ext_orport'])
-
-    def test_unknown_transport(self):
-        """Application only supports unknown transport."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "dummy-127.0.0.1:5556,boom-127.0.0.1:6666",
-                         "TOR_PT_SERVER_TRANSPORTS" : "dummy,boom" }
+        os.environ = BASE_ENVIRON
+        config = self.plugin._loadConfigFromEnv()
+        self.assertIsNone(config.getExtendedORPort())
 
+    def test_fromEnv_ext_or_but_no_auth_cookie(self):
+        """TOR_PT_EXTENDED_SERVER_PORT without TOR_PT_AUTH_COOKIE_FILE."""
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_EXTENDED_SERVER_PORT"] = "127.0.0.1:5555"
         os.environ = TEST_ENVIRON
-        retval = pyptlib.server.init(["inexistent"])
-        self.assertEqual(len(retval['transports']), 0)
-
-    def test_matched_transports(self):
-        """Application only supports some transport."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "midnight-127.0.0.1:5556,herbie-127.0.0.1:6666,landing-127.0.0.1:9999",
-                         "TOR_PT_SERVER_TRANSPORTS" : "midnight,herbie,landing" }
+        self.assertRaises(EnvError, self.plugin._loadConfigFromEnv)
 
+    def test_fromEnv_auth_cookie_but_no_ext_or(self):
+        """TOR_PT_AUTH_COOKIE_FILE without TOR_PT_EXTENDED_SERVER_PORT."""
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON.pop("TOR_PT_EXTENDED_SERVER_PORT")
+        TEST_ENVIRON["TOR_PT_AUTH_COOKIE_FILE"] = "/lulzie"
         os.environ = TEST_ENVIRON
-        retval = pyptlib.server.init(["midnight","landing"])
-        self.assertIn("midnight",retval['transports'])
-        self.assertIn("landing",retval['transports'])
-        self.assertEquals(len(retval['transports']), 2)
+        self.assertRaises(EnvError, self.plugin.init, ["what"])
 
-    def test_correct_ext_orport(self):
+    def test_init_correct_ext_orport(self):
         """Correct Extended ORPort configuration."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
-                         "TOR_PT_AUTH_COOKIE_FILE" : "/lulzie",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "what-127.0.0.1:5556",
-                         "TOR_PT_SERVER_TRANSPORTS" : "what" }
-
-        os.environ = TEST_ENVIRON
-        retval = pyptlib.server.init(["what"])
-        self.assertEquals(retval['auth_cookie_file'], '/lulzie')
-        self.assertEquals(retval['ext_orport'], ('127.0.0.1', 5555))
-
-    def test_ext_or_but_no_auth_cookie(self):
-        """TOR_PT_EXTENDED_SERVER_PORT without TOR_PT_AUTH_COOKIE_FILE."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_EXTENDED_SERVER_PORT" : "127.0.0.1:5555",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "what-127.0.0.1:5556",
-                         "TOR_PT_SERVER_TRANSPORTS" : "what" }
-
+        TEST_ENVIRON = dict(BASE_ENVIRON)
+        TEST_ENVIRON["TOR_PT_EXTENDED_SERVER_PORT"] = "127.0.0.1:5555"
+        TEST_ENVIRON["TOR_PT_AUTH_COOKIE_FILE"] = "/lulzie"
         os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["what"])
-
-    def test_auth_cookie_but_no_ext_or(self):
-        """TOR_PT_AUTH_COOKIE_FILE without TOR_PT_EXTENDED_SERVER_PORT."""
-        TEST_ENVIRON = { "TOR_PT_STATE_LOCATION" : "/pt_stat",
-                         "TOR_PT_MANAGED_TRANSPORT_VER" : "1",
-                         "TOR_PT_AUTH_COOKIE_FILE" : "/lulzie",
-                         "TOR_PT_ORPORT" : "127.0.0.1:43210",
-                         "TOR_PT_SERVER_BINDADDR" : "what-127.0.0.1:5556",
-                         "TOR_PT_SERVER_TRANSPORTS" : "what" }
+        self.plugin.init([])
+        self.assertEquals(self.plugin.config.getAuthCookieFile(), '/lulzie')
+        self.assertEquals(self.plugin.config.getExtendedORPort(), ('127.0.0.1', 5555))
+        self.assertOutputLinesStartWith("VERSION ")
 
-        os.environ = TEST_ENVIRON
-        self.assertRaises(pyptlib.config.EnvError, pyptlib.server.init, ["what"])
+    def test_init_correct_transport_bindaddr(self):
+        """Correct Extended ORPort configuration."""
+        os.environ = BASE_ENVIRON
+        self.plugin.init(["dummy", "boom"])
+        bindaddr = self.plugin.getServedBindAddresses()
+        self.assertEquals(bindaddr["dummy"], ('127.0.0.1', 5556))
+        self.assertEquals(bindaddr["boom"], ('127.0.0.1', 6666))
+        self.assertOutputLinesStartWith("VERSION ")
 
 if __name__ == '__main__':
     unittest.main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git



More information about the Pkg-privacy-commits mailing list