Adding in tests and changing formatting

This commit is contained in:
co98357 2025-05-23 12:14:14 +01:00
parent 2058f8a1eb
commit 7adb820c40
3 changed files with 98 additions and 9 deletions

View file

@ -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);
}