def test_get_pid_by_name_ps_linux(self): """ Tests the get_pid_by_name function with the linux variant of ps. """ mocking.mock(system.is_bsd, mocking.return_false()) responses = dict(GET_PID_BY_NAME_BASE_RESULTS) responses["success"] = ["PID", " 1111"] responses["multiple_results"] = ["PID", " 123", " 456", " 789"] mocking.mock(system.call, mock_call(system.GET_PID_BY_NAME_PS_LINUX, responses)) for test_input in responses: expected_response = 1111 if test_input == "success" else None self.assertEquals(expected_response, system.get_pid_by_name(test_input))
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 setUp(self): test.runner.require_control(self) mocking.mock(stem.util.proc.is_available, mocking.return_false()) mocking.mock(stem.util.system.is_available, mocking.return_true())
def setUp(self): mocking.mock(stem.util.proc.is_available, mocking.return_false()) mocking.mock(stem.util.system.is_available, mocking.return_true())