aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/crypto/node-crypto.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/node/crypto/node-crypto.test.js')
-rw-r--r--test/js/node/crypto/node-crypto.test.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js
index bf5414196..9bed5a47b 100644
--- a/test/js/node/crypto/node-crypto.test.js
+++ b/test/js/node/crypto/node-crypto.test.js
@@ -68,6 +68,7 @@ describe("createHash", () => {
s.end();
});
+
it("repeated calls doesnt segfault", () => {
function fn() {
crypto.createHash("sha1").update(Math.random(), "ascii").digest("base64");
@@ -75,6 +76,40 @@ describe("createHash", () => {
for (let i = 0; i < 10; i++) fn();
});
+
+ it("multiple calls to digest throws exception", () => {
+ const hash = crypto.createHash("sha256");
+ hash.update("hello world");
+ expect(hash.digest("hex")).toBe("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
+ expect(() => hash.digest("hex")).toThrow();
+ });
+
+ it("copy is the same", () => {
+ const hash = crypto.createHash("sha256");
+ hash.update("hello");
+ const copy = hash.copy();
+
+ expect(copy.digest("hex")).toBe(hash.digest("hex"));
+ });
+
+ it("copy is not linked", () => {
+ const hash = crypto.createHash("sha256");
+ hash.update("hello");
+ const copy = hash.copy();
+
+ hash.update("world");
+ expect(copy.digest("hex")).not.toBe(hash.digest("hex"));
+ });
+
+ it("copy updates the same", () => {
+ const hash = crypto.createHash("sha256");
+ hash.update("hello");
+ const copy = hash.copy();
+
+ hash.update("world");
+ copy.update("world");
+ expect(copy.digest("hex")).toBe(hash.digest("hex"));
+ });
});
it("crypto.createHmac", () => {