Skip to content

Commit 4da5162

Browse files
committed
Add tests for EC and fix some RSA ones
1 parent 881c280 commit 4da5162

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

tests/test_03_key_bundle.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import responses
1010
from cryptography.hazmat.primitives.asymmetric import rsa
1111
from cryptojwt.jwk.ec import new_ec_key
12+
from cryptojwt.jwk.ec import ECKey
1213
from cryptojwt.jwk.hmac import SYMKey
1314
from cryptojwt.jwk.rsa import RSAKey
1415
from cryptojwt.jwk.rsa import import_rsa_key_from_cert_file
@@ -39,6 +40,7 @@ def full_path(local_file):
3940

4041
RSAKEY = os.path.join(BASE_PATH, "cert.key")
4142
RSA0 = os.path.join(BASE_PATH, "rsa.key")
43+
EC0 = os.path.join(BASE_PATH, 'ec.key')
4244
CERT = full_path("cert.pem")
4345

4446
JWK0 = {"keys": [
@@ -319,17 +321,27 @@ def test_get_all():
319321

320322
def test_keybundle_from_local_der():
321323
kb = keybundle_from_local_file(
322-
"{}".format(os.path.join(BASE_PATH, 'rsa.key')),
324+
"{}".format(RSA0),
323325
"der", ['enc'])
324326
assert len(kb) == 1
325327
keys = kb.get('rsa')
326328
assert len(keys) == 1
327329
assert isinstance(keys[0], RSAKey)
328330

329331

332+
def test_ec_keybundle_from_local_der():
333+
kb = keybundle_from_local_file(
334+
"{}".format(EC0),
335+
"der", ['enc'], keytype='EC')
336+
assert len(kb) == 1
337+
keys = kb.get('ec')
338+
assert len(keys) == 1
339+
assert isinstance(keys[0], ECKey)
340+
341+
330342
def test_keybundle_from_local_der_update():
331343
kb = keybundle_from_local_file(
332-
"file://{}".format(os.path.join(BASE_PATH, 'rsa.key')),
344+
"file://{}".format(RSA0),
333345
"der", ['enc'])
334346
assert len(kb) == 1
335347
keys = kb.get('rsa')

tests/test_04_key_jar.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test_keys"))
2424
RSAKEY = os.path.join(BASE_PATH, "cert.key")
2525
RSA0 = os.path.join(BASE_PATH, "rsa.key")
26+
EC0 = os.path.join(BASE_PATH, "ec.key")
2627
BASEDIR = os.path.abspath(os.path.dirname(__file__))
2728

2829

@@ -238,6 +239,42 @@ def test_build_keyjar_missing(tmpdir):
238239
assert len(key_jar[""]) == 1
239240

240241

242+
def test_build_RSA_keyjar_from_file(tmpdir):
243+
keys = [
244+
{
245+
"type": "RSA", "key": RSA0,
246+
"use": ["enc", "sig"]
247+
}]
248+
249+
key_jar = build_keyjar(keys)
250+
251+
assert len(key_jar[""]) == 1
252+
253+
254+
def test_build_EC_keyjar_missing(tmpdir):
255+
keys = [
256+
{
257+
"type": "EC", "key": os.path.join(tmpdir.dirname, "missing_file"),
258+
"use": ["enc", "sig"]
259+
}]
260+
261+
key_jar = build_keyjar(keys)
262+
263+
assert len(key_jar[""]) == 1
264+
265+
266+
def test_build_EC_keyjar_from_file(tmpdir):
267+
keys = [
268+
{
269+
"type": "EC", "key": EC0,
270+
"use": ["enc", "sig"]
271+
}]
272+
273+
key_jar = build_keyjar(keys)
274+
275+
assert len(key_jar[""]) == 1
276+
277+
241278
class TestKeyJar(object):
242279
def test_keyjar_add(self):
243280
kj = KeyJar()

tests/test_keys/ec.key

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN EC PRIVATE KEY-----
2+
MHcCAQEEIATa+jC26Vl3hw5oVDpiufCZuUOnvHdlaxW2VusNGKGqoAoGCCqGSM49
3+
AwEHoUQDQgAEoLqcipC3uBcQA7AfzSI5A9GrEpLl1fJsBPjukveTkOkL2Z5BI4Ja
4+
5eByAQku71nVtQQhZ9tnP2BR9IrBRK/KpQ==
5+
-----END EC PRIVATE KEY-----

0 commit comments

Comments
 (0)