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 00000000..12c3f5df Binary files /dev/null and b/lang/js/DemoExtension/testicon.png differ 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',