diff options
author | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
commit | 99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch) | |
tree | e663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /school/node_modules/node-forge/nodejs/test/random.js | |
parent | 9871b03912fc28ad38b4037ebf26a78aa937baba (diff) | |
download | pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2 pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip |
Update - This is an automated commit
Diffstat (limited to 'school/node_modules/node-forge/nodejs/test/random.js')
-rw-r--r-- | school/node_modules/node-forge/nodejs/test/random.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/school/node_modules/node-forge/nodejs/test/random.js b/school/node_modules/node-forge/nodejs/test/random.js new file mode 100644 index 0000000..efeec2b --- /dev/null +++ b/school/node_modules/node-forge/nodejs/test/random.js @@ -0,0 +1,70 @@ +(function() { + +function Tests(ASSERT, RANDOM, UTIL) { + var random = RANDOM(); + + describe('random', function() { + it('should generate 10 random bytes', function() { + random.getBytes(16); + random.getBytes(24); + random.getBytes(32); + + var b = random.getBytes(10); + ASSERT.equal(b.length, 10); + }); + + it('should use a synchronous seed file', function() { + var rand = RANDOM(); + rand.seedFileSync = function(needed) { + return UTIL.fillString('a', needed); + }; + var b = rand.getBytes(10); + ASSERT.equal(UTIL.bytesToHex(b), '80a7901a239c3e606319'); + }); + + it('should use an asynchronous seed file', function(done) { + var rand = RANDOM(); + rand.seedFile = function(needed, callback) { + callback(null, UTIL.fillString('a', needed)); + }; + rand.getBytes(10, function(err, b) { + ASSERT.equal(err, null); + ASSERT.equal(UTIL.bytesToHex(b), '80a7901a239c3e606319'); + done(); + }); + }); + + it('should collect some random bytes', function() { + var rand = RANDOM(); + rand.seedFileSync = function(needed) { + return UTIL.fillString('a', needed); + }; + rand.collect('bbb'); + var b = rand.getBytes(10); + ASSERT.equal(UTIL.bytesToHex(b), 'ff8d213516047c94ca46'); + }); + }); +} + +// check for AMD +if(typeof define === 'function') { + define([ + 'forge/random', + 'forge/util' + ], function(RANDOM, UTIL) { + Tests( + // Global provided by test harness + ASSERT, + RANDOM, + UTIL() + ); + }); +} else if(typeof module === 'object' && module.exports) { + // assume NodeJS + Tests( + require('assert'), + require('../../js/random'), + require('../../js/util')()); +} + +})(); |