def test_loadconf(self): """ Exercises Controller.load_conf with valid and invalid requests. """ if test.runner.require_control(self): return elif test.runner.require_version(self, stem.version.Requirement.LOADCONF): return runner = test.runner.get_runner() with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: # invalid requests self.assertRaises(stem.InvalidRequest, controller.load_conf, "ContactInfo confloaded") try: controller.load_conf("Blahblah blah") self.fail() except stem.InvalidArguments as exc: self.assertEqual(["Blahblah"], exc.arguments) # valid config controller.load_conf(runner.get_torrc_contents() + "\nContactInfo confloaded\n") self.assertEqual("confloaded", controller.get_conf("ContactInfo")) finally: # reload original valid config controller.load_conf(oldconf)
def test_loadconf(self): """ Exercises Controller.load_conf with valid and invalid requests. """ if test.runner.require_control(self): return elif test.runner.require_version(self, stem.version.Requirement.LOADCONF): return runner = test.runner.get_runner() with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: # invalid requests self.assertRaises(stem.InvalidRequest, controller.load_conf, "ContactInfo confloaded") try: controller.load_conf("Blahblah blah") self.fail() except stem.InvalidArguments, exc: self.assertEqual(["Blahblah"], exc.arguments) # valid config controller.load_conf(runner.get_torrc_contents() + "\nContactInfo confloaded\n") self.assertEqual("confloaded", controller.get_conf("ContactInfo")) finally:
def test_loadconf(self): """ Exercises Controller.load_conf with valid and invalid requests. """ runner = test.runner.get_runner() with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: # Check a request that changes our DataDir. Tor should rightfully balk # at this... # # InvalidRequest: Transition not allowed: Failed to parse/validate # config: While Tor is running, changing DataDirectory # ("/home/atagar/Desktop/stem/test/data"->"/home/atagar/.tor") is not # allowed. self.assertRaises(stem.InvalidRequest, controller.load_conf, 'ContactInfo confloaded') try: controller.load_conf('Blahblah blah') self.fail() except stem.InvalidArguments as exc: self.assertEqual(['Blahblah'], exc.arguments) # valid config controller.load_conf(runner.get_torrc_contents() + '\nContactInfo confloaded\n') self.assertEqual('confloaded', controller.get_conf('ContactInfo')) finally: # reload original valid config controller.load_conf(oldconf) controller.reset_conf('__OwningControllerProcess')
def test_loadconf(self): """ Exercises Controller.load_conf with valid and invalid requests. """ if test.runner.require_control(self): return elif test.runner.require_version(self, stem.version.Requirement.LOADCONF): return runner = test.runner.get_runner() with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: # Check a request that changes our DataDir. Tor should rightfully balk # at this... # # InvalidRequest: Transition not allowed: Failed to parse/validate # config: While Tor is running, changing DataDirectory # ("/home/atagar/Desktop/stem/test/data"->"/home/atagar/.tor") is not # allowed. self.assertRaises(stem.InvalidRequest, controller.load_conf, 'ContactInfo confloaded') try: controller.load_conf('Blahblah blah') self.fail() except stem.InvalidArguments as exc: self.assertEqual(['Blahblah'], exc.arguments) # valid config controller.load_conf(runner.get_torrc_contents() + '\nContactInfo confloaded\n') self.assertEqual('confloaded', controller.get_conf('ContactInfo')) finally: # reload original valid config controller.load_conf(oldconf) controller.reset_conf('__OwningControllerProcess')
def test_getinfo_config_text(self): """ Parses the 'GETINFO config-text' response. """ if test.runner.require_control(self): return elif test.runner.require_version( self, stem.version.Requirement.GETINFO_CONFIG_TEXT): return runner = test.runner.get_runner() # We can't be certain of the order, and there may be extra config-text # entries as per... # https://trac.torproject.org/projects/tor/ticket/2362 # # so we'll just check that the response is a superset of our config torrc_contents = [] for line in runner.get_torrc_contents().splitlines(): line = line.strip() if line and not line.startswith("#"): torrc_contents.append(line) with runner.get_tor_socket() as control_socket: control_socket.send("GETINFO config-text") config_text_response = control_socket.recv() # the response should contain two entries, the first being a data response self.assertEqual(2, len(list(config_text_response))) self.assertEqual("OK", list(config_text_response)[1]) self.assertEqual(("250", " ", "OK"), config_text_response.content()[1]) self.assertTrue(config_text_response.raw_content().startswith( "250+config-text=\r\n")) self.assertTrue(config_text_response.raw_content().endswith( "\r\n.\r\n250 OK\r\n")) self.assertTrue( str(config_text_response).startswith("config-text=\n")) self.assertTrue(str(config_text_response).endswith("\nOK")) for torrc_entry in torrc_contents: self.assertTrue("\n%s\n" % torrc_entry in str(config_text_response)) self.assertTrue(torrc_entry in list(config_text_response)[0]) self.assertTrue( "%s\r\n" % torrc_entry in config_text_response.raw_content()) self.assertTrue( "%s" % torrc_entry in config_text_response.content()[0][2])
def test_loadconf(self): """ Exercises Controller.load_conf with valid and invalid requests. """ if test.runner.require_control(self): return elif test.runner.require_version(self, stem.version.Requirement.LOADCONF): return runner = test.runner.get_runner() with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: # Check a request that changes our DataDir. Tor should rightfully balk # at this... # # InvalidRequest: Transition not allowed: Failed to parse/validate # config: While Tor is running, changing DataDirectory # ("/home/atagar/Desktop/stem/test/data"->"/home/atagar/.tor") is not # allowed. self.assertRaises(stem.InvalidRequest, controller.load_conf, "ContactInfo confloaded") try: controller.load_conf("Blahblah blah") self.fail() except stem.InvalidArguments as exc: self.assertEqual(["Blahblah"], exc.arguments) # valid config controller.load_conf(runner.get_torrc_contents() + "\nContactInfo confloaded\n") self.assertEqual("confloaded", controller.get_conf("ContactInfo")) finally: # reload original valid config controller.load_conf(oldconf) controller.reset_conf("__OwningControllerProcess")
async def test_getinfo_config_text(self): """ Parses the 'GETINFO config-text' response. """ runner = test.runner.get_runner() # We can't be certain of the order, and there may be extra config-text # entries as per... # https://trac.torproject.org/projects/tor/ticket/2362 # # so we'll just check that the response is a superset of our config torrc_contents = [] for line in runner.get_torrc_contents().splitlines(): line = line.strip() if line and not line.startswith('#'): torrc_contents.append(line) async with await runner.get_tor_socket() as control_socket: await control_socket.send('GETINFO config-text') config_text_response = await control_socket.recv() # the response should contain two entries, the first being a data response self.assertEqual(2, len(list(config_text_response))) self.assertEqual('OK', list(config_text_response)[1]) self.assertEqual(('250', ' ', 'OK'), config_text_response.content()[1]) self.assertTrue(config_text_response.raw_content().startswith( '250+config-text=\r\n')) self.assertTrue(config_text_response.raw_content().endswith( '\r\n.\r\n250 OK\r\n')) self.assertTrue( str(config_text_response).startswith('config-text=\n')) self.assertTrue(str(config_text_response).endswith('\nOK')) for torrc_entry in torrc_contents: self.assertTrue('\n%s\n' % torrc_entry in str(config_text_response)) self.assertTrue(torrc_entry in list(config_text_response)[0]) self.assertTrue( '%s\r\n' % torrc_entry in config_text_response.raw_content()) self.assertTrue( '%s' % torrc_entry in config_text_response.content()[0][2])
def test_saveconf(self): if test.runner.require_control(self): return runner = test.runner.get_runner() # only testing for success, since we need to run out of disk space to test # for failure with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: controller.set_conf("ContactInfo", "confsaved") controller.save_conf() with file(runner.get_torrc_path()) as torrcfile: self.assertTrue("\nContactInfo confsaved\n" in torrcfile.read()) finally: controller.load_conf(oldconf) controller.save_conf()
def test_saveconf(self): runner = test.runner.get_runner() # only testing for success, since we need to run out of disk space to test # for failure with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: controller.set_conf('ContactInfo', 'confsaved') controller.save_conf() with open(runner.get_torrc_path()) as torrcfile: self.assertTrue('\nContactInfo confsaved\n' in torrcfile.read()) finally: controller.load_conf(oldconf) controller.save_conf() controller.reset_conf('__OwningControllerProcess')
def test_getinfo_config_text(self): """ Parses the 'GETINFO config-text' response. """ if test.runner.require_control(self): return elif test.runner.require_version(self, stem.version.Requirement.GETINFO_CONFIG_TEXT): return runner = test.runner.get_runner() # We can't be certain of the order, and there may be extra config-text # entries as per... # https://trac.torproject.org/projects/tor/ticket/2362 # # so we'll just check that the response is a superset of our config torrc_contents = [] for line in runner.get_torrc_contents().splitlines(): line = line.strip() if line and not line.startswith("#"): torrc_contents.append(line) with runner.get_tor_socket() as control_socket: control_socket.send("GETINFO config-text") config_text_response = control_socket.recv() # the response should contain two entries, the first being a data response self.assertEqual(2, len(list(config_text_response))) self.assertEqual("OK", list(config_text_response)[1]) self.assertEqual(("250", " ", "OK"), config_text_response.content()[1]) self.assertTrue(config_text_response.raw_content().startswith("250+config-text=\r\n")) self.assertTrue(config_text_response.raw_content().endswith("\r\n.\r\n250 OK\r\n")) self.assertTrue(str(config_text_response).startswith("config-text=\n")) self.assertTrue(str(config_text_response).endswith("\nOK")) for torrc_entry in torrc_contents: self.assertTrue("\n%s\n" % torrc_entry in str(config_text_response)) self.assertTrue(torrc_entry in list(config_text_response)[0]) self.assertTrue("%s\r\n" % torrc_entry in config_text_response.raw_content()) self.assertTrue("%s" % torrc_entry in config_text_response.content()[0][2])
def test_saveconf(self): if test.runner.require_control(self): return runner = test.runner.get_runner() # only testing for success, since we need to run out of disk space to test # for failure with runner.get_tor_controller() as controller: oldconf = runner.get_torrc_contents() try: controller.set_conf("ContactInfo", "confsaved") controller.save_conf() with open(runner.get_torrc_path()) as torrcfile: self.assertTrue( "\nContactInfo confsaved\n" in torrcfile.read()) finally: controller.load_conf(oldconf) controller.save_conf()
def test_getinfo_config_text(self): """ Parses the 'GETINFO config-text' response. """ runner = test.runner.get_runner() # We can't be certain of the order, and there may be extra config-text # entries as per... # https://trac.torproject.org/projects/tor/ticket/2362 # # so we'll just check that the response is a superset of our config torrc_contents = [] for line in runner.get_torrc_contents().splitlines(): line = line.strip() if line and not line.startswith('#'): torrc_contents.append(line) with runner.get_tor_socket() as control_socket: control_socket.send('GETINFO config-text') config_text_response = control_socket.recv() # the response should contain two entries, the first being a data response self.assertEqual(2, len(list(config_text_response))) self.assertEqual('OK', list(config_text_response)[1]) self.assertEqual(('250', ' ', 'OK'), config_text_response.content()[1]) self.assertTrue(config_text_response.raw_content().startswith('250+config-text=\r\n')) self.assertTrue(config_text_response.raw_content().endswith('\r\n.\r\n250 OK\r\n')) self.assertTrue(str(config_text_response).startswith('config-text=\n')) self.assertTrue(str(config_text_response).endswith('\nOK')) for torrc_entry in torrc_contents: self.assertTrue('\n%s\n' % torrc_entry in str(config_text_response)) self.assertTrue(torrc_entry in list(config_text_response)[0]) self.assertTrue('%s\r\n' % torrc_entry in config_text_response.raw_content()) self.assertTrue('%s' % torrc_entry in config_text_response.content()[0][2])