diff --git a/tests/test_jose.py b/tests/test_jose.py index 6d0ebf9..d6255e2 100644 --- a/tests/test_jose.py +++ b/tests/test_jose.py @@ -1,7 +1,11 @@ +import json +import os import unittest import jose +HERE = os.path.dirname(os.path.abspath(__file__)) + class JoseTests(unittest.TestCase): def test_jwk_generate(self): @@ -25,3 +29,32 @@ def test_jwk_thumbprint(self): u'k': u'cVoUQRUE5rk3V2YbqZG38Q'} self.assertEqual(jose.jwk_thumbprint(jwk), 'lUPQ1EXWqsVivPRUWgUssyOULBw') + + +class JoseVectorTests(unittest.TestCase): + def json_vector(self, name): + filename = os.path.join(HERE, 'vectors', name) + with open(filename) as f: + js = json.load(f) + self.assertIsInstance(js, dict) + return js + + def compact_vector(self, name): + filename = os.path.join(HERE, 'vectors', name) + with open(filename) as f: + data = f.read() + js = jose.from_compact(data) + self.assertIsInstance(js, dict) + self.assertEqual(jose.to_compact(js), data) + return js + + def test_jws_rfc7515(self): + names = ['rfc7515_A.1', 'rfc7515_A.2', 'rfc7515_A.3', 'rfc7515_A.4'] + for name in names: + jws = self.compact_vector(name + '.jwsc') + jwk = self.json_vector(name + '.jwk') + self.assertTrue(jose.jws_verify(jws, jwk), name) + # 'rfc7515_A.5' not supported + # 'rfc7515_A.6' + # 'rfc7515_A.7' + # 'rfc7515_B'