mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-14 10:14:53 -04:00
Adding in tests and changing formatting
This commit is contained in:
parent
2058f8a1eb
commit
7adb820c40
3 changed files with 98 additions and 9 deletions
|
@ -25,7 +25,13 @@ class JWTDecode extends Operation {
|
||||||
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
this.infoURL = "https://wikipedia.org/wiki/JSON_Web_Token";
|
||||||
this.inputType = "string";
|
this.inputType = "string";
|
||||||
this.outputType = "JSON";
|
this.outputType = "JSON";
|
||||||
this.args = [];
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Include header",
|
||||||
|
type: "boolean",
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
];
|
||||||
this.checks = [
|
this.checks = [
|
||||||
{
|
{
|
||||||
pattern: "^ey([A-Za-z0-9_-]+)\\.ey([A-Za-z0-9_-]+)\\.([A-Za-z0-9_-]+)$",
|
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) {
|
run(input, args) {
|
||||||
try {
|
try {
|
||||||
|
const headerInclude = args[0];
|
||||||
|
|
||||||
const decoded = jwt.decode(input, {
|
const decoded = jwt.decode(input, {
|
||||||
json: true,
|
json: true,
|
||||||
complete: true
|
complete: true
|
||||||
});
|
});
|
||||||
|
if (headerInclude)
|
||||||
return {header: decoded.header, payload: decoded.payload};
|
{
|
||||||
|
return {header: decoded.header, payload: decoded.payload};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return decoded.payload;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError(err);
|
throw new OperationError(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,18 @@ const outputObject = JSON.stringify({
|
||||||
iat: 1
|
iat: 1
|
||||||
}, null, 4);
|
}, null, 4);
|
||||||
|
|
||||||
|
const outputWithHeaderObject = JSON.stringify({
|
||||||
|
header: {
|
||||||
|
alg: "algorithm",
|
||||||
|
typ: "algo"
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
String: "SomeString",
|
||||||
|
Number: 42,
|
||||||
|
iat: 1
|
||||||
|
}
|
||||||
|
}, null, 4);
|
||||||
|
|
||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
name: "JWT Decode: HS",
|
name: "JWT Decode: HS",
|
||||||
|
@ -47,5 +59,68 @@ TestRegister.addTests([
|
||||||
args: [],
|
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],
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -92,7 +92,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -107,7 +107,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -122,7 +122,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -137,7 +137,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -152,7 +152,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -167,7 +167,7 @@ TestRegister.addTests([
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "JWT Decode",
|
op: "JWT Decode",
|
||||||
args: []
|
args: [false]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue