js: more testing
authorMaximilian Krambach <maximilian.krambach@intevation.de>
Tue, 8 May 2018 16:33:41 +0000 (18:33 +0200)
committerMaximilian Krambach <maximilian.krambach@intevation.de>
Tue, 8 May 2018 16:33:41 +0000 (18:33 +0200)
--

* Tests: Under certain circumstances, some data change during
  encrypt-decrypt. Committing the current state so the problem can be
  discussed.

* Fixes:
  - disconnecting the test ports after tests are complete
  - fixed passing of the error message from gpgme-json

lang/js/BrowserTestExtension/testkey.pub [new file with mode: 0644]
lang/js/BrowserTestExtension/testkey.sec [new file with mode: 0644]
lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
lang/js/BrowserTestExtension/tests/encryptTest.js
lang/js/BrowserTestExtension/tests/inputvalues.js
lang/js/src/Errors.js
lang/js/src/gpgmejs.js

diff --git a/lang/js/BrowserTestExtension/testkey.pub b/lang/js/BrowserTestExtension/testkey.pub
new file mode 100644 (file)
index 0000000..cfc329f
--- /dev/null
@@ -0,0 +1,30 @@
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+
+mQENBFrsKEkBCADKw4Wt8J6M/88qD8PO6lSMCxH1cpwH8iK0uPaFFYsJkkXo7kWf
+PTAtrV+REqF/o80dvYcdLvRsV21pvncZz/HXLu1yQ18mC3XObrKokbdgrTTKA5XE
+BZkNsqyaMMJauT18H4hYkSg62/tTdO1cu/zWv/LFf7Xyn6+uA74ovXCJlO1s0N2c
+PShtr98QRzPMf2owgVk37JnDNp4gGVDGHxSZOuUwxgYAZYnA8SFc+c+3ZrQfY870
++O4j3Mz4p7yD13AwP4buQLBsb/icxekeQCqpRJhLH9f7MdEcGXa1x36RcEkHdu+M
+yJ392eMgD+dKNfRCtyTPhjZTxvbNELIBYICfABEBAAG0EHRlc3RAZXhhbXBsZS5v
+cmeJAVQEEwEIAD4WIQTUFzW5Ejb9uIIEjFojAWNe7/DLBQUCWuwoSQIbAwUJA8Jn
+AAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRAjAWNe7/DLBf9kB/wOQ/S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7ESO9JsWvJbyBmuiZpu9JjScOjYH9xpQLqRNyw4WHpZriN69F0t9Mmd7bM1
++UyPgbPEr0iWMeyctYsuOLeUyQKMscDT
+=QyY6
+-----END PGP PUBLIC KEY BLOCK-----
diff --git a/lang/js/BrowserTestExtension/testkey.sec b/lang/js/BrowserTestExtension/testkey.sec
new file mode 100644 (file)
index 0000000..ced8f3e
--- /dev/null
@@ -0,0 +1,57 @@
+-----BEGIN PGP PRIVATE KEY BLOCK-----
+
+lQOYBFrsKEkBCADKw4Wt8J6M/88qD8PO6lSMCxH1cpwH8iK0uPaFFYsJkkXo7kWf
+PTAtrV+REqF/o80dvYcdLvRsV21pvncZz/HXLu1yQ18mC3XObrKokbdgrTTKA5XE
+BZkNsqyaMMJauT18H4hYkSg62/tTdO1cu/zWv/LFf7Xyn6+uA74ovXCJlO1s0N2c
+PShtr98QRzPMf2owgVk37JnDNp4gGVDGHxSZOuUwxgYAZYnA8SFc+c+3ZrQfY870
++O4j3Mz4p7yD13AwP4buQLBsb/icxekeQCqpRJhLH9f7MdEcGXa1x36RcEkHdu+M
+yJ392eMgD+dKNfRCtyTPhjZTxvbNELIBYICfABEBAAEAB/wLJ0gyMjs2fFfT83wM
+5Lzz2yQIwV4t3bblBAujdHTqeN5Zmsm/oakFyjSokULK96Kv0R4ej9eoIgMFvxFk
+HRkrggxTrbsNJ7I6QcKYHTPeIIj318ykNL6fj0WJUcdPIENukXl5jbqNyk3/4D2y
+TTDySyq6jHTgvMH4K4KJUSpglvSJPntTk9RhuFGHAF+sNR9atygDYctAaERMRtSg
+LCoSt/AoX5GRMlQjXT9oqQjwSQoZyF4s8HMC8wdTFIE/E0L4IVdHVp8sz2UszNtT
+W/evmCA+KVruKjRH/Fhrq4hHkEamW28+j4L6uAyagONP7BONs+S5Oo2zTT9+tV2R
+ILTZBADdgLuAgF6C5Lu9jCF6DfFgaT/uafMyQNkEGNlxOHMWHTgLHe475V2eG9gA
+amd4yXKyEFKU1PWnvlGuicQSGdzVcw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vUQ
+d9ulxJw7V9rs75uNBatTNC0kXuGoXhehw4Bn93xa67gYGd3LfrH+oT0GCDpTSHCJ
+ATwEGAEIACYWIQTUFzW5Ejb9uIIEjFojAWNe7/DLBQUCWuwoSQIbDAUJA8JnAAAK
+CRAjAWNe7/DLBf0pCACPp5hBuUWngu2Hqvg+tNiujfsiYzId3MffFxEk3CbXeHcJ
+5F32NDJ9PYCnra4L8wSv+NZt9gIa8lFwoFSFQCjzH7KE86XcV3MhfdJTNb/+9CR7
+Jq3e/4Iy0N5ip7PNYMCyakcAsxvsNCJKrSaDuYe/OAoTXRBtgRWE2uyT315em02L
+kr+2Cc/Qk6H+vlNOHGRgnpI/OZZjnUuUfBUvMGHr1phW+y7aeymC9PnUGdViRdJe
+23nntMSDA+0/I7ESO9JsWvJbyBmuiZpu9JjScOjYH9xpQLqRNyw4WHpZriN69F0t
+9Mmd7bM1+UyPgbPEr0iWMeyctYsuOLeUyQKMscDT
+=hkUm
+-----END PGP PRIVATE KEY BLOCK-----
index 7abf2d9..e28dd66 100644 (file)
@@ -24,30 +24,144 @@ describe('Encryption and Decryption', function () {
         prm.then(function (context) {
             context.encrypt(
                 inputvalues.encrypt.good.data,
-                inputvalues.encrypt.good.fingerprint).then( function(answer){
+                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){
+                    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);
+                        context.connection.disconnect();
                         done();
                     });
                 });
         });
     });
 
+    /**
+     * Fails with random data! Some bytes (up to 100) of the original are missing in
+     * the result
+*/
 /**
- * Fails with random data! Some bytes (up to 100) of the original are missing in
- * the result
- */
+    for (let j = 0; j < 10; j++){
+    it('Successful encrypt and decrypt specific sets: ',
+            function (done) {
+                let prm = Gpgmejs.init();
+                let data = bigBoringString(5); //see ./inputvalues.js
+                expect(Object.prototype.toString.call(data)).to.equal("[object String]");
+                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) {
+                                    if (data.length !== result.data.length) {
+
+                                        for (let k = 0; k < data.length; k++) {
+                                            if (data[k] !== result.data[k]) {
+                                                console.log(k);
+                                                console.log(data[k - 2] + data[k - 1] + data[k] + data[k + 1]);
+                                                console.log(result.data[k - 2] + result.data[k - 1] + result.data[k] + result.data[k + 1]);
+                                                break;
+                                            }
+                                        }
+                                    }
+                                    expect(result).to.not.be.empty;
+                                    expect(result.data).to.be.a('string');
+                                    expect(result.data).to.equal(data);
+                                    context.connection.disconnect();
+                                    done();
+
+                                });
+                        });
+                });
+            }).timeout(5000);
+        }
+
+
+    it('Roundtrip does not destroy trailing whitespace',
+        function (done) {
+            let prm = Gpgmejs.init();
+            prm.then(function (context) {
+                let data = 'Keks. \rKeks \n Keks \r\n';
+                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);
+                                context.connection.disconnect();
+                                done();
+
+                            });
+                    });
+            });
+        }).timeout(3000);
+
+    it('Test with simple non-ascii input',
+        function (done) {
+            let prm = Gpgmejs.init();
+            prm.then(function (context) {
+                let data = '';
+                for (let i=0; i < 1024 * 1024 * 0.1; i++){
+                    data += inputvalues.encrypt.good.data_nonascii;
+                }
+                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');
+                        console.log(answer);
+                        context.decrypt(answer.data).then(
+                            function (result) {
+                                expect(result).to.not.be.empty;
+                                expect(result.data).to.be.a('string');
+                                if (data.length !== result.data.length) {
+
+                                    for (let k = 0; k < data.length; k++) {
+                                        if (data[k] !== result.data[k]) {
+                                            console.log(k);
+                                            console.log(data[k - 2] + data[k - 1] + data[k] + data[k + 1]);
+                                            console.log(result.data[k - 2] + result.data[k - 1] + result.data[k] + result.data[k + 1]);
+                                            break;
+                                        }
+                                    }
+                                }
+                                console.log(data.length - result.data.length);
+                                expect(result.data).to.equal(data);
+                                context.connection.disconnect();
+                                done();
+
+                            });
+                    });
+            });
+        }).timeout(3000);
+*/
 /**
-    for (let i=0; i< 20; i++) {
-        it('Successful encrypt 1 MB '+ i+ '/20', function (done) {
+    for (let i=0; i< 100; i++) {
+        it('Successful encrypt random data '+ (i+1) + '/100', function (done) {
             let prm = Gpgmejs.init();
-            let data = bigString(0.1);
+            let data = bigString(0.2); // << set source data here
                 prm.then(function (context) {
                     context.encrypt(data,
                         inputvalues.encrypt.good.fingerprint).then(
@@ -63,10 +177,62 @@ describe('Encryption and Decryption', function () {
                                         expect(result).to.not.be.empty;
                                         expect(result.data).to.be.a('string');
                                         expect(result.data).to.equal(data);
+                                        context.connection.disconnect();
                                         done();
                                 });
                         });
                 });
-        }).timeout(10000);
-    };*/
+        }).timeout(5000);
+    };
+*/
+
+/** still fails
+    it('Successful encrypt 0.8 MB Uint8Array', function (done) {
+        let prm = Gpgmejs.init();
+        let data = bigUint8(0.8);
+        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(5000);
+*/
+
+    it('Decrypt simple non-ascii',
+        function (done) {
+            let prm = Gpgmejs.init();
+            prm.then(function (context) {
+                data = encryptedData;
+                context.decrypt(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_nonascii);
+                        context.encrypt(inputvalues.encrypt.good.data_nonascii, inputvalues.encrypt.good.fingerprint).then(
+                            function(result){
+                                context.decrypt(result.data).then(function(answer){
+                                    expect(answer.data).to.equal(inputvalues.encrypt.good.data_nonascii);
+                                    context.connection.disconnect();
+                                    done();
+                                });
+                            });
+                        });
+
+            });
+    }).timeout(8000);
+
 });
\ No newline at end of file
index 37b319e..2e95151 100644 (file)
@@ -28,6 +28,7 @@ describe('Encryption', function () {
                     expect(answer.data).to.be.a("string");
                     expect(answer.data).to.include('BEGIN PGP MESSAGE');
                     expect(answer.data).to.include('END PGP MESSAGE');
+                    context.connection.disconnect();
                     done();
                 });
         });
@@ -44,11 +45,13 @@ describe('Encryption', function () {
                     expect(answer.data).to.be.a("string");
                     expect(answer.data).to.include('BEGIN PGP MESSAGE');
                     expect(answer.data).to.include('END PGP MESSAGE');
+                    context.connection.disconnect();
                     done();
                 });
         });
     }).timeout(5000);
 
+/**
     it('Successful encrypt 20 MB', function (done) {
         let prm = Gpgmejs.init();
         let data = bigString(20);
@@ -60,11 +63,12 @@ describe('Encryption', function () {
                     expect(answer.data).to.be.a("string");
                     expect(answer.data).to.include('BEGIN PGP MESSAGE');
                     expect(answer.data).to.include('END PGP MESSAGE');
+                    context.connection.disconnect();
                     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
@@ -78,6 +82,7 @@ describe('Encryption', function () {
                     expect(answer.data).to.be.a("string");
                     expect(answer.data).to.include('BEGIN PGP MESSAGE');
                     expect(answer.data).to.include('END PGP MESSAGE');
+                    context.connection.disconnect();
                     done();
                 });
         });
@@ -94,6 +99,7 @@ describe('Encryption', function () {
                 }, function(error){
                     expect(error).to.be.an('Error');
                     expect(error.code).to.equal('MSG_INCOMPLETE');
+                    context.connection.disconnect();
                     done();
                 });
         });
@@ -108,6 +114,7 @@ describe('Encryption', function () {
                 }, function (error) {
                     expect(error).to.be.an.instanceof(Error);
                     expect(error.code).to.equal('MSG_INCOMPLETE');
+                    context.connection.disconnect();
                     done();
                 });
         });
@@ -125,10 +132,11 @@ describe('Encryption', function () {
                     expect(error).to.be.an('Error');
                     expect(error.code).to.not.be.undefined;
                     expect(error.code).to.equal('GNUPG_ERROR');
+                    context.connection.disconnect();
                     done();
                 });
         });
-    });
+    }).timeout(5000);;
 
     it('Overly large message ( >= 48MB) is rejected', function (done) {
         let prm = Gpgmejs.init();
@@ -141,6 +149,7 @@ describe('Encryption', function () {
                     expect(error).to.be.an.instanceof(Error);
                     // TODO who is throwing the error here?
                     // It is not a GPGME_Error!
+                    context.connection.disconnect();
                     done();
                 });
         });
index 3cd1e92..bc8c97b 100644 (file)
@@ -22,7 +22,8 @@ var inputvalues = {
     encrypt: {
         good:{
             data : 'Hello World.',
-            fingerprint : 'CDC3A2B2860625CCBFC5A5A9FC6D1B604967FC40'
+            fingerprint : 'D41735B91236FDB882048C5A2301635EEFF0CB05',
+            data_nonascii: '¡Äußerste µ€ før ñoquis@hóme! Добрый день\n'
         },
         bad: {
             fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
@@ -42,3 +43,62 @@ function bigString(megabytes){
     }
     return new TextDecoder('utf-8').decode(uint);
 }
+
+function bigUint8(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 uint;
+}
+
+function bigBoringString(megabytes){
+    let maxlength = 1024 * 1024 * megabytes;
+    let string = '';
+    let chars = ' ä0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    for (let i= 0; i < maxlength; i++){
+        string = string + chars[Math.floor(Math.random() * chars.length)];
+    }
+    return string;
+}
+
+function slightlyLessBoringString(megabytes, set){
+    let maxlength = 1024 * 1024 * megabytes;
+    let string = '';
+    let chars = '';
+    if (!set){
+
+    } else if (set ===1 ) {
+        chars = '\n\"\r \'';
+    } else if (set === 2 ) {
+        chars = '()=?`#+-{}[]';
+    } else if (set === 3){
+        chars = '^°/';
+            //'*<>\\^°/';
+    } else if (set ===4) {
+        chars = 'äüßµüþÖ~ɁÑ||@';
+    } else {
+        chars = '*<>\n\"\r§$%&/()=?`#+-{}[] \''; //fails!
+
+    }
+    for (let i= 0; i < maxlength; i++){
+        string = string + chars[Math.floor(Math.random() * chars.length)];
+    }
+    return string;
+}
+
+var encryptedData =
+    '-----BEGIN PGP MESSAGE-----\n' +
+    '\n' +
+    'hQEMA6B8jfIUScGEAQgAlANd3uyhmhYLzVcfz4LEqA8tgUC3n719YH0iuKEzG/dv\n' +
+    'B8fsIK2HoeQh2T3/Cc2LBMjgn4K33ksG3k2MqrbIvxWGUQlOAuggc259hquWtX9B\n' +
+    'EcEoOAeh5DuZT/b8CM5seJKNEpPzNxbEDiGikp9DV9gfIQTTUnrDjAu5YtgCN9vA\n' +
+    '3PJxihioH8ODoQw2jlYSkqgXpBVP2Fbx7qgTuxGNu5w36E0/P93//4hDXcKou7ez\n' +
+    'o0+NEGSkbaY+OPk1k7k9n+vBSC3F440dxsTNs5WmRvx9XZEotJkUBweE+8XaoLCn\n' +
+    '3RrtyD/lj63qi3dbyI5XFLuPU1baFskJ4UAmI4wNhdJ+ASailpnFBnNgiFBh3ZfB\n' +
+    'G5Rmd3ocSL7l6lq1bVK9advXb7vcne502W1ldAfHgTdQgc2CueIDFUYAaXP2OvhP\n' +
+    'isGL7jOlDCBKwep67ted0cTRPLWkk3NSuLIlvD5xs6L4z3rPu92gXYgbZoMMdP0N\n' +
+    'kSAQYOHplfA7YJWkrlRm\n' +
+    '=zap6\n' +
+    '-----END PGP MESSAGE-----\n';
\ No newline at end of file
index d26aab1..b71004a 100644 (file)
@@ -110,7 +110,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){
         }
         return null;
     } else if (code === 'GNUPG_ERROR'){
-        return new GPGME_Error(code, info.msg);
+        return new GPGME_Error(code, info);
     }
     else {
         return new GPGME_Error('GENERIC_ERROR');
index 9475b2b..c1a0137 100644 (file)
@@ -170,18 +170,19 @@ function putData(message, data){
     if (!data){
         return gpgme_error('PARAM_WRONG');
     } else if (data instanceof Uint8Array){
-        let decoder = new TextDecoder('utf8');
         message.setParameter('base64', true);
-        message.setParameter ('data', decoder.decode(data));
+        message.setParameter ('data', btoa(data));
     } else if (typeof(data) === 'string') {
         message.setParameter('base64', false);
         message.setParameter('data', data);
-    } else if ( typeof(data) === 'object' && data.hasOwnProperty(getText)){
+    } else if ( typeof(data) === 'object' && data.hasOwnProperty('getText')){
         let txt = data.getText();
         if (txt instanceof Uint8Array){
-            let decoder = new TextDecoder('utf8');
             message.setParameter('base64', true);
-            message.setParameter ('data', decoder.decode(txt));
+            message.setParameter ('data', btoa(txt));
+        }
+        else {
+            return gpgme_error('PARAM_WRONG');
         }
     } else {
         return gpgme_error('PARAM_WRONG');