Skip to content

Commit 72dc685

Browse files
committed
Made sure init_key_jar created the necessary directories.
Test for the same.
1 parent a2d4a7e commit 72dc685

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/cryptojwt/key_jar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ def init_key_jar(public_path='', private_path='', key_defs='', owner=''):
800800

801801
if public_path:
802802
jwks = _kj.export_jwks(issuer=owner) # public part
803+
head, tail = os.path.split(public_path)
804+
if head and not os.path.isdir(head):
805+
os.makedirs(head)
803806
fp = open(public_path, 'w')
804807
fp.write(json.dumps(jwks))
805808
fp.close()

tests/test_04_key_jar.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import shutil
34
import time
45

56
import pytest
@@ -874,3 +875,21 @@ def test_init_key_jar_update():
874875

875876
assert len(_keyjar_3.get_signing_key('RSA')) == 1
876877
assert len(_keyjar_3.get_signing_key('EC')) == 2
878+
879+
880+
OIDC_KEYS = {
881+
'private_path': "{}/priv/jwks.json".format(BASEDIR),
882+
'key_defs': KEYSPEC,
883+
'public_path': '{}/public/jwks.json'.format(BASEDIR)
884+
}
885+
886+
887+
def test_init_key_jar_create_directories():
888+
# make sure the directories are gone
889+
for _dir in ['priv', 'public']:
890+
if os.path.isdir("{}/{}".format(BASEDIR, _dir)):
891+
shutil.rmtree("{}/{}".format(BASEDIR,_dir))
892+
893+
_keyjar = init_key_jar(**OIDC_KEYS)
894+
assert len(_keyjar.get_signing_key('RSA')) == 1
895+
assert len(_keyjar.get_signing_key('EC')) == 1

0 commit comments

Comments
 (0)