-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FABN-1391] Refactor cryptosuite tape UT
- Created new User, Utils, CryptoSuite UTs - migrated constants to TestUtils - Also removed a duplicate test Signed-off-by: heatherlp <[email protected]> Change-Id: Iad69240a46a38c2dd4e7e45ec0b94649f48ae6fb
- Loading branch information
Showing
10 changed files
with
475 additions
and
543 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
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
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,99 @@ | ||
/** | ||
* Copyright 2019 IBM All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
'use strict'; | ||
|
||
const {Utils} = require('..'); | ||
const path = require('path'); | ||
const CryptoSuite_ECDSA_AES = require('../lib/impl/CryptoSuite_ECDSA_AES'); | ||
const testUtils = require('./TestUtils'); | ||
|
||
const chai = require('chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
const sinonChai = require('sinon-chai'); | ||
|
||
const should = chai.should(); | ||
chai.use(chaiAsPromised); | ||
chai.use(sinonChai); | ||
|
||
describe('Utils', () => { | ||
|
||
describe('#newCryptoSuite', () => { | ||
|
||
beforeEach(() => { | ||
testUtils.setCryptoConfigSettings(); | ||
}); | ||
|
||
it('should return a default instance of CryptoSuite_ECDSA_AES with the correct properties', () => { | ||
const defaultCryptoSuite = Utils.newCryptoSuite(); | ||
defaultCryptoSuite.should.be.an.instanceOf(CryptoSuite_ECDSA_AES); | ||
defaultCryptoSuite._keySize.should.equal(256); | ||
should.exist(defaultCryptoSuite._ecdsaCurve); | ||
should.exist(defaultCryptoSuite._ecdsa); | ||
}); | ||
|
||
it('should return an instance of CryptoSuite_ECDSA_AES with the correct keysize', () => { | ||
const cryptoSuite = Utils.newCryptoSuite({keysize: 384, algorithm: 'EC'}); | ||
cryptoSuite.should.be.an.instanceOf(CryptoSuite_ECDSA_AES); | ||
cryptoSuite._keySize.should.equal(384); | ||
}); | ||
|
||
it('should return an instance of CryptoSuite_ECDSA_AES with the correct keysize', () => { | ||
const cryptoSuite = Utils.newCryptoSuite({keysize: 384}); | ||
cryptoSuite.should.be.an.instanceOf(CryptoSuite_ECDSA_AES); | ||
cryptoSuite._keySize.should.equal(384); | ||
}); | ||
|
||
it('should return an instance of CryptoSuite_ECDSA_AES with the default keysize', () => { | ||
const cryptoSuite = Utils.newCryptoSuite({algorithm: 'EC'}); | ||
cryptoSuite.should.be.an.instanceOf(CryptoSuite_ECDSA_AES); | ||
cryptoSuite._keySize.should.equal(256); | ||
}); | ||
|
||
it('should throw an error when an illegal key size is given', () => { | ||
(() => { | ||
Utils.newCryptoSuite({keysize: 123}); | ||
}).should.throw(/Illegal key size/); | ||
}); | ||
|
||
it('should throw an error when using HSM and a fake library path', () => { | ||
Utils.setConfigSetting('crypto-hsm', true); | ||
Utils.setConfigSetting('crypto-suite-hsm', {'EC': 'fabric-common/lib/impl/bccsp_pkcs11.js'}); | ||
const fakePath = path.join('some', 'fake', 'path'); | ||
(() => { | ||
Utils.newCryptoSuite({lib: fakePath, slot: 0, pin: '1234'}); | ||
}).should.throw(fakePath); | ||
}); | ||
it('should throw an error when using HSM and no library path is given', () => { | ||
Utils.setConfigSetting('crypto-hsm', true); | ||
Utils.setConfigSetting('crypto-suite-hsm', {'EC': 'fabric-common/lib/impl/bccsp_pkcs11.js'}); | ||
(() => { | ||
Utils.newCryptoSuite({keysize: 384, algorithm: 'EC'}); | ||
}).should.throw(/PKCS11 library path must be specified/); | ||
}); | ||
|
||
it('should throw an error when an illegal hashing algorithm has been set', () => { | ||
Utils.setConfigSetting('crypto-hash-algo', 19745); | ||
(() => { | ||
Utils.newCryptoSuite({}); | ||
}).should.throw(/Unsupported hash algorithm/); | ||
}); | ||
|
||
it('should throw an error when an unsupported hashing algorithm has been set', () => { | ||
Utils.setConfigSetting('crypto-hash-algo', '12345'); | ||
(() => { | ||
Utils.newCryptoSuite({}); | ||
}).should.throw(/Unsupported hash algorithm and key size pair/); | ||
}); | ||
|
||
it('should throw an error when an incorrect hashing algorithm is specified', () => { | ||
(() => { | ||
Utils.newCryptoSuite({algorithm: 'cake'}); | ||
}).should.throw(/Desired CryptoSuite module not found supporting algorithm/); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.