Skip to content

Commit

Permalink
Vector test for RFC7515 JWS
Browse files Browse the repository at this point in the history
See: latchset#6
Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran committed Sep 29, 2016
1 parent 7523a13 commit 2629c0c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_jose.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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'

0 comments on commit 2629c0c

Please sign in to comment.