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 acme.jose.jws import JWS self.assertEqual(JWS.from_json(protected_jobj), self.protected) self.assertEqual(JWS.from_json(unprotected_jobj), self.unprotected)
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 acme.jose.jws import JWS self.assertEqual(JWS.from_json(protected_jobj), self.protected) self.assertEqual(JWS.from_json(unprotected_jobj), self.unprotected)
def test_json_not_flat(self): jobj_to = {"signatures": (self.mixed.signature,), "payload": json_util.encode_b64jose(b"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 acme.jose.jws import JWS self.assertEqual(self.mixed, JWS.from_json(jobj_from))
def test_json_not_flat(self): jobj_to = { 'signatures': (self.mixed.signature, ), 'payload': json_util.encode_b64jose(b'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 acme.jose.jws import JWS self.assertEqual(self.mixed, JWS.from_json(jobj_from))
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 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 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 acme.jose.jws import JWS self.assertEqual(self.mixed, JWS.from_json(jobj_from))
def test_json_flat(self): jobj_to = { "signature": json_util.encode_b64jose(self.mixed.signature.signature), "payload": json_util.encode_b64jose(b"foo"), "header": self.mixed.signature.header, "protected": json_util.encode_b64jose(self.mixed.signature.protected.encode("utf-8")), } 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 acme.jose.jws import JWS self.assertEqual(self.mixed, JWS.from_json(jobj_from))
def test_from_json_hashable(self): from acme.jose.jws import JWS hash(JWS.from_json(self.mixed.to_json()))
def test_from_json_hashable(self): from acme.jose.jws import JWS hash(JWS.from_json(self.mixed.to_json()))