From 2058f8a1ebba539f5c294ce54f109066e378d2af Mon Sep 17 00:00:00 2001 From: co98357 <210502954+co98357@users.noreply.github.com> Date: Fri, 23 May 2025 11:28:39 +0100 Subject: [PATCH 1/5] Change to JWT Decode to include header --- src/core/operations/JWTDecode.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/JWTDecode.mjs b/src/core/operations/JWTDecode.mjs index b6356b5a..116fcad6 100644 --- a/src/core/operations/JWTDecode.mjs +++ b/src/core/operations/JWTDecode.mjs @@ -46,8 +46,8 @@ class JWTDecode extends Operation { json: true, complete: true }); - - return decoded.payload; + + return {header: decoded.header, payload: decoded.payload}; } catch (err) { throw new OperationError(err); } From 7adb820c400d75c7d53d7507c2dcb330b34d333c Mon Sep 17 00:00:00 2001 From: co98357 <210502954+co98357@users.noreply.github.com> Date: Fri, 23 May 2025 12:14:14 +0100 Subject: [PATCH 2/5] Adding in tests and changing formatting --- src/core/operations/JWTDecode.mjs | 20 ++++++-- tests/operations/tests/JWTDecode.mjs | 75 ++++++++++++++++++++++++++++ tests/operations/tests/JWTSign.mjs | 12 ++--- 3 files changed, 98 insertions(+), 9 deletions(-) diff --git a/src/core/operations/JWTDecode.mjs b/src/core/operations/JWTDecode.mjs index 116fcad6..af574e78 100644 --- a/src/core/operations/JWTDecode.mjs +++ b/src/core/operations/JWTDecode.mjs @@ -25,7 +25,13 @@ class JWTDecode extends Operation { this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token"; this.inputType = "string"; this.outputType = "JSON"; - this.args = []; + this.args = [ + { + name: "Include header", + type: "boolean", + value: false + } + ]; this.checks = [ { pattern: "^ey([A-Za-z0-9_-]+)\\.ey([A-Za-z0-9_-]+)\\.([A-Za-z0-9_-]+)$", @@ -42,12 +48,20 @@ class JWTDecode extends Operation { */ run(input, args) { try { + const headerInclude = args[0]; + const decoded = jwt.decode(input, { json: true, complete: true }); - - return {header: decoded.header, payload: decoded.payload}; + if (headerInclude) + { + return {header: decoded.header, payload: decoded.payload}; + } + else + { + return decoded.payload; + } } catch (err) { throw new OperationError(err); } diff --git a/tests/operations/tests/JWTDecode.mjs b/tests/operations/tests/JWTDecode.mjs index 1ef47f81..c181b975 100644 --- a/tests/operations/tests/JWTDecode.mjs +++ b/tests/operations/tests/JWTDecode.mjs @@ -14,6 +14,18 @@ const outputObject = JSON.stringify({ iat: 1 }, null, 4); +const outputWithHeaderObject = JSON.stringify({ + header: { + alg: "algorithm", + typ: "algo" + }, + payload: { + String: "SomeString", + Number: 42, + iat: 1 + } +}, null, 4); + TestRegister.addTests([ { name: "JWT Decode: HS", @@ -47,5 +59,68 @@ TestRegister.addTests([ args: [], } ], + }, + { + name: "JWT Decode: HS", + input: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.0ha6-j4FwvEIKPVZ-hf3S_R9Hy_UtXzq4dnedXcUrXk", + expectedOutput: JSON.stringify({ + header: { + alg: "HS256", + typ: "JWT" + }, + payload: { + String: "SomeString", + Number: 42, + iat: 1 + } + }, null, 4), + recipeConfig: [ + { + op: "JWT Decode", + args: [true], + } + ], + }, + { + name: "JWT Decode: RS", + input: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.MjEJhtZk2nXzigi24piMzANmrj3mILHJcDl0xOjl5a8EgdKVL1oaMEjTkMQp5RA8YrqeRBFaX-BGGCKOXn5zPY1DJwWsBUyN9C-wGR2Qye0eogH_3b4M9EW00TPCUPXm2rx8URFj7Wg9VlsmrGzLV2oKkPgkVxuFSxnpO3yjn1Y", + expectedOutput: JSON.stringify({ + header: { + alg: "RS256", + typ: "JWT" + }, + payload: { + String: "SomeString", + Number: 42, + iat: 1 + } + }, null, 4), + recipeConfig: [ + { + op: "JWT Decode", + args: [true], + } + ], + }, + { + name: "JWT Decode: ES", + input: "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.WkECT51jSfpRkcpQ4x0h5Dwe7CFBI6u6Et2gWp91HC7mpN_qCFadRpsvJLtKubm6cJTLa68xtei0YrDD8fxIUA", + expectedOutput: JSON.stringify({ + header: { + alg: "ES256", + typ: "JWT" + }, + payload: { + String: "SomeString", + Number: 42, + iat: 1 + } + }, null, 4), + recipeConfig: [ + { + op: "JWT Decode", + args: [true], + } + ], } ]); diff --git a/tests/operations/tests/JWTSign.mjs b/tests/operations/tests/JWTSign.mjs index a7752138..77483785 100644 --- a/tests/operations/tests/JWTSign.mjs +++ b/tests/operations/tests/JWTSign.mjs @@ -92,7 +92,7 @@ TestRegister.addTests([ }, { op: "JWT Decode", - args: [] + args: [false] } ], }, @@ -107,7 +107,7 @@ TestRegister.addTests([ }, { op: "JWT Decode", - args: [] + args: [false] } ], }, @@ -122,7 +122,7 @@ TestRegister.addTests([ }, { op: "JWT Decode", - args: [] + args: [false] } ], }, @@ -137,7 +137,7 @@ TestRegister.addTests([ }, { op: "JWT Decode", - args: [] + args: [false] } ], }, @@ -152,7 +152,7 @@ TestRegister.addTests([ }, { op: "JWT Decode", - args: [] + args: [false] } ], }, @@ -167,7 +167,7 @@ TestRegister.addTests([ }, { op: "JWT Decode", - args: [] + args: [false] } ], } From 04db463f812f70b7e32c6fedc130ae37d8b7de87 Mon Sep 17 00:00:00 2001 From: co98357 <210502954+co98357@users.noreply.github.com> Date: Fri, 23 May 2025 12:21:01 +0100 Subject: [PATCH 3/5] Formatting --- src/core/operations/JWTDecode.mjs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/core/operations/JWTDecode.mjs b/src/core/operations/JWTDecode.mjs index af574e78..67974a03 100644 --- a/src/core/operations/JWTDecode.mjs +++ b/src/core/operations/JWTDecode.mjs @@ -26,11 +26,11 @@ class JWTDecode extends Operation { this.inputType = "string"; this.outputType = "JSON"; this.args = [ - { - name: "Include header", - type: "boolean", - value: false - } + { + name: "Include header", + type: "boolean", + value: false + } ]; this.checks = [ { @@ -54,12 +54,9 @@ class JWTDecode extends Operation { json: true, complete: true }); - if (headerInclude) - { + if (headerInclude){ return {header: decoded.header, payload: decoded.payload}; - } - else - { + }else{ return decoded.payload; } } catch (err) { From e3a4f4cc85e66a28077bf2d3b4c761a27d21d22f Mon Sep 17 00:00:00 2001 From: co98357 <210502954+co98357@users.noreply.github.com> Date: Fri, 23 May 2025 12:28:33 +0100 Subject: [PATCH 4/5] Formatting --- src/core/operations/JWTDecode.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/JWTDecode.mjs b/src/core/operations/JWTDecode.mjs index 67974a03..55941f4e 100644 --- a/src/core/operations/JWTDecode.mjs +++ b/src/core/operations/JWTDecode.mjs @@ -54,9 +54,9 @@ class JWTDecode extends Operation { json: true, complete: true }); - if (headerInclude){ + if (headerInclude) { return {header: decoded.header, payload: decoded.payload}; - }else{ + } else { return decoded.payload; } } catch (err) { From 5f185a364824bfe021eb68724d74ec206f2c6f47 Mon Sep 17 00:00:00 2001 From: co98357 <210502954+co98357@users.noreply.github.com> Date: Fri, 23 May 2025 12:30:43 +0100 Subject: [PATCH 5/5] Formatting --- tests/operations/tests/JWTDecode.mjs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/operations/tests/JWTDecode.mjs b/tests/operations/tests/JWTDecode.mjs index c181b975..4d915d6d 100644 --- a/tests/operations/tests/JWTDecode.mjs +++ b/tests/operations/tests/JWTDecode.mjs @@ -14,18 +14,6 @@ const outputObject = JSON.stringify({ iat: 1 }, null, 4); -const outputWithHeaderObject = JSON.stringify({ - header: { - alg: "algorithm", - typ: "algo" - }, - payload: { - String: "SomeString", - Number: 42, - iat: 1 - } -}, null, 4); - TestRegister.addTests([ { name: "JWT Decode: HS", @@ -60,7 +48,7 @@ TestRegister.addTests([ } ], }, - { + { name: "JWT Decode: HS", input: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.0ha6-j4FwvEIKPVZ-hf3S_R9Hy_UtXzq4dnedXcUrXk", expectedOutput: JSON.stringify({