9 changed files with 2559 additions and 131 deletions
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
const TSConsoleReporter = require('jasmine-ts-console-reporter'); |
||||
jasmine.getEnv().clearReporters(); // Clear default console reporter
|
||||
jasmine.getEnv().addReporter(new TSConsoleReporter()); |
||||
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
import { NodeCryptoFunctionService } from '../../../src/services/nodeCryptoFunction.service'; |
||||
|
||||
import { UtilsService } from '../../../src/services/utils.service'; |
||||
|
||||
describe('NodeCrypto Function Service', () => { |
||||
describe('aesEncrypt', () => { |
||||
it('should successfully aes encrypt data', async () => { |
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService(); |
||||
const iv = makeStaticByteArray(16); |
||||
const key = makeStaticByteArray(32); |
||||
const data = UtilsService.fromUtf8ToArray('EncryptMe!'); |
||||
const encValue = await nodeCryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); |
||||
expect(UtilsService.fromBufferToB64(encValue)).toBe('ByUF8vhyX4ddU9gcooznwA=='); |
||||
}); |
||||
}); |
||||
|
||||
describe('aesDecryptSmall', () => { |
||||
it('should successfully aes decrypt data', async () => { |
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService(); |
||||
const iv = makeStaticByteArray(16); |
||||
const key = makeStaticByteArray(32); |
||||
const data = UtilsService.fromB64ToArray('ByUF8vhyX4ddU9gcooznwA=='); |
||||
const decValue = await nodeCryptoFunctionService.aesDecryptLarge(data.buffer, iv.buffer, key.buffer); |
||||
expect(UtilsService.fromBufferToUtf8(decValue)).toBe('EncryptMe!'); |
||||
}); |
||||
}); |
||||
|
||||
describe('aesDecryptLarge', () => { |
||||
it('should successfully aes decrypt data', async () => { |
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService(); |
||||
const iv = makeStaticByteArray(16); |
||||
const key = makeStaticByteArray(32); |
||||
const data = UtilsService.fromB64ToArray('ByUF8vhyX4ddU9gcooznwA=='); |
||||
const decValue = await nodeCryptoFunctionService.aesDecryptLarge(data.buffer, iv.buffer, key.buffer); |
||||
expect(UtilsService.fromBufferToUtf8(decValue)).toBe('EncryptMe!'); |
||||
}); |
||||
}); |
||||
|
||||
describe('randomBytes', () => { |
||||
it('should make a value of the correct length', async () => { |
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService(); |
||||
const randomData = await nodeCryptoFunctionService.randomBytes(16); |
||||
expect(randomData.byteLength).toBe(16); |
||||
}); |
||||
|
||||
it('should not make the same value twice', async () => { |
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService(); |
||||
const randomData = await nodeCryptoFunctionService.randomBytes(16); |
||||
const randomData2 = await nodeCryptoFunctionService.randomBytes(16); |
||||
expect(randomData.byteLength === randomData2.byteLength && randomData !== randomData2).toBeTruthy(); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
function makeStaticByteArray(length: number) { |
||||
const arr = new Uint8Array(length); |
||||
for (let i = 0; i < length; i++) { |
||||
arr[i] = i; |
||||
} |
||||
return arr; |
||||
} |
||||
|
||||
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
{ |
||||
"spec_dir": "dist/spec", |
||||
"spec_files": [ |
||||
"common/**/*[sS]pec.js", |
||||
"node/**/*[sS]pec.js" |
||||
], |
||||
"helpers": [ |
||||
"helpers.js" |
||||
], |
||||
"stopSpecOnExpectationFailure": false, |
||||
"random": true |
||||
} |
||||
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
import { UtilsService } from './utils.service'; |
||||
import { UtilsService } from '../../../src/services/utils.service'; |
||||
|
||||
describe('Utils Service', () => { |
||||
describe('getHostname', () => { |
||||
@ -1,10 +1,10 @@
@@ -1,10 +1,10 @@
|
||||
import { DeviceType } from '../enums/deviceType'; |
||||
import { DeviceType } from '../../../src/enums/deviceType'; |
||||
|
||||
import { PlatformUtilsService } from '../abstractions/platformUtils.service'; |
||||
import { PlatformUtilsService } from '../../../src/abstractions/platformUtils.service'; |
||||
|
||||
import { WebCryptoFunctionService } from './webCryptoFunction.service'; |
||||
import { WebCryptoFunctionService } from '../../../src/services/webCryptoFunction.service'; |
||||
|
||||
import { UtilsService } from './utils.service'; |
||||
import { UtilsService } from '../../../src/services/utils.service'; |
||||
|
||||
describe('WebCrypto Function Service', () => { |
||||
describe('pbkdf2', () => { |
||||
@ -1,20 +1,21 @@
@@ -1,20 +1,21 @@
|
||||
{ |
||||
"compilerOptions": { |
||||
"moduleResolution": "node", |
||||
"target": "ES2016", |
||||
"module": "es6", |
||||
"target": "ES6", |
||||
"module": "commonjs", |
||||
"sourceMap": true, |
||||
"declaration": true, |
||||
"allowSyntheticDefaultImports": true, |
||||
"experimentalDecorators": true, |
||||
"emitDecoratorMetadata": true, |
||||
"declarationDir": "dist/types", |
||||
"outDir": "dist/es", |
||||
"outDir": "dist", |
||||
"typeRoots": [ |
||||
"node_modules/@types" |
||||
] |
||||
}, |
||||
"include": [ |
||||
"src" |
||||
"src", |
||||
"spec" |
||||
] |
||||
} |
||||
|
||||
Loading…
Reference in new issue