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_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())
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_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")