def test_json_omitempty(self):
        protected_jobj = self.protected.to_partial_json(flat=True)
        unprotected_jobj = self.unprotected.to_partial_json(flat=True)

        self.assertTrue('protected' not in unprotected_jobj)
        self.assertTrue('header' not in protected_jobj)

        unprotected_jobj['header'] = unprotected_jobj['header'].to_json()

        from letsencrypt.acme.jose.jws import JWS
        self.assertEqual(JWS.from_json(protected_jobj), self.protected)
        self.assertEqual(JWS.from_json(unprotected_jobj), self.unprotected)
Beispiel #2
0
    def test_json_omitempty(self):
        protected_jobj = self.protected.to_partial_json(flat=True)
        unprotected_jobj = self.unprotected.to_partial_json(flat=True)

        self.assertTrue('protected' not in unprotected_jobj)
        self.assertTrue('header' not in protected_jobj)

        unprotected_jobj['header'] = unprotected_jobj['header'].to_json()

        from letsencrypt.acme.jose.jws import JWS
        self.assertEqual(JWS.from_json(protected_jobj), self.protected)
        self.assertEqual(JWS.from_json(unprotected_jobj), self.unprotected)
    def setUp(self):
        self.privkey = jwk.JWKRSA(key=RSA512_KEY)
        self.pubkey = self.privkey.public()

        from letsencrypt.acme.jose.jws import JWS
        self.unprotected = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256)
        self.protected = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['jwk', 'alg']))
        self.mixed = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['alg']))
Beispiel #4
0
    def setUp(self):
        self.privkey = jwk.JWKRSA(key=RSA512_KEY)
        self.pubkey = self.privkey.public()

        from letsencrypt.acme.jose.jws import JWS
        self.unprotected = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256)
        self.protected = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['jwk', 'alg']))
        self.mixed = JWS.sign(
            payload='foo', key=self.privkey, alg=jwa.RS256,
            protect=frozenset(['alg']))
    def test_json_not_flat(self):
        jobj_to = {
            'signatures': (self.mixed.signature,),
            'payload': b64.b64encode('foo'),
        }
        jobj_from = jobj_to.copy()
        jobj_from['signatures'] = [jobj_to['signatures'][0].to_json()]

        self.assertEqual(self.mixed.to_partial_json(flat=False), jobj_to)
        from letsencrypt.acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
Beispiel #6
0
    def test_json_not_flat(self):
        jobj_to = {
            'signatures': (self.mixed.signature, ),
            'payload': b64.b64encode('foo'),
        }
        jobj_from = jobj_to.copy()
        jobj_from['signatures'] = [jobj_to['signatures'][0].fully_serialize()]

        self.assertEqual(self.mixed.to_json(flat=False), jobj_to)
        from letsencrypt.acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
    def test_json_flat(self):
        jobj_to = {
            'signature': b64.b64encode(self.mixed.signature.signature),
            'payload': b64.b64encode('foo'),
            'header': self.mixed.signature.header,
            'protected': b64.b64encode(self.mixed.signature.protected),
        }
        jobj_from = jobj_to.copy()
        jobj_from['header'] = jobj_from['header'].to_json()

        self.assertEqual(self.mixed.to_partial_json(flat=True), jobj_to)
        from letsencrypt.acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
    def test_compact_lost_unprotected(self):
        compact = self.mixed.to_compact()
        self.assertEqual(
            'eyJhbGciOiAiUlMyNTYifQ.Zm9v.OHdxFVj73l5LpxbFp1AmYX4yJM0Pyb'
            '_893n1zQjpim_eLS5J1F61lkvrCrCDErTEJnBGOGesJ72M7b6Ve1cAJA',
            compact)

        from letsencrypt.acme.jose.jws import JWS
        mixed = JWS.from_compact(compact)

        self.assertNotEqual(self.mixed, mixed)
        self.assertEqual(
            set(['alg']), set(mixed.signature.combined.not_omitted()))
Beispiel #9
0
    def test_json_flat(self):
        jobj_to = {
            'signature': b64.b64encode(self.mixed.signature.signature),
            'payload': b64.b64encode('foo'),
            'header': self.mixed.signature.header,
            'protected': b64.b64encode(self.mixed.signature.protected),
        }
        jobj_from = jobj_to.copy()
        jobj_from['header'] = jobj_from['header'].fully_serialize()

        self.assertEqual(self.mixed.to_json(flat=True), jobj_to)
        from letsencrypt.acme.jose.jws import JWS
        self.assertEqual(self.mixed, JWS.from_json(jobj_from))
Beispiel #10
0
    def test_compact_lost_unprotected(self):
        compact = self.mixed.to_compact()
        self.assertEqual(
            'eyJhbGciOiAiUlMyNTYifQ.Zm9v.KBvYScRMEqJlp2xsReoY3CNDpVCWEU'
            '1PyRrf44nPBsmyQz__iuNR56pPNcACeHzJQnXhTVTxqFgjge2i_vw9NA',
            compact)

        from letsencrypt.acme.jose.jws import JWS
        mixed = JWS.from_compact(compact)

        self.assertNotEqual(self.mixed, mixed)
        self.assertEqual(set(['alg']),
                         set(mixed.signature.combined.not_omitted()))
Beispiel #11
0
    def test_compact_lost_unprotected(self):
        compact = self.mixed.to_compact()
        self.assertEqual(
            'eyJhbGciOiAiUlMyNTYifQ.Zm9v.KBvYScRMEqJlp2xsReoY3CNDpVCWEU'
            '1PyRrf44nPBsmyQz__iuNR56pPNcACeHzJQnXhTVTxqFgjge2i_vw9NA',
            compact)

        from letsencrypt.acme.jose.jws import JWS
        mixed = JWS.from_compact(compact)

        self.assertNotEqual(self.mixed, mixed)
        self.assertEqual(
            set(['alg']), set(mixed.signature.combined.not_omitted()))
 def test_from_json_hashable(self):
     from letsencrypt.acme.jose.jws import JWS
     hash(JWS.from_json(self.mixed.to_json()))
Beispiel #13
0
 def test_from_json_hashable(self):
     from letsencrypt.acme.jose.jws import JWS
     hash(JWS.from_json(self.mixed.to_json()))