2018-08-29 23:43:10 +02:00
|
|
|
/**
|
|
|
|
* JWT Verify tests
|
|
|
|
*
|
|
|
|
* @author gchq77703 []
|
|
|
|
*
|
|
|
|
* @copyright Crown Copyright 2018
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
import TestRegister from "../../TestRegister";
|
|
|
|
|
|
|
|
const outputObject = JSON.stringify({
|
|
|
|
String: "SomeString",
|
|
|
|
Number: 42,
|
|
|
|
iat: 1
|
2018-08-31 15:58:06 +02:00
|
|
|
}, null, 4);
|
2018-08-29 23:43:10 +02:00
|
|
|
|
2018-08-31 15:58:06 +02:00
|
|
|
const invalidAlgorithm = "JsonWebTokenError: invalid algorithm";
|
2018-08-29 23:43:10 +02:00
|
|
|
|
|
|
|
const hsKey = "secret_cat";
|
|
|
|
const rsKey = `-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw
|
|
|
|
33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW
|
|
|
|
+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB
|
|
|
|
AoGAD+onAtVye4ic7VR7V50DF9bOnwRwNXrARcDhq9LWNRrRGElESYYTQ6EbatXS
|
|
|
|
3MCyjjX2eMhu/aF5YhXBwkppwxg+EOmXeh+MzL7Zh284OuPbkglAaGhV9bb6/5Cp
|
|
|
|
uGb1esyPbYW+Ty2PC0GSZfIXkXs76jXAu9TOBvD0ybc2YlkCQQDywg2R/7t3Q2OE
|
|
|
|
2+yo382CLJdrlSLVROWKwb4tb2PjhY4XAwV8d1vy0RenxTB+K5Mu57uVSTHtrMK0
|
|
|
|
GAtFr833AkEA6avx20OHo61Yela/4k5kQDtjEf1N0LfI+BcWZtxsS3jDM3i1Hp0K
|
|
|
|
Su5rsCPb8acJo5RO26gGVrfAsDcIXKC+bQJAZZ2XIpsitLyPpuiMOvBbzPavd4gY
|
|
|
|
6Z8KWrfYzJoI/Q9FuBo6rKwl4BFoToD7WIUS+hpkagwWiz+6zLoX1dbOZwJACmH5
|
|
|
|
fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523
|
|
|
|
Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP
|
|
|
|
FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==
|
|
|
|
-----END RSA PRIVATE KEY-----`;
|
|
|
|
const esKey = `-----BEGIN PRIVATE KEY-----
|
|
|
|
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2
|
|
|
|
OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r
|
|
|
|
1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G
|
|
|
|
-----END PRIVATE KEY-----`;
|
|
|
|
|
|
|
|
TestRegister.addTests([
|
|
|
|
{
|
2018-08-31 15:58:06 +02:00
|
|
|
name: "JWT Verify: HS",
|
2018-08-29 23:43:10 +02:00
|
|
|
input: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.0ha6-j4FwvEIKPVZ-hf3S_R9Hy_UtXzq4dnedXcUrXk",
|
|
|
|
expectedOutput: outputObject,
|
|
|
|
recipeConfig: [
|
|
|
|
{
|
|
|
|
op: "JWT Verify",
|
|
|
|
args: [hsKey],
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2018-08-31 15:58:06 +02:00
|
|
|
name: "JWT Verify: RS",
|
2018-08-29 23:43:10 +02:00
|
|
|
input: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.MjEJhtZk2nXzigi24piMzANmrj3mILHJcDl0xOjl5a8EgdKVL1oaMEjTkMQp5RA8YrqeRBFaX-BGGCKOXn5zPY1DJwWsBUyN9C-wGR2Qye0eogH_3b4M9EW00TPCUPXm2rx8URFj7Wg9VlsmrGzLV2oKkPgkVxuFSxnpO3yjn1Y",
|
|
|
|
expectedOutput: invalidAlgorithm,
|
|
|
|
recipeConfig: [
|
|
|
|
{
|
|
|
|
op: "JWT Verify",
|
|
|
|
args: [rsKey],
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2018-08-31 15:58:06 +02:00
|
|
|
name: "JWT Verify: ES",
|
2018-08-29 23:43:10 +02:00
|
|
|
input: "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.WkECT51jSfpRkcpQ4x0h5Dwe7CFBI6u6Et2gWp91HC7mpN_qCFadRpsvJLtKubm6cJTLa68xtei0YrDD8fxIUA",
|
|
|
|
expectedOutput: invalidAlgorithm,
|
|
|
|
recipeConfig: [
|
|
|
|
{
|
|
|
|
op: "JWT Verify",
|
|
|
|
args: [esKey],
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
]);
|