Exemple #1
0
 def test_router_digest(self):
   """
   Constructs with a router-digest line with both valid and invalid contents.
   """
   
   # checks with valid content
   
   router_digest = "068A2E28D4C934D9490303B7A645BA068DCA0504"
   desc = get_bridge_server_descriptor({"router-digest": router_digest})
   self.assertEquals(router_digest, desc.digest())
   
   # checks when missing
   
   desc_text = get_bridge_server_descriptor(exclude = ["router-digest"], content = True)
   self.assertRaises(ValueError, BridgeDescriptor, desc_text)
   
   # check that we can still construct it without validation
   desc = BridgeDescriptor(desc_text, validate = False)
   self.assertEquals(None, desc.digest())
   
   # checks with invalid content
   
   test_values = (
     "",
     "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB44",
     "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB",
     "006FD96BA35E7785A6A3B8B75FE2E2435A13BDBH",
   )
   
   for value in test_values:
     desc_text = get_bridge_server_descriptor({"router-digest": value}, content = True)
     self.assertRaises(ValueError, BridgeDescriptor, desc_text)
     
     desc = BridgeDescriptor(desc_text, validate = False)
     self.assertEquals(value, desc.digest())
Exemple #2
0
  def test_bridge_unsanitized_relay(self):
    """
    Checks that parsing a normal relay descriptor as a bridge will fail due to
    its unsanatized content.
    """

    desc_text = RelayDescriptor.content({'router-digest': '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'})
    desc = BridgeDescriptor(desc_text)
    self.assertFalse(desc.is_scrubbed())
Exemple #3
0
 def test_bridge_unsanitized_relay(self):
   """
   Checks that parsing a normal relay descriptor as a bridge will fail due to
   its unsanatized content.
   """
   
   desc_text = get_relay_server_descriptor({"router-digest": "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4"}, content = True)
   desc = BridgeDescriptor(desc_text)
   self.assertFalse(desc.is_scrubbed())
Exemple #4
0
  def test_bridge_unsanitized_relay(self):
    """
    Checks that parsing a normal relay descriptor as a bridge will fail due to
    its unsanatized content.
    """

    desc_text = RelayDescriptor.content({'router-digest': '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'})
    desc = BridgeDescriptor(desc_text)
    self.assertFalse(desc.is_scrubbed())
Exemple #5
0
  def test_bridge_unsanitized_relay(self):
    """
    Checks that parsing a normal relay descriptor as a bridge will fail due to
    its unsanatized content.
    """

    desc_text = get_relay_server_descriptor({"router-digest": "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4"}, content = True)
    desc = BridgeDescriptor(desc_text)
    self.assertFalse(desc.is_scrubbed())
Exemple #6
0
    def test_router_digest(self):
        """
    Constructs with a router-digest line with both valid and invalid contents.
    """

        # checks with valid content

        router_digest = '068A2E28D4C934D9490303B7A645BA068DCA0504'
        desc = BridgeDescriptor.create({'router-digest': router_digest})
        self.assertEqual(router_digest, desc.digest())

        # checks when missing

        desc_text = BridgeDescriptor.content(exclude=['router-digest'])
        self.assertRaises(ValueError, BridgeDescriptor, desc_text, True)

        # check that we can still construct it without validation
        desc = BridgeDescriptor(desc_text, validate=False)
        self.assertEqual(None, desc.digest())

        # checks with invalid content

        test_values = (
            '',
            '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB44',
            '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB',
            '006FD96BA35E7785A6A3B8B75FE2E2435A13BDBH',
        )

        for value in test_values:
            desc_text = BridgeDescriptor.content({'router-digest': value})
            self.assertRaises(ValueError, BridgeDescriptor, desc_text, True)

            desc = BridgeDescriptor(desc_text, validate=False)
            self.assertEqual(None, desc.digest())
Exemple #7
0
  def test_or_address_v6(self):
    """
    Constructs a bridge descriptor with a sanatized IPv6 or-address entry.
    """

    desc = BridgeDescriptor.create({'or-address': '[fd9f:2e19:3bcf::02:9970]:9001'})
    self.assertEqual([('fd9f:2e19:3bcf::02:9970', 9001, True)], desc.or_addresses)
Exemple #8
0
  def test_or_address_v4(self):
    """
    Constructs a bridge descriptor with a sanatized IPv4 or-address entry.
    """

    desc = BridgeDescriptor.create({'or-address': '10.45.227.253:9001'})
    self.assertEqual([('10.45.227.253', 9001, False)], desc.or_addresses)
Exemple #9
0
  def test_or_address_v6(self):
    """
    Constructs a bridge descriptor with a sanatized IPv6 or-address entry.
    """

    desc = BridgeDescriptor.create({'or-address': '[fd9f:2e19:3bcf::02:9970]:9001'})
    self.assertEqual([('fd9f:2e19:3bcf::02:9970', 9001, True)], desc.or_addresses)
Exemple #10
0
    def test_or_address_v4(self):
        """
    Constructs a bridge descriptor with a sanatized IPv4 or-address entry.
    """

        desc = BridgeDescriptor.create({'or-address': '10.45.227.253:9001'})
        self.assertEqual([('10.45.227.253', 9001, False)], desc.or_addresses)
 def test_minimal_bridge_descriptor(self):
   """
   Basic sanity check that we can parse a descriptor with minimal attributes.
   """
   
   desc_text = _make_descriptor(is_bridge = True)
   desc = BridgeDescriptor(desc_text)
   
   self.assertEquals("Unnamed", desc.nickname)
   self.assertEquals("10.45.227.253", desc.address)
   self.assertEquals(None, desc.fingerprint)
   self.assertEquals("006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4", desc.digest())
   
   # check that we don't have crypto fields
   self.assertRaises(AttributeError, getattr, desc, "onion_key")
   self.assertRaises(AttributeError, getattr, desc, "signing_key")
   self.assertRaises(AttributeError, getattr, desc, "signature")
Exemple #12
0
    def test_multiple_descriptor_types(self):
        """
    Attempts to make a csv with multiple descriptor types.
    """

        self.assertRaises(
            ValueError, export_csv,
            (RelayDescriptor.create(), BridgeDescriptor.create()))
Exemple #13
0
  def test_router_digest(self):
    """
    Constructs with a router-digest line with both valid and invalid contents.
    """

    # checks with valid content

    router_digest = '068A2E28D4C934D9490303B7A645BA068DCA0504'
    desc = BridgeDescriptor.create({'router-digest': router_digest})
    self.assertEqual(router_digest, desc.digest())

    # checks when missing

    desc_text = BridgeDescriptor.content(exclude = ['router-digest'])
    self.assertRaises(ValueError, BridgeDescriptor, desc_text, True)

    # check that we can still construct it without validation
    desc = BridgeDescriptor(desc_text, validate = False)
    self.assertEqual(None, desc.digest())

    # checks with invalid content

    test_values = (
      '',
      '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB44',
      '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB',
      '006FD96BA35E7785A6A3B8B75FE2E2435A13BDBH',
    )

    for value in test_values:
      desc_text = BridgeDescriptor.content({'router-digest': value})
      self.assertRaises(ValueError, BridgeDescriptor, desc_text, True)

      desc = BridgeDescriptor(desc_text, validate = False)
      self.assertEqual(None, desc.digest())
Exemple #14
0
    def test_or_address_multiple(self):
        """
    Constructs a bridge descriptor with multiple or-address entries and multiple ports.
    """

        desc_text = b'\n'.join((
            BridgeDescriptor.content(),
            b'or-address 10.45.227.253:9001',
            b'or-address [fd9f:2e19:3bcf::02:9970]:443',
        ))

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

        desc = BridgeDescriptor(desc_text)
        self.assertEqual(expected_or_addresses, desc.or_addresses)
 def test_bridge_unsanitized(self):
   """
   Targeted check that individual unsanitized attributes will be detected.
   """
   
   unsanitized_attr = [
     {"router": "Unnamed 75.45.227.253 9001 0 0"},
     {"contact": "Damian"},
     {"or-address": "71.35.133.197:9001"},
     {"or-address": "[12ab:2e19:3bcf::02:9970]:9001"},
     {"onion-key": "\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----" % CRYPTO_BLOB},
     {"signing-key": "\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----" % CRYPTO_BLOB},
     {"router-signature": "\n-----BEGIN SIGNATURE-----%s-----END SIGNATURE-----" % CRYPTO_BLOB},
   ]
   
   for attr in unsanitized_attr:
     desc_text = _make_descriptor(attr, is_bridge = True)
     desc = BridgeDescriptor(desc_text)
     self.assertFalse(desc.is_scrubbed())
Exemple #16
0
  def test_router_digest(self):
    """
    Constructs with a router-digest line with both valid and invalid contents.
    """

    # checks with valid content

    router_digest = "068A2E28D4C934D9490303B7A645BA068DCA0504"
    desc = get_bridge_server_descriptor({"router-digest": router_digest})
    self.assertEquals(router_digest, desc.digest())

    # checks when missing

    desc_text = get_bridge_server_descriptor(exclude = ["router-digest"], content = True)
    self.assertRaises(ValueError, BridgeDescriptor, desc_text)

    # check that we can still construct it without validation
    desc = BridgeDescriptor(desc_text, validate = False)
    self.assertEquals(None, desc.digest())

    # checks with invalid content

    test_values = (
      "",
      "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB44",
      "006FD96BA35E7785A6A3B8B75FE2E2435A13BDB",
      "006FD96BA35E7785A6A3B8B75FE2E2435A13BDBH",
    )

    for value in test_values:
      desc_text = get_bridge_server_descriptor({"router-digest": value}, content = True)
      self.assertRaises(ValueError, BridgeDescriptor, desc_text)

      desc = BridgeDescriptor(desc_text, validate = False)
      self.assertEquals(value, desc.digest())
Exemple #17
0
  def test_minimal_bridge_descriptor(self):
    """
    Basic sanity check that we can parse a descriptor with minimal attributes.
    """

    desc = BridgeDescriptor.create()

    self.assertTrue(desc.nickname.startswith('Unnamed'))
    self.assertEqual(None, desc.fingerprint)
    self.assertEqual('006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4', desc.digest())

    # check that we don't have crypto fields
    self.assertRaises(AttributeError, getattr, desc, 'onion_key')
    self.assertRaises(AttributeError, getattr, desc, 'signing_key')
    self.assertRaises(AttributeError, getattr, desc, 'signature')
Exemple #18
0
  def test_minimal_bridge_descriptor(self):
    """
    Basic sanity check that we can parse a descriptor with minimal attributes.
    """

    desc = BridgeDescriptor.create()

    self.assertTrue(desc.nickname.startswith('Unnamed'))
    self.assertEqual(None, desc.fingerprint)
    self.assertEqual('006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4', desc.digest())

    # check that we don't have crypto fields
    self.assertRaises(AttributeError, getattr, desc, 'onion_key')
    self.assertRaises(AttributeError, getattr, desc, 'signing_key')
    self.assertRaises(AttributeError, getattr, desc, 'signature')
Exemple #19
0
    def test_or_address_multiple(self):
        """
    Constructs a bridge descriptor with multiple or-address entries and multiple ports.
    """

        desc_text = b"\n".join((get_bridge_server_descriptor(content=True),
                                b"or-address 10.45.227.253:9001",
                                b"or-address [fd9f:2e19:3bcf::02:9970]:443"))

        expected_or_addresses = [
            ("10.45.227.253", 9001, False),
            ("fd9f:2e19:3bcf::02:9970", 443, True),
        ]

        desc = BridgeDescriptor(desc_text)
        self.assertEquals(expected_or_addresses, desc.or_addresses)
Exemple #20
0
  def test_bridge_unsanitized(self):
    """
    Targeted check that individual unsanitized attributes will be detected.
    """

    unsanitized_attr = [
      {'router': 'Unnamed 75.45.227.253 9001 0 0'},
      {'contact': 'Damian'},
      {'or-address': '71.35.133.197:9001'},
      {'or-address': '[12ab:2e19:3bcf::02:9970]:9001'},
      {'onion-key': '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----' % stem.descriptor.CRYPTO_BLOB},
      {'signing-key': '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----' % stem.descriptor.CRYPTO_BLOB},
      {'router-signature': '\n-----BEGIN SIGNATURE-----%s-----END SIGNATURE-----' % stem.descriptor.CRYPTO_BLOB},
    ]

    for attr in unsanitized_attr:
      desc = BridgeDescriptor.create(attr)
      self.assertFalse(desc.is_scrubbed())
Exemple #21
0
  def test_bridge_unsanitized(self):
    """
    Targeted check that individual unsanitized attributes will be detected.
    """

    unsanitized_attr = [
      {'router': 'Unnamed 75.45.227.253 9001 0 0'},
      {'contact': 'Damian'},
      {'or-address': '71.35.133.197:9001'},
      {'or-address': '[12ab:2e19:3bcf::02:9970]:9001'},
      {'onion-key': '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----' % stem.descriptor.CRYPTO_BLOB},
      {'signing-key': '\n-----BEGIN RSA PUBLIC KEY-----%s-----END RSA PUBLIC KEY-----' % stem.descriptor.CRYPTO_BLOB},
      {'router-signature': '\n-----BEGIN SIGNATURE-----%s-----END SIGNATURE-----' % stem.descriptor.CRYPTO_BLOB},
    ]

    for attr in unsanitized_attr:
      desc = BridgeDescriptor.create(attr)
      self.assertFalse(desc.is_scrubbed())
Exemple #22
0
  def test_or_address_multiple(self):
    """
    Constructs a bridge descriptor with multiple or-address entries and multiple ports.
    """

    desc_text = b'\n'.join((
      BridgeDescriptor.content(),
      b'or-address 10.45.227.253:9001',
      b'or-address [fd9f:2e19:3bcf::02:9970]:443',
    ))

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

    desc = BridgeDescriptor(desc_text)
    self.assertEqual(expected_or_addresses, desc.or_addresses)
Exemple #23
0
  def test_multiple_descriptor_types(self):
    """
    Attempts to make a csv with multiple descriptor types.
    """

    self.assertRaises(ValueError, export_csv, (RelayDescriptor.create(), BridgeDescriptor.create()))