Skip to content

Commit

Permalink
fix: update secureBuffer cipherName
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan authored and tnoonan-salesforce committed Jul 2, 2019
1 parent 874d5b6 commit 1e8037b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/unit/secureStringTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { expect } from 'chai';
import * as crypto from 'crypto';
import { stub } from 'sinon';
import { SecureBuffer } from '../../src/secureBuffer';

describe('secureBuffer', async () => {
Expand Down Expand Up @@ -49,4 +51,23 @@ describe('secureBuffer', async () => {
expect(buffer.toString('utf8')).to.not.be.equal(secretText);
});
});

it('test backwards compatibility between aes256 and aes-256-cbc', () => {
const key = Buffer.from('aaaabbbbccccddddeeeeffffgggghhhh');
const iv = Buffer.from('aaaabbbbccccdddd');
const cipher = crypto.createCipheriv('aes256', key, iv);
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
const createCipherStub = stub(crypto, 'createCipheriv').returns(cipher);
const createDecipherStub = stub(crypto, 'createDecipheriv').returns(decipher);
try {
const secure = new SecureBuffer();
secure.consume(Buffer.from(secretText, 'utf8'));
expect(createCipherStub.calledOnce).to.be.true;
secure.value(val => expect(val.toString('utf8')).to.be.equal(secretText));
expect(createDecipherStub.calledOnce).to.be.true;
} finally {
createCipherStub.restore();
createDecipherStub.restore();
}
});
});

0 comments on commit 1e8037b

Please sign in to comment.