Esempio n. 1
0
    def test_key_blocks(self):
        """
    Parses the dir-identity-key, dir-signing-key, dir-key-crosscert, and
    dir-key-certification fields which all just have signature content.
    """

        # the only non-mandatory field that we haven't exercised yet is dir-key-crosscert

        certificate = KeyCertificate.create({
            'dir-key-crosscert':
            '\n-----BEGIN ID SIGNATURE-----%s-----END ID SIGNATURE-----' %
            stem.descriptor.CRYPTO_BLOB
        })
        self.assertTrue(stem.descriptor.CRYPTO_BLOB in certificate.crosscert)

        test_value = '\n-----BEGIN ID SIGNATURE-----%s-----END UGABUGA SIGNATURE-----' % stem.descriptor.CRYPTO_BLOB

        for field, attr in (('dir-identity-key', 'identity_key'),
                            ('dir-signing-key', 'signing_key'),
                            ('dir-key-crosscert', 'crosscert'),
                            ('dir-key-certification', 'certification')):
            content = KeyCertificate.content({field: test_value})
            self.assertRaises(ValueError, KeyCertificate, content, True)

            certificate = KeyCertificate(content, False)
            self.assertEqual(None, getattr(certificate, attr))
Esempio n. 2
0
  def test_blank_lines(self):
    """
    Includes blank lines, which should be ignored.
    """

    certificate = KeyCertificate.create({'dir-key-published': '2011-11-28 21:51:04\n\n\n'})
    self.assertEqual(datetime.datetime(2011, 11, 28, 21, 51, 4), certificate.published)
Esempio n. 3
0
    def test_dir_address(self):
        """
    Parses the dir-address field.
    """

        certificate = KeyCertificate.create({'dir-address': '127.0.0.1:80'})
        self.assertEqual('127.0.0.1', certificate.address)
        self.assertEqual(80, certificate.dir_port)

        test_values = (
            (''),
            ('   '),
            ('127.0.0.1'),
            ('127.0.0.1:'),
            ('80'),
            (':80'),
            ('127.0.0.1a:80'),
            ('127.0.0.1:80a'),
        )

        for test_value in test_values:
            content = KeyCertificate.content({'dir-address': test_value})
            self.assertRaises(ValueError, KeyCertificate, content, True)

            certificate = KeyCertificate(content, False)
            self.assertEqual(None, certificate.address)
            self.assertEqual(None, certificate.dir_port)
Esempio n. 4
0
  def test_dir_address(self):
    """
    Parses the dir-address field.
    """

    certificate = KeyCertificate.create({'dir-address': '127.0.0.1:80'})
    self.assertEqual('127.0.0.1', certificate.address)
    self.assertEqual(80, certificate.dir_port)

    test_values = (
      (''),
      ('   '),
      ('127.0.0.1'),
      ('127.0.0.1:'),
      ('80'),
      (':80'),
      ('127.0.0.1a:80'),
      ('127.0.0.1:80a'),
    )

    for test_value in test_values:
      content = KeyCertificate.content({'dir-address': test_value})
      self.assertRaises(ValueError, KeyCertificate, content, True)

      certificate = KeyCertificate(content, False)
      self.assertEqual(None, certificate.address)
      self.assertEqual(None, certificate.dir_port)
Esempio n. 5
0
  def test_unrecognized_line(self):
    """
    Includes unrecognized content in the descriptor.
    """

    certificate = KeyCertificate.create({'pepperjack': 'is oh so tasty!'})
    self.assertEqual(['pepperjack is oh so tasty!'], certificate.get_unrecognized_lines())
Esempio n. 6
0
  def test_blank_lines(self):
    """
    Includes blank lines, which should be ignored.
    """

    certificate = KeyCertificate.create({'dir-key-published': '2011-11-28 21:51:04\n\n\n'})
    self.assertEqual(datetime.datetime(2011, 11, 28, 21, 51, 4), certificate.published)
Esempio n. 7
0
  def test_unrecognized_line(self):
    """
    Includes unrecognized content in the descriptor.
    """

    certificate = KeyCertificate.create({'pepperjack': 'is oh so tasty!'})
    self.assertEqual(['pepperjack is oh so tasty!'], certificate.get_unrecognized_lines())
Esempio n. 8
0
    def test_minimal(self):
        """
    Parses a minimal key certificate.
    """

        certificate = KeyCertificate.create()

        self.assertEqual(3, certificate.version)
        self.assertEqual(None, certificate.address)
        self.assertEqual(None, certificate.dir_port)
        self.assertEqual(40, len(certificate.fingerprint))
        self.assertEqual(None, certificate.crosscert)
        self.assertEqual([], certificate.get_unrecognized_lines())
Esempio n. 9
0
  def test_minimal(self):
    """
    Parses a minimal key certificate.
    """

    certificate = KeyCertificate.create()

    self.assertEqual(3, certificate.version)
    self.assertEqual(None, certificate.address)
    self.assertEqual(None, certificate.dir_port)
    self.assertEqual(40, len(certificate.fingerprint))
    self.assertEqual(None, certificate.crosscert)
    self.assertEqual([], certificate.get_unrecognized_lines())
Esempio n. 10
0
  def test_version(self):
    """
    Parses the dir-key-certificate-version field, including trying to handle a
    different certificate version with the v3 parser.
    """

    certificate = KeyCertificate.create({'dir-key-certificate-version': '3'})
    self.assertEqual(3, certificate.version)

    content = KeyCertificate.content({'dir-key-certificate-version': '4'})
    self.assertRaises(ValueError, KeyCertificate, content, True)
    self.assertEqual(4, KeyCertificate(content, False).version)

    content = KeyCertificate.content({'dir-key-certificate-version': 'boo'})
    self.assertRaises(ValueError, KeyCertificate, content, True)
    self.assertEqual(None, KeyCertificate(content, False).version)
Esempio n. 11
0
  def test_version(self):
    """
    Parses the dir-key-certificate-version field, including trying to handle a
    different certificate version with the v3 parser.
    """

    certificate = KeyCertificate.create({'dir-key-certificate-version': '3'})
    self.assertEqual(3, certificate.version)

    content = KeyCertificate.content({'dir-key-certificate-version': '4'})
    self.assertRaises(ValueError, KeyCertificate, content, True)
    self.assertEqual(4, KeyCertificate(content, False).version)

    content = KeyCertificate.content({'dir-key-certificate-version': 'boo'})
    self.assertRaises(ValueError, KeyCertificate, content, True)
    self.assertEqual(None, KeyCertificate(content, False).version)
Esempio n. 12
0
  def test_key_blocks(self):
    """
    Parses the dir-identity-key, dir-signing-key, dir-key-crosscert, and
    dir-key-certification fields which all just have signature content.
    """

    # the only non-mandatory field that we haven't exercised yet is dir-key-crosscert

    certificate = KeyCertificate.create({'dir-key-crosscert': '\n-----BEGIN ID SIGNATURE-----%s-----END ID SIGNATURE-----' % stem.descriptor.CRYPTO_BLOB})
    self.assertTrue(stem.descriptor.CRYPTO_BLOB in certificate.crosscert)

    test_value = '\n-----BEGIN ID SIGNATURE-----%s-----END UGABUGA SIGNATURE-----' % stem.descriptor.CRYPTO_BLOB

    for field, attr in (('dir-identity-key', 'identity_key'),
                        ('dir-signing-key', 'signing_key'),
                        ('dir-key-crosscert', 'crosscert'),
                        ('dir-key-certification', 'certification')):
      content = KeyCertificate.content({field: test_value})
      self.assertRaises(ValueError, KeyCertificate, content, True)

      certificate = KeyCertificate(content, False)
      self.assertEqual(None, getattr(certificate, attr))