コード例 #1
0
  def test_identifier(self):
    """
    Basic check for 'id' lines.
    """

    desc = get_microdescriptor({'id': 'rsa1024 Cd47okjCHD83YGzThGBDptXs9Z4'})
    self.assertEqual({'rsa1024': 'Cd47okjCHD83YGzThGBDptXs9Z4'}, desc.identifiers)
    self.assertEqual('rsa1024', desc.identifier_type)
    self.assertEqual('Cd47okjCHD83YGzThGBDptXs9Z4', desc.identifier)

    # check when there's multiple key types

    desc_text = b'\n'.join((get_microdescriptor(content = True),
                            b'id rsa1024 Cd47okjCHD83YGzThGBDptXs9Z4',
                            b'id ed25519 50f6ddbecdc848dcc6b818b14d1'))

    desc = Microdescriptor(desc_text, validate = True)
    self.assertEqual({'rsa1024': 'Cd47okjCHD83YGzThGBDptXs9Z4', 'ed25519': '50f6ddbecdc848dcc6b818b14d1'}, desc.identifiers)
    self.assertEqual('ed25519', desc.identifier_type)
    self.assertEqual('50f6ddbecdc848dcc6b818b14d1', desc.identifier)

    # check when there's conflicting keys

    desc_text = b'\n'.join((get_microdescriptor(content = True),
                            b'id rsa1024 Cd47okjCHD83YGzThGBDptXs9Z4',
                            b'id rsa1024 50f6ddbecdc848dcc6b818b14d1'))

    desc = Microdescriptor(desc_text)
    self.assertEqual({}, desc.identifiers)

    try:
      Microdescriptor(desc_text, validate = True)
      self.fail('constructor validation should fail')
    except ValueError as exc:
      self.assertEqual("There can only be one 'id' line per a key type, but 'rsa1024' appeared multiple times", str(exc))
コード例 #2
0
  def test_unrecognized_line(self):
    """
    Includes unrecognized content in the descriptor.
    """

    desc = get_microdescriptor({'pepperjack': 'is oh so tasty!'})
    self.assertEqual(['pepperjack is oh so tasty!'], desc.get_unrecognized_lines())
コード例 #3
0
  def test_unrecognized_line(self):
    """
    Includes unrecognized content in the descriptor.
    """

    desc = get_microdescriptor({'pepperjack': 'is oh so tasty!'})
    self.assertEqual(['pepperjack is oh so tasty!'], desc.get_unrecognized_lines())
コード例 #4
0
ファイル: microdescriptor.py プロジェクト: ankitmodi/Projects
  def test_unrecognized_line(self):
    """
    Includes unrecognized content in the descriptor.
    """

    desc = get_microdescriptor({"pepperjack": "is oh so tasty!"})
    self.assertEquals(["pepperjack is oh so tasty!"], desc.get_unrecognized_lines())
コード例 #5
0
  def test_exit_policy(self):
    """
    Basic check for 'p' lines. The router status entries contain an identical
    field so we're not investing much effort here.
    """

    desc = get_microdescriptor({'p': 'accept 80,110,143,443'})
    self.assertEqual(stem.exit_policy.MicroExitPolicy('accept 80,110,143,443'), desc.exit_policy)
コード例 #6
0
    def test_unrecognized_line(self):
        """
    Includes unrecognized content in the descriptor.
    """

        desc = get_microdescriptor({"pepperjack": "is oh so tasty!"})
        self.assertEquals(["pepperjack is oh so tasty!"],
                          desc.get_unrecognized_lines())
コード例 #7
0
  def test_exit_policy(self):
    """
    Basic check for 'p' lines. The router status entries contain an identical
    field so we're not investing much effort here.
    """

    desc = get_microdescriptor({'p': 'accept 80,110,143,443'})
    self.assertEqual(stem.exit_policy.MicroExitPolicy('accept 80,110,143,443'), desc.exit_policy)
コード例 #8
0
  def test_identifier(self):
    """
    Basic check for 'id' lines.
    """

    desc = get_microdescriptor({'id': 'rsa1024 Cd47okjCHD83YGzThGBDptXs9Z4'})
    self.assertEqual('rsa1024', desc.identifier_type)
    self.assertEqual('Cd47okjCHD83YGzThGBDptXs9Z4', desc.identifier)
コード例 #9
0
    def test_identifier(self):
        """
    Basic check for 'id' lines.
    """

        desc = get_microdescriptor(
            {'id': 'rsa1024 Cd47okjCHD83YGzThGBDptXs9Z4'})
        self.assertEqual('rsa1024', desc.identifier_type)
        self.assertEqual('Cd47okjCHD83YGzThGBDptXs9Z4', desc.identifier)
コード例 #10
0
  def test_proceeding_line(self):
    """
    Includes a line prior to the 'onion-key' entry.
    """

    desc_text = b'family Amunet1\n' + get_microdescriptor(content = True)
    self.assertRaises(ValueError, Microdescriptor, desc_text, True)

    desc = Microdescriptor(desc_text, validate = False)
    self.assertEqual(['Amunet1'], desc.family)
コード例 #11
0
  def test_family(self):
    """
    Check the family line.
    """

    desc = get_microdescriptor({'family': 'Amunet1 Amunet2 Amunet3'})
    self.assertEqual(['Amunet1', 'Amunet2', 'Amunet3'], desc.family)

    # try multiple family lines

    desc_text = get_microdescriptor(content = True)
    desc_text += b'\nfamily Amunet1'
    desc_text += b'\nfamily Amunet2'

    self.assertRaises(ValueError, Microdescriptor, desc_text, True)

    # family entries will overwrite each other
    desc = Microdescriptor(desc_text, validate = False)
    self.assertEqual(1, len(desc.family))
コード例 #12
0
  def test_proceeding_line(self):
    """
    Includes a line prior to the 'onion-key' entry.
    """

    desc_text = b'family Amunet1\n' + get_microdescriptor(content = True)
    self.assertRaises(ValueError, Microdescriptor, desc_text, True)

    desc = Microdescriptor(desc_text, validate = False)
    self.assertEqual(['Amunet1'], desc.family)
コード例 #13
0
    def test_family(self):
        """
    Check the family line.
    """

        desc = get_microdescriptor({"family": "Amunet1 Amunet2 Amunet3"})
        self.assertEquals(["Amunet1", "Amunet2", "Amunet3"], desc.family)

        # try multiple family lines

        desc_text = get_microdescriptor(content=True)
        desc_text += b"\nfamily Amunet1"
        desc_text += b"\nfamily Amunet2"

        self.assertRaises(ValueError, Microdescriptor, desc_text)

        # family entries will overwrite each other
        desc = Microdescriptor(desc_text, validate=False)
        self.assertEquals(1, len(desc.family))
コード例 #14
0
ファイル: microdescriptor.py プロジェクト: paraschetal/stem
    def test_protocols(self):
        """
    Basic check for 'pr' lines.
    """

        desc = get_microdescriptor({
            'pr':
            'Cons=1 Desc=1 DirCache=1 HSDir=1 HSIntro=3 HSRend=1 Link=1-4 LinkAuth=1 Microdesc=1 Relay=1-2'
        })
        self.assertEqual(10, len(desc.protocols))
コード例 #15
0
ファイル: microdescriptor.py プロジェクト: ankitmodi/Projects
  def test_family(self):
    """
    Check the family line.
    """

    desc = get_microdescriptor({"family": "Amunet1 Amunet2 Amunet3"})
    self.assertEquals(["Amunet1", "Amunet2", "Amunet3"], desc.family)

    # try multiple family lines

    desc_text = get_microdescriptor(content = True)
    desc_text += b"\nfamily Amunet1"
    desc_text += b"\nfamily Amunet2"

    self.assertRaises(ValueError, Microdescriptor, desc_text)

    # family entries will overwrite each other
    desc = Microdescriptor(desc_text, validate = False)
    self.assertEquals(1, len(desc.family))
コード例 #16
0
  def test_family(self):
    """
    Check the family line.
    """

    desc = get_microdescriptor({'family': 'Amunet1 Amunet2 Amunet3'})
    self.assertEqual(['Amunet1', 'Amunet2', 'Amunet3'], desc.family)

    # try multiple family lines

    desc_text = get_microdescriptor(content = True)
    desc_text += b'\nfamily Amunet1'
    desc_text += b'\nfamily Amunet2'

    self.assertRaises(ValueError, Microdescriptor, desc_text, True)

    # family entries will overwrite each other
    desc = Microdescriptor(desc_text, validate = False)
    self.assertEqual(1, len(desc.family))
コード例 #17
0
ファイル: microdescriptor.py プロジェクト: ankitmodi/Projects
  def test_minimal_microdescriptor(self):
    """
    Basic sanity check that we can parse a microdescriptor with minimal
    attributes.
    """

    desc = get_microdescriptor()

    self.assertTrue(CRYPTO_BLOB in desc.onion_key)
    self.assertEquals(None, desc.ntor_onion_key)
    self.assertEquals([], desc.or_addresses)
    self.assertEquals([], desc.family)
    self.assertEquals(stem.exit_policy.MicroExitPolicy("reject 1-65535"), desc.exit_policy)
    self.assertEquals(None, desc.exit_policy_v6)
    self.assertEquals([], desc.get_unrecognized_lines())
コード例 #18
0
    def test_minimal_microdescriptor(self):
        """
    Basic sanity check that we can parse a microdescriptor with minimal
    attributes.
    """

        desc = get_microdescriptor()

        self.assertTrue(CRYPTO_BLOB in desc.onion_key)
        self.assertEquals(None, desc.ntor_onion_key)
        self.assertEquals([], desc.or_addresses)
        self.assertEquals([], desc.family)
        self.assertEquals(stem.exit_policy.MicroExitPolicy("reject 1-65535"),
                          desc.exit_policy)
        self.assertEquals(None, desc.exit_policy_v6)
        self.assertEquals([], desc.get_unrecognized_lines())
コード例 #19
0
  def test_a_line(self):
    """
    Sanity test with both an IPv4 and IPv6 address.
    """

    desc_text = get_microdescriptor(content = True)
    desc_text += b'\na 10.45.227.253:9001'
    desc_text += b'\na [fd9f:2e19:3bcf::02:9970]:9001'

    expected = [
      ('10.45.227.253', 9001, False),
      ('fd9f:2e19:3bcf::02:9970', 9001, True),
    ]

    desc = Microdescriptor(desc_text)
    self.assertEqual(expected, desc.or_addresses)
コード例 #20
0
  def test_a_line(self):
    """
    Sanity test with both an IPv4 and IPv6 address.
    """

    desc_text = get_microdescriptor(content = True)
    desc_text += b'\na 10.45.227.253:9001'
    desc_text += b'\na [fd9f:2e19:3bcf::02:9970]:9001'

    expected = [
      ('10.45.227.253', 9001, False),
      ('fd9f:2e19:3bcf::02:9970', 9001, True),
    ]

    desc = Microdescriptor(desc_text)
    self.assertEqual(expected, desc.or_addresses)