diff options
author | Maximilian Krambach <[email protected]> | 2018-04-26 15:13:34 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-04-26 15:13:34 +0000 |
commit | 1f7b19512cfa7e1b153b99d6a2b40bad82a5496e (patch) | |
tree | 73a0392bd738eb5023b904e3ab7b7b4e0a820768 /lang/js/src/index.js | |
parent | js: First testing and improvements (diff) | |
download | gpgme-1f7b19512cfa7e1b153b99d6a2b40bad82a5496e.tar.gz gpgme-1f7b19512cfa7e1b153b99d6a2b40bad82a5496e.zip |
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
Diffstat (limited to 'lang/js/src/index.js')
-rw-r--r-- | lang/js/src/index.js | 70 |
1 files changed, 47 insertions, 23 deletions
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 { |