[tor-commits] [stem/master] Test 'tor --list-fingerprint' and 'tor --list-torrc-options'

atagar at torproject.org atagar at torproject.org
Mon Feb 9 04:30:53 UTC 2015


commit 776faae5cba979e031f4e2df7586f63a083f6761
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Feb 8 11:08:32 2015 -0800

    Test 'tor --list-fingerprint' and 'tor --list-torrc-options'
---
 test/integ/process.py |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/test/integ/process.py b/test/integ/process.py
index 65f4a7a..b9b168a 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -4,6 +4,7 @@ Tests the stem.process functions with various use cases.
 
 import binascii
 import hashlib
+import os
 import re
 import shutil
 import subprocess
@@ -15,6 +16,7 @@ import stem.prereq
 import stem.process
 import stem.socket
 import stem.util.system
+import stem.util.tor_tools
 import stem.version
 import test.runner
 
@@ -24,6 +26,14 @@ try:
 except ImportError:
   from mock import patch
 
+BASIC_RELAY_TORRC = """\
+ORPort 6000
+Nickname stemIntegTest
+ExitPolicy reject *:*
+PublishServerDescriptor 0  # don't actually publish to the dirauths
+DataDirectory %s
+"""
+
 
 class TestProcess(unittest.TestCase):
   def setUp(self):
@@ -134,6 +144,44 @@ class TestProcess(unittest.TestCase):
 
     self.run_tor('--verify-config', '-f', __file__, expect_failure = True)
 
+  def test_list_fingerprint_argument(self):
+    """
+    Exercise our 'tor --list-fingerprint' argument.
+    """
+
+    # This command should only work with a relay (which our test instance isn't).
+
+    output = self.run_tor('--list-fingerprint', with_torrc = True, expect_failure = True)
+    self.assertTrue("Clients don't have long-term identity keys. Exiting." in output)
+
+    torrc_path = os.path.join(self.data_directory, 'torrc')
+
+    with open(torrc_path, 'w') as torrc_file:
+      torrc_file.write(BASIC_RELAY_TORRC % self.data_directory)
+
+    output = self.run_tor('--list-fingerprint', '-f', torrc_path)
+    nickname, fingerprint_with_spaces = output.splitlines()[-1].split(' ', 1)
+    fingerprint = fingerprint_with_spaces.replace(' ', '')
+
+    self.assertEqual('stemIntegTest', nickname)
+    self.assertEqual(49, len(fingerprint_with_spaces))
+    self.assertTrue(stem.util.tor_tools.is_valid_fingerprint(fingerprint))
+
+    with open(os.path.join(self.data_directory, 'fingerprint')) as fingerprint_file:
+      expected = 'stemIntegTest %s\n' % fingerprint
+      self.assertEqual(expected, fingerprint_file.read())
+
+  def test_list_torrc_options_argument(self):
+    """
+    Exercise our 'tor --list-torrc-options' argument.
+    """
+
+    output = self.run_tor('--list-torrc-options')
+    self.assertTrue(len(output.splitlines()) > 50)
+    self.assertTrue(output.splitlines()[0] <= 'AccountingMax')
+    self.assertTrue('UseBridges' in output)
+    self.assertTrue('SocksPort' in output)
+
   def test_launch_tor_with_config(self):
     """
     Exercises launch_tor_with_config.





More information about the tor-commits mailing list