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_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), )
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_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 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']) )
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), )