[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-15-g1f7b195
by Maximilian Krambach
cvs at cvs.gnupg.org
Thu Apr 26 17:16:47 CEST 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".
The branch, javascript-binding has been updated
via 1f7b19512cfa7e1b153b99d6a2b40bad82a5496e (commit)
from 3685913bf510a14b8cb324d980217d90489e6453 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1f7b19512cfa7e1b153b99d6a2b40bad82a5496e
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date: Thu Apr 26 17:13:34 2018 +0200
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
diff --git a/lang/js/BrowserTestExtension/browsertest.html b/lang/js/BrowserTestExtension/browsertest.html
new file mode 100644
index 0000000..d2c6396
--- /dev/null
+++ b/lang/js/BrowserTestExtension/browsertest.html
@@ -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
index 0000000..a9e605b
--- /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/testapplication_index.html b/lang/js/BrowserTestExtension/popup.html
similarity index 65%
copy from lang/js/testapplication_index.html
copy to lang/js/BrowserTestExtension/popup.html
index 866b113..f17f262 100644
--- a/lang/js/testapplication_index.html
+++ b/lang/js/BrowserTestExtension/popup.html
@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
- <script src="test_index.js"></script>
+ <script src="popup.js"></script>
</head>
<body>
</body>
diff --git a/lang/js/test_index.js b/lang/js/BrowserTestExtension/popup.js
similarity index 51%
copy from lang/js/test_index.js
copy to lang/js/BrowserTestExtension/popup.js
index 9119d27..4764df5 100644
--- a/lang/js/test_index.js
+++ b/lang/js/BrowserTestExtension/popup.js
@@ -16,10 +16,29 @@
* 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: './ui2.html'
+ url: './browsertest.html'
});
});
diff --git a/lang/js/test_index.js b/lang/js/BrowserTestExtension/runbrowsertest.js
similarity index 87%
copy from lang/js/test_index.js
copy to lang/js/BrowserTestExtension/runbrowsertest.js
index 9119d27..39bc3fb 100644
--- a/lang/js/test_index.js
+++ b/lang/js/BrowserTestExtension/runbrowsertest.js
@@ -16,10 +16,6 @@
* 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: './ui2.html'
- });
-});
+
+mocha.run();
diff --git a/lang/js/test_index.js b/lang/js/BrowserTestExtension/setup_testing.js
similarity index 87%
copy from lang/js/test_index.js
copy to lang/js/BrowserTestExtension/setup_testing.js
index 9119d27..7f70d34 100644
--- a/lang/js/test_index.js
+++ b/lang/js/BrowserTestExtension/setup_testing.js
@@ -16,10 +16,7 @@
* 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: './ui2.html'
- });
-});
+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%
copy from lang/js/testicon.png
copy to lang/js/BrowserTestExtension/testicon.png
diff --git a/lang/js/test_index.js b/lang/js/BrowserTestExtension/tests/inputvalues.js
similarity index 83%
copy from lang/js/test_index.js
copy to lang/js/BrowserTestExtension/tests/inputvalues.js
index 9119d27..47600c8 100644
--- a/lang/js/test_index.js
+++ b/lang/js/BrowserTestExtension/tests/inputvalues.js
@@ -16,10 +16,13 @@
* 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: './ui2.html'
- });
-});
+
+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 0000000..14d12c0
--- /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 <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);
+ });
+ });
+ });
diff --git a/lang/js/CHECKLIST b/lang/js/CHECKLIST
index 49b1726..75664ae 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 19eb214..a7c8d08 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%
copy from lang/js/test_index.js
copy to lang/js/DemoExtension/entry.js
index 9119d27..7e5e1ff 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 8d0abd9..d85e7a4 100644
--- a/lang/js/ui2.html
+++ b/lang/js/DemoExtension/mainui.html
@@ -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>
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 e5e17aa..9e057b3 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/testicon.png b/lang/js/DemoExtension/testicon.png
similarity index 100%
rename from lang/js/testicon.png
rename to lang/js/DemoExtension/testicon.png
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 0000000..be7b058
--- /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/test_index.js b/lang/js/src/Config.js
similarity index 74%
rename from lang/js/test_index.js
rename to lang/js/src/Config.js
index 9119d27..e18728d 100644
--- a/lang/js/test_index.js
+++ b/lang/js/src/Config.js
@@ -16,10 +16,16 @@
* 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: './ui2.html'
- });
-});
+
+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 470eeee..364bfb4 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 4d24227..9e7a883 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 4e5e1ea..cc2afde 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 4890431..4de9845 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 590f9f6..5d8909f 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.'
-}
-
-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
diff --git a/lang/js/test/Message.js b/lang/js/test/Message.js
index 454b8ca..44206fb 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 0000000..a50c816
--- /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 7a5392e..b2ad909 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',
-----------------------------------------------------------------------
Summary of changes:
lang/js/BrowserTestExtension/browsertest.html | 23 ++++
lang/js/BrowserTestExtension/manifest.json | 13 ++
.../popup.html} | 2 +-
.../popup.js} | 21 +++-
.../runbrowsertest.js} | 8 +-
.../setup_testing.js} | 9 +-
lang/js/{ => BrowserTestExtension}/testicon.png | Bin
.../tests/inputvalues.js} | 15 ++-
lang/js/BrowserTestExtension/tests/startup.js | 51 ++++++++
lang/js/CHECKLIST | 8 +-
lang/js/CHECKLIST_build | 6 -
lang/js/{test_index.js => DemoExtension/entry.js} | 2 +-
.../maindemo.js} | 0
lang/js/{ui2.html => DemoExtension/mainui.html} | 4 +-
lang/js/{ => DemoExtension}/manifest.json | 6 +-
.../popup.html} | 0
lang/js/{ => DemoExtension}/testicon.png | Bin
lang/js/{ => DemoExtension}/ui.css | 0
lang/js/build_extensions.sh | 14 +++
lang/js/{test_index.js => src/Config.js} | 18 ++-
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, 321 insertions(+), 169 deletions(-)
create mode 100644 lang/js/BrowserTestExtension/browsertest.html
create mode 100644 lang/js/BrowserTestExtension/manifest.json
copy lang/js/{testapplication_index.html => BrowserTestExtension/popup.html} (65%)
copy lang/js/{test_index.js => BrowserTestExtension/popup.js} (51%)
copy lang/js/{test_index.js => BrowserTestExtension/runbrowsertest.js} (87%)
copy lang/js/{test_index.js => BrowserTestExtension/setup_testing.js} (87%)
copy lang/js/{ => BrowserTestExtension}/testicon.png (100%)
copy lang/js/{test_index.js => BrowserTestExtension/tests/inputvalues.js} (83%)
create mode 100644 lang/js/BrowserTestExtension/tests/startup.js
copy 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%)
rename lang/js/{ => DemoExtension}/testicon.png (100%)
rename lang/js/{ => DemoExtension}/ui.css (100%)
create mode 100755 lang/js/build_extensions.sh
rename lang/js/{test_index.js => src/Config.js} (74%)
create mode 100644 lang/js/test/inputvalues.js
hooks/post-receive
--
GnuPG Made Easy
http://git.gnupg.org
More information about the Gnupg-commits
mailing list