diff options
Diffstat (limited to '')
-rw-r--r-- | lang/js/test/Helpers.js | 2 | ||||
-rw-r--r-- | lang/js/test/Message.js | 62 | ||||
-rw-r--r-- | lang/js/test/index.js | 28 | ||||
-rw-r--r-- | lang/js/test/inputvalues.js | 10 |
4 files changed, 95 insertions, 7 deletions
diff --git a/lang/js/test/Helpers.js b/lang/js/test/Helpers.js index 5d8909f9..6b5a5382 100644 --- a/lang/js/test/Helpers.js +++ b/lang/js/test/Helpers.js @@ -24,7 +24,7 @@ import { GPGME_Key } from "../src/Key"; import { isLongId, isFingerprint, toKeyIdArray } from "../src/Helpers" import { helper_params } from "./inputvalues"; -function Helpertest(){ +export function Helpertest(){ describe('Error Object handling', function(){ it('check the Timeout error', function(){ let test0 = gpgme_error('CONN_TIMEOUT'); diff --git a/lang/js/test/Message.js b/lang/js/test/Message.js index 44206fba..a7dd3af5 100644 --- a/lang/js/test/Message.js +++ b/lang/js/test/Message.js @@ -21,23 +21,73 @@ import { expect } from "../node_modules/chai/chai"; import { GPGME_Message, createMessage } from "../src/Message"; -import { message_params } from "./inputvalues"; +import { message_params as mp, helper_params as hp} from "./inputvalues"; -function Messagetest(){ +export function Messagetest(){ describe('Message Object', function(){ - describe('incorrect initialization', function(){ + describe('correct initialization of an encrypt Message', function(){ + it('creating Message', function(){ + let test0 = createMessage('encrypt'); + expect(test0).to.be.an.instanceof(GPGME_Message); + expect(test0.isComplete).to.be.false; + }); + it('Message is complete after setting mandatoy data', function(){ + let test0 = createMessage('encrypt'); + test0.setParameter('data', mp.valid_encrypt_data); + test0.setParameter('keys', hp.validFingerprints); + expect(test0.isComplete).to.be.true; + }); + it('Complete Message contains the data that was set', function(){ + let test0 = createMessage('encrypt'); + test0.setParameter('data', mp.valid_encrypt_data); + test0.setParameter('keys', hp.validFingerprints); + + expect(test0.message).to.not.be.null; + expect(test0.message).to.have.keys('op', 'data', 'keys'); + expect(test0.message.op).to.equal('encrypt'); + expect(test0.message.data).to.equal( + mp.valid_encrypt_data); + }); + }); + + describe('Incorrect initialization', function(){ it('non-allowed operation', function(){ - let test0 = createMessage(message_params.invalid_op_action); + let test0 = createMessage(mp.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); + let test0 = createMessage(mp.invalid_op_type); expect(test0).to.be.an.instanceof(Error); expect(test0.code).to.equal('PARAM_WRONG'); }); }); + + describe('Setting wrong parameters', function(){ + it('Wrong parameter name', function(){ + let test0 = createMessage(mp.invalid_param_test.valid_op); + for (let i=0; i < mp.invalid_param_test.invalid_param_names.length; i++){ + let ret = test0.setParameter( + mp.invalid_param_test.invalid_param_names[i], + 'Somevalue'); + expect(ret).to.be.an.instanceof(Error); + expect(ret.code).to.equal('PARAM_WRONG'); + } + }); + it('Wrong parameter value', function(){ + let test0 = createMessage(mp.invalid_param_test.valid_op); + for (let j=0; + j < mp.invalid_param_test.invalid_values_0.length; + j++){ + let ret = test0.setParameter( + mp.invalid_param_test.validparam_name_0, + mp.invalid_param_test.invalid_values_0[j]); + expect(ret).to.be.an.instanceof(Error); + expect(ret.code).to.equal('PARAM_WRONG'); + } + }); + }); }); -}; +} export default Messagetest;
\ No newline at end of file diff --git a/lang/js/test/index.js b/lang/js/test/index.js new file mode 100644 index 00000000..b8520515 --- /dev/null +++ b/lang/js/test/index.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 <http://www.gnu.org/licenses/>. + * SPDX-License-Identifier: LGPL-2.1+ + */ +import { Helpertest } from "./Helpers"; +import { Messagetest } from "./Message"; + +/** + * Unit tests. + */ + +Helpertest(); +Messagetest(); diff --git a/lang/js/test/inputvalues.js b/lang/js/test/inputvalues.js index a50c8162..f6cd75aa 100644 --- a/lang/js/test/inputvalues.js +++ b/lang/js/test/inputvalues.js @@ -8,6 +8,8 @@ export const helper_params = { 'ADDBC303B6D31026F5EB4591A27EABDF283121BB', new GPGME_Key('EE17AEE730F88F1DE7713C54BBE0A4FF7851650A')], validFingerprint: '9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A', + validFingerprints: ['9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A', + '9AAE7A338A9A9A7A7A8A9A9A7A7A8A9A9A7A7DDA'], invalidLongId: '9A9A7A7A8A9A9A7A7A8A', invalidFingerprint: [{hello:'World'}], invalidKeyArray: {curiosity:'uncat'}, @@ -21,8 +23,16 @@ export const helper_params = { export const message_params = { invalid_op_action : 'dance', invalid_op_type : [234, 34, '<>'], + valid_encrypt_data: "مرحبا بالعالم", + invalid_param_test: { + valid_op: 'encrypt', + invalid_param_names: [22,'dance', {}], + validparam_name_0: 'mime', + invalid_values_0: [2134, 'All your passwords', new GPGME_Key('12AE9F3E41B33BF77DF52B6BE8EE1992D7909B08'), null] + } } + export default { helper_params: helper_params, message_params: message_params |