From 25d59828ab7fef098713af0f57eeb23a3ec98eba Mon Sep 17 00:00:00 2001 From: Vladimir Ignatov Date: Mon, 18 Jan 2021 12:53:25 -0500 Subject: [PATCH] Fix tests --- tests/bulk_data.test.js | 21 ++++++++++++++------- token_handler.js | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/bulk_data.test.js b/tests/bulk_data.test.js index aee531c..a40cf9c 100644 --- a/tests/bulk_data.test.js +++ b/tests/bulk_data.test.js @@ -1,6 +1,7 @@ const request = require("request"); const base64url = require("base64-url"); const moment = require("moment"); +/** @type {any} */ const assert = require("assert"); const crypto = require("crypto"); const jwkToPem = require("jwk-to-pem"); @@ -2468,7 +2469,7 @@ describe("Error responses", () => { error: "invalid_grant", error_description: `No public keys found in the JWKS with "kid" equal to "${ jwks.keys[1].kid - }" and "kty" equal to "${jwks.keys[1].kty}"` + }"` }, 400); }) }); @@ -2520,7 +2521,7 @@ describe("Error responses", () => { } }); - return assertError({ + return lib.requestPromise({ method: "POST", json : true, url : tokenUrl, @@ -2530,11 +2531,17 @@ describe("Error responses", () => { client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", client_assertion : signed } - }, { - error: "invalid_grant", - error_description: `Unable to verify the token with any of the public keys found in the JWKS` - }, 400); - }) + }) + }).then( + () => { + throw new Error("This request should have failed"); + }, + result => { + assert.strictEqual(result.response.statusCode, 400); + assert.strictEqual(result.response.body.error, "invalid_grant", 'The "error" property should equal "invalid_grant"'); + assert.match(result.response.body.error_description, /^Unable to verify the token with any of the public keys found in the JWKS\b/); + } + ); }); it("returns 401 invalid_client if the id token contains {err:'token_invalid_token'}", () => { diff --git a/token_handler.js b/token_handler.js index 2f0b5ca..b70add5 100644 --- a/token_handler.js +++ b/token_handler.js @@ -292,5 +292,5 @@ module.exports = async (req, res) => { res.json(token); }) - .catch(e => res.end(e.toString())); + .catch(e => res.end(String(e || ""))); };