Skip to content

Commit

Permalink
3fd6837fce9b339b8b09a800a969e0950e78250c
Browse files Browse the repository at this point in the history
  • Loading branch information
toberndo committed Aug 23, 2018
1 parent 59dd53e commit 9aaf28c
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 297 deletions.
35 changes: 19 additions & 16 deletions BrowserTestExtension/tests/KeyImportExport.js
Expand Up @@ -35,7 +35,7 @@ describe('Key importing', function () {
const prm = Gpgmejs.init();
prm.then(function (gpgmejs){
context = gpgmejs;
context.Keyring.getKeys(fpr).then(
context.Keyring.getKeys({ pattern: fpr }).then(
function (result){
if (result.length === 1) {
result[0].delete().then(function (){
Expand All @@ -52,7 +52,7 @@ describe('Key importing', function () {

afterEach(function (done){
// delete the test key if still present
context.Keyring.getKeys(fpr).then(
context.Keyring.getKeys({ pattern: fpr }).then(
function (result){
if (result.length === 1) {
result[0].delete().then(function (){
Expand All @@ -67,7 +67,7 @@ describe('Key importing', function () {
});

it('Importing Key', function (done) {
context.Keyring.getKeys(fpr).then(function (result){
context.Keyring.getKeys({ pattern: fpr }).then(function (result){
expect(result).to.be.an('array');
expect(result.length).to.equal(0);
context.Keyring.importKey(pubKey).then(function (result){
Expand Down Expand Up @@ -127,23 +127,26 @@ describe('Key importing', function () {

it('exporting armored Key with getKeysArmored', function (done) {
context.Keyring.importKey(pubKey).then(function (){
context.Keyring.getKeysArmored(fpr).then(function (result){
expect(result).to.be.an('object');
expect(result.armored).to.be.a('string');
expect(result.secret_fprs).to.be.undefined;
done();
});
context.Keyring.getKeysArmored({ pattern: fpr })
.then(function (result){
expect(result).to.be.an('object');
expect(result.armored).to.be.a('string');
expect(result.secret_fprs).to.be.undefined;
done();
});
});
});

it('Exporting Key (including secret fingerprints)', function (done) {
const key_secret = inputvalues.encrypt.good.fingerprint;
context.Keyring.getKeysArmored(key_secret, true).then(function (result){
expect(result).to.be.an('object');
expect(result.armored).to.be.a('string');
expect(result.secret_fprs).to.be.an('array');
expect(result.secret_fprs[0]).to.equal(key_secret);
done();
});
context.Keyring.getKeysArmored({
pattern: key_secret, with_secret_fpr: true })
.then(function (result){
expect(result).to.be.an('object');
expect(result.armored).to.be.a('string');
expect(result.secret_fprs).to.be.an('array');
expect(result.secret_fprs[0]).to.equal(key_secret);
done();
});
});
});
2 changes: 1 addition & 1 deletion BrowserTestExtension/tests/KeyInfos.js
Expand Up @@ -36,7 +36,7 @@ describe('Key information', function () {

it('A fingerprint is consistently returned upper case hex', function (done){
const mixedCase = inputvalues.encrypt.good.fingerprint_mixedcase;
context.Keyring.getKeys(mixedCase).then(function (result){
context.Keyring.getKeys({ pattern: mixedCase }).then(function (result){
expect(result).to.be.an('array');
expect(result.length).to.equal(1);
expect(result[0].fingerprint).to.equal(mixedCase.toUpperCase());
Expand Down
23 changes: 12 additions & 11 deletions BrowserTestExtension/tests/decryptTest.js
Expand Up @@ -38,7 +38,7 @@ describe('Decryption', function () {

it('Decryption of random string fails', function (done) {
let data = bigString(20 * 1024);
context.decrypt(data).then(
context.decrypt({ data: data }).then(
function (){},
function (error){
expect(error).to.be.an('error');
Expand All @@ -49,21 +49,22 @@ describe('Decryption', function () {

it('Decryption of slightly corrupted message fails', function (done) {
const data = bigString(10000);
context.encrypt(data, good_fpr).then(function (enc){
context.decrypt(sabotageMsg(enc.data)).then(
function (){},
function (error){
expect(error).to.be.an('error');
expect(error.code).to.equal('GNUPG_ERROR');
done();
});
});
context.encrypt({ data: data, publicKeys:good_fpr }).then(
function (enc){
context.decrypt({ data: sabotageMsg(enc.data) }).then(
function (){},
function (error){
expect(error).to.be.an('error');
expect(error.code).to.equal('GNUPG_ERROR');
done();
});
});
}).timeout(5000);


it('decrypt/verify operations return proper information', function (done){
const data = inputvalues.encryptSignedMessage;
context.decrypt(data).then(function (result){
context.decrypt({ data: data }).then(function (result){
expect(result).to.be.an('object');
expect(result.signatures).to.be.an('object');
expect(result.signatures.all_valid).to.be.true;
Expand Down
182 changes: 106 additions & 76 deletions BrowserTestExtension/tests/encryptDecryptTest.js
Expand Up @@ -38,25 +38,25 @@ describe('Encryption and Decryption', function (){

it('Successful encrypt and decrypt simple string', function (done) {
let data = inputvalues.encrypt.good.data;
context.encrypt(data, good_fpr).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');

context.decrypt(answer.data).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(
inputvalues.encrypt.good.data);
done();
context.encrypt({ data: data, publicKeys: good_fpr }).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(
inputvalues.encrypt.good.data);
done();
});
});
});
});

it('Decrypt simple non-ascii', function (done) {
let data = encryptedData;
context.decrypt(data).then(function (result) {
context.decrypt({ data: data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(
Expand All @@ -67,77 +67,105 @@ describe('Encryption and Decryption', function (){

it('Trailing whitespace and different line endings', function (done) {
const data = 'Keks. \rKeks \n Keks \r\n';
context.encrypt(data, good_fpr).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.encrypt({ data: data, publicKeys: good_fpr }).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');

context.decrypt(answer.data).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
});
}).timeout(5000);

it('Random data, as string', function (done) {
let data = bigString(1000);
context.encrypt(data, good_fpr).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
context.encrypt({ data:data, publicKeys: good_fpr }).then(
function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
});
}).timeout(3000);

it('Data, input as base64', function (done) {
let data = inputvalues.encrypt.good.data;
let b64data = btoa(data);
context.encrypt(b64data, good_fpr, true).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function (result) {
context.encrypt({ data: b64data, publicKeys: good_fpr, base64: true })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data: answer.data }).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(data).to.equal(data);
expect(result.data).to.equal(data);
done();
});
});
});
}).timeout(3000);

it('Random data, input as base64', function (done) {
let data = bigBoringString(0.001);
let b64data = btoa(data);
context.encrypt(b64data, good_fpr, true).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(
function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(b64data);
done();
context.encrypt(
{ data: b64data, publicKeys: good_fpr, base64: true })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data:answer.data }).then(
function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
}).timeout(3000);

it('Random data, original data is and should stay base64 encoded',
function (done) {
let data = bigBoringString(0.001);
let b64data = btoa(data);
context.encrypt(
{ data: b64data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({
data:answer.data, expect: 'base64' })
.then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(b64data);
done();
});
});
});
}).timeout(3000);

for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){
Expand All @@ -151,20 +179,22 @@ describe('Encryption and Decryption', function (){
for (let i=0; i < 34 * 1024; i++){
data += input;
}
context.encrypt(data,good_fpr).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt(answer.data).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
context.encrypt({ data: data, publicKeys: good_fpr })
.then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include(
'BEGIN PGP MESSAGE');
expect(answer.data).to.include(
'END PGP MESSAGE');
context.decrypt({ data: answer.data })
.then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
done();
});
});
});
}).timeout(5000);
}
});

0 comments on commit 9aaf28c

Please sign in to comment.