Example #1
0
 def setUp(self):
     self.thedir = self.mktemp()
     os.mkdir(self.thedir)
     protocol = FakeControlProtocol([])
     self.config = TorConfig(protocol)
     self.hs = FilesystemAuthenticatedOnionService(
         config=self.config,
         thedir=self.thedir,
         ports=["80 127.0.0.1:1234"],
         auth=AuthBasic(['foo', 'bar']))
Example #2
0
    def test_create_progress_old_tor(self):
        hsdir = "/dev/null"
        ports = ["80 127.0.0.1:1234"]

        def progress(pct, tag, msg):
            pass  # print(pct, tag, msg)
        self.config.tor_protocol.version = "0.2.0.0"
        FilesystemAuthenticatedOnionService.create(
            Mock(), self.config, hsdir, ports,
            auth=AuthBasic(['alice']),
            progress=progress,
        )
Example #3
0
    def test_create_progress_old_tor(self):
        hsdir = "/dev/null"
        ports = ["80 127.0.0.1:1234"]

        def progress(pct, tag, msg):
            pass  # print(pct, tag, msg)
        self.config.tor_protocol.version = "0.2.0.0"
        FilesystemAuthenticatedOnionService.create(
            Mock(), self.config, hsdir, ports,
            auth=AuthBasic(['alice']),
            progress=progress,
        )
Example #4
0
    def test_get_client_expected_not_found(self):
        self.hs = FilesystemAuthenticatedOnionService(
            self.config, self.thedir, ["80 127.0.0.1:1234"],
            auth=AuthBasic(["foo", "bar", "baz"]),
        )
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )

        with self.assertRaises(RuntimeError) as ctx:
            self.hs.get_client("baz")
        self.assertIn(
            "Didn't find expected client",
            str(ctx.exception),
        )
Example #5
0
 def test_bad_client_name(self):
     with self.assertRaises(ValueError) as ctx:
         FilesystemAuthenticatedOnionService(
             self.config, self.thedir, ["80 127.0.0.1:1234"],
             auth=AuthBasic(["bob can't have spaces"]),
         )
     self.assertIn(
         "can't have spaces",
         str(ctx.exception),
     )
Example #6
0
 def test_unknown_auth_type(self):
     with self.assertRaises(ValueError) as ctx:
         FilesystemAuthenticatedOnionService(
             self.config, self.thedir, ["80 127.0.0.1:1234"],
             auth=object(),
         )
     self.assertIn(
         "must be one of AuthBasic or AuthStealth",
         str(ctx.exception),
     )
Example #7
0
 def setUp(self):
     self.thedir = self.mktemp()
     os.mkdir(self.thedir)
     protocol = FakeControlProtocol([])
     self.config = TorConfig(protocol)
     self.hs = FilesystemAuthenticatedOnionService(
         config=self.config,
         thedir=self.thedir,
         ports=["80 127.0.0.1:1234"],
         auth=AuthBasic(['foo', 'bar'])
     )
Example #8
0
    def test_get_client_expected_not_found(self):
        self.hs = FilesystemAuthenticatedOnionService(
            self.config, self.thedir, ["80 127.0.0.1:1234"],
            auth=AuthBasic(["foo", "bar", "baz"]),
        )
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )

        with self.assertRaises(RuntimeError) as ctx:
            self.hs.get_client("baz")
        self.assertIn(
            "Didn't find expected client",
            str(ctx.exception),
        )
Example #9
0
class AuthenticatedFilesystemHiddenServiceTest(unittest.TestCase):

    def setUp(self):
        self.thedir = self.mktemp()
        os.mkdir(self.thedir)
        protocol = FakeControlProtocol([])
        self.config = TorConfig(protocol)
        self.hs = FilesystemAuthenticatedOnionService(
            config=self.config,
            thedir=self.thedir,
            ports=["80 127.0.0.1:1234"],
            auth=AuthBasic(['foo', 'bar'])
        )

    def test_create_progress_old_tor(self):
        hsdir = "/dev/null"
        ports = ["80 127.0.0.1:1234"]

        def progress(pct, tag, msg):
            pass  # print(pct, tag, msg)
        self.config.tor_protocol.version = "0.2.0.0"
        FilesystemAuthenticatedOnionService.create(
            Mock(), self.config, hsdir, ports,
            auth=AuthBasic(['alice']),
            progress=progress,
        )

    def test_unknown_auth_type(self):
        with self.assertRaises(ValueError) as ctx:
            FilesystemAuthenticatedOnionService(
                self.config, self.thedir, ["80 127.0.0.1:1234"],
                auth=object(),
            )
        self.assertIn(
            "must be one of AuthBasic or AuthStealth",
            str(ctx.exception),
        )

    def test_bad_client_name(self):
        with self.assertRaises(ValueError) as ctx:
            FilesystemAuthenticatedOnionService(
                self.config, self.thedir, ["80 127.0.0.1:1234"],
                auth=AuthBasic(["bob can't have spaces"]),
            )
        self.assertIn(
            "can't have spaces",
            str(ctx.exception),
        )

    def test_get_client_missing(self):
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )
        with self.assertRaises(KeyError) as ctx:
            self.hs.get_client("quux")
        self.assertIn(
            "No such client",
            str(ctx.exception),
        )

    def test_get_client(self):
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )

        client = self.hs.get_client("foo")
        with self.assertRaises(KeyError):
            client.private_key
        client.group_readable

    def test_get_client_private_key_error(self):
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )
        with open(join(self.thedir, "client_keys"), "w") as f:
            f.write("foo blargly baz baz\n")

        client = self.hs.get_client("foo")
        with self.assertRaises(RuntimeError) as ctx:
            client.private_key
        self.assertIn(
            "Parse error at",
            str(ctx.exception),
        )

    def test_get_client_expected_not_found(self):
        self.hs = FilesystemAuthenticatedOnionService(
            self.config, self.thedir, ["80 127.0.0.1:1234"],
            auth=AuthBasic(["foo", "bar", "baz"]),
        )
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )

        with self.assertRaises(RuntimeError) as ctx:
            self.hs.get_client("baz")
        self.assertIn(
            "Didn't find expected client",
            str(ctx.exception),
        )
Example #10
0
class AuthenticatedFilesystemHiddenServiceTest(unittest.TestCase):

    def setUp(self):
        self.thedir = self.mktemp()
        os.mkdir(self.thedir)
        protocol = FakeControlProtocol([])
        self.config = TorConfig(protocol)
        self.hs = FilesystemAuthenticatedOnionService(
            config=self.config,
            thedir=self.thedir,
            ports=["80 127.0.0.1:1234"],
            auth=AuthBasic(['foo', 'bar'])
        )

    def test_create_progress_old_tor(self):
        hsdir = "/dev/null"
        ports = ["80 127.0.0.1:1234"]

        def progress(pct, tag, msg):
            pass  # print(pct, tag, msg)
        self.config.tor_protocol.version = "0.2.0.0"
        FilesystemAuthenticatedOnionService.create(
            Mock(), self.config, hsdir, ports,
            auth=AuthBasic(['alice']),
            progress=progress,
        )

    def test_unknown_auth_type(self):
        with self.assertRaises(ValueError) as ctx:
            FilesystemAuthenticatedOnionService(
                self.config, self.thedir, ["80 127.0.0.1:1234"],
                auth=object(),
            )
        self.assertIn(
            "must be one of AuthBasic or AuthStealth",
            str(ctx.exception),
        )

    def test_bad_client_name(self):
        with self.assertRaises(ValueError) as ctx:
            FilesystemAuthenticatedOnionService(
                self.config, self.thedir, ["80 127.0.0.1:1234"],
                auth=AuthBasic(["bob can't have spaces"]),
            )
        self.assertIn(
            "can't have spaces",
            str(ctx.exception),
        )

    def test_get_client_missing(self):
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )
        with self.assertRaises(KeyError) as ctx:
            self.hs.get_client("quux")
        self.assertIn(
            "No such client",
            str(ctx.exception),
        )

    def test_get_client(self):
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )

        client = self.hs.get_client("foo")
        with self.assertRaises(KeyError):
            client.private_key
        client.group_readable

    def test_get_client_private_key_error(self):
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )
        with open(join(self.thedir, "client_keys"), "w") as f:
            f.write("foo blargly baz baz\n")

        client = self.hs.get_client("foo")
        with self.assertRaises(RuntimeError) as ctx:
            client.private_key
        self.assertIn(
            "Parse error at",
            str(ctx.exception),
        )

    def test_get_client_expected_not_found(self):
        self.hs = FilesystemAuthenticatedOnionService(
            self.config, self.thedir, ["80 127.0.0.1:1234"],
            auth=AuthBasic(["foo", "bar", "baz"]),
        )
        with open(join(self.thedir, "hostname"), "w") as f:
            f.write(
                "foo.onion fooauthtoken # client: foo\n"
                "bar.onion barauthtoken # client: bar\n"
            )

        with self.assertRaises(RuntimeError) as ctx:
            self.hs.get_client("baz")
        self.assertIn(
            "Didn't find expected client",
            str(ctx.exception),
        )