def test_json(self): ''' nose2 jose.tests.test_jws.TestJwsMessage.test_json ''' plaintext = "This is a message to be signed by me" jku="https://me.com/jwkset" signer = TestEntity( identifier="https://me.com", jku=jku, ) msg = Message(payload=plaintext, sender=signer) for alg in SigDict.values(): alg = SigEnum.create(alg) msg.add_signature( sender=signer, protected=Jws(alg=alg, kid=None, jku=jku), header=Jws(typ="text"), ) json_msg = msg.serialize_json(indent=2) with open("/tmp/test_json.json", "w") as out: out.write(json_msg) msg2 = Message.from_token(json_msg, sender=signer) self.assertTrue(msg2.verify())
def test_compact(self): ''' nose2 jose.tests.test_jws.TestJwsMessage.test_compact''' jku="https://me.com/jwkset" signer = TestEntity( identifier="https://me.com", jku=jku, ) for alg in SigDict.values(): alg = SigEnum.create(alg) plaintext = "This is a message to be signed by %s" % alg.value msg = Message( payload=_BE(plaintext), sender=signer) msg.add_signature( sender=signer, protected=Jws(alg=alg, kid=None, jku=jku), header=Jws(typ="text"), ) token = msg.serialize_compact() msg2 = Message.from_token(token, sender=signer) print "TOKEN=", token self.assertTrue(msg2.verify())