From 836ec0ebf3a73b7612bc6351f0cfc326cb71470b Mon Sep 17 00:00:00 2001 From: Vladislav Hristov Date: Fri, 1 Nov 2019 13:49:59 +0200 Subject: [PATCH] fit(tests): use new Key in keys test --- test/keys.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/test/keys.js b/test/keys.js index c9736e1..b911f3d 100644 --- a/test/keys.js +++ b/test/keys.js @@ -2,16 +2,16 @@ const { assert } = require('chai'); const fixtures = require('./fixtures/keys'); -const Key = require('../lib/keymanagers/keyRSA'); +// const Key = require('../lib/keymanagers/keyRSA'); +const Key = require('../lib/keymanagers/Key'); const stripWhitespace = str => str.replace(/\s+/g, ''); describe('Keys management', () => { describe('generates brand new', () => { const keySize = 2048; - const newKey = Key().generate(keySize); - - // newKey.key = Key().generate(keySize); + // const newKey = Key().generate(keySize); + const newKey = Key.generate(); it('private key', () => { assert.isTrue(newKey.isPrivate()); @@ -29,14 +29,16 @@ describe('Keys management', () => { describe('that are strings', () => { const m = Buffer.from(mod.string, 'base64'); const e = Buffer.from(exp.string, 'base64'); - const newKey = Key().importKey({ + /* const newKey = Key().importKey({ mod: m, exp: e, modulus: mod.string, exponent: exp.string, - }); + }); */ + const newKey = new Key({ mod: m, exp: e }); it('and is really public', () => { assert.isTrue(newKey.isPublic()); }); + it('and has a propper mod in bytes', () => { assert.deepEqual([...newKey.n()], mod.bytes); }); @@ -49,9 +51,10 @@ describe('Keys management', () => { describe('that are bytes', () => { const m = Buffer.from(mod.bytes); const e = Buffer.from(exp.bytes); - const newKey = Key().importKey({ + /* const newKey = Key().importKey({ mod: m, exp: e, modulus: mod.string, exponent: exp.string, - }); + }); */ + const newKey = new Key({ mod: m, exp: e }); it('and is really public', () => { assert.isTrue(newKey.isPublic()); @@ -68,18 +71,19 @@ describe('Keys management', () => { }); describe('creates public key from pem string', () => { - const { pem, mod, exp } = fixtures.pblc.big; - const newKey = Key(pem); + const { pem } = fixtures.pblc.big; + // const newKey = Key(pem); + const newKey = new Key({ pem }); it('and is really public', () => { assert.isTrue(newKey.isPublic()); }); it('and has a propper(the same) pem string', () => { - newKey.pempem = { + /* newKey.pempem = { modulus: mod.string, exponent: exp.string, - }; + }; */ assert.equal(stripWhitespace(newKey.toPem()), stripWhitespace(pem)); }); });