예제 #1
0
파일: process.py 프로젝트: patrickod/stem
  def test_list_fingerprint_argument(tor_cmd):
    """
    Exercise our 'tor --list-fingerprint' argument.
    """

    # This command should only work with a relay (which our test instance isn't).

    output = run_tor(tor_cmd, '--list-fingerprint', with_torrc = True, expect_failure = True)
    assert_in("Clients don't have long-term identity keys. Exiting.", output, 'Should fail to start due to lacking an ORPort')

    with tmp_directory() as data_directory:
      torrc_path = os.path.join(data_directory, 'torrc')

      with open(torrc_path, 'w') as torrc_file:
        torrc_file.write(BASIC_RELAY_TORRC % data_directory + '\nORPort 6954')

      output = run_tor(tor_cmd, '--list-fingerprint', '-f', torrc_path)
      nickname, fingerprint_with_spaces = output.splitlines()[-1].split(' ', 1)
      fingerprint = fingerprint_with_spaces.replace(' ', '')

      assert_equal('stemIntegTest', nickname)
      assert_equal(49, len(fingerprint_with_spaces))

      if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
        raise AssertionError('We should have a valid fingerprint: %s' % fingerprint)

      with open(os.path.join(data_directory, 'fingerprint')) as fingerprint_file:
        expected = 'stemIntegTest %s\n' % fingerprint
        assert_equal(expected, fingerprint_file.read())
예제 #2
0
파일: process.py 프로젝트: zmchu/stem
  def test_list_fingerprint_argument(tor_cmd):
    """
    Exercise our 'tor --list-fingerprint' argument.
    """

    # This command should only work with a relay (which our test instance isn't).

    output = run_tor(tor_cmd, '--list-fingerprint', with_torrc = True, expect_failure = True)
    assert_in("Clients don't have long-term identity keys. Exiting.", output, 'Should fail to start due to lacking an ORPort')

    with tempfile.TemporaryDirectory() as data_directory:
      torrc_path = os.path.join(data_directory, 'torrc')

      with open(torrc_path, 'w') as torrc_file:
        torrc_file.write(BASIC_RELAY_TORRC % data_directory + '\nORPort 6954')

      output = run_tor(tor_cmd, '--list-fingerprint', '-f', torrc_path)
      nickname, fingerprint_with_spaces = output.splitlines()[-1].split(' ', 1)
      fingerprint = fingerprint_with_spaces.replace(' ', '')

      assert_equal('stemIntegTest', nickname)
      assert_equal(49, len(fingerprint_with_spaces))

      if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
        raise AssertionError('We should have a valid fingerprint: %s' % fingerprint)

      with open(os.path.join(data_directory, 'fingerprint')) as fingerprint_file:
        expected = 'stemIntegTest %s\n' % fingerprint
        assert_equal(expected, fingerprint_file.read())
예제 #3
0
파일: process.py 프로젝트: patrickod/stem
  def test_validate_config_argument(tor_cmd):
    """
    Exercises our 'tor --validate-config' argument.
    """

    valid_output = run_tor(tor_cmd, '--verify-config', with_torrc = True)
    assert_in('Configuration was valid\n', valid_output, 'Expected configuration to be valid')
    run_tor(tor_cmd, '--verify-config', '-f', __file__, expect_failure = True)
예제 #4
0
파일: process.py 프로젝트: patrickod/stem
  def test_hash_password_requires_argument(tor_cmd):
    """
    Check that 'tor --hash-password' balks if not provided with something to
    hash.
    """

    output = run_tor(tor_cmd, '--hash-password', expect_failure = True)
    assert_in("[warn] Command-line option '--hash-password' with no value. Failing.", output)
예제 #5
0
파일: process.py 프로젝트: zmchu/stem
  def test_validate_config_argument(tor_cmd):
    """
    Exercises our 'tor --validate-config' argument.
    """

    valid_output = run_tor(tor_cmd, '--verify-config', with_torrc = True)
    assert_in('Configuration was valid\n', valid_output, 'Expected configuration to be valid')
    run_tor(tor_cmd, '--verify-config', '-f', __file__, expect_failure = True)
예제 #6
0
파일: process.py 프로젝트: zmchu/stem
  def test_hash_password_requires_argument(tor_cmd):
    """
    Check that 'tor --hash-password' balks if not provided with something to
    hash.
    """

    output = run_tor(tor_cmd, '--hash-password', expect_failure = True)
    assert_in("[warn] Command-line option '--hash-password' with no value. Failing.", output)
예제 #7
0
파일: process.py 프로젝트: patrickod/stem
  def test_with_missing_torrc(tor_cmd):
    """
    Provide a torrc path that doesn't exist.
    """

    output = run_tor(tor_cmd, '-f', '/path/that/really/shouldnt/exist', '--verify-config', expect_failure = True)
    assert_in('[warn] Unable to open configuration file "/path/that/really/shouldnt/exist".', output, 'Tor should refuse to read a non-existant torrc file')

    output = run_tor(tor_cmd, '-f', '/path/that/really/shouldnt/exist', '--verify-config', '--ignore-missing-torrc')
    assert_in('[notice] Configuration file "/path/that/really/shouldnt/exist" not present, using reasonable defaults.', output, 'Missing torrc should be allowed with --ignore-missing-torrc')
예제 #8
0
파일: process.py 프로젝트: patrickod/stem
  def test_hush_argument(tor_cmd):
    """
    Check that we only get warnings and errors when running 'tor --hush'.
    """

    output = run_tor(tor_cmd, '--hush', '--invalid_argument', expect_failure = True)
    assert_in("[warn] Command-line option '--invalid_argument' with no value. Failing.", output)

    output = run_tor(tor_cmd, '--hush', '--invalid_argument', 'true', expect_failure = True)
    assert_in("[warn] Failed to parse/validate config: Unknown option 'invalid_argument'.  Failing.", output)
예제 #9
0
파일: process.py 프로젝트: zmchu/stem
  def test_with_missing_torrc(tor_cmd):
    """
    Provide a torrc path that doesn't exist.
    """

    output = run_tor(tor_cmd, '-f', '/path/that/really/shouldnt/exist', '--verify-config', expect_failure = True)
    assert_in('[warn] Unable to open configuration file "/path/that/really/shouldnt/exist".', output, 'Tor should refuse to read a non-existant torrc file')

    output = run_tor(tor_cmd, '-f', '/path/that/really/shouldnt/exist', '--verify-config', '--ignore-missing-torrc')
    assert_in('[notice] Configuration file "/path/that/really/shouldnt/exist" not present, using reasonable defaults.', output, 'Missing torrc should be allowed with --ignore-missing-torrc')
예제 #10
0
파일: process.py 프로젝트: zmchu/stem
  def test_hush_argument(tor_cmd):
    """
    Check that we only get warnings and errors when running 'tor --hush'.
    """

    output = run_tor(tor_cmd, '--hush', '--invalid_argument', with_torrc = True, expect_failure = True)
    assert_in("[warn] Command-line option '--invalid_argument' with no value. Failing.", output)

    output = run_tor(tor_cmd, '--hush', '--invalid_argument', 'true', with_torrc = True, expect_failure = True)
    assert_in("[warn] Failed to parse/validate config: Unknown option 'invalid_argument'.  Failing.", output)
예제 #11
0
파일: process.py 프로젝트: txrproject/stem
    def test_dump_config_argument(tor_cmd):
        """
    Exercises our 'tor --dump-config' arugments.
    """

        short_output = run_tor(tor_cmd,
                               '--dump-config',
                               'short',
                               with_torrc=True)
        non_builtin_output = run_tor(tor_cmd,
                                     '--dump-config',
                                     'non-builtin',
                                     with_torrc=True)
        full_output = run_tor(tor_cmd,
                              '--dump-config',
                              'full',
                              with_torrc=True)
        run_tor(tor_cmd,
                '--dump-config',
                'invalid_option',
                with_torrc=True,
                expect_failure=True)

        assert_in('Nickname stemIntegTest', short_output)
        assert_in('Nickname stemIntegTest', non_builtin_output)
        assert_in('Nickname stemIntegTest', full_output)
예제 #12
0
파일: process.py 프로젝트: patrickod/stem
  def test_dump_config_argument(tor_cmd):
    """
    Exercises our 'tor --dump-config' arugments.
    """

    short_output = run_tor(tor_cmd, '--dump-config', 'short', with_torrc = True)
    non_builtin_output = run_tor(tor_cmd, '--dump-config', 'non-builtin', with_torrc = True)
    full_output = run_tor(tor_cmd, '--dump-config', 'full', with_torrc = True)
    run_tor(tor_cmd, '--dump-config', 'invalid_option', with_torrc = True, expect_failure = True)

    assert_in('Nickname stemIntegTest', short_output)
    assert_in('Nickname stemIntegTest', non_builtin_output)
    assert_in('Nickname stemIntegTest', full_output)