Example #1
0
    def test_parse_user_path(self):
        # this makes sure we expand users and symlinks in
        # hiddenServiceDir args. see Issue #77

        # make sure we have a valid thing from get_global_tor without
        # actually launching tor
        config = TorConfig()
        config.post_bootstrap = defer.succeed(config)
        from txtorcon import torconfig
        torconfig._global_tor_config = None
        get_global_tor(
            self.reactor,
            _tor_launcher=lambda react, config, prog: defer.succeed(config)
        )
        ep = serverFromString(
            self.reactor,
            'onion:88:localPort=1234:hiddenServiceDir=~/blam/blarg'
        )
        # would be nice to have a fixed path here, but then would have
        # to run as a known user :/
        # maybe using the docker stuff to run integration tests better here?
        self.assertEqual(
            os.path.expanduser('~/blam/blarg'),
            ep.hidden_service_dir
        )
Example #2
0
    def test_parse_relative_path(self):
        # this makes sure we convert a relative path to absolute
        # hiddenServiceDir args. see Issue #77

        # make sure we have a valid thing from get_global_tor without
        # actually launching tor
        config = TorConfig()
        config.post_bootstrap = defer.succeed(config)
        from txtorcon import torconfig
        torconfig._global_tor_config = None
        get_global_tor(
            self.reactor,
            _tor_launcher=lambda react, config, prog: defer.succeed(config)
        )

        orig = os.path.realpath('.')
        try:
            with util.TempDir() as t:
                t = str(t)
                os.chdir(t)
                os.mkdir(os.path.join(t, 'foo'))
                hsdir = os.path.join(t, 'foo', 'blam')
                os.mkdir(hsdir)

                ep = serverFromString(
                    self.reactor,
                    'onion:88:localPort=1234:hiddenServiceDir=foo/blam'
                )
                self.assertEqual(
                    os.path.realpath(hsdir),
                    ep.hidden_service_dir
                )

        finally:
            os.chdir(orig)
Example #3
0
    def test_parse_relative_path(self):
        # this makes sure we convert a relative path to absolute
        # hiddenServiceDir args. see Issue #77

        # make sure we have a valid thing from get_global_tor without
        # actually launching tor
        config = TorConfig()
        config.post_bootstrap = defer.succeed(config)
        from txtorcon import torconfig
        torconfig._global_tor_config = None
        get_global_tor(
            self.reactor,
            _tor_launcher=lambda react, config, prog: defer.succeed(config))

        orig = os.path.realpath('.')
        try:
            with util.TempDir() as t:
                t = str(t)
                os.chdir(t)
                os.mkdir(os.path.join(t, 'foo'))
                hsdir = os.path.join(t, 'foo', 'blam')
                os.mkdir(hsdir)

                ep = serverFromString(
                    self.reactor,
                    'onion:88:localPort=1234:hiddenServiceDir=foo/blam')
                self.assertEqual(os.path.realpath(hsdir),
                                 ep.hidden_service_dir)

        finally:
            os.chdir(orig)
Example #4
0
    def test_parse_user_path(self, ftb):
        # this makes sure we expand users and symlinks in
        # hiddenServiceDir args. see Issue #77

        # make sure we have a valid thing from get_global_tor without
        # actually launching tor
        config = TorConfig()
        config.post_bootstrap = defer.succeed(config)
        from txtorcon import torconfig
        torconfig._global_tor_config = None
        get_global_tor(
            self.reactor,
            _tor_launcher=lambda react, config, prog: defer.succeed(config)
        )
        ep = serverFromString(
            self.reactor,
            'onion:88:localPort=1234:hiddenServiceDir=~/blam/blarg'
        )
        # would be nice to have a fixed path here, but then would have
        # to run as a known user :/
        # maybe using the docker stuff to run integration tests better here?
        self.assertEqual(
            os.path.expanduser('~/blam/blarg'),
            ep.hidden_service_dir
        )
Example #5
0
 def test_global_tor_error(self):
     config0 = yield get_global_tor(Mock(), _tor_launcher=lambda x, y, z: True)
     # now if we specify a control_port it should be an error since
     # the above should have launched one.
     try:
         config1 = yield get_global_tor(Mock(), control_port=111, _tor_launcher=lambda x, y, z: True)
         self.fail()
     except RuntimeError as e:
         # should be an error
         pass
Example #6
0
 def test_parse_via_plugin(self):
     # make sure we have a valid thing from get_global_tor without actually launching tor
     config = TorConfig()
     config.post_bootstrap = defer.succeed(config)
     from txtorcon import torconfig
     torconfig._global_tor_config = None
     get_global_tor(self.reactor,
                    _tor_launcher=lambda react, config, prog: defer.succeed(config))
     ep = serverFromString(self.reactor, 'onion:88:localPort=1234:hiddenServiceDir=/foo/bar')
     self.assertEqual(ep.public_port, 88)
     self.assertEqual(ep.local_port, 1234)
     self.assertEqual(ep.hidden_service_dir, '/foo/bar')
Example #7
0
 def test_global_tor_error(self):
     config0 = yield get_global_tor(Mock(),
                                    _tor_launcher=lambda x, y, z: True)
     # now if we specify a control_port it should be an error since
     # the above should have launched one.
     try:
         config1 = yield get_global_tor(Mock(),
                                        control_port=111,
                                        _tor_launcher=lambda x, y, z: True)
         self.fail()
     except RuntimeError as e:
         # should be an error
         pass
Example #8
0
 def test_parse_via_plugin(self):
     # make sure we have a valid thing from get_global_tor without actually launching tor
     config = TorConfig()
     config.post_bootstrap = defer.succeed(config)
     from txtorcon import torconfig
     torconfig._global_tor_config = None
     get_global_tor(
         self.reactor,
         _tor_launcher=lambda react, config, prog: defer.succeed(config))
     ep = serverFromString(
         self.reactor, 'onion:88:localPort=1234:hiddenServiceDir=/foo/bar')
     self.assertEqual(ep.public_port, 88)
     self.assertEqual(ep.local_port, 1234)
     self.assertEqual(ep.hidden_service_dir, '/foo/bar')
Example #9
0
 def test_global_tor(self):
     config = yield get_global_tor(
         Mock(),
         _tor_launcher=lambda x, y, z: True
     )
     self.assertEqual(0, config.SOCKSPort)
Example #10
0
 def test_global_tor(self):
     config = yield get_global_tor(Mock(),
                                   _tor_launcher=lambda x, y, z: True)
     self.assertEqual(0, config.SOCKSPort)