From 1f7b19512cfa7e1b153b99d6a2b40bad82a5496e Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Thu, 26 Apr 2018 17:13:34 +0200 Subject: [PATCH] js: created TestExtension and smaller fixes -- * 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 --- lang/js/BrowserTestExtension/browsertest.html | 23 +++ lang/js/BrowserTestExtension/manifest.json | 13 ++ lang/js/BrowserTestExtension/popup.html | 9 ++ lang/js/BrowserTestExtension/popup.js | 44 ++++++ .../js/BrowserTestExtension/runbrowsertest.js | 21 +++ lang/js/BrowserTestExtension/setup_testing.js | 22 +++ .../{ => BrowserTestExtension}/testicon.png | Bin .../BrowserTestExtension/tests/inputvalues.js | 28 ++++ lang/js/BrowserTestExtension/tests/startup.js | 51 +++++++ lang/js/CHECKLIST | 8 +- lang/js/CHECKLIST_build | 6 - .../{test_index.js => DemoExtension/entry.js} | 2 +- .../maindemo.js} | 0 .../{ui2.html => DemoExtension/mainui.html} | 4 +- lang/js/{ => DemoExtension}/manifest.json | 6 +- .../popup.html} | 0 lang/js/DemoExtension/testicon.png | Bin 0 -> 16192 bytes lang/js/{ => DemoExtension}/ui.css | 0 lang/js/build_extensions.sh | 14 ++ lang/js/src/Config.js | 31 ++++ lang/js/src/Keyring.js | 1 + lang/js/src/Message.js | 2 +- lang/js/src/gpgmejs_openpgpjs.js | 14 +- lang/js/src/index.js | 70 ++++++--- lang/js/test/Helpers.js | 139 ++++++++---------- lang/js/test/Message.js | 33 +++-- lang/js/test/inputvalues.js | 29 ++++ lang/js/webpack.conf.js | 2 +- 28 files changed, 429 insertions(+), 143 deletions(-) create mode 100644 lang/js/BrowserTestExtension/browsertest.html create mode 100644 lang/js/BrowserTestExtension/manifest.json create mode 100644 lang/js/BrowserTestExtension/popup.html create mode 100644 lang/js/BrowserTestExtension/popup.js create mode 100644 lang/js/BrowserTestExtension/runbrowsertest.js create mode 100644 lang/js/BrowserTestExtension/setup_testing.js rename lang/js/{ => BrowserTestExtension}/testicon.png (100%) create mode 100644 lang/js/BrowserTestExtension/tests/inputvalues.js create mode 100644 lang/js/BrowserTestExtension/tests/startup.js rename lang/js/{test_index.js => DemoExtension/entry.js} (96%) rename lang/js/{testapplication.js => DemoExtension/maindemo.js} (100%) rename lang/js/{ui2.html => DemoExtension/mainui.html} (89%) rename lang/js/{ => DemoExtension}/manifest.json (54%) rename lang/js/{testapplication_index.html => DemoExtension/popup.html} (100%) create mode 100644 lang/js/DemoExtension/testicon.png rename lang/js/{ => DemoExtension}/ui.css (100%) create mode 100755 lang/js/build_extensions.sh create mode 100644 lang/js/src/Config.js create mode 100644 lang/js/test/inputvalues.js diff --git a/lang/js/BrowserTestExtension/browsertest.html b/lang/js/BrowserTestExtension/browsertest.html new file mode 100644 index 00000000..d2c6396f --- /dev/null +++ b/lang/js/BrowserTestExtension/browsertest.html @@ -0,0 +1,23 @@ + + + + + + + +

Browsertest

+
+ + + + + + + + + + + + + + diff --git a/lang/js/BrowserTestExtension/manifest.json b/lang/js/BrowserTestExtension/manifest.json new file mode 100644 index 00000000..a9e605bc --- /dev/null +++ b/lang/js/BrowserTestExtension/manifest.json @@ -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 index 00000000..f17f262a --- /dev/null +++ b/lang/js/BrowserTestExtension/popup.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/lang/js/BrowserTestExtension/popup.js b/lang/js/BrowserTestExtension/popup.js new file mode 100644 index 00000000..4764df55 --- /dev/null +++ b/lang/js/BrowserTestExtension/popup.js @@ -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 . + * 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 . + * 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 index 00000000..39bc3fb9 --- /dev/null +++ b/lang/js/BrowserTestExtension/runbrowsertest.js @@ -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 . + * 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 index 00000000..7f70d347 --- /dev/null +++ b/lang/js/BrowserTestExtension/setup_testing.js @@ -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 . + * 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/testicon.png b/lang/js/BrowserTestExtension/testicon.png similarity index 100% rename from lang/js/testicon.png rename to lang/js/BrowserTestExtension/testicon.png diff --git a/lang/js/BrowserTestExtension/tests/inputvalues.js b/lang/js/BrowserTestExtension/tests/inputvalues.js new file mode 100644 index 00000000..47600c84 --- /dev/null +++ b/lang/js/BrowserTestExtension/tests/inputvalues.js @@ -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 . + * 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 index 00000000..14d12c0a --- /dev/null +++ b/lang/js/BrowserTestExtension/tests/startup.js @@ -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 . + * 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); + }); + }); + }); diff --git a/lang/js/CHECKLIST b/lang/js/CHECKLIST index 49b17265..75664ae5 100644 --- a/lang/js/CHECKLIST +++ b/lang/js/CHECKLIST @@ -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 diff --git a/lang/js/CHECKLIST_build b/lang/js/CHECKLIST_build index 19eb2146..a7c8d08d 100644 --- a/lang/js/CHECKLIST_build +++ b/lang/js/CHECKLIST_build @@ -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! diff --git a/lang/js/test_index.js b/lang/js/DemoExtension/entry.js similarity index 96% rename from lang/js/test_index.js rename to lang/js/DemoExtension/entry.js index 9119d271..7e5e1ffe 100644 --- a/lang/js/test_index.js +++ b/lang/js/DemoExtension/entry.js @@ -20,6 +20,6 @@ */ document.addEventListener('DOMContentLoaded', function() { chrome.tabs.create({ - url: './ui2.html' + url: './uimainui.html' }); }); diff --git a/lang/js/testapplication.js b/lang/js/DemoExtension/maindemo.js similarity index 100% rename from lang/js/testapplication.js rename to lang/js/DemoExtension/maindemo.js diff --git a/lang/js/ui2.html b/lang/js/DemoExtension/mainui.html similarity index 89% rename from lang/js/ui2.html rename to lang/js/DemoExtension/mainui.html index 8d0abd97..d85e7a46 100644 --- a/lang/js/ui2.html +++ b/lang/js/DemoExtension/mainui.html @@ -3,8 +3,8 @@ - - + +
    diff --git a/lang/js/manifest.json b/lang/js/DemoExtension/manifest.json similarity index 54% rename from lang/js/manifest.json rename to lang/js/DemoExtension/manifest.json index e5e17aa5..9e057b35 100644 --- a/lang/js/manifest.json +++ b/lang/js/DemoExtension/manifest.json @@ -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/testapplication_index.html b/lang/js/DemoExtension/popup.html similarity index 100% rename from lang/js/testapplication_index.html rename to lang/js/DemoExtension/popup.html diff --git a/lang/js/DemoExtension/testicon.png b/lang/js/DemoExtension/testicon.png new file mode 100644 index 0000000000000000000000000000000000000000..12c3f5df5d3e71f286f5cc84e4d520bd84461489 GIT binary patch literal 16192 zcmeHuiC0rs*Y`qsB~;N66wS( z^nZzF#g4Q1=$;fhEot)Nn55*{OXid0J3C?ifW=Enk1& z2)G(Lbm#u+g)hVA{;UbSQGQ|a&*glU(IxVpoo_L3Qr$XTe(v3y2Y))(H=b{JZ52vt zC!dVV@C$9Yy!pp3@)xTcrmsAB@Sp@--hP)>=74|6lRosXiAhV`c=|%@T(;HZ zSmc7iiBuEegpP{@~pdQhe135QADY72O4ntMphTCEKa$)1Ee_ z3o~TIcOqWgZe`4De6J<^MT-8y?(Q%12Pn_K+^X*LGmEB8(Xf58dM&q?@5M)y;ZJ#L5FS(#Dt0APv z60m7J)sQj&vVQ$8LS|8gd^O`)v#=!&KQvfgfHh>T3jdXHD%Cse(8O;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HcmV?d00001 diff --git a/lang/js/ui.css b/lang/js/DemoExtension/ui.css 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 index 00000000..be7b0584 --- /dev/null +++ b/lang/js/build_extensions.sh @@ -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 index 00000000..e18728de --- /dev/null +++ b/lang/js/src/Config.js @@ -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 . + * 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 diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js index 470eeeec..364bfb46 100644 --- a/lang/js/src/Keyring.js +++ b/lang/js/src/Keyring.js @@ -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){ diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js index 4d242277..9e7a8835 100644 --- a/lang/js/src/Message.js +++ b/lang/js/src/Message.js @@ -36,7 +36,7 @@ export function createMessage(operation){ * ./permittedOperations. * @param {String} operation */ -class GPGME_Message { +export class GPGME_Message { //TODO getter constructor(operation){ diff --git a/lang/js/src/gpgmejs_openpgpjs.js b/lang/js/src/gpgmejs_openpgpjs.js index 4e5e1ea0..cc2afde1 100644 --- a/lang/js/src/gpgmejs_openpgpjs.js +++ b/lang/js/src/gpgmejs_openpgpjs.js @@ -50,18 +50,12 @@ 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: @@ -115,7 +109,7 @@ 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 @@ -152,7 +146,7 @@ return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED')); } } - return this.GpgME.decrypt(message); + return this._GpgME.decrypt(message); // TODO: translate between: // openpgp: // { data:Uint8Array|String, diff --git a/lang/js/src/index.js b/lang/js/src/index.js index 48904316..4de98457 100644 --- a/lang/js/src/index.js +++ b/lang/js/src/index.js @@ -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 { diff --git a/lang/js/test/Helpers.js b/lang/js/test/Helpers.js index 590f9f65..5d8909f9 100644 --- a/lang/js/test/Helpers.js +++ b/lang/js/test/Helpers.js @@ -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.' -} +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('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'); + }); -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; + }); }); - 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); + describe('Fingerprint checking', function(){ + it('isFingerprint(): valid Fingerprint', function(){ + let test0 = isFingerprint(helper_params.validFingerprint); + expect(test0).to.be.true; }); - 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('isFingerprint(): invalid Fingerprint', function(){ + let test0 = isFingerprint(helper_params.invalidFingerprint); + expect(test0).to.be.false; }); }); - describe('Incorrect inputs', function(){ - it('valid Long ID', function(){ - let test0 = toKeyIdArray(helper_params.validLongId); - 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('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); + 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 diff --git a/lang/js/test/Message.js b/lang/js/test/Message.js index 454b8ca3..44206fba 100644 --- a/lang/js/test/Message.js +++ b/lang/js/test/Message.js @@ -21,22 +21,23 @@ 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 index 00000000..a50c8162 --- /dev/null +++ b/lang/js/test/inputvalues.js @@ -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 diff --git a/lang/js/webpack.conf.js b/lang/js/webpack.conf.js index 7a5392ee..b2ad9098 100644 --- a/lang/js/webpack.conf.js +++ b/lang/js/webpack.conf.js @@ -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',