From 310b1ecaa0a7a1da0fc80412749b67435da372e5 Mon Sep 17 00:00:00 2001 From: Gerhard Stoebich Date: Mon, 5 Nov 2018 17:07:48 +0100 Subject: [PATCH] crypto: allow monkey patching of pseudoRandomBytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make `pseudoRandomBytes` and it's aliases `prng` and `rng` configurable to allow monkey patching. PR-URL: https://github.com/nodejs/node/pull/24108 Refs: https://github.com/nodejs/node/pull/22519 Refs: https://github.com/nodejs/node/pull/23017 Reviewed-By: Sam Roberts Reviewed-By: Tobias Nießen Reviewed-By: Ujjwal Sharma Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Vladimir de Turckheim Reviewed-By: James M Snell --- lib/crypto.js | 6 ++++++ test/parallel/test-crypto-random.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/crypto.js b/lib/crypto.js index f6c5b7313b69af..cce9bfea86f61a 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -247,12 +247,16 @@ Object.defineProperties(exports, { // The ecosystem needs those to exist for backwards compatibility. prng: { enumerable: false, + configurable: true, + writable: true, value: pendingDeprecation ? deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') : randomBytes }, pseudoRandomBytes: { enumerable: false, + configurable: true, + writable: true, value: pendingDeprecation ? deprecate(randomBytes, 'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') : @@ -260,6 +264,8 @@ Object.defineProperties(exports, { }, rng: { enumerable: false, + configurable: true, + writable: true, value: pendingDeprecation ? deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') : randomBytes diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index df06134e4326f9..4c85545b4e40b1 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -306,3 +306,12 @@ assert.throws( } ); }); + + +['pseudoRandomBytes', 'prng', 'rng'].forEach((f) => { + const desc = Object.getOwnPropertyDescriptor(crypto, f); + assert.ok(desc); + assert.strictEqual(desc.configurable, true); + assert.strictEqual(desc.writable, true); + assert.strictEqual(desc.enumerable, false); +});