[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-22-g8f3d83e

by Maximilian Krambach cvs at cvs.gnupg.org
Mon May 7 18:31:32 CEST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, javascript-binding has been updated
       via  8f3d83e5f0903323ec92f588f60dcecb0ae96de4 (commit)
      from  cf075846fb48c8d71937100d2c45069d37d54a38 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8f3d83e5f0903323ec92f588f60dcecb0ae96de4
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date:   Mon May 7 18:27:25 2018 +0200

    js: fixing errors found by testing: encrypt/decrypt
    
    --
    
    * Key.js: Error code for wrong parameter in createKey should be
      "PARAM_WRONG"
    * Helpers.js: The property openpgpjs-like Objects were checked for in
      toKeyIdArray was not defined.
    * src/permittedOperations.js: updated more expectations and assumptions
      for the native API
    
    * new Problems:
      - There seems to be a message size limit of about 21 MB for
        nativeMessaging, much lower than the documented 4GB.
      - Some bytes are lost with random data in an encrypt-decrypt
        roundtrip. The culprit is unclear.

diff --git a/lang/js/BrowserTestExtension/browsertest.html b/lang/js/BrowserTestExtension/browsertest.html
index ce037a1..d12e03c 100644
--- a/lang/js/BrowserTestExtension/browsertest.html
+++ b/lang/js/BrowserTestExtension/browsertest.html
@@ -18,6 +18,7 @@
 <!-- insert tests here-->
     <script src="tests/startup.js"></script>
     <script src="tests/encryptTest.js"></script>
+    <script src="tests/encryptDecryptTest.js"></script>
 
 <!-- run tests -->
     <script src="runbrowsertest.js"></script>
diff --git a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
new file mode 100644
index 0000000..7abf2d9
--- /dev/null
+++ b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
@@ -0,0 +1,72 @@
+/* gpgme.js - Javascript integration for gpgme
+ * Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GPGME is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+describe('Encryption and Decryption', function () {
+    it('Successful encrypt and decrypt', function (done) {
+        let prm = Gpgmejs.init();
+        prm.then(function (context) {
+            context.encrypt(
+                inputvalues.encrypt.good.data,
+                inputvalues.encrypt.good.fingerprint).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();
+                    });
+                });
+        });
+    });
+
+/**
+ * Fails with random data! Some bytes (up to 100) of the original are missing in
+ * the result
+ */
+/**
+    for (let i=0; i< 20; i++) {
+        it('Successful encrypt 1 MB '+ i+ '/20', function (done) {
+            let prm = Gpgmejs.init();
+            let data = bigString(0.1);
+                prm.then(function (context) {
+                    context.encrypt(data,
+                        inputvalues.encrypt.good.fingerprint).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();
+                                });
+                        });
+                });
+        }).timeout(10000);
+    };*/
+});
\ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/encryptTest.js b/lang/js/BrowserTestExtension/tests/encryptTest.js
index 2178efa..37b319e 100644
--- a/lang/js/BrowserTestExtension/tests/encryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/encryptTest.js
@@ -17,47 +17,133 @@
  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  * SPDX-License-Identifier: LGPL-2.1+
  */
-describe('Encryption', function(){
-    it('Successfull encrypt', function(){
+describe('Encryption', function () {
+    it('Successful encrypt', function (done) {
         let prm = Gpgmejs.init();
-        prm.then(function(context){
+        prm.then(function (context) {
             context.encrypt(
-            inputvalues.encrypt.good.data,
-            inputvalues.encrypt.good.fingerprint).then(function(answer){
+                inputvalues.encrypt.good.data,
+                inputvalues.encrypt.good.fingerprint).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');
+                    done();
                 });
         });
     });
 
-    it('Sending encryption without keys fails', function(){
+    it('Successful encrypt 5 MB', function (done) {
         let prm = Gpgmejs.init();
-        prm.then(function(context){
+        let data = bigString(5);
+        prm.then(function (context) {
+            context.encrypt(
+                data,
+                inputvalues.encrypt.good.fingerprint).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');
+                    done();
+                });
+        });
+    }).timeout(5000);
+
+    it('Successful encrypt 20 MB', function (done) {
+        let prm = Gpgmejs.init();
+        let data = bigString(20);
+        prm.then(function (context) {
+            context.encrypt(
+                data,
+                inputvalues.encrypt.good.fingerprint).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');
+                    done();
+                });
+        });
+    }).timeout(20000);
+
+/**
+    it('Successful encrypt 30 MB', function (done) {
+        // TODO: There seems to be a limit imposed at least by chrome at about 21 MB
+        let prm = Gpgmejs.init();
+        let data = bigString(30);
+        prm.then(function (context) {
+            context.encrypt(
+                data,
+                inputvalues.encrypt.good.fingerprint).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');
+                    done();
+                });
+        });
+    }).timeout(20000);
+*/
+
+    it('Sending encryption without keys fails', function (done) {
+        let prm = Gpgmejs.init();
+        prm.then(function (context) {
             context.encrypt(
                 inputvalues.encrypt.good.data,
-                null).then(function(answer){
+                null).then(function (answer) {
                     expect(answer).to.be.undefined;
                 }, function(error){
                     expect(error).to.be.an('Error');
                     expect(error.code).to.equal('MSG_INCOMPLETE');
-                    //TODO: MSG_INCOMPLETE desired, GNUPG_ERROR coming
+                    done();
                 });
         });
     });
 
-    it('Sending encryption without data fails', function(){
+    it('Sending encryption without data fails', function (done) {
         let prm = Gpgmejs.init();
-        prm.then(function(context){
+        prm.then(function (context) {
             context.encrypt(
-                null,inputvalues.encrypt.good.keyid).then(function(answer){
+                null, inputvalues.encrypt.good.keyid).then(function (answer) {
                     expect(answer).to.be.undefined;
-                }, function(error){
+                }, function (error) {
                     expect(error).to.be.an.instanceof(Error);
-                    expect(error.code).to.equal('PARAM_WRONG');
+                    expect(error.code).to.equal('MSG_INCOMPLETE');
+                    done();
+                });
+        });
+    });
+
+
+    it('Sending encryption with non existing keys fails', function (done) {
+        let prm = Gpgmejs.init();
+        prm.then(function (context) {
+            context.encrypt(
+                inputvalues.encrypt.good.data,
+                inputvalues.encrypt.bad.fingerprint).then(function (answer) {
+                    expect(answer).to.be.undefined;
+                }, function(error){
+                    expect(error).to.be.an('Error');
+                    expect(error.code).to.not.be.undefined;
+                    expect(error.code).to.equal('GNUPG_ERROR');
+                    done();
                 });
         });
     });
+
+    it('Overly large message ( >= 48MB) is rejected', function (done) {
+        let prm = Gpgmejs.init();
+        prm.then(function (context) {
+            context.encrypt(
+                bigString(48),
+                inputvalues.encrypt.good.fingerprint).then(function (answer) {
+                    expect(answer).to.be.undefined;
+                }, function(error){
+                    expect(error).to.be.an.instanceof(Error);
+                    // TODO who is throwing the error here?
+                    // It is not a GPGME_Error!
+                    done();
+                });
+        });
+    }).timeout(8000);
     // TODO check different valid parameter
 });
diff --git a/lang/js/BrowserTestExtension/tests/inputvalues.js b/lang/js/BrowserTestExtension/tests/inputvalues.js
index 1761c82..3cd1e92 100644
--- a/lang/js/BrowserTestExtension/tests/inputvalues.js
+++ b/lang/js/BrowserTestExtension/tests/inputvalues.js
@@ -23,6 +23,9 @@ var inputvalues = {
         good:{
             data : 'Hello World.',
             fingerprint : 'CDC3A2B2860625CCBFC5A5A9FC6D1B604967FC40'
+        },
+        bad: {
+            fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
         }
     },
     init: {
@@ -30,3 +33,12 @@ var inputvalues = {
     }
 
 };
+
+function bigString(megabytes){
+    let maxlength = 1024 * 1024 * megabytes;
+    let uint = new Uint8Array(maxlength);
+    for (let i= 0; i < maxlength; i++){
+        uint[i] = Math.random() * Math.floor(256);
+    }
+    return new TextDecoder('utf-8').decode(uint);
+}
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index a198bdc..2c8792d 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -99,11 +99,12 @@ export class Connection{
                     me._connection.onMessage.removeListener(listener)
                     reject(gpgme_error('CONN_EMPTY_GPG_ANSWER'));
                 } else if (msg.type === "error"){
-                    me._connection.onMessage.removeListener(listener)
+                    me._connection.onMessage.removeListener(listener);
                     reject(gpgme_error('GNUPG_ERROR', msg.msg));
                 } else {
                     let answer_result = answer.add(msg);
                     if (answer_result !== true){
+                        me._connection.onMessage.removeListener(listener);
                         reject(answer_result);
                     }
                     if (msg.more === true){
@@ -127,8 +128,12 @@ export class Connection{
                         }, 5000);
                     }]).then(function(result){
                     return result;
-                }, function(error){
-                    return error;
+                }, function(reject){
+                    if(!reject instanceof Error) {
+                        return gpgme_error('GNUPG_ERROR', reject);
+                    } else {
+                        return reject;
+                    }
                 });
             }
         });
@@ -196,7 +201,7 @@ class Answer{
                         this._response.push(msg[key]);
                     }
                     else {
-                        return gpgme_error('CONN_UNEXPECTED_ANSWER', key);
+                        return gpgme_error('CONN_UNEXPECTED_ANSWER');
                     }
                     break;
             }
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js
index c42480f..6a59c3e 100644
--- a/lang/js/src/Message.js
+++ b/lang/js/src/Message.js
@@ -84,9 +84,22 @@ export class GPGME_Message {
         let checktype = function(val){
             switch(typeof(val)){
                 case 'string':
+                    if (poparam.allowed.indexOf(typeof(val)) >= 0
+                        && val.length > 0) {
+                        return true;
+                    }
+                    return gpgme_error('PARAM_WRONG');
+                    break;
                 case 'number':
+                    if (
+                        poparam.allowed.indexOf('number') >= 0
+                        && isNaN(value) === false){
+                            return true;
+                    }
+                    return gpgme_error('PARAM_WRONG');
+                    break;
                 case 'boolean':
-                    if (poparam.allowed.indexOf(typeof(val)) >= 0){
+                    if (poparam.allowed.indexOf('boolean') >= 0){
                         return true;
                     }
                     return gpgme_error('PARAM_WRONG');
@@ -102,7 +115,9 @@ export class GPGME_Message {
                                 return res;
                             }
                         }
-                        return true;
+                        if (val.length > 0) {
+                            return true;
+                        }
                     } else if (val instanceof Uint8Array){
                         if (poparam.allowed.indexOf('Uint8Array') >= 0){
                             return true;
diff --git a/lang/js/unittests.js b/lang/js/unittests.js
index 6c0d189..c437d59 100644
--- a/lang/js/unittests.js
+++ b/lang/js/unittests.js
@@ -130,7 +130,6 @@ function unittests (){
             let test0 = toKeyIdArray(hp.valid_openpgplike);
 
             expect(test0).to.be.an('array').with.lengthOf(1);
-            console.log(test0);
             expect(test0).to.include(
                 hp.valid_openpgplike.primaryKey.getFingerprint());
         });
@@ -255,7 +254,7 @@ function unittests (){
             expect(test0.isComplete).to.be.false;
         });
 
-        it('Message is complete after setting mandatoy data', function(){
+        it('Message is complete after setting mandatory data', function(){
             let test0 = createMessage('encrypt');
             test0.setParameter('data', mp.valid_encrypt_data);
             test0.setParameter('keys', hp.validFingerprints);
@@ -263,6 +262,13 @@ function unittests (){
             expect(test0.isComplete).to.be.true;
         });
 
+        it('Message is not complete after mandatory data is empty', function(){
+            let test0 = createMessage('encrypt');
+            test0.setParameter('data', '');
+            test0.setParameter('keys', hp.validFingerprints);
+            expect(test0.isComplete).to.be.false;
+        });
+
         it('Complete Message contains the data that was set', function(){
             let test0 = createMessage('encrypt');
             test0.setParameter('data', mp.valid_encrypt_data);
@@ -315,7 +321,6 @@ function unittests (){
         });
     });
 
-    mocha.run();
 }
 
 export default {unittests};
\ No newline at end of file

-----------------------------------------------------------------------

Summary of changes:
 lang/js/BrowserTestExtension/browsertest.html      |   1 +
 .../tests/encryptDecryptTest.js                    |  72 +++++++++++++
 lang/js/BrowserTestExtension/tests/encryptTest.js  | 114 ++++++++++++++++++---
 lang/js/BrowserTestExtension/tests/inputvalues.js  |  12 +++
 lang/js/src/Connection.js                          |  13 ++-
 lang/js/src/Message.js                             |  19 +++-
 lang/js/unittests.js                               |  11 +-
 7 files changed, 219 insertions(+), 23 deletions(-)
 create mode 100644 lang/js/BrowserTestExtension/tests/encryptDecryptTest.js


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list