This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for different rsa crypto libs
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict' | ||
|
||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
chai.use(require('chai-string')) | ||
|
||
const LIBS = ['ursa', 'keypair'] | ||
|
||
describe('RSA crypto libs', function () { | ||
this.timeout(20 * 1000) | ||
|
||
LIBS.forEach(lib => { | ||
describe(lib, () => { | ||
let crypto | ||
let rsa | ||
|
||
before(() => { | ||
process.env.LP2P_FORCE_CRYPTO_LIB = lib | ||
|
||
for (const path in require.cache) { // clear module cache | ||
if (path.endsWith('.js')) { | ||
delete require.cache[path] | ||
} | ||
} | ||
|
||
crypto = require('../../src') | ||
rsa = crypto.keys.supportedKeys.rsa | ||
}) | ||
|
||
it('generates a valid key', (done) => { | ||
crypto.keys.generateKeyPair('RSA', 512, (err, key) => { | ||
if (err) { | ||
return done(err) | ||
} | ||
|
||
expect(key).to.be.an.instanceof(rsa.RsaPrivateKey) | ||
|
||
key.hash((err, digest) => { | ||
if (err) { | ||
return done(err) | ||
} | ||
|
||
expect(digest).to.have.length(34) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after(() => { | ||
for (const path in require.cache) { // clear module cache | ||
if (path.endsWith('.js')) { | ||
delete require.cache[path] | ||
} | ||
} | ||
|
||
delete process.env.LP2P_FORCE_CRYPTO_LIB | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
require('./keys/rsa-crypto-libs') |