def test_relative_cookie(self): """ Checks an authentication cookie with a relative path where expansion both succeeds and fails. """ # TODO: move into stem.connection unit tests? # we need to mock both pid and cwd lookups since the general cookie # expanion works by... # - resolving the pid of the "tor" process # - using that to get tor's cwd def call_mocking(command): if command == stem.util.system.GET_PID_BY_NAME_PGREP % "tor": return ["10"] elif command == stem.util.system.GET_CWD_PWDX % 10: return ["10: /tmp/foo"] mocking.mock(stem.util.proc.is_available, mocking.return_false()) mocking.mock(stem.util.system.is_available, mocking.return_true()) mocking.mock(stem.util.system.call, call_mocking) control_message = mocking.get_message(RELATIVE_COOKIE_PATH) stem.response.convert("PROTOCOLINFO", control_message) stem.connection._expand_cookie_path(control_message, stem.util.system.get_pid_by_name, "tor") self.assertEquals( os.path.join("/tmp/foo", "tor-browser_en-US", "Data", "control_auth_cookie"), control_message.cookie_path) # exercise cookie expansion where both calls fail (should work, just # leaving the path unexpanded) mocking.mock(stem.util.system.call, mocking.return_none()) control_message = mocking.get_message(RELATIVE_COOKIE_PATH) stem.response.convert("PROTOCOLINFO", control_message) self.assertEquals("./tor-browser_en-US/Data/control_auth_cookie", control_message.cookie_path) # reset system call mocking mocking.revert_mocking()
def test_relative_cookie(self): """ Checks an authentication cookie with a relative path where expansion both succeeds and fails. """ # TODO: move into stem.connection unit tests? # we need to mock both pid and cwd lookups since the general cookie # expanion works by... # - resolving the pid of the "tor" process # - using that to get tor's cwd def call_mocking(command): if command == stem.util.system.GET_PID_BY_NAME_PGREP % "tor": return ["10"] elif command == stem.util.system.GET_CWD_PWDX % 10: return ["10: /tmp/foo"] mocking.mock(stem.util.proc.is_available, mocking.return_false()) mocking.mock(stem.util.system.is_available, mocking.return_true()) mocking.mock(stem.util.system.call, call_mocking) control_message = mocking.get_message(RELATIVE_COOKIE_PATH) stem.response.convert("PROTOCOLINFO", control_message) stem.connection._expand_cookie_path(control_message, stem.util.system.get_pid_by_name, "tor") self.assertEquals(os.path.join("/tmp/foo", "tor-browser_en-US", "Data", "control_auth_cookie"), control_message.cookie_path) # exercise cookie expansion where both calls fail (should work, just # leaving the path unexpanded) mocking.mock(stem.util.system.call, mocking.return_none()) control_message = mocking.get_message(RELATIVE_COOKIE_PATH) stem.response.convert("PROTOCOLINFO", control_message) self.assertEquals("./tor-browser_en-US/Data/control_auth_cookie", control_message.cookie_path) # reset system call mocking mocking.revert_mocking()
def tearDown(self): revert_mocking()
def tearDown(self): mocking.revert_mocking()
def tearDown(self): mocking.revert_mocking() shutil.rmtree(self.data_directory)
def setUp(self): socket = stem.socket.ControlSocket() mocking.mock_method(Controller, "add_event_listener", mocking.no_op()) self.controller = Controller(socket) mocking.revert_mocking()
def tearDown(self): mocking.revert_mocking() sys.stdout = self.stdout_real
def setUp(self): socket = stem.socket.ControlSocket() mocking.mock_method(Controller, "add_event_listener", mocking.no_op()) self.controller = Controller(socket, enable_caching = True) mocking.revert_mocking()