summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJay Doane <jay.s.doane@gmail.com>2017-05-24 09:37:01 -0700
committerRobert Newson <rnewson@apache.org>2017-05-24 17:37:01 +0100
commit5b31b0d79aa2c0fefefb0b35e2e3fab9822eca94 (patch)
tree8866106bd4ac5da18079a46f0fb43b00bf56be2e /src
parentceeb019ebbc1d6aadb44b7f55d112e806403ce53 (diff)
downloadcouchdb-5b31b0d79aa2c0fefefb0b35e2e3fab9822eca94.tar.gz
Improve pubkey not found error handling (#4)
* Improve pubkey not found error handling When the public key identified by the {Alg, KID} tuple is not found on the IAM keystore server, it's possible to see errors like: (node1@127.0.0.1)140> epep:jwt_decode(SampleJWT). ** exception error: no function clause matching public_key:do_verify(<<"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTcwNTIwLTAwOjAwOjAwIn0.eyJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjEyMzIx"...>>, sha256, <<229,188,162,247,201,233,118,32,115,206,156, 169,17,221,78,157,161,147,46,179,42,219,66, 15,139,91,...>>, {error,not_found}) (public_key.erl, line 782) in function jwtf:public_key_verify/4 (src/jwtf.erl, line 212) in call from jwtf:decode/3 (src/jwtf.erl, line 30) Modify key/1 and public_key_not_found_test/0 to account for keystore changing from returning an error tuple to throwing one.
Diffstat (limited to 'src')
-rw-r--r--src/jwtf.erl9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/jwtf.erl b/src/jwtf.erl
index ae1b95a2b..78b36a9c3 100644
--- a/src/jwtf.erl
+++ b/src/jwtf.erl
@@ -360,6 +360,15 @@ missing_kid_test() ->
?assertEqual({error, missing_kid}, decode(Encoded, [kid], nil)).
+public_key_not_found_test() ->
+ Encoded = encode(
+ {[{<<"alg">>, <<"RS256">>}, {<<"kid">>, <<"1">>}]},
+ {[]}),
+ KS = fun(_, _) -> throw({error, not_found}) end,
+ Expected = {error, not_found},
+ ?assertEqual(Expected, decode(Encoded, [], KS)).
+
+
bad_rs256_sig_test() ->
Encoded = encode(
{[{<<"typ">>, <<"JWT">>}, {<<"alg">>, <<"RS256">>}]},