js: code cleanup (eslint)
[gpgme.git] / lang / js / BrowserTestExtension / tests / longRunningTests.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 /* global describe, it, expect, Gpgmejs */
24 /* global bigString, inputvalues */
25
26 describe('Long running Encryption/Decryption', function () {
27     for (let i=0; i < 100; i++) {
28         it('Successful encrypt/decrypt completely random data ' +
29             (i+1) + '/100', function (done) {
30             let prm = Gpgmejs.init();
31             let data = bigString(2*1024*1024);
32             prm.then(function (context) {
33                 context.encrypt(data,
34                     inputvalues.encrypt.good.fingerprint).then(
35                     function (answer){
36                         expect(answer).to.not.be.empty;
37                         expect(answer.data).to.be.a('string');
38                         expect(answer.data).to.include(
39                             'BEGIN PGP MESSAGE');
40                         expect(answer.data).to.include(
41                             'END PGP MESSAGE');
42                         context.decrypt(answer.data).then(
43                             function(result){
44                                 expect(result).to.not.be.empty;
45                                 expect(result.data).to.be.a('string');
46                                 if (result.data.length !== data.length) {
47                                     // console.log('diff: ' +
48                                     // (result.data.length - data.length));
49                                     for (let i=0; i < result.data.length; i++){
50                                         if (result.data[i] !== data[i]){
51                                             // console.log('position: ' + i);
52                                             // console.log('result : ' +
53                                             // result.data.charCodeAt(i) +
54                                             // result.data[i-2] +
55                                             // result.data[i-1] +
56                                             // result.data[i] +
57                                             // result.data[i+1] +
58                                             // result.data[i+2]);
59                                             // console.log('original: ' +
60                                             // data.charCodeAt(i) +
61                                             // data[i-2] +
62                                             // data[i-1] +
63                                             // data[i] +
64                                             // data[i+1] +
65                                             // data[i+2]);
66                                             break;
67                                         }
68                                     }
69                                 }
70                                 expect(result.data).to.equal(data);
71                                 done();
72                             });
73                     });
74             });
75         }).timeout(8000);
76     }
77
78 });