Imported Upstream version 1.12.0
[platform/upstream/gpgme.git] / lang / js / BrowserTestExtension / tests / signTest.js
1 /* gpgme.js - Javascript integration for gpgme
2  * Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
3  *
4  * This file is part of GPGME.
5  *
6  * GPGME is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * GPGME is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18  * SPDX-License-Identifier: LGPL-2.1+
19  *
20  * Author(s):
21  *     Maximilian Krambach <mkrambach@intevation.de>
22  */
23
24 /* global describe, it, expect, before, Gpgmejs */
25 /* global bigString, inputvalues */
26
27 describe('Signing', function () {
28     let context = null;
29     const good_fpr = inputvalues.encrypt.good.fingerprint;
30
31     before(function (done){
32         const prm = Gpgmejs.init({ timeout: 2000 });
33         prm.then(function (gpgmejs){
34             context = gpgmejs;
35             done();
36         });
37     });
38
39     it('Sign a message', function (done) {
40         const data = bigString(100);
41         context.sign({ data: data, keys: good_fpr }).then(function (answer) {
42             expect(answer).to.not.be.empty;
43             expect(answer.data).to.be.a('string');
44             expect(answer.data).to.include('BEGIN PGP SIGNATURE');
45             expect(answer.data).to.include('END PGP SIGNATURE');
46             expect(answer.data).to.include(data);
47             done();
48         });
49     });
50
51     it('Detached sign a message', function (done) {
52         const data = bigString(100);
53         context.sign({ data: data, keys: good_fpr, mode: 'detached' })
54             .then(function (answer) {
55                 expect(answer).to.not.be.empty;
56                 expect(answer.data).to.be.a('string');
57                 expect(answer.data).to.include(data);
58                 expect(answer.signature).to.be.a('string');
59                 expect(answer.signature).to.be.a('string');
60                 done();
61             });
62     });
63
64 });