|
1 | 1 | var ASSERT = require('assert'); |
| 2 | +var JSBN = require('../../lib/jsbn'); |
2 | 3 |
|
3 | | -(function() { |
4 | | - if(typeof process === 'undefined' || |
5 | | - !process.versions || !process.versions.node) { |
6 | | - return; |
7 | | - } |
8 | | - |
9 | | - var moduleRequire = module.require ? module.require.bind(module) : require; |
10 | | - var PATH = moduleRequire('path'); |
11 | | - var spawnSync = moduleRequire('child_process').spawnSync; |
12 | | - |
13 | | - describe('jsbn', function() { |
14 | | - it('should return 0 for BigInteger(0).modInverse(3) without hanging', function() { |
15 | | - var script = [ |
16 | | - 'var JSBN = require("./lib/jsbn");', |
17 | | - 'var BigInteger = JSBN.BigInteger;', |
18 | | - 'var zero = new BigInteger("0", 10);', |
19 | | - 'var mod = new BigInteger("3", 10);', |
20 | | - 'var inv = zero.modInverse(mod);', |
21 | | - 'process.stdout.write(inv.toString());' |
22 | | - ].join('\n'); |
23 | | - |
24 | | - var result = spawnSync(process.execPath, ['-e', script], { |
25 | | - cwd: PATH.join(__dirname, '../..'), |
26 | | - encoding: 'utf8', |
27 | | - timeout: 2000 |
28 | | - }); |
29 | | - |
30 | | - if(result.error) { |
31 | | - if(result.error.code === 'EPERM') { |
32 | | - this.skip(); |
33 | | - return; |
34 | | - } |
35 | | - if(result.error.code === 'ETIMEDOUT') { |
36 | | - ASSERT.fail('BigInteger(0).modInverse(3) timed out.'); |
37 | | - } |
38 | | - throw result.error; |
39 | | - } |
40 | | - |
41 | | - ASSERT.equal(result.status, 0, result.stderr); |
42 | | - ASSERT.equal(result.stdout, '0'); |
| 4 | +describe.only('jsbn', function() { |
| 5 | + describe('GHSA-5m6q-g25r-mvwx', function() { |
| 6 | + // regression tests for GHSA-5m6q-g25r-mvwx |
| 7 | + // test BigInteger.modInverse does not infinite loop with 0 inputs. |
| 8 | + var BigInteger = JSBN.BigInteger; |
| 9 | + it('should test BigInteger(0).modInverse(0) returns 0', function() { |
| 10 | + var n = BigInteger.ZERO; |
| 11 | + var mod = BigInteger.ZERO; |
| 12 | + var inv = n.modInverse(mod); |
| 13 | + ASSERT(inv.equals(BigInteger.ZERO)); |
| 14 | + }); |
| 15 | + it('should test BigInteger(0).modInverse(3) returns 0', function() { |
| 16 | + var n = BigInteger.ZERO; |
| 17 | + var mod = new BigInteger('3', 10); |
| 18 | + var inv = n.modInverse(mod); |
| 19 | + ASSERT(inv.equals(BigInteger.ZERO)); |
| 20 | + }); |
| 21 | + it('should test BigInteger(3).modInverse(0) returns 0', function() { |
| 22 | + var n = new BigInteger('3', 10); |
| 23 | + var mod = BigInteger.ZERO; |
| 24 | + var inv = n.modInverse(mod); |
| 25 | + ASSERT(inv.equals(BigInteger.ZERO)); |
| 26 | + }); |
| 27 | + it('should test BigInteger(3).modInverse(3) returns 0', function() { |
| 28 | + var n = new BigInteger('3', 10); |
| 29 | + var mod = new BigInteger('3', 10); |
| 30 | + var inv = n.modInverse(mod); |
| 31 | + ASSERT(inv.equals(BigInteger.ZERO)); |
| 32 | + }); |
| 33 | + it('should test BigInteger(7).modInverse(20) returns 3', function() { |
| 34 | + var n = new BigInteger('7', 10); |
| 35 | + var mod = new BigInteger('20', 10); |
| 36 | + var inv = n.modInverse(mod); |
| 37 | + ASSERT(inv.equals(new BigInteger('3', 10))); |
43 | 38 | }); |
44 | 39 | }); |
45 | | -})(); |
| 40 | +}); |
0 commit comments