Example #1
0
    def setUp(self):
        # test_util.load_comparable_{csr,cert} return ComparableX509
        self.req1 = test_util.load_comparable_csr('csr.pem')
        self.req2 = test_util.load_comparable_csr('csr.pem')
        self.req_other = test_util.load_comparable_csr('csr-san.pem')

        self.cert1 = test_util.load_comparable_cert('cert.pem')
        self.cert2 = test_util.load_comparable_cert('cert.pem')
        self.cert_other = test_util.load_comparable_cert('cert-san.pem')
"""Tests for acme.messages."""
import unittest

import josepy as jose
import mock

from acme import challenges
import test_util

CERT = test_util.load_comparable_cert('cert.der')
CSR = test_util.load_comparable_csr('csr.der')
KEY = test_util.load_rsa_private_key('rsa512_key.pem')


class ErrorTest(unittest.TestCase):
    """Tests for acme.messages.Error."""

    def setUp(self):
        from acme.messages import Error, ERROR_PREFIX
        self.error = Error.with_code('malformed', detail='foo', title='title')
        self.jobj = {
            'detail': 'foo',
            'title': 'some title',
            'type': ERROR_PREFIX + 'malformed',
        }
        self.error_custom = Error(typ='custom', detail='bar')
        self.empty_error = Error()

    def test_default_typ(self):
        from acme.messages import Error
        self.assertEqual(Error().typ, 'about:blank')
Example #3
0
"""Tests for josepy.json_util."""
import itertools
import unittest
from unittest import mock

import test_util

from josepy import errors, interfaces, util

CERT = test_util.load_comparable_cert('cert.pem')
CSR = test_util.load_comparable_csr('csr.pem')


class FieldTest(unittest.TestCase):
    """Tests for josepy.json_util.field and josepy.json_util.Field."""
    def test_field_function(self):
        from josepy.json_util import Field, field

        test = field("foo", default="bar")
        self.assertIsInstance(test, Field)
        self.assertEqual(test.json_name, "foo")
        self.assertEqual(test.default, "bar")

    def test_type_field_control(self):
        from josepy.json_util import JSONObjectWithFields, field

        class DummyProperlyTyped(JSONObjectWithFields):
            type: str = field('type')
            index: int = field('index')

        with self.assertRaises(ValueError):