From 24548e3a48b99480a4005e744c28463bcef42609 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 9 Feb 2021 14:23:02 +0000 Subject: [PATCH] Tidied up JWT tests --- src/core/operations/JWTVerify.mjs | 4 +++- tests/operations/tests/JWTVerify.mjs | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/operations/JWTVerify.mjs b/src/core/operations/JWTVerify.mjs index ae698d42..604edc9c 100644 --- a/src/core/operations/JWTVerify.mjs +++ b/src/core/operations/JWTVerify.mjs @@ -42,9 +42,11 @@ class JWTVerify extends Operation { */ run(input, args) { const [key] = args; + const algos = JWT_ALGORITHMS; + algos[algos.indexOf("None")] = "none"; try { - const verified = jwt.verify(input, key, { algorithms: JWT_ALGORITHMS }); + const verified = jwt.verify(input, key, { algorithms: algos }); if (Object.prototype.hasOwnProperty.call(verified, "name") && verified.name === "JsonWebTokenError") { throw new OperationError(verified.message); diff --git a/tests/operations/tests/JWTVerify.mjs b/tests/operations/tests/JWTVerify.mjs index 017bcf04..0a0817cc 100644 --- a/tests/operations/tests/JWTVerify.mjs +++ b/tests/operations/tests/JWTVerify.mjs @@ -14,11 +14,9 @@ const outputObject = JSON.stringify({ iat: 1 }, null, 4); -// const invalidAlgorithm = "JsonWebTokenError: invalid algorithm"; - const hsKey = "secret_cat"; /* Retaining private key as a comment -const rsKey = `-----BEGIN RSA PRIVATE KEY----- +const rsPriv = `-----BEGIN RSA PRIVATE KEY----- MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw 33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW +jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB @@ -41,7 +39,7 @@ HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D o2kQ+X5xK9cipRgEKwIDAQAB -----END PUBLIC KEY-----`; /* Retaining private key as a comment -const esKey = `-----BEGIN PRIVATE KEY----- +const esPriv = `-----BEGIN PRIVATE KEY----- MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2 OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r 1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G