Skip to content

Commit c31bd1e

Browse files
committed
test jwk_from_pem caches jwk object
1 parent 69a6fae commit c31bd1e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from oauth2_provider import utils
2+
3+
4+
def test_jwk_from_pem_caches_jwk():
5+
a_tiny_rsa_key = """-----BEGIN RSA PRIVATE KEY-----
6+
MGQCAQACEQCxqYaL6GtPooVMhVwcZrCfAgMBAAECECyNmdsuHvMqIEl9/Fex27kC
7+
CQDlc0deuSVrtQIJAMY4MTw2eCeDAgkA5VzfMykQ5yECCQCgkF4Zl0nHPwIJALPv
8+
+IAFUPv3
9+
-----END RSA PRIVATE KEY-----"""
10+
11+
# For the same private key we expect the same object to be returned
12+
13+
jwk1 = utils.jwk_from_pem(a_tiny_rsa_key)
14+
jwk2 = utils.jwk_from_pem(a_tiny_rsa_key)
15+
16+
assert jwk1 is jwk2
17+
18+
a_different_tiny_rsa_key = """-----BEGIN RSA PRIVATE KEY-----
19+
MGMCAQACEQCvyNNNw4J201yzFVogcfgnAgMBAAECEE3oXe5bNlle+xU4EVHTUIEC
20+
CQDpSvwIvDMSIQIJAMDk47DzG9FHAghtvg1TWpy3oQIJAL6NHlS+RBufAgkA6QLA
21+
2GK4aDc=
22+
-----END RSA PRIVATE KEY-----"""
23+
24+
# But for a different key, a different object
25+
jwk3 = utils.jwk_from_pem(a_different_tiny_rsa_key)
26+
27+
assert jwk3 is not jwk1

0 commit comments

Comments
 (0)