Skip to content

Commit

Permalink
crypto: allow monkey patching of pseudoRandomBytes
Browse files Browse the repository at this point in the history
Make `pseudoRandomBytes` and it's aliases `prng` and `rng`
configurable to allow monkey patching.

PR-URL: nodejs#24108
Refs: nodejs#22519
Refs: nodejs#23017
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Ujjwal Sharma <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Flarna authored and refack committed Jan 10, 2019
1 parent 4bd18a3 commit 6ad6588
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,25 @@ 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') :
randomBytes
},
rng: {
enumerable: false,
configurable: true,
writable: true,
value: pendingDeprecation ?
deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') :
randomBytes
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 6ad6588

Please sign in to comment.