js: created TestExtension and smaller fixes
authorMaximilian Krambach <maximilian.krambach@intevation.de>
Thu, 26 Apr 2018 15:13:34 +0000 (17:13 +0200)
committerMaximilian Krambach <maximilian.krambach@intevation.de>
Thu, 26 Apr 2018 15:13:34 +0000 (17:13 +0200)
--

* Extensions:

  - Moved testapplication to Demoextension
  - Created BrowserTestExtension.
    Includes mocha and chai. For running tests that cannot be run
    outside a WebExtension

  Both Extensions can be found zipped in build/extensions after
  running build_extensions.sh

* Code changes:
  - src/Config: Place for the configuration
  - small fixes raised during testing in Keyring.js, Message.js,
  - src/gpgmejs_openpgpjs.js don't offer direct GpgME object to the
    outside, as it only causes confusion
  - index.js init() now checks the config for validity

* Tests:
  - Reordered tests in test/.
  - Input values are now in a separate file which may be of use for
    bulk testing

* moved the build directory from dist to build

28 files changed:
lang/js/BrowserTestExtension/browsertest.html [new file with mode: 0644]
lang/js/BrowserTestExtension/manifest.json [new file with mode: 0644]
lang/js/BrowserTestExtension/popup.html [new file with mode: 0644]
lang/js/BrowserTestExtension/popup.js [new file with mode: 0644]
lang/js/BrowserTestExtension/runbrowsertest.js [new file with mode: 0644]
lang/js/BrowserTestExtension/setup_testing.js [new file with mode: 0644]
lang/js/BrowserTestExtension/testicon.png [moved from lang/js/testicon.png with 100% similarity]
lang/js/BrowserTestExtension/tests/inputvalues.js [new file with mode: 0644]
lang/js/BrowserTestExtension/tests/startup.js [new file with mode: 0644]
lang/js/CHECKLIST
lang/js/CHECKLIST_build
lang/js/DemoExtension/entry.js [moved from lang/js/test_index.js with 96% similarity]
lang/js/DemoExtension/maindemo.js [moved from lang/js/testapplication.js with 100% similarity]
lang/js/DemoExtension/mainui.html [moved from lang/js/ui2.html with 89% similarity]
lang/js/DemoExtension/manifest.json [moved from lang/js/manifest.json with 54% similarity]
lang/js/DemoExtension/popup.html [moved from lang/js/testapplication_index.html with 100% similarity]
lang/js/DemoExtension/testicon.png [new file with mode: 0644]
lang/js/DemoExtension/ui.css [moved from lang/js/ui.css with 100% similarity]
lang/js/build_extensions.sh [new file with mode: 0755]
lang/js/src/Config.js [new file with mode: 0644]
lang/js/src/Keyring.js
lang/js/src/Message.js
lang/js/src/gpgmejs_openpgpjs.js
lang/js/src/index.js
lang/js/test/Helpers.js
lang/js/test/Message.js
lang/js/test/inputvalues.js [new file with mode: 0644]
lang/js/webpack.conf.js

diff --git a/lang/js/BrowserTestExtension/browsertest.html b/lang/js/BrowserTestExtension/browsertest.html
new file mode 100644 (file)
index 0000000..d2c6396
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <link href="libs/mocha.css" rel="stylesheet" />
+    </head>
+<body>
+    <h3>Browsertest</h3>
+    <div id="mocha"></div>
+    <!-- load unit tests -->
+    <script src="libs/mocha.js"></script>
+    <script src="libs/chai.js"></script>
+    <script src="setup_testing.js"></script>
+    <script src="libs/gpgmejs.bundle.js"></script>
+
+    <script src="tests/inputvalues.js"></script>
+<!-- insert tests here-->
+    <script src="tests/startup.js"></script>
+    <script src="tests/encryptTest.js"></script>
+<!-- run tests -->
+    <script src="runbrowsertest.js"></script>
+    </body>
+</html>
diff --git a/lang/js/BrowserTestExtension/manifest.json b/lang/js/BrowserTestExtension/manifest.json
new file mode 100644 (file)
index 0000000..a9e605b
--- /dev/null
@@ -0,0 +1,13 @@
+{
+    "manifest_version": 2,
+
+    "name": "Browsertests for gpgmejs",
+    "description": "Run the browsertests.",
+    "version": "0.1",
+    "content_security_policy": "default-src 'self' filesystem:",
+    "browser_action": {
+      "default_icon": "testicon.png",
+      "default_popup": "popup.html"
+    },
+    "permissions": ["nativeMessaging", "activeTab"]
+  }
diff --git a/lang/js/BrowserTestExtension/popup.html b/lang/js/BrowserTestExtension/popup.html
new file mode 100644 (file)
index 0000000..f17f262
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <script src="popup.js"></script>
+    </head>
+    <body>
+    </body>
+</html>
\ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/popup.js b/lang/js/BrowserTestExtension/popup.js
new file mode 100644 (file)
index 0000000..4764df5
--- /dev/null
@@ -0,0 +1,44 @@
+/* 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+
+ */
+/* 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+
+ */
+
+document.addEventListener('DOMContentLoaded', function() {
+    chrome.tabs.create({
+        url: './browsertest.html'
+    });
+});
diff --git a/lang/js/BrowserTestExtension/runbrowsertest.js b/lang/js/BrowserTestExtension/runbrowsertest.js
new file mode 100644 (file)
index 0000000..39bc3fb
--- /dev/null
@@ -0,0 +1,21 @@
+/* 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+
+ */
+
+mocha.run();
diff --git a/lang/js/BrowserTestExtension/setup_testing.js b/lang/js/BrowserTestExtension/setup_testing.js
new file mode 100644 (file)
index 0000000..7f70d34
--- /dev/null
@@ -0,0 +1,22 @@
+/* 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+
+ */
+mocha.setup('bdd');
+var expect = chai.expect;
+chai.config.includeStack = true;
\ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/inputvalues.js b/lang/js/BrowserTestExtension/tests/inputvalues.js
new file mode 100644 (file)
index 0000000..47600c8
--- /dev/null
@@ -0,0 +1,28 @@
+/* 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+
+ */
+
+var inputvalues = {
+    encrypt: {
+        good:{
+            data : 'Hello World.',
+            keyid : 'CDC3A2B2860625CCBFC5A5A9FC6D1B604967FC40'
+        }
+    }
+};
diff --git a/lang/js/BrowserTestExtension/tests/startup.js b/lang/js/BrowserTestExtension/tests/startup.js
new file mode 100644 (file)
index 0000000..14d12c0
--- /dev/null
@@ -0,0 +1,51 @@
+/* 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('GPGME context', function(){
+    it('Starting a GpgME instance', function(done){
+        Gpgmejs.init().then(
+         function(context){
+             expect(context.connection).to.not.be.undefined;
+             expect(context).to.be.an('object');
+             expect(context.connection).to.be.an('object');
+             expect(context.Keyring).to.be.undefined;
+             expect(context.encrypt).to.be.a('function');
+             expect(context.decrypt).to.be.a('function');
+         done();
+        }, function(err){
+        done(err);
+        });
+    });
+    it('Starting an openpgp mode GPGME instance', function(done){
+        Gpgmejs.init({api_style:"gpgme_openpgpjs"}).then(
+         function(context){
+             console.log(context);
+             done();
+        //      expect(context).to.be.an('object');
+        //      expect(context.connection).to.be.undefined;
+        //      expect(context.Keyring).to.be.an('object');
+        //      expect(context.encrypt).to.be.a('function');
+        //      expect(context.decrypt).to.be.a('function');
+        //  done();
+        }, function(err){
+        done(err);
+        });
+    });
+ });
index 49b1726..75664ae 100644 (file)
@@ -8,8 +8,8 @@ receiving an answer
 
 replicating Openpgpjs API:
 
-    [*] Message handling (encrypt, verify, sign)
-        [x] encrypt
+    [*] Message handling (encrypt, decrypt verify, sign)
+        [x] encrypt, decrypt
         [ ] verify
         [ ] sign
     [*] Key handling (import/export, modifying, status queries)
@@ -23,6 +23,6 @@ Communication with other implementations
 
 Management:
     [*] Define the gpgme interface
-    [ ] check Permissions (e.g. csp) for the different envs
+    [x] check Permissions (e.g. csp) for the different envs
     [X] agree on license
-    [ ] tests
+    [*] tests
index 19eb214..a7c8d08 100644 (file)
@@ -1,9 +1,3 @@
 - Checklist for build/install:
 
 browsers'  manifests (see README) need allowedextension added, and the path set
-
-manifest.json/ csp needs adaption
-
-/dist should be built which is used by the example app.
-
-csp in manifest.json MUST NOT contain "unsafe-eval" in production!
similarity index 96%
rename from lang/js/test_index.js
rename to lang/js/DemoExtension/entry.js
index 9119d27..7e5e1ff 100644 (file)
@@ -20,6 +20,6 @@
  */
 document.addEventListener('DOMContentLoaded', function() {
     chrome.tabs.create({
-        url: './ui2.html'
+        url: './uimainui.html'
     });
 });
similarity index 89%
rename from lang/js/ui2.html
rename to lang/js/DemoExtension/mainui.html
index 8d0abd9..d85e7a4 100644 (file)
@@ -3,8 +3,8 @@
     <head>
         <meta charset="utf-8">
         <link rel="stylesheet" href="ui.css"/>
-        <script src="dist/gpgmejs.bundle.js"></script>
-        <script src="testapplication.js"></script>
+        <script src="gpgmejs.bundle.js"></script>
+        <script src="maindemo.js"></script>
     </head>
     <body>
        <ul>
similarity index 54%
rename from lang/js/manifest.json
rename to lang/js/DemoExtension/manifest.json
index e5e17aa..9e057b3 100644 (file)
@@ -2,13 +2,13 @@
   "manifest_version": 2,
 
   "name": "gpgme-json with native Messaging",
-  "description": "This should be able to encrypt a text using gpgme-json",
+  "description": "A simple demo application",
   "version": "0.1",
-  "content_security_policy": "default-src 'self' 'unsafe-eval' filesystem:",
+  "content_security_policy": "default-src 'self' filesystem:",
   "browser_action": {
     "default_icon": "testicon.png",
     "default_title": "gpgme.js",
-    "default_popup": "testapplication_index.html"
+    "default_popup": "popup.html"
   },
   "permissions": ["nativeMessaging", "activeTab"]
 }
diff --git a/lang/js/DemoExtension/testicon.png b/lang/js/DemoExtension/testicon.png
new file mode 100644 (file)
index 0000000..12c3f5d
Binary files /dev/null and b/lang/js/DemoExtension/testicon.png differ
similarity index 100%
rename from lang/js/ui.css
rename to lang/js/DemoExtension/ui.css
diff --git a/lang/js/build_extensions.sh b/lang/js/build_extensions.sh
new file mode 100755 (executable)
index 0000000..be7b058
--- /dev/null
@@ -0,0 +1,14 @@
+#/!bin/bash
+
+npx webpack --config webpack.conf.js
+mkdir -p BrowserTestExtension/libs
+cp node_modules/chai/chai.js \
+    node_modules/mocha/mocha.css \
+    node_modules/mocha/mocha.js \
+    build/gpgmejs.bundle.js BrowserTestExtension/libs
+mkdir -p build/extensions
+zip -r build/extensions/browsertest.zip BrowserTestExtension
+
+mkdir -p DemoExtension/libs
+cp build/gpgmejs.bundle.js DemoExtension/libs
+zip -r build/extensions/demoextension.zip DemoExtension
diff --git a/lang/js/src/Config.js b/lang/js/src/Config.js
new file mode 100644 (file)
index 0000000..e18728d
--- /dev/null
@@ -0,0 +1,31 @@
+/* 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+
+ */
+
+export const availableConf = {
+    api_style: ['gpgme', 'gpgme_openpgpjs'],
+    null_expire_is_never: [true, false],
+    unconsidered_params: ['warn','reject', 'ignore'],
+};
+
+export const defaultConf = {
+    api_style: 'gpgme',
+    null_expire_is_never: false,
+    unconsidered_params: 'reject',
+};
\ No newline at end of file
index 470eeee..364bfb4 100644 (file)
@@ -22,6 +22,7 @@ import {createMessage} from './Message'
 import {GPGME_Key} from './Key'
 import { isFingerprint, isLongId } from './Helpers';
 import { gpgme_error } from './Errors';
+import { Connection } from './Connection';
 
 export class GPGME_Keyring {
     constructor(connection){
index 4d24227..9e7a883 100644 (file)
@@ -36,7 +36,7 @@ export function createMessage(operation){
  * ./permittedOperations.
  * @param {String} operation
  */
-class GPGME_Message {
+export class GPGME_Message {
     //TODO getter
 
     constructor(operation){
index 4e5e1ea..cc2afde 100644 (file)
             if (!this._GPGME){
                 this._GpgME = new GpgME(connection, config);
             }
-            if (!this._Keyring){
-                this._Keyring = new GPGME_Keyring_openpgpmode(connection);
+            if (!this._keyring){
+                this._keyring = new GPGME_Keyring_openpgpmode(connection);
             }
         }
     }
 
-    get GpgME(){
-        if (this._GpGME){
-            return this._GpGME;
-        }
-    }
-
     /**
      * Encrypt Message
      * Supported:
                 return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED'));
             }
         }
-        return this.GpgME.encrypt(data, translateKeyInput(publicKeys), wildcard);
+        return this._GpgME.encrypt(data, translateKeyInput(publicKeys), wildcard);
     }
 
     /** Decrypt Message
                 return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED'));
             }
         }
-        return this.GpgME.decrypt(message);
+        return this._GpgME.decrypt(message);
         // TODO: translate between:
         // openpgp:
         // { data:Uint8Array|String,
index 4890431..4de9845 100644 (file)
@@ -22,36 +22,60 @@ import { GpgME } from "./gpgmejs";
 import { gpgme_error } from "./Errors";
 import { GpgME_openpgpmode } from "./gpgmejs_openpgpjs";
 import { Connection } from "./Connection";
+import { defaultConf, availableConf } from "./Config";
 
 /**
  * Initializes a nativeMessaging Connection and returns a GPGMEjs object
- * @param {*} conf Configuration. TBD
+ * @param {Object} config Configuration. See Config.js for available parameters. Still TODO
  */
-function init( config = {
-    api_style: 'gpgme', //  | gpgme_openpgpjs
-    null_expire_is_never: true, // Boolean
-    unconsidered_params: 'warn'//'warn' || 'reject'
-    }){
-        return new Promise(function(resolve, reject){
-            let connection = new Connection;
-            // TODO: Delayed reaction is ugly. We need to listen to the port's
-            // event listener in isConnected, but this takes some time (<5ms) to
-            // disconnect if there is no successfull connection.
-            let delayedreaction = function(){
-                if (connection.isConnected === true){
-                    let gpgme = null;
-                    if (config.api_style && config.api_style === 'gpgme_openpgpjs'){
-                        resolve(
-                            new GpgME_openpgpmode(connection, config));
-                    } else {
-                        resolve(new GpgME(connection));
-                    }
+function init(config){
+    let _conf = parseconfiguration(config);
+    if (_conf instanceof Error){
+        return Promise.reject(_conf);
+    }
+    return new Promise(function(resolve, reject){
+        let connection = new Connection;
+        // TODO: Delayed reaction is ugly. We need to listen to the port's
+        // event listener in isConnected, but this takes some time (<5ms) to
+        // disconnect if there is no successfull connection.
+        let delayedreaction = function(){
+            if (connection.isConnected === true){
+                if (_conf.api_style && _conf.api_style === 'gpgme_openpgpjs'){
+                    resolve(new GpgME_openpgpmode(connection, _conf));
                 } else {
-                    reject(gpgme_error('CONN_NO_CONNECT'));
+                    resolve(new GpgME(connection));
                 }
-            };
-            setTimeout(delayedreaction, 5);
+            } else {
+                reject(gpgme_error('CONN_NO_CONNECT'));
+            }
+        };
+        setTimeout(delayedreaction, 5);
     });
+}
+
+function parseconfiguration(config){
+    if (!config){
+        return defaultConf;
+    }
+    if ( typeof(config) !== 'object'){
+        return gpgme_error('PARAM_WRONG');
+    };
+    let result_config = defaultConf;
+    let conf_keys = Object.keys(config);
+    for (let i=0; i < conf_keys; i++){
+        if (availableConf.hasOwnProperty(conf_keys[i])){
+            let value = config[conf_keys[i]];
+            if (availableConf[conf_keys[i]].indexOf(value) < 0){
+                return gpgme_error('PARAM_WRONG');
+            } else {
+                result_config[conf_keys[i]] = value;
+            }
+        }
+        else {
+            return gpgme_error('PARAM_WRONG');
+        }
+    }
+    return result_config;
 };
 
 export default {
index 590f9f6..5d8909f 100644 (file)
@@ -22,89 +22,76 @@ import { expect } from "../node_modules/chai/chai";
 import { gpgme_error} from "../src/Errors";
 import { GPGME_Key } from "../src/Key";
 import { isLongId, isFingerprint, toKeyIdArray } from "../src/Helpers"
+import { helper_params } from "./inputvalues";
 
-const helper_params = {
-    validLongId: '0A0A0A0A0A0A0A0A',
-    validGPGME_Key: new GPGME_Key('ADDBC303B6D31026F5EB4591A27EABDF283121BB'),
-    validKeys: [new GPGME_Key('A1E3BC45BDC8E87B74F4392D53B151A1368E50F3'),
-        'ADDBC303B6D31026F5EB4591A27EABDF283121BB',
-        new GPGME_Key('EE17AEE730F88F1DE7713C54BBE0A4FF7851650A')],
-    validFingerprint: '9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A',
-    invalidLongId: '9A9A7A7A8A9A9A7A7A8A',
-    invalidFingerprint: [{hello:'World'}],
-    invalidKeyArray: {curiosity:'uncat'},
-    invalidKeyArray_OneBad: [
-        new GPGME_Key('12AE9F3E41B33BF77DF52B6BE8EE1992D7909B08'),
-        'E1D18E6E994FA9FE9360Bx0E687B940FEFEB095A',
-        '3AEA7FE4F5F416ED18CEC63DD519450D9C0FAEE5'],
-    invalidErrorCode: 'Please type in all your passwords.'
-}
-
-describe('Error Object handling', function(){
-    it('check the Timeout error', function(){
-        let test0 = gpgme_error('CONN_TIMEOUT');
-        expect(test0).to.be.an.instanceof(Error);
-        expect(test0.code).to.equal('CONN_TIMEOUT');
-    });
-    it('Error Object returns generic code if code is not listed', function(){
-        let test0 = gpgme_error(helper_params.invalidErrorCode);
-        expect(test0).to.be.an.instanceof(Error);
-        expect(test0.code).to.equal('GENERIC_ERROR');
-    });
-
-    it('Warnings like PARAM_IGNORED should not return errors', function(){
-        let test0 = gpgme_error('PARAM_IGNORED');
-        expect(test0).to.be.null;
-    });
-});
-
-describe('Fingerprint checking', function(){
-    it('isFingerprint(): valid Fingerprint', function(){
-        let test0  = isFingerprint(helper_params.validFingerprint);
-        expect(test0).to.be.true;
-    });
-    it('isFingerprint(): invalid Fingerprint', function(){
-        let test0 = isFingerprint(helper_params.invalidFingerprint);
-        expect(test0).to.be.false;
-    });
-});
-describe('Converting to Fingerprint', function(){
-    it('Correct Inputs', function(){
-        it('Fingerprint string', function(){
-            let test0 = toKeyIdArray(helper_params.validFingerprint);
-            expect(test0).to.be.an('array');
-            expect(test0).to.include(helper_params.validFingerprint);
+function Helpertest(){
+    describe('Error Object handling', function(){
+        it('check the Timeout error', function(){
+            let test0 = gpgme_error('CONN_TIMEOUT');
+            expect(test0).to.be.an.instanceof(Error);
+            expect(test0.code).to.equal('CONN_TIMEOUT');
         });
-        it('GPGME_Key', function(){
-            expect(helper_params.validGPGME_Key).to.be.an.instanceof(GPGME_Key);
-            let test0 = toKeyIdArray(helper_params.validGPGME_Key);
-            expect(test0).to.be.an('array');
-            expect(test0).to.include(helper_params.validGPGME_Key.fingerprint);
+        it('Error Object returns generic code if code is not listed', function(){
+            let test0 = gpgme_error(helper_params.invalidErrorCode);
+            expect(test0).to.be.an.instanceof(Error);
+            expect(test0.code).to.equal('GENERIC_ERROR');
         });
-        it('Array of valid inputs', function(){
-            let test0 = toKeyIdArray(helper_params.validKeys);
-            expect(test0).to.be.an('array');
-            expect(test0).to.have.lengthOf(helper_params.validKeys.length);
+
+        it('Warnings like PARAM_IGNORED should not return errors', function(){
+            let test0 = gpgme_error('PARAM_IGNORED');
+            expect(test0).to.be.null;
         });
     });
-    describe('Incorrect inputs', function(){
-        it('valid Long ID', function(){
-            let test0 = toKeyIdArray(helper_params.validLongId);
-            expect(test0).to.be.empty;
+
+    describe('Fingerprint checking', function(){
+        it('isFingerprint(): valid Fingerprint', function(){
+            let test0  = isFingerprint(helper_params.validFingerprint);
+            expect(test0).to.be.true;
         });
-        it('invalidFingerprint', function(){
-            let test0 = toKeyIdArray(helper_params.invalidFingerprint);
-            expect(test0).to.be.empty;
+        it('isFingerprint(): invalid Fingerprint', function(){
+            let test0 = isFingerprint(helper_params.invalidFingerprint);
+            expect(test0).to.be.false;
         });
-        it('invalidKeyArray', function(){
-            let test0 = toKeyIdArray(helper_params.invalidKeyArray);
-            expect(test0).to.be.empty;
+    });
+    describe('Converting to Fingerprint', function(){
+        it('Correct Inputs', function(){
+            it('Fingerprint string', function(){
+                let test0 = toKeyIdArray(helper_params.validFingerprint);
+                expect(test0).to.be.an('array');
+                expect(test0).to.include(helper_params.validFingerprint);
+            });
+            it('GPGME_Key', function(){
+                expect(helper_params.validGPGME_Key).to.be.an.instanceof(GPGME_Key);
+                let test0 = toKeyIdArray(helper_params.validGPGME_Key);
+                expect(test0).to.be.an('array');
+                expect(test0).to.include(helper_params.validGPGME_Key.fingerprint);
+            });
+            it('Array of valid inputs', function(){
+                let test0 = toKeyIdArray(helper_params.validKeys);
+                expect(test0).to.be.an('array');
+                expect(test0).to.have.lengthOf(helper_params.validKeys.length);
+            });
         });
-        it('Partially invalid array', function(){
-            let test0 = toKeyIdArray(helper_params.invalidKeyArray_OneBad);
-            expect(test0).to.be.an('array');
-            expect(test0).to.have.lengthOf(
-                helper_params.invalidKeyArray_OneBad.length - 1);
+        describe('Incorrect inputs', function(){
+            it('valid Long ID', function(){
+                let test0 = toKeyIdArray(helper_params.validLongId);
+                expect(test0).to.be.empty;
+            });
+            it('invalidFingerprint', function(){
+                let test0 = toKeyIdArray(helper_params.invalidFingerprint);
+                expect(test0).to.be.empty;
+            });
+            it('invalidKeyArray', function(){
+                let test0 = toKeyIdArray(helper_params.invalidKeyArray);
+                expect(test0).to.be.empty;
+            });
+            it('Partially invalid array', function(){
+                let test0 = toKeyIdArray(helper_params.invalidKeyArray_OneBad);
+                expect(test0).to.be.an('array');
+                expect(test0).to.have.lengthOf(
+                    helper_params.invalidKeyArray_OneBad.length - 1);
+            });
         });
     });
-});
+};
+export default Helpertest;
\ No newline at end of file
index 454b8ca..44206fb 100644 (file)
 import { expect } from "../node_modules/chai/chai";
 import { GPGME_Message, createMessage } from "../src/Message";
 
-const message_params = {
-    invalid_op_action : 'dance',
-    invalid_op_type : [234, 34, '<>'],
-}
+import { message_params } from "./inputvalues";
 
-describe('Message Object', function(){
-    describe('incorrect initialization', function(){
-        it('non-allowed operation', function(){
-            let test0 = createMessage(message_params.invalid_op_action);
-            expect(test0).to.be.an.instanceof(Error);
-            expect(test0.code).to.equal('MSG_WRONG_OP');
-        });
-        it('wrong parameter type in constructor', function(){
-            let test0 = createMessage(message_params.invalid_op_type);
-            expect(test0).to.be.an.instanceof(Error);
-            expect(test0.code).to.equal('PARAM_WRONG');
+function Messagetest(){
+
+    describe('Message Object', function(){
+        describe('incorrect initialization', function(){
+            it('non-allowed operation', function(){
+                let test0 = createMessage(message_params.invalid_op_action);
+                expect(test0).to.be.an.instanceof(Error);
+                expect(test0.code).to.equal('MSG_WRONG_OP');
+            });
+            it('wrong parameter type in constructor', function(){
+                let test0 = createMessage(message_params.invalid_op_type);
+                expect(test0).to.be.an.instanceof(Error);
+                expect(test0.code).to.equal('PARAM_WRONG');
+            });
         });
     });
-});
+};
+export default Messagetest;
\ No newline at end of file
diff --git a/lang/js/test/inputvalues.js b/lang/js/test/inputvalues.js
new file mode 100644 (file)
index 0000000..a50c816
--- /dev/null
@@ -0,0 +1,29 @@
+
+import {GPGME_Key} from "../src/Key"
+
+export const helper_params = {
+    validLongId: '0A0A0A0A0A0A0A0A',
+    validGPGME_Key: new GPGME_Key('ADDBC303B6D31026F5EB4591A27EABDF283121BB'),
+    validKeys: [new GPGME_Key('A1E3BC45BDC8E87B74F4392D53B151A1368E50F3'),
+        'ADDBC303B6D31026F5EB4591A27EABDF283121BB',
+        new GPGME_Key('EE17AEE730F88F1DE7713C54BBE0A4FF7851650A')],
+    validFingerprint: '9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A',
+    invalidLongId: '9A9A7A7A8A9A9A7A7A8A',
+    invalidFingerprint: [{hello:'World'}],
+    invalidKeyArray: {curiosity:'uncat'},
+    invalidKeyArray_OneBad: [
+        new GPGME_Key('12AE9F3E41B33BF77DF52B6BE8EE1992D7909B08'),
+        'E1D18E6E994FA9FE9360Bx0E687B940FEFEB095A',
+        '3AEA7FE4F5F416ED18CEC63DD519450D9C0FAEE5'],
+    invalidErrorCode: 'Please type in all your passwords.'
+}
+
+export const message_params = {
+    invalid_op_action : 'dance',
+    invalid_op_type : [234, 34, '<>'],
+}
+
+export default {
+    helper_params: helper_params,
+    message_params: message_params
+}
\ No newline at end of file
index 7a5392e..b2ad909 100644 (file)
@@ -26,7 +26,7 @@ module.exports = {
   // mode: 'development',
   mode: 'production',
   output: {
-    path: path.resolve(__dirname, 'dist'),
+    path: path.resolve(__dirname, 'build'),
     filename: 'gpgmejs.bundle.js',
     libraryTarget: 'var',
     libraryExport: 'default',