-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4948618
commit 8f9b64f
Showing
8 changed files
with
1,124 additions
and
362 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(''); | ||
}); | ||
}); |
Oops, something went wrong.