js: fixing errors found by testing: encrypt/decrypt
[gpgme.git] / lang / js / BrowserTestExtension / tests / encryptDecryptTest.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
21 describe('Encryption and Decryption', function () {
22     it('Successful encrypt and decrypt', function (done) {
23         let prm = Gpgmejs.init();
24         prm.then(function (context) {
25             context.encrypt(
26                 inputvalues.encrypt.good.data,
27                 inputvalues.encrypt.good.fingerprint).then( function(answer){
28                     expect(answer).to.not.be.empty;
29                     expect(answer.data).to.be.a("string");
30                     expect(answer.data).to.include('BEGIN PGP MESSAGE');
31                     expect(answer.data).to.include('END PGP MESSAGE');
32                     context.decrypt(answer.data).then(function(result){
33                         expect(result).to.not.be.empty;
34                         expect(result.data).to.be.a('string');
35                         expect(result.data).to.equal(inputvalues.encrypt.good.data);
36                         done();
37                     });
38                 });
39         });
40     });
41
42 /**
43  * Fails with random data! Some bytes (up to 100) of the original are missing in
44  * the result
45  */
46 /**
47     for (let i=0; i< 20; i++) {
48         it('Successful encrypt 1 MB '+ i+ '/20', function (done) {
49             let prm = Gpgmejs.init();
50             let data = bigString(0.1);
51                 prm.then(function (context) {
52                     context.encrypt(data,
53                         inputvalues.encrypt.good.fingerprint).then(
54                             function (answer){
55                                 expect(answer).to.not.be.empty;
56                                 expect(answer.data).to.be.a("string");
57                                 expect(answer.data).to.include(
58                                     'BEGIN PGP MESSAGE');
59                                 expect(answer.data).to.include(
60                                     'END PGP MESSAGE');
61                                 context.decrypt(answer.data).then(
62                                     function(result){
63                                         expect(result).to.not.be.empty;
64                                         expect(result.data).to.be.a('string');
65                                         expect(result.data).to.equal(data);
66                                         done();
67                                 });
68                         });
69                 });
70         }).timeout(10000);
71     };*/
72 });