test(utils): update

This commit is contained in:
Micooz 2017-04-22 16:31:23 +08:00
parent 407cc446f6
commit 48c4f6cc04

@ -59,7 +59,7 @@ describe('Utils#getRandomInt', function () {
it('should return a number', function () {
const number = Utils.getRandomInt(1, 2);
expect(number).toBeGreaterThanOrEqual(1);
expect(number).toBeLessThan(2);
expect(number).toBeLessThanOrEqual(2);
});
});
@ -86,6 +86,24 @@ describe('Utils#getChunks', function () {
});
describe('Utils#getUTC', function () {
it('should return 4 bytes', function () {
const utc = Utils.getUTC();
expect(utc.length).toBe(4);
});
});
describe('Utils#hexStringToBuffer', function () {
it('should return expected buffer', function () {
const buffer = Utils.hexStringToBuffer('abcd');
expect(buffer.equals(Buffer.from([0xab, 0xcd]))).toBe(true);
});
});
describe('Utils#isValidHostname', function () {
it('should return false', function () {
@ -132,6 +150,16 @@ describe('Utils#md5', function () {
});
describe('Utils#hmac', function () {
it('should return expected buffer', function () {
const src = Buffer.from([1, 2, 3, 4]);
const dst = Buffer.from('7f8adea19a1ac02186fa895af72a7fa1', 'hex');
expect(Utils.hmac('md5', '', src).equals(dst)).toBe(true);
});
});
describe('Utils#EVP_BytesToKey', function () {
it('should return true', function () {
@ -143,3 +171,17 @@ describe('Utils#EVP_BytesToKey', function () {
});
});
describe('Utils#HKDF', function () {
it('should return expected buffer', function () {
const hash = 'md5';
const salt = Buffer.alloc(0);
const ikm = Buffer.from([1, 2, 3, 4]);
const info = Buffer.alloc(0);
const length = 16;
const dst = Buffer.from('160ade10f83c4275fca1c8cd0583e4e6', 'hex');
expect(Utils.HKDF(hash, salt, ikm, info, length).equals(dst)).toBe(true);
});
});