PNG  IHDR* pHYs+ IDATx]n#; cdLb Ǚ[at¤_:uP}>!Usă cag޿ ֵNu`ݼTâabO7uL&y^wFٝA"l[|ŲHLN밪4*sG3|Dv}?+y߉{OuOAt4Jj.u]Gz*҉sP'VQKbA1u\`& Af;HWj hsO;ogTu uj7S3/QzUr&wS`M$X_L7r2;aE+ώ%vikDA:dR+%KzƉo>eOth$z%: :{WwaQ:wz%4foɹE[9<]#ERINƻv溂E%P1i01 |Jvҗ&{b?9g=^wζXn/lK::90KwrюO\!ջ3uzuGv^;騢wq<Iatv09:tt~hEG`v;3@MNZD.1]L:{ծI3`L(÷ba")Y.iljCɄae#I"1 `3*Bdz>j<fU40⨬%O$3cGt]j%Fߠ_twJ;ABU8vP3uEԑwQ V:h%))LfraqX-ۿX]v-\9I gl8tzX ]ecm)-cgʒ#Uw=Wlێn(0hPP/ӨtQ“&J35 $=]r1{tLuǮ*i0_;NƝ8;-vݏr8+U-kruȕYr0RnC]*ެ(M:]gE;{]tg(#ZJ9y>utRDRMdr9㪩̞zֹb<ģ&wzJM"iI( .ꮅX)Qw:9,i좜\Ԛi7&N0:asϓc];=ΗOӣ APqz93 y $)A*kVHZwBƺnWNaby>XMN*45~ղM6Nvm;A=jֲ.~1}(9`KJ/V F9[=`~[;sRuk]rєT!)iQO)Y$V ی ۤmzWz5IM Zb )ˆC`6 rRa}qNmUfDsWuˤV{ Pݝ'=Kֳbg,UҘVz2ﴻnjNgBb{? ߮tcsͻQuxVCIY۠:(V뺕 ٥2;t`@Fo{Z9`;]wMzU~%UA蛚dI vGq\r82iu +St`cR.6U/M9IENDB` REDROOM
PHP 5.6.40
Preview: util_test.py Size: 8.15 KB
/proc/thread-self/root/lib/python3.6/site-packages/josepy/util_test.py

"""Tests for josepy.util."""
import functools
import unittest


from josepy import test_util


class ComparableX509Test(unittest.TestCase):
    """Tests for josepy.util.ComparableX509."""

    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')

    def test_getattr_proxy(self):
        self.assertIs(self.cert1.has_expired(), True)

    def test_eq(self):
        self.assertEqual(self.req1, self.req2)
        self.assertEqual(self.cert1, self.cert2)

    def test_ne(self):
        self.assertNotEqual(self.req1, self.req_other)
        self.assertNotEqual(self.cert1, self.cert_other)

    def test_ne_wrong_types(self):
        self.assertNotEqual(self.req1, 5)
        self.assertNotEqual(self.cert1, 5)

    def test_hash(self):
        self.assertEqual(hash(self.req1), hash(self.req2))
        self.assertNotEqual(hash(self.req1), hash(self.req_other))

        self.assertEqual(hash(self.cert1), hash(self.cert2))
        self.assertNotEqual(hash(self.cert1), hash(self.cert_other))

    def test_repr(self):
        for x509 in self.req1, self.cert1:
            self.assertEqual(repr(x509),
                             '<ComparableX509({0!r})>'.format(x509.wrapped))


class ComparableRSAKeyTest(unittest.TestCase):
    """Tests for josepy.util.ComparableRSAKey."""

    def setUp(self):
        # test_utl.load_rsa_private_key return ComparableRSAKey
        self.key = test_util.load_rsa_private_key('rsa256_key.pem')
        self.key_same = test_util.load_rsa_private_key('rsa256_key.pem')
        self.key2 = test_util.load_rsa_private_key('rsa512_key.pem')

    def test_getattr_proxy(self):
        self.assertEqual(256, self.key.key_size)

    def test_eq(self):
        self.assertEqual(self.key, self.key_same)

    def test_ne(self):
        self.assertNotEqual(self.key, self.key2)

    def test_ne_different_types(self):
        self.assertNotEqual(self.key, 5)

    def test_ne_not_wrapped(self):
        # pylint: disable=protected-access
        self.assertNotEqual(self.key, self.key_same._wrapped)

    def test_ne_no_serialization(self):
        from josepy.util import ComparableRSAKey
        self.assertNotEqual(ComparableRSAKey(5), ComparableRSAKey(5))

    def test_hash(self):
        self.assertIsInstance(hash(self.key), int)
        self.assertEqual(hash(self.key), hash(self.key_same))
        self.assertNotEqual(hash(self.key), hash(self.key2))

    def test_repr(self):
        self.assertIs(repr(self.key).startswith(
            '<ComparableRSAKey(<cryptography.hazmat.'), True)

    def test_public_key(self):
        from josepy.util import ComparableRSAKey
        self.assertIsInstance(self.key.public_key(), ComparableRSAKey)


class ComparableECKeyTest(unittest.TestCase):
    """Tests for josepy.util.ComparableECKey."""

    def setUp(self):
        # test_utl.load_ec_private_key return ComparableECKey
        self.p256_key = test_util.load_ec_private_key('ec_p256_key.pem')
        self.p256_key_same = test_util.load_ec_private_key('ec_p256_key.pem')
        self.p384_key = test_util.load_ec_private_key('ec_p384_key.pem')
        self.p521_key = test_util.load_ec_private_key('ec_p521_key.pem')

    def test_getattr_proxy(self):
        self.assertEqual(256, self.p256_key.key_size)

    def test_eq(self):
        self.assertEqual(self.p256_key, self.p256_key_same)

    def test_ne(self):
        self.assertNotEqual(self.p256_key, self.p384_key)
        self.assertNotEqual(self.p256_key, self.p521_key)

    def test_ne_different_types(self):
        self.assertNotEqual(self.p256_key, 5)

    def test_ne_not_wrapped(self):
        # pylint: disable=protected-access
        self.assertNotEqual(self.p256_key, self.p256_key_same._wrapped)

    def test_ne_no_serialization(self):
        from josepy.util import ComparableECKey
        self.assertNotEqual(ComparableECKey(5), ComparableECKey(5))

    def test_hash(self):
        self.assertIsInstance(hash(self.p256_key), int)
        self.assertEqual(hash(self.p256_key), hash(self.p256_key_same))
        self.assertNotEqual(hash(self.p256_key), hash(self.p384_key))
        self.assertNotEqual(hash(self.p256_key), hash(self.p521_key))

    def test_repr(self):
        self.assertIs(repr(self.p256_key).startswith(
            '<ComparableECKey(<cryptography.hazmat.'), True)

    def test_public_key(self):
        from josepy.util import ComparableECKey
        self.assertIsInstance(self.p256_key.public_key(), ComparableECKey)


class ImmutableMapTest(unittest.TestCase):
    """Tests for josepy.util.ImmutableMap."""

    def setUp(self):
        # pylint: disable=invalid-name,too-few-public-methods
        # pylint: disable=missing-docstring
        from josepy.util import ImmutableMap

        class A(ImmutableMap):
            __slots__ = ('x', 'y')

        class B(ImmutableMap):
            __slots__ = ('x', 'y')

        self.A = A
        self.B = B

        self.a1 = self.A(x=1, y=2)
        self.a1_swap = self.A(y=2, x=1)
        self.a2 = self.A(x=3, y=4)
        self.b = self.B(x=1, y=2)

    def test_update(self):
        self.assertEqual(self.A(x=2, y=2), self.a1.update(x=2))
        self.assertEqual(self.a2, self.a1.update(x=3, y=4))

    def test_get_missing_item_raises_key_error(self):
        self.assertRaises(KeyError, self.a1.__getitem__, 'z')

    def test_order_of_args_does_not_matter(self):
        self.assertEqual(self.a1, self.a1_swap)

    def test_type_error_on_missing(self):
        self.assertRaises(TypeError, self.A, x=1)
        self.assertRaises(TypeError, self.A, y=2)

    def test_type_error_on_unrecognized(self):
        self.assertRaises(TypeError, self.A, x=1, z=2)
        self.assertRaises(TypeError, self.A, x=1, y=2, z=3)

    def test_get_attr(self):
        self.assertEqual(1, self.a1.x)
        self.assertEqual(2, self.a1.y)
        self.assertEqual(1, self.a1_swap.x)
        self.assertEqual(2, self.a1_swap.y)

    def test_set_attr_raises_attribute_error(self):
        self.assertRaises(
            AttributeError, functools.partial(self.a1.__setattr__, 'x'), 10)

    def test_equal(self):
        self.assertEqual(self.a1, self.a1)
        self.assertEqual(self.a2, self.a2)
        self.assertNotEqual(self.a1, self.a2)

    def test_hash(self):
        self.assertEqual(hash((1, 2)), hash(self.a1))

    def test_unhashable(self):
        self.assertRaises(TypeError, self.A(x=1, y={}).__hash__)

    def test_repr(self):
        self.assertEqual('A(x=1, y=2)', repr(self.a1))
        self.assertEqual('A(x=1, y=2)', repr(self.a1_swap))
        self.assertEqual('B(x=1, y=2)', repr(self.b))
        self.assertEqual("B(x='foo', y='bar')", repr(self.B(x='foo', y='bar')))


class frozendictTest(unittest.TestCase):  # pylint: disable=invalid-name
    """Tests for josepy.util.frozendict."""

    def setUp(self):
        from josepy.util import frozendict
        self.fdict = frozendict(x=1, y='2')

    def test_init_dict(self):
        from josepy.util import frozendict
        self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))

    def test_init_other_raises_type_error(self):
        from josepy.util import frozendict
        # specifically fail for generators...
        self.assertRaises(TypeError, frozendict, {'a': 'b'}.items())

    def test_len(self):
        self.assertEqual(2, len(self.fdict))

    def test_hash(self):
        self.assertIsInstance(hash(self.fdict), int)

    def test_getattr_proxy(self):
        self.assertEqual(1, self.fdict.x)
        self.assertEqual('2', self.fdict.y)

    def test_getattr_raises_attribute_error(self):
        self.assertRaises(AttributeError, self.fdict.__getattr__, 'z')

    def test_setattr_immutable(self):
        self.assertRaises(AttributeError, self.fdict.__setattr__, 'z', 3)

    def test_repr(self):
        self.assertEqual("frozendict(x=1, y='2')", repr(self.fdict))


if __name__ == '__main__':
    unittest.main()  # pragma: no cover

Directory Contents

Dirs: 2 × Files: 20

Name Size Perms Modified Actions
testdata DIR
- drwxr-xr-x 2025-04-13 08:21:05
Edit Download
- drwxr-xr-x 2025-04-13 08:21:05
Edit Download
1.40 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
2.20 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
762 B lrw-r--r-- 2021-09-09 21:33:18
Edit Download
463 B lrw-r--r-- 2021-09-09 21:33:18
Edit Download
7.51 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
3.51 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
15.35 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
13.83 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
8.17 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
8.80 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
13.12 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
12.69 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
13.84 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
8.32 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
529 B lrw-r--r-- 2021-09-09 21:33:18
Edit Download
1.05 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
2.57 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
8.37 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
8.15 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download
1.66 KB lrw-r--r-- 2021-09-09 21:33:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 REDROOM — Secure File Manager. All rights reserved. Built with ❤️ & Red Dark UI