Skip to content

Commit ac9761f

Browse files
authored
Merge pull request #11 from gchq/enforce-required-args
Enforce required args
2 parents 7b6b3d9 + b39d1c5 commit ac9761f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ typings/
6060
# next.js build output
6161
.next
6262

63-
.vscode
63+
.vscode/*

lib/errorHandler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { OperationError } from "cyberchef/src/node/index.mjs";
2+
3+
14
/**
25
* errorHandler
36
*
@@ -14,7 +17,7 @@ export default function errorHandler(err, req, res, next) {
1417
return next(err);
1518
}
1619

17-
if (err instanceof TypeError) {
20+
if (err instanceof TypeError || err instanceof OperationError) {
1821
res.status(400).send(err.message).end();
1922
} else {
2023
res.status(500).send(err.stack).end();

test/bake.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,21 @@ describe("POST /bake", function() {
105105
.expect("begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something", done);
106106
});
107107

108+
it("should return a useful error if we give an input/recipe combination that results in an OperationError", (done) => {
109+
request(app)
110+
.post("/bake")
111+
.set("Content-Type", "application/json")
112+
.send({
113+
input: "irrelevant",
114+
recipe: {
115+
op: "AES Encrypt",
116+
args: {
117+
key: "notsixteencharslong"
118+
}
119+
}
120+
})
121+
.expect(400)
122+
.expect("Invalid key length: 2 bytes\n\nThe following algorithms will be used based on the size of the key:\n 16 bytes = AES-128\n 24 bytes = AES-192\n 32 bytes = AES-256", done);
123+
});
124+
108125
});

0 commit comments

Comments
 (0)