diff options
author | 2023-07-19 20:01:36 -0300 | |
---|---|---|
committer | 2023-07-19 16:01:36 -0700 | |
commit | 2fbf73535c744ede4ee70d56399f8fe8ec22d405 (patch) | |
tree | 6ed41c60ba13e21a771bc7475ad2cde201ed9955 /test/js | |
parent | ebbbd63ed663b3492a2676badf2546aec3085774 (diff) | |
download | bun-2fbf73535c744ede4ee70d56399f8fe8ec22d405.tar.gz bun-2fbf73535c744ede4ee70d56399f8fe8ec22d405.tar.zst bun-2fbf73535c744ede4ee70d56399f8fe8ec22d405.zip |
fix createDecipheriv (#3680)
* fix createDecipheriv
* fix createDecipheriv iv and password validations
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/node/crypto/node-crypto.test.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js index 8db87d9f3..9fff88b5d 100644 --- a/test/js/node/crypto/node-crypto.test.js +++ b/test/js/node/crypto/node-crypto.test.js @@ -203,3 +203,21 @@ it("hash regression #2110", () => { var s = "6fbf7e2948e0c2f29eaacac1733546a4af5ca482"; expect(crypto.createHash("sha1").update(s, "binary").digest("hex")).toBe("e7c8b3c6f114c523d07ee355c534ee9bef3c044b"); }); + +// https://github.com/oven-sh/bun/issues/3680 +it("createDecipheriv should validate iv and password", () => { + const key = Buffer.alloc(16); + + expect(() => crypto.createDecipheriv("aes-128-ecb", key, undefined).setAutoPadding(false)).toThrow(); + expect(() => crypto.createDecipheriv("aes-128-ecb", key).setAutoPadding(false)).toThrow(); + expect(() => crypto.createDecipheriv("aes-128-ecb", key, null).setAutoPadding(false)).not.toThrow(); + expect(() => + crypto.createDecipheriv("aes-128-ecb", Buffer.from("Random", "utf8"), null).setAutoPadding(false), + ).toThrow(); + expect(() => crypto.createDecipheriv("aes-128-ecb", key, Buffer.alloc(0)).setAutoPadding(false)).not.toThrow(); + + expect(() => crypto.createDecipheriv("aes-128-cbc", key, undefined).setAutoPadding(false)).toThrow(); + expect(() => crypto.createDecipheriv("aes-128-cbc", key, null).setAutoPadding(false)).toThrow(); + expect(() => crypto.createDecipheriv("aes-128-cbc", key).setAutoPadding(false)).toThrow(); + expect(() => crypto.createDecipheriv("aes-128-cbc", key, Buffer.alloc(16)).setAutoPadding(false)).not.toThrow(); +}); |