Skip to content

Commit 16d7060

Browse files
Flarnarvagg
authored andcommittedNov 28, 2018
crypto: allow monkey patching of pseudoRandomBytes
Make `pseudoRandomBytes` and it's aliases `prng` and `rng` configurable to allow monkey patching. PR-URL: #24108 Refs: #22519 Refs: #23017 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 091238a commit 16d7060

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎lib/crypto.js

+6
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,25 @@ Object.defineProperties(exports, {
247247
// The ecosystem needs those to exist for backwards compatibility.
248248
prng: {
249249
enumerable: false,
250+
configurable: true,
251+
writable: true,
250252
value: pendingDeprecation ?
251253
deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') :
252254
randomBytes
253255
},
254256
pseudoRandomBytes: {
255257
enumerable: false,
258+
configurable: true,
259+
writable: true,
256260
value: pendingDeprecation ?
257261
deprecate(randomBytes,
258262
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') :
259263
randomBytes
260264
},
261265
rng: {
262266
enumerable: false,
267+
configurable: true,
268+
writable: true,
263269
value: pendingDeprecation ?
264270
deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') :
265271
randomBytes

‎test/parallel/test-crypto-random.js

+9
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,12 @@ assert.throws(
306306
}
307307
);
308308
});
309+
310+
311+
['pseudoRandomBytes', 'prng', 'rng'].forEach((f) => {
312+
const desc = Object.getOwnPropertyDescriptor(crypto, f);
313+
assert.ok(desc);
314+
assert.strictEqual(desc.configurable, true);
315+
assert.strictEqual(desc.writable, true);
316+
assert.strictEqual(desc.enumerable, false);
317+
});

0 commit comments

Comments
 (0)