Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
generalpiston committed Oct 5, 2020
1 parent 4948618 commit 8f9b64f
Show file tree
Hide file tree
Showing 8 changed files with 1,124 additions and 362 deletions.
1,154 changes: 952 additions & 202 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"devDependencies": {
"@types/chai": "^4.0.5",
"@types/mocha": "^2.2.44",
"@types/node": "^9.6.0",
"@types/chai": "^4.2.13",
"@types/mocha": "^8.0.3",
"@types/node": "^14.11.2",
"chai": "^4.1.2",
"mocha": "^4.0.1",
"mocha": "^8.1.3",
"prettier": "^2.0.5",
"sqlite3": "^4.1.1",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
"ts-node": "^9.0.0",
"tslint": "^6.1.3",
"typeorm": "^0.2.25",
"typescript": "^3.3.3333"
},
Expand Down
2 changes: 2 additions & 0 deletions src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export function decryptData(data: Buffer, options: EncryptionOptions): Buffer {
let dataToUse = data.slice(options.ivLength);

if (hasAuthTag(options.algorithm)) {
// Add ts-ignore due to build error TS2339: Property 'setAuthTag' does not exist on type 'Decipher'.
// @ts-ignore
decipher.setAuthTag(dataToUse.slice(0, authTagLength));
dataToUse = dataToUse.slice(authTagLength);
}
Expand Down
37 changes: 20 additions & 17 deletions test/active-record.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { expect } from 'chai';
import { encrypt, decrypt } from '../src/entity';
import { withConnection } from './utils';
import { getConnection } from './utils';
import ColumnOptionsEntity1 from './entities/ColumnOptionsEntity1';

describe('Column Options - Active Record', () => {
it('should encrypt', () => {
describe('Column Options - Active Record', function() {
this.timeout(10000);

before(async function () {
await getConnection();
})

it('should encrypt', function() {
let result = new ColumnOptionsEntity1();
result.secret = 'test';
encrypt(result);
Expand All @@ -13,26 +19,23 @@ describe('Column Options - Active Record', () => {
);
});

it('should decrypt', () => {
it('should decrypt', function() {
let result = new ColumnOptionsEntity1();
result.secret = '/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A=';
decrypt(result);
expect(result.secret).to.equal('test');
});

it('should automatically encrypt and decrypt', (done) => {
withConnection(async () => {
let result = new ColumnOptionsEntity1();
result.secret = 'test';
await result.save();
expect(result.secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);
it('should automatically encrypt and decrypt', async function() {
let result = new ColumnOptionsEntity1();
result.secret = 'test';
await result.save();
expect(result.secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);

let results = await ColumnOptionsEntity1.find();
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
done();
});
let results = await ColumnOptionsEntity1.find();
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
});
});
6 changes: 3 additions & 3 deletions test/crypto.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'chai';
import { encryptData, decryptData } from '../src/crypto';

describe('Crypto', () => {
it('should encrypt', () => {
describe('Crypto', function() {
it('should encrypt', function() {
let result = encryptData(Buffer.from('test', 'utf8'), {
key: 'e41c966f21f9e1577802463f8924e6a3fe3e9751f201304213b2f845d8841d61',
algorithm: 'aes-256-cbc',
Expand All @@ -14,7 +14,7 @@ describe('Crypto', () => {
);
});

it('should decrypt', () => {
it('should decrypt', function() {
let result = decryptData(
Buffer.from('/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A=', 'base64'),
{
Expand Down
32 changes: 19 additions & 13 deletions test/data-mapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { expect } from 'chai';
import { Connection } from 'typeorm';
import { withConnection } from './utils';
import { getConnection } from './utils';
import ColumnOptionsEntity2 from './entities/ColumnOptionsEntity2';

describe('Column Options - Data Mapper', () => {
it('should automatically encrypt and decrypt with loose matching', async () => {
await withConnection(async (connection: Connection) => {
const repo = connection.getRepository(ColumnOptionsEntity2);
let result = await repo.save({ looseSecret: 'test' });
expect(result.looseSecret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);
describe('Column Options - Data Mapper', function() {
let connection: Connection;

let results = await repo.find();
expect(results.length).to.equal(1);
expect(results[0].looseSecret).to.equal('test');
});
this.timeout(10000);

before(async function () {
connection = await getConnection();
})

it('should automatically encrypt and decrypt with loose matching', async function() {
const repo = connection.getRepository(ColumnOptionsEntity2);
let result = await repo.save({ looseSecret: 'test' });
expect(result.looseSecret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);

let results = await repo.find();
expect(results.length).to.equal(1);
expect(results[0].looseSecret).to.equal('test');
});
});
204 changes: 96 additions & 108 deletions test/transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,154 +1,142 @@
import { expect } from 'chai';
import { Connection } from 'typeorm';
import { withConnection } from './utils';
import { getConnection } from './utils';
import TransformerOptionsEntityEmptyString1 from './entities/TransformerOptionsEntityEmptyString1';
import TransformerOptionsEntity1 from './entities/TransformerOptionsEntity1';
import TransformerOptionsEntityNullable1 from './entities/TransformerOptionsEntityNullable1';
import TransformerOptionsEntityNullable2 from './entities/TransformerOptionsEntityNullable2';
import TransformerOptionsAES256GCMEntity1 from './entities/TransformerOptionsAES256GCMEntity1';
import TransformerOptionsAES256GCMEntity2 from './entities/TransformerOptionsAES256GCMEntity2';

describe('Transformer', () => {
it('should automatically encrypt and decrypt', async () => {
await withConnection(async (connection: Connection) => {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntity1);
const instance = await repo.create({ secret: 'test' });
await repo.save(instance);
describe('Transformer', function() {
let connection: Connection;

const result = await manager.query(
'SELECT secret FROM transformer_options_entity1'
);
this.timeout(10000);

expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);
before(async function () {
connection = await getConnection();
})

const results = await repo.find();
it('should automatically encrypt and decrypt', async function() {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntity1);
const instance = await repo.create({ secret: 'test' });
await repo.save(instance);

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
});
const result = await manager.query(
'SELECT secret FROM transformer_options_entity1'
);

expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);

const results = await repo.find();

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
});

it('should automatically encrypt and decrypt aes-256-gcm', async () => {
await withConnection(async (connection: Connection) => {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsAES256GCMEntity1);
const instance = await repo.create({ secret: 'test' });
await repo.save(instance);
it('should automatically encrypt and decrypt aes-256-gcm', async function() {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsAES256GCMEntity1);
const instance = await repo.create({ secret: 'test' });
await repo.save(instance);

const result = await manager.query(
'SELECT secret FROM transformer_options_entity1'
);
const result = await manager.query(
'SELECT secret FROM transformer_options_entity1'
);

expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);
expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);

const results = await repo.find();
const results = await repo.find();

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
});
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
});

it('should automatically encrypt and decrypt aes-256-gcm with 8-byte long auth tag length', (done) => {
withConnection(async (connection: Connection) => {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsAES256GCMEntity2);
const instance = await repo.create({ secret: 'test' });
await repo.save(instance);
it('should automatically encrypt and decrypt aes-256-gcm with 8-byte long auth tag length', async function() {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsAES256GCMEntity2);
const instance = await repo.create({ secret: 'test' });
await repo.save(instance);

const result = await manager.query(
'SELECT secret FROM transformer_options_entity1'
);
const result = await manager.query(
'SELECT secret FROM transformer_options_entity1'
);

expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);
expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVhKzmHsDDv0EvRtMBFiaE3A='
);

const results = await repo.find();
const results = await repo.find();

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');

done();
});
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('test');
});

it('should not encrypt / decrypt null values', (done) => {
withConnection(async (connection: Connection) => {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntityNullable1);
const instance = await repo.create({ secret: null });
await repo.save(instance);
it('should not encrypt / decrypt null values', async function() {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntityNullable1);
const instance = await repo.create({ secret: null });

const result = await manager.query(
'SELECT secret FROM transformer_options_entity_nullable1'
);

await repo.save(instance);

expect(result[0].secret).to.equal(
null
);
const result = await manager.query(
'SELECT secret FROM transformer_options_entity_nullable1'
);

const results = await repo.find();
expect(result[0].secret).to.equal(
null
);

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal(undefined);
const results = await repo.find();

done()
});
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal(undefined);
});

it('should not encrypt / decrypt undefined values', (done) => {
withConnection(async (connection: Connection) => {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntityNullable2);
const instance = await repo.create({ secret: undefined });
await repo.save(instance);

const result = await manager.query(
'SELECT secret FROM transformer_options_entity_nullable2'
);

it('should not encrypt / decrypt undefined values', async function() {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntityNullable2);
const instance = await repo.create({ secret: undefined });
await repo.save(instance);

expect(result[0].secret).to.equal(
null
);
const result = await manager.query(
'SELECT secret FROM transformer_options_entity_nullable2'
);


const results = await repo.find();
expect(result[0].secret).to.equal(
null
);

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal(undefined);
const results = await repo.find();

done()
});
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal(undefined);
});

it('should encrypt / decrypt empty strings', (done) => {
withConnection(async (connection: Connection) => {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntityEmptyString1);
const instance = await repo.create({ secret: '' });
await repo.save(instance);

const result = await manager.query(
'SELECT secret FROM transformer_options_entity_empty_string1'
);

it('should encrypt / decrypt empty strings', async function() {
const manager = connection.manager;
const repo = connection.getRepository(TransformerOptionsEntityEmptyString1);
const instance = await repo.create({ secret: '' });
await repo.save(instance);

expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVvnjveB6onZ3uoKZCOZfzbk='
);
const result = await manager.query(
'SELECT secret FROM transformer_options_entity_empty_string1'
);


const results = await repo.find();
expect(result[0].secret).to.equal(
'/1rBkZBCSx2I+UGe+UmuVvnjveB6onZ3uoKZCOZfzbk='
);

expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('');
const results = await repo.find();

done()
});
expect(results.length).to.equal(1);
expect(results[0].secret).to.equal('');
});
});
Loading

0 comments on commit 8f9b64f

Please sign in to comment.