mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-12 10:14:10 +01:00
node vs web testing with jasmine
This commit is contained in:
parent
172f2de4ff
commit
9b4069cb19
2346
package-lock.json
generated
2346
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -18,8 +18,10 @@
|
|||||||
"build:watch": "tsc -watch",
|
"build:watch": "tsc -watch",
|
||||||
"lint": "tslint src/**/*.ts || true",
|
"lint": "tslint src/**/*.ts || true",
|
||||||
"lint:fix": "tslint src/**/*.ts --fix",
|
"lint:fix": "tslint src/**/*.ts --fix",
|
||||||
"test": "karma start --single-run",
|
"test": "karma start ./spec/support/karma.conf.js --single-run",
|
||||||
"test:watch": "karma start"
|
"test:watch": "karma start ./spec/support/karma.conf.js",
|
||||||
|
"test:node": "npm run build && jasmine",
|
||||||
|
"test:node:watch": "npm run build:watch & nodemon -w ./dist jasmine"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jasmine": "^2.8.2",
|
"@types/jasmine": "^2.8.2",
|
||||||
@ -28,6 +30,8 @@
|
|||||||
"@types/node-forge": "0.7.1",
|
"@types/node-forge": "0.7.1",
|
||||||
"@types/papaparse": "4.1.31",
|
"@types/papaparse": "4.1.31",
|
||||||
"@types/webcrypto": "0.0.28",
|
"@types/webcrypto": "0.0.28",
|
||||||
|
"jasmine": "^3.1.0",
|
||||||
|
"jasmine-ts-console-reporter": "^3.1.1",
|
||||||
"jasmine-core": "^2.8.0",
|
"jasmine-core": "^2.8.0",
|
||||||
"jasmine-spec-reporter": "^4.2.1",
|
"jasmine-spec-reporter": "^4.2.1",
|
||||||
"karma": "^1.7.1",
|
"karma": "^1.7.1",
|
||||||
@ -37,6 +41,7 @@
|
|||||||
"karma-jasmine": "^1.1.0",
|
"karma-jasmine": "^1.1.0",
|
||||||
"karma-jasmine-html-reporter": "^0.2.2",
|
"karma-jasmine-html-reporter": "^0.2.2",
|
||||||
"karma-typescript": "^3.0.8",
|
"karma-typescript": "^3.0.8",
|
||||||
|
"nodemon": "^1.17.3",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"tslint": "^5.8.0",
|
"tslint": "^5.8.0",
|
||||||
"typescript": "^2.7.1"
|
"typescript": "^2.7.1"
|
||||||
|
3
spec/helpers.ts
Normal file
3
spec/helpers.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const TSConsoleReporter = require('jasmine-ts-console-reporter');
|
||||||
|
jasmine.getEnv().clearReporters(); // Clear default console reporter
|
||||||
|
jasmine.getEnv().addReporter(new TSConsoleReporter());
|
62
spec/node/services/nodeCryptoFunction.service.spec.ts
Normal file
62
spec/node/services/nodeCryptoFunction.service.spec.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
12
spec/support/jasmine.json
Normal file
12
spec/support/jasmine.json
Normal file
@ -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,7 +1,7 @@
|
|||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
config.set({
|
config.set({
|
||||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||||
basePath: '',
|
basePath: '../../',
|
||||||
|
|
||||||
// frameworks to use
|
// frameworks to use
|
||||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||||
@ -9,6 +9,8 @@ module.exports = function(config) {
|
|||||||
|
|
||||||
// list of files / patterns to load in the browser
|
// list of files / patterns to load in the browser
|
||||||
files: [
|
files: [
|
||||||
|
'spec/common/**/*.ts',
|
||||||
|
'spec/web/**/*.ts',
|
||||||
'src/abstractions/**/*.ts',
|
'src/abstractions/**/*.ts',
|
||||||
'src/enums/**/*.ts',
|
'src/enums/**/*.ts',
|
||||||
'src/models/**/*.ts',
|
'src/models/**/*.ts',
|
||||||
@ -54,9 +56,6 @@ module.exports = function(config) {
|
|||||||
|
|
||||||
karmaTypescriptConfig: {
|
karmaTypescriptConfig: {
|
||||||
tsconfig: './tsconfig.json',
|
tsconfig: './tsconfig.json',
|
||||||
compilerOptions: {
|
|
||||||
module: 'CommonJS'
|
|
||||||
},
|
|
||||||
bundlerOptions: {
|
bundlerOptions: {
|
||||||
entrypoints: /\.spec\.ts$/,
|
entrypoints: /\.spec\.ts$/,
|
||||||
sourceMap: true
|
sourceMap: true
|
@ -1,4 +1,4 @@
|
|||||||
import { UtilsService } from './utils.service';
|
import { UtilsService } from '../../../src/services/utils.service';
|
||||||
|
|
||||||
describe('Utils Service', () => {
|
describe('Utils Service', () => {
|
||||||
describe('getHostname', () => {
|
describe('getHostname', () => {
|
@ -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('WebCrypto Function Service', () => {
|
||||||
describe('pbkdf2', () => {
|
describe('pbkdf2', () => {
|
@ -1,20 +1,21 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"target": "ES2016",
|
"target": "ES6",
|
||||||
"module": "es6",
|
"module": "commonjs",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"declarationDir": "dist/types",
|
"declarationDir": "dist/types",
|
||||||
"outDir": "dist/es",
|
"outDir": "dist",
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
"node_modules/@types"
|
"node_modules/@types"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src"
|
"src",
|
||||||
|
"spec"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user