Example #1
0
  def test_with_microdescriptor_router_status_entries(self):
    """
    Includes microdescriptor flavored router status entries within the
    document.
    """

    entry1 = get_router_status_entry_micro_v3({'s': "Fast"})
    entry2 = get_router_status_entry_micro_v3({
      'r': "tornodeviennasil AcWxDFxrHetHYS5m6/MVt8ZN6AM 2013-03-13 22:09:13 78.142.142.246 443 80",
      's': "Valid",
    })

    document = get_network_status_document_v3({"network-status-version": "3 microdesc"}, routers = (entry1, entry2))

    self.assertTrue(entry1 in document.routers.values())
    self.assertTrue(entry2 in document.routers.values())

    # try with an invalid RouterStatusEntry

    entry3 = RouterStatusEntryMicroV3(get_router_status_entry_micro_v3({'r': "ugabuga"}, content = True), False)

    content = get_network_status_document_v3({"network-status-version": "3 microdesc"}, routers = (entry3,), content = True)
    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)

    document = NetworkStatusDocumentV3(content, False)
    self.assertEquals([entry3], document.routers.values())

    # try including microdescriptor entry in a normal consensus

    content = get_network_status_document_v3(routers = (entry1,), content = True)
    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)

    document = NetworkStatusDocumentV3(content, False)
    self.assertEqual([RouterStatusEntryV3(str(entry1), False)], document.routers.values())
Example #2
0
  def test_with_router_status_entries(self):
    """
    Includes router status entries within the document. This isn't to test the
    RouterStatusEntry parsing but rather the inclusion of it within the
    document.
    """

    entry1 = get_router_status_entry_v3({'s': "Fast"})
    entry2 = get_router_status_entry_v3({
      'r': "Nightfae AWt0XNId/OU2xX5xs5hVtDc5Mes 6873oEfM7fFIbxYtwllw9GPDwkA 2013-02-20 11:12:27 85.177.66.233 9001 9030",
      's': "Valid",
    })

    document = get_network_status_document_v3(routers = (entry1, entry2))

    self.assertTrue(entry1 in document.routers.values())
    self.assertTrue(entry2 in document.routers.values())

    # try with an invalid RouterStatusEntry

    entry3 = RouterStatusEntryV3(get_router_status_entry_v3({'r': "ugabuga"}, content = True), False)
    content = get_network_status_document_v3(routers = (entry3,), content = True)

    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
    document = NetworkStatusDocumentV3(content, False)
    self.assertEquals([entry3], document.routers.values())

    # try including with a microdescriptor consensus

    content = get_network_status_document_v3({"network-status-version": "3 microdesc"}, routers = (entry1,), content = True)
    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)

    document = NetworkStatusDocumentV3(content, False)
    self.assertEqual([RouterStatusEntryMicroV3(str(entry1), False)], document.routers.values())
Example #3
0
    def test_with_router_status_entries(self):
        """
    Includes router status entries within the document. This isn't to test the
    RouterStatusEntry parsing but rather the inclusion of it within the
    document.
    """

        entry1 = get_router_status_entry_v3({'s': "Fast"})
        entry2 = get_router_status_entry_v3({'s': "Valid"})
        document = get_network_status_document_v3(routers=(entry1, entry2))

        self.assertEquals((entry1, entry2), document.routers)

        # try with an invalid RouterStatusEntry

        entry3 = RouterStatusEntryV3(
            get_router_status_entry_v3({'r': "ugabuga"}, content=True), False)
        content = get_network_status_document_v3(routers=(entry3, ),
                                                 content=True)

        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
        document = NetworkStatusDocumentV3(content, False)
        self.assertEquals((entry3, ), document.routers)

        # try including with a microdescriptor consensus

        content = get_network_status_document_v3(
            {"network-status-version": "3 microdesc"},
            routers=(entry1, entry2),
            content=True)
        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)

        expected_routers = (
            RouterStatusEntryMicroV3(str(entry1), False),
            RouterStatusEntryMicroV3(str(entry2), False),
        )

        document = NetworkStatusDocumentV3(content, False)
        self.assertEquals(expected_routers, document.routers)
Example #4
0
  def test_minimal_micro_v3(self):
    """
    Parses a minimal microdescriptor v3 router status entry.
    """

    entry = RouterStatusEntryMicroV3.create()

    expected_flags = set([Flag.FAST, Flag.GUARD, Flag.HSDIR, Flag.NAMED, Flag.RUNNING, Flag.STABLE, Flag.V2DIR, Flag.VALID])
    self.assertEqual(None, entry.document)
    self.assertTrue(entry.nickname.startswith('Unnamed'))
    self.assertEqual(9001, entry.or_port)
    self.assertEqual(9030, entry.dir_port)
    self.assertEqual(expected_flags, set(entry.flags))
    self.assertEqual(None, entry.version_line)
    self.assertEqual(None, entry.version)
    self.assertEqual('6A252497006BB9AF36A1B1B902C4D7FA2129923400DBE0101F167B1B031F63BD', entry.digest)
    self.assertEqual([], entry.get_unrecognized_lines())
Example #5
0
    def test_with_ipv6(self):
        """
    Parse a router status entry with an IPv6 address.
    """

        expected_protocols = OrderedDict((
            ('Cons', [1]),
            ('Desc', [1]),
            ('DirCache', [1]),
            ('HSDir', [1]),
            ('HSIntro', [3]),
            ('HSRend', [1]),
            ('Link', [1, 2, 3, 4]),
            ('LinkAuth', [1]),
            ('Microdesc', [1]),
            ('Relay', [1, 2]),
        ))

        entry = RouterStatusEntryMicroV3(ENTRY_WITH_IPV6, validate=True)
        self.assertEqual('MYLEX', entry.nickname)
        self.assertEqual('010B7728454411F485CE29D4C79A14534151C2C4',
                         entry.fingerprint)
        self.assertEqual(datetime.datetime(2018, 7, 15, 16, 38, 10),
                         entry.published)
        self.assertEqual('77.123.42.148', entry.address)
        self.assertEqual(444, entry.or_port)
        self.assertEqual(800, entry.dir_port)
        self.assertEqual(
            set([
                Flag.FAST, Flag.GUARD, Flag.HSDIR, Flag.RUNNING, Flag.STABLE,
                Flag.V2DIR, Flag.VALID
            ]), set(entry.flags))
        self.assertEqual('Tor 0.2.5.16', entry.version_line)
        self.assertEqual(Version('0.2.5.16'), entry.version)
        self.assertEqual([('2001:470:71:9b9:f66d:4ff:fee7:954c', 444, True)],
                         entry.or_addresses)
        self.assertEqual(4950, entry.bandwidth)
        self.assertEqual(None, entry.measured)
        self.assertEqual(False, entry.is_unmeasured)
        self.assertEqual([], entry.unrecognized_bandwidth_entries)
        self.assertEqual(expected_protocols, entry.protocols)
        self.assertEqual(
            '1966FEC636AFD1FB2EC0FC0F36752F5BD43522F9399F3F26D4C70408CE0A63C0',
            entry.digest)
        self.assertEqual([], entry.get_unrecognized_lines())
Example #6
0
  def test_minimal_micro_v3(self):
    """
    Parses a minimal microdescriptor v3 router status entry.
    """

    entry = RouterStatusEntryMicroV3.create()

    expected_flags = set([Flag.FAST, Flag.GUARD, Flag.HSDIR, Flag.NAMED, Flag.RUNNING, Flag.STABLE, Flag.V2DIR, Flag.VALID])
    self.assertEqual(None, entry.document)
    self.assertTrue(entry.nickname.startswith('Unnamed'))
    self.assertEqual(9001, entry.or_port)
    self.assertEqual(9030, entry.dir_port)
    self.assertEqual(expected_flags, set(entry.flags))
    self.assertEqual(None, entry.version_line)
    self.assertEqual(None, entry.version)
    self.assertEqual('aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70', entry.microdescriptor_digest)
    self.assertEqual('6A252497006BB9AF36A1B1B902C4D7FA2129923400DBE0101F167B1B031F63BD', entry.digest)
    self.assertEqual([], entry.get_unrecognized_lines())