No need to override keystore in test due to support of multiple keystores

parent ee8a463b
Pipeline #28230 passed with stage
in 31 seconds
......@@ -60,37 +60,30 @@ vLu9XxKFHYlWPccluz3pqDfaGNPO12968DAldwvAV6hTGgx7oMaNPu0UltgD/aaj
(deftest unsign-jwt
(testing "Unsigns jwt and returns payload"
(is (= (with-redefs [clj-jwt/keystore (atom {"test-key" {:public-key ec-pubkey}})]
(clj-jwt/unsign (resource "jwks.json") signed-jwt))
(is (= (clj-jwt/unsign (resource "jwks.json") signed-jwt)
jwt-payload)))
(testing "Fails if key referenced in jwt header is not found"
(is (thrown? Exception
(with-redefs [clj-jwt/keystore (atom {})]
(clj-jwt/unsign (resource "jwks-other.json") signed-jwt))))))
(clj-jwt/unsign (resource "jwks-other.json") signed-jwt)))))
(deftest verify-jwt
(testing "Unsigns jwt and returns payload"
(is (= (with-redefs [clj-jwt/keystore (atom {"test-key" {:public-key ec-pubkey}})]
(clj-jwt/unsign (resource "jwks.json") signed-jwt))
(is (= (clj-jwt/unsign (resource "jwks.json") signed-jwt)
jwt-payload)))
(testing "Refetches keys if no matching keys found"
(is (= (with-redefs [clj-jwt/keystore (atom {})]
(clj-jwt/unsign (resource "jwks.json") signed-jwt))
(is (= (clj-jwt/unsign (resource "jwks.json") signed-jwt)
jwt-payload)))
(testing "Fails if key referenced in jwt head is not found"
(is (thrown? Exception
(with-redefs [clj-jwt/keystore (atom {})]
(clj-jwt/unsign (resource "jwks-other.json") signed-jwt))))))
(clj-jwt/unsign (resource "jwks-other.json") signed-jwt)))))
(deftest sign-claims
(testing "Signs claims and return a valid jwt"
(is (= (with-redefs [clj-jwt/keystore (atom {"test-key" {:private-key ec-privkey}})]
(clj-jwt/sign (resource "jwks.json") "test-key" {:sub "foo"}))
(is (= (clj-jwt/sign (resource "jwks.json") "test-key" {:sub "foo"})
"eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJmb28ifQ.PuYhFdk67n-DQHFjgMYeL2WBq1bLQ9yo-9CZulTIWjc_GqN66YuyM6kv1-aKlamH6ZPE3I4W20SgjQWpx84Fl9OuTG9YE6bKsbPCSDRb6w_fY8uWVh6vZpEj6yGL2_fpqdvg3cNK1qfD0x8V-dD24766LMKH1DzawPENer9WB-A")))
(testing "Fails if given key-id not in jwks resource"
(is (thrown? Exception (with-redefs [clj-jwt/keystore (atom {"test-key" {:private-key ec-privkey}})]
(clj-jwt/sign (resource "jwks.json") "no-such-key" {:sub "foo"}))))))
(is (thrown? Exception (clj-jwt/sign (resource "jwks.json") "no-such-key" {:sub "foo"})))))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment