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())
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_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)
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())
def test_multiple_descriptor_types(self): """ Attempts to make a csv with multiple descriptor types. """ self.assertRaises( ValueError, export_csv, (RelayDescriptor.create(), BridgeDescriptor.create()))
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')
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())
def test_multiple_descriptor_types(self): """ Attempts to make a csv with multiple descriptor types. """ self.assertRaises(ValueError, export_csv, (RelayDescriptor.create(), BridgeDescriptor.create()))