aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/BrowserTestExtension
diff options
context:
space:
mode:
Diffstat (limited to 'lang/js/BrowserTestExtension')
-rw-r--r--lang/js/BrowserTestExtension/browsertest.html26
-rw-r--r--lang/js/BrowserTestExtension/manifest.json13
-rw-r--r--lang/js/BrowserTestExtension/popup.html9
-rw-r--r--lang/js/BrowserTestExtension/popup.js44
-rw-r--r--lang/js/BrowserTestExtension/runbrowsertest.js22
-rw-r--r--lang/js/BrowserTestExtension/setup_testing.js22
-rw-r--r--lang/js/BrowserTestExtension/testicon.pngbin0 -> 16192 bytes
-rw-r--r--lang/js/BrowserTestExtension/testkey.pub30
-rw-r--r--lang/js/BrowserTestExtension/testkey.sec57
-rw-r--r--lang/js/BrowserTestExtension/tests/encryptDecryptTest.js238
-rw-r--r--lang/js/BrowserTestExtension/tests/encryptTest.js158
-rw-r--r--lang/js/BrowserTestExtension/tests/inputvalues.js104
-rw-r--r--lang/js/BrowserTestExtension/tests/startup.js70
13 files changed, 793 insertions, 0 deletions
diff --git a/lang/js/BrowserTestExtension/browsertest.html b/lang/js/BrowserTestExtension/browsertest.html
new file mode 100644
index 00000000..d12e03cf
--- /dev/null
+++ b/lang/js/BrowserTestExtension/browsertest.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <link href="libs/mocha.css" rel="stylesheet" />
+ </head>
+<body>
+ <h3>Browsertest</h3>
+ <div id="mocha"></div>
+ <!-- load unit tests -->
+ <script src="libs/mocha.js"></script>
+ <script src="libs/chai.js"></script>
+ <script src="setup_testing.js"></script>
+ <script src="libs/gpgmejs.bundle.js"></script>
+
+ <script src="tests/inputvalues.js"></script>
+ <script src="libs/gpgmejs_unittests.bundle.js"></script>
+<!-- insert tests here-->
+ <script src="tests/startup.js"></script>
+ <script src="tests/encryptTest.js"></script>
+ <script src="tests/encryptDecryptTest.js"></script>
+
+<!-- run tests -->
+ <script src="runbrowsertest.js"></script>
+ </body>
+</html>
diff --git a/lang/js/BrowserTestExtension/manifest.json b/lang/js/BrowserTestExtension/manifest.json
new file mode 100644
index 00000000..a9e605bc
--- /dev/null
+++ b/lang/js/BrowserTestExtension/manifest.json
@@ -0,0 +1,13 @@
+{
+ "manifest_version": 2,
+
+ "name": "Browsertests for gpgmejs",
+ "description": "Run the browsertests.",
+ "version": "0.1",
+ "content_security_policy": "default-src 'self' filesystem:",
+ "browser_action": {
+ "default_icon": "testicon.png",
+ "default_popup": "popup.html"
+ },
+ "permissions": ["nativeMessaging", "activeTab"]
+ }
diff --git a/lang/js/BrowserTestExtension/popup.html b/lang/js/BrowserTestExtension/popup.html
new file mode 100644
index 00000000..f17f262a
--- /dev/null
+++ b/lang/js/BrowserTestExtension/popup.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script src="popup.js"></script>
+ </head>
+ <body>
+ </body>
+</html> \ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/popup.js b/lang/js/BrowserTestExtension/popup.js
new file mode 100644
index 00000000..4764df55
--- /dev/null
+++ b/lang/js/BrowserTestExtension/popup.js
@@ -0,0 +1,44 @@
+/* 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+
+ */
+/* 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+
+ */
+
+document.addEventListener('DOMContentLoaded', function() {
+ chrome.tabs.create({
+ url: './browsertest.html'
+ });
+});
diff --git a/lang/js/BrowserTestExtension/runbrowsertest.js b/lang/js/BrowserTestExtension/runbrowsertest.js
new file mode 100644
index 00000000..308c716d
--- /dev/null
+++ b/lang/js/BrowserTestExtension/runbrowsertest.js
@@ -0,0 +1,22 @@
+/* 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+
+ */
+
+mocha.run();
+Gpgmejs_test.unittests();
diff --git a/lang/js/BrowserTestExtension/setup_testing.js b/lang/js/BrowserTestExtension/setup_testing.js
new file mode 100644
index 00000000..7f70d347
--- /dev/null
+++ b/lang/js/BrowserTestExtension/setup_testing.js
@@ -0,0 +1,22 @@
+/* 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+
+ */
+mocha.setup('bdd');
+var expect = chai.expect;
+chai.config.includeStack = true; \ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/testicon.png b/lang/js/BrowserTestExtension/testicon.png
new file mode 100644
index 00000000..12c3f5df
--- /dev/null
+++ b/lang/js/BrowserTestExtension/testicon.png
Binary files differ
diff --git a/lang/js/BrowserTestExtension/testkey.pub b/lang/js/BrowserTestExtension/testkey.pub
new file mode 100644
index 00000000..cfc329f3
--- /dev/null
+++ b/lang/js/BrowserTestExtension/testkey.pub
@@ -0,0 +1,30 @@
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+
+mQENBFrsKEkBCADKw4Wt8J6M/88qD8PO6lSMCxH1cpwH8iK0uPaFFYsJkkXo7kWf
+PTAtrV+REqF/o80dvYcdLvRsV21pvncZz/HXLu1yQ18mC3XObrKokbdgrTTKA5XE
+BZkNsqyaMMJauT18H4hYkSg62/tTdO1cu/zWv/LFf7Xyn6+uA74ovXCJlO1s0N2c
+PShtr98QRzPMf2owgVk37JnDNp4gGVDGHxSZOuUwxgYAZYnA8SFc+c+3ZrQfY870
++O4j3Mz4p7yD13AwP4buQLBsb/icxekeQCqpRJhLH9f7MdEcGXa1x36RcEkHdu+M
+yJ392eMgD+dKNfRCty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FQCjzH7KE86XcV3MhfdJTNb/+9CR7Jq3e/4Iy
+0N5ip7PNYMCyakcAsxvsNCJKrSaDuYe/OAoTXRBtgRWE2uyT315em02Lkr+2Cc/Q
+k6H+vlNOHGRgnpI/OZZjnUuUfBUvMGHr1phW+y7aeymC9PnUGdViRdJe23nntMSD
+A+0/I7ESO9JsWvJbyBmuiZpu9JjScOjYH9xpQLqRNyw4WHpZriN69F0t9Mmd7bM1
++UyPgbPEr0iWMeyctYsuOLeUyQKMscDT
+=QyY6
+-----END PGP PUBLIC KEY BLOCK-----
diff --git a/lang/js/BrowserTestExtension/testkey.sec b/lang/js/BrowserTestExtension/testkey.sec
new file mode 100644
index 00000000..ced8f3ec
--- /dev/null
+++ b/lang/js/BrowserTestExtension/testkey.sec
@@ -0,0 +1,57 @@
+-----BEGIN PGP PRIVATE KEY BLOCK-----
+
+lQOYBFrsKEkBCADKw4Wt8J6M/88qD8PO6lSMCxH1cpwH8iK0uPaFFYsJkkXo7kWf
+PTAtrV+REqF/o80dvYcdLvRsV21pvncZz/HXLu1yQ18mC3XObrKokbdgrTTKA5XE
+BZkNsqyaMMJauT18H4hYkSg62/tTdO1cu/zWv/LFf7Xyn6+uA74ovXCJlO1s0N2c
+PShtr98QRzPMf2owgVk37JnDNp4gGVDGHxSZOuUwxgYAZYnA8SFc+c+3ZrQfY870
++O4j3Mz4p7yD13AwP4buQLBsb/icxekeQCqpRJhLH9f7MdEcGXa1x36RcEkHdu+M
+yJ392eMgD+dKNfRCtyTPhjZTxvbNELIBYICfABEBAAEAB/wLJ0gyMjs2fFfT83wM
+5Lzz2yQIwV4t3bblBAujdHTqeN5Zmsm/oakFyjSokULK96Kv0R4ej9eoIgMFvxFk
+HRkrggxTrbsNJ7I6QcKYHTPeIIj318ykNL6fj0WJUcdPIENukXl5jbqNyk3/4D2y
+TTDySyq6jHTgvMH4K4KJUSpglvSJPntTk9RhuFGHAF+sNR9atygDYctAaERMRtSg
+LCoSt/AoX5GRMlQjXT9oqQj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1iGAkc148cX1q
+lL9w2ksXuaHR3LXud2VcfVTIdxU/7h7u1dD/85+c0+7jlGObD9cXKxlM6OjpIJz1
+l5/1h3C5S0TuxHkEAL/3BGihkhNfv1Xx0rWu0/732usX/nE/A9C26hGu41FUf3fp
+0ilonKpKZUEwWt5hWSEFCSrznNVekiO0rxvuu3RVegvzThPNU4Pf4JZtJpRVhvUQ
+d9ulxJw7V9rs75uNBatTNC0kXuGoXhehw4Bn93xa67gYGd3LfrH+oT0GCDpTSHCJ
+ATwEGAEIACYWIQTUFzW5Ejb9uIIEjFojAWNe7/DLBQUCWuwoSQIbDAUJA8JnAAAK
+CRAjAWNe7/DLBf0pCACPp5hBuUWngu2Hqvg+tNiujfsiYzId3MffFxEk3CbXeHcJ
+5F32NDJ9PYCnra4L8wSv+NZt9gIa8lFwoFSFQCjzH7KE86XcV3MhfdJTNb/+9CR7
+Jq3e/4Iy0N5ip7PNYMCyakcAsxvsNCJKrSaDuYe/OAoTXRBtgRWE2uyT315em02L
+kr+2Cc/Qk6H+vlNOHGRgnpI/OZZjnUuUfBUvMGHr1phW+y7aeymC9PnUGdViRdJe
+23nntMSDA+0/I7ESO9JsWvJbyBmuiZpu9JjScOjYH9xpQLqRNyw4WHpZriN69F0t
+9Mmd7bM1+UyPgbPEr0iWMeyctYsuOLeUyQKMscDT
+=hkUm
+-----END PGP PRIVATE KEY BLOCK-----
diff --git a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
new file mode 100644
index 00000000..e28dd66b
--- /dev/null
+++ b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js
@@ -0,0 +1,238 @@
+/* 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+
+ */
+
+describe('Encryption and Decryption', function () {
+ it('Successful encrypt and decrypt', function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ context.encrypt(
+ inputvalues.encrypt.good.data,
+ inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include('BEGIN PGP MESSAGE');
+ expect(answer.data).to.include('END PGP MESSAGE');
+ context.decrypt(answer.data).then(function (result) {
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(inputvalues.encrypt.good.data);
+ context.connection.disconnect();
+ done();
+ });
+ });
+ });
+ });
+
+ /**
+ * Fails with random data! Some bytes (up to 100) of the original are missing in
+ * the result
+*/
+/**
+ for (let j = 0; j < 10; j++){
+ it('Successful encrypt and decrypt specific sets: ',
+ function (done) {
+ let prm = Gpgmejs.init();
+ let data = bigBoringString(5); //see ./inputvalues.js
+ expect(Object.prototype.toString.call(data)).to.equal("[object String]");
+ prm.then(function (context) {
+ context.encrypt(data,
+ inputvalues.encrypt.good.fingerprint).then(
+ function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include(
+ 'BEGIN PGP MESSAGE');
+ expect(answer.data).to.include(
+ 'END PGP MESSAGE');
+ context.decrypt(answer.data).then(
+ function (result) {
+ if (data.length !== result.data.length) {
+
+ for (let k = 0; k < data.length; k++) {
+ if (data[k] !== result.data[k]) {
+ console.log(k);
+ console.log(data[k - 2] + data[k - 1] + data[k] + data[k + 1]);
+ console.log(result.data[k - 2] + result.data[k - 1] + result.data[k] + result.data[k + 1]);
+ break;
+ }
+ }
+ }
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(data);
+ context.connection.disconnect();
+ done();
+
+ });
+ });
+ });
+ }).timeout(5000);
+ }
+
+
+ it('Roundtrip does not destroy trailing whitespace',
+ function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ let data = 'Keks. \rKeks \n Keks \r\n';
+ context.encrypt(data,
+ inputvalues.encrypt.good.fingerprint).then(
+ function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include(
+ 'BEGIN PGP MESSAGE');
+ expect(answer.data).to.include(
+ 'END PGP MESSAGE');
+ context.decrypt(answer.data).then(
+ function (result) {
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(data);
+ context.connection.disconnect();
+ done();
+
+ });
+ });
+ });
+ }).timeout(3000);
+
+ it('Test with simple non-ascii input',
+ function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ let data = '';
+ for (let i=0; i < 1024 * 1024 * 0.1; i++){
+ data += inputvalues.encrypt.good.data_nonascii;
+ }
+ context.encrypt(data,
+ inputvalues.encrypt.good.fingerprint).then(
+ function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include(
+ 'BEGIN PGP MESSAGE');
+ expect(answer.data).to.include(
+ 'END PGP MESSAGE');
+ console.log(answer);
+ context.decrypt(answer.data).then(
+ function (result) {
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ if (data.length !== result.data.length) {
+
+ for (let k = 0; k < data.length; k++) {
+ if (data[k] !== result.data[k]) {
+ console.log(k);
+ console.log(data[k - 2] + data[k - 1] + data[k] + data[k + 1]);
+ console.log(result.data[k - 2] + result.data[k - 1] + result.data[k] + result.data[k + 1]);
+ break;
+ }
+ }
+ }
+ console.log(data.length - result.data.length);
+ expect(result.data).to.equal(data);
+ context.connection.disconnect();
+ done();
+
+ });
+ });
+ });
+ }).timeout(3000);
+*/
+/**
+ for (let i=0; i< 100; i++) {
+ it('Successful encrypt random data '+ (i+1) + '/100', function (done) {
+ let prm = Gpgmejs.init();
+ let data = bigString(0.2); // << set source data here
+ prm.then(function (context) {
+ context.encrypt(data,
+ inputvalues.encrypt.good.fingerprint).then(
+ function (answer){
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include(
+ 'BEGIN PGP MESSAGE');
+ expect(answer.data).to.include(
+ 'END PGP MESSAGE');
+ context.decrypt(answer.data).then(
+ function(result){
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(data);
+ context.connection.disconnect();
+ done();
+ });
+ });
+ });
+ }).timeout(5000);
+ };
+*/
+
+/** still fails
+ it('Successful encrypt 0.8 MB Uint8Array', function (done) {
+ let prm = Gpgmejs.init();
+ let data = bigUint8(0.8);
+ prm.then(function (context) {
+ context.encrypt(data,
+ inputvalues.encrypt.good.fingerprint).then(
+ function (answer){
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include(
+ 'BEGIN PGP MESSAGE');
+ expect(answer.data).to.include(
+ 'END PGP MESSAGE');
+ context.decrypt(answer.data).then(
+ function(result){
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(data);
+ done();
+ });
+ });
+ });
+ }).timeout(5000);
+*/
+
+ it('Decrypt simple non-ascii',
+ function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ data = encryptedData;
+ context.decrypt(data).then(
+ function (result) {
+ expect(result).to.not.be.empty;
+ expect(result.data).to.be.a('string');
+ expect(result.data).to.equal(inputvalues.encrypt.good.data_nonascii);
+ context.encrypt(inputvalues.encrypt.good.data_nonascii, inputvalues.encrypt.good.fingerprint).then(
+ function(result){
+ context.decrypt(result.data).then(function(answer){
+ expect(answer.data).to.equal(inputvalues.encrypt.good.data_nonascii);
+ context.connection.disconnect();
+ done();
+ });
+ });
+ });
+
+ });
+ }).timeout(8000);
+
+}); \ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/encryptTest.js b/lang/js/BrowserTestExtension/tests/encryptTest.js
new file mode 100644
index 00000000..2e95151b
--- /dev/null
+++ b/lang/js/BrowserTestExtension/tests/encryptTest.js
@@ -0,0 +1,158 @@
+/* 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+
+ */
+describe('Encryption', function () {
+ it('Successful encrypt', function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ context.encrypt(
+ inputvalues.encrypt.good.data,
+ inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include('BEGIN PGP MESSAGE');
+ expect(answer.data).to.include('END PGP MESSAGE');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ });
+
+ it('Successful encrypt 5 MB', function (done) {
+ let prm = Gpgmejs.init();
+ let data = bigString(5);
+ prm.then(function (context) {
+ context.encrypt(
+ data,
+ inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include('BEGIN PGP MESSAGE');
+ expect(answer.data).to.include('END PGP MESSAGE');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ }).timeout(5000);
+
+/**
+ it('Successful encrypt 20 MB', function (done) {
+ let prm = Gpgmejs.init();
+ let data = bigString(20);
+ prm.then(function (context) {
+ context.encrypt(
+ data,
+ inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include('BEGIN PGP MESSAGE');
+ expect(answer.data).to.include('END PGP MESSAGE');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ }).timeout(20000);
+*/
+/**
+ it('Successful encrypt 30 MB', function (done) {
+ // TODO: There seems to be a limit imposed at least by chrome at about 21 MB
+ let prm = Gpgmejs.init();
+ let data = bigString(30);
+ prm.then(function (context) {
+ context.encrypt(
+ data,
+ inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a("string");
+ expect(answer.data).to.include('BEGIN PGP MESSAGE');
+ expect(answer.data).to.include('END PGP MESSAGE');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ }).timeout(20000);
+*/
+
+ it('Sending encryption without keys fails', function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ context.encrypt(
+ inputvalues.encrypt.good.data,
+ null).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function(error){
+ expect(error).to.be.an('Error');
+ expect(error.code).to.equal('MSG_INCOMPLETE');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ });
+
+ it('Sending encryption without data fails', function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ context.encrypt(
+ null, inputvalues.encrypt.good.keyid).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function (error) {
+ expect(error).to.be.an.instanceof(Error);
+ expect(error.code).to.equal('MSG_INCOMPLETE');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ });
+
+
+ it('Sending encryption with non existing keys fails', function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ context.encrypt(
+ inputvalues.encrypt.good.data,
+ inputvalues.encrypt.bad.fingerprint).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function(error){
+ expect(error).to.be.an('Error');
+ expect(error.code).to.not.be.undefined;
+ expect(error.code).to.equal('GNUPG_ERROR');
+ context.connection.disconnect();
+ done();
+ });
+ });
+ }).timeout(5000);;
+
+ it('Overly large message ( >= 48MB) is rejected', function (done) {
+ let prm = Gpgmejs.init();
+ prm.then(function (context) {
+ context.encrypt(
+ bigString(48),
+ inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function(error){
+ expect(error).to.be.an.instanceof(Error);
+ // TODO who is throwing the error here?
+ // It is not a GPGME_Error!
+ context.connection.disconnect();
+ done();
+ });
+ });
+ }).timeout(8000);
+ // TODO check different valid parameter
+});
diff --git a/lang/js/BrowserTestExtension/tests/inputvalues.js b/lang/js/BrowserTestExtension/tests/inputvalues.js
new file mode 100644
index 00000000..bc8c97bb
--- /dev/null
+++ b/lang/js/BrowserTestExtension/tests/inputvalues.js
@@ -0,0 +1,104 @@
+/* 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+
+ */
+
+var inputvalues = {
+ encrypt: {
+ good:{
+ data : 'Hello World.',
+ fingerprint : 'D41735B91236FDB882048C5A2301635EEFF0CB05',
+ data_nonascii: '¡Äußerste µ€ før ñoquis@hóme! Добрый день\n'
+ },
+ bad: {
+ fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
+ }
+ },
+ init: {
+ invalid_startups: [{all_passwords: true}, 'openpgpmode', {api_style:"frankenstein"}]
+ }
+
+};
+
+function bigString(megabytes){
+ let maxlength = 1024 * 1024 * megabytes;
+ let uint = new Uint8Array(maxlength);
+ for (let i= 0; i < maxlength; i++){
+ uint[i] = Math.random() * Math.floor(256);
+ }
+ return new TextDecoder('utf-8').decode(uint);
+}
+
+function bigUint8(megabytes){
+ let maxlength = 1024 * 1024 * megabytes;
+ let uint = new Uint8Array(maxlength);
+ for (let i= 0; i < maxlength; i++){
+ uint[i] = Math.random() * Math.floor(256);
+ }
+ return uint;
+}
+
+function bigBoringString(megabytes){
+ let maxlength = 1024 * 1024 * megabytes;
+ let string = '';
+ let chars = ' ä0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ for (let i= 0; i < maxlength; i++){
+ string = string + chars[Math.floor(Math.random() * chars.length)];
+ }
+ return string;
+}
+
+function slightlyLessBoringString(megabytes, set){
+ let maxlength = 1024 * 1024 * megabytes;
+ let string = '';
+ let chars = '';
+ if (!set){
+
+ } else if (set ===1 ) {
+ chars = '\n\"\r \'';
+ } else if (set === 2 ) {
+ chars = '()=?`#+-{}[]';
+ } else if (set === 3){
+ chars = '^°/';
+ //'*<>\\^°/';
+ } else if (set ===4) {
+ chars = 'äüßµüþÖ~ɁÑ||@';
+ } else {
+ chars = '*<>\n\"\r§$%&/()=?`#+-{}[] \''; //fails!
+
+ }
+ for (let i= 0; i < maxlength; i++){
+ string = string + chars[Math.floor(Math.random() * chars.length)];
+ }
+ return string;
+}
+
+var encryptedData =
+ '-----BEGIN PGP MESSAGE-----\n' +
+ '\n' +
+ 'hQEMA6B8jfIUScGEAQgAlANd3uyhmhYLzVcfz4LEqA8tgUC3n719YH0iuKEzG/dv\n' +
+ 'B8fsIK2HoeQh2T3/Cc2LBMjgn4K33ksG3k2MqrbIvxWGUQlOAuggc259hquWtX9B\n' +
+ 'EcEoOAeh5DuZT/b8CM5seJKNEpPzNxbEDiGikp9DV9gfIQTTUnrDjAu5YtgCN9vA\n' +
+ '3PJxihioH8ODoQw2jlYSkqgXpBVP2Fbx7qgTuxGNu5w36E0/P93//4hDXcKou7ez\n' +
+ 'o0+NEGSkbaY+OPk1k7k9n+vBSC3F440dxsTNs5WmRvx9XZEotJkUBweE+8XaoLCn\n' +
+ '3RrtyD/lj63qi3dbyI5XFLuPU1baFskJ4UAmI4wNhdJ+ASailpnFBnNgiFBh3ZfB\n' +
+ 'G5Rmd3ocSL7l6lq1bVK9advXb7vcne502W1ldAfHgTdQgc2CueIDFUYAaXP2OvhP\n' +
+ 'isGL7jOlDCBKwep67ted0cTRPLWkk3NSuLIlvD5xs6L4z3rPu92gXYgbZoMMdP0N\n' +
+ 'kSAQYOHplfA7YJWkrlRm\n' +
+ '=zap6\n' +
+ '-----END PGP MESSAGE-----\n'; \ No newline at end of file
diff --git a/lang/js/BrowserTestExtension/tests/startup.js b/lang/js/BrowserTestExtension/tests/startup.js
new file mode 100644
index 00000000..a5614a83
--- /dev/null
+++ b/lang/js/BrowserTestExtension/tests/startup.js
@@ -0,0 +1,70 @@
+/* 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+
+ */
+
+ describe('GPGME context', function(){
+ it('Starting a GpgME instance', function(done){
+ let prm = Gpgmejs.init();
+ prm.then(
+ function(context){
+ expect(context.connection).to.not.be.undefined;
+ expect(context).to.be.an('object');
+ expect(context.connection).to.be.an('object');
+ expect(context.Keyring).to.be.undefined;
+ expect(context.encrypt).to.be.a('function');
+ expect(context.decrypt).to.be.a('function');
+ done();
+ }, function(errorr){
+ expect(error).to.be.undefined;
+ done();
+ });
+ });
+});
+describe('openpgp mode', function(){
+ it('startup of openpgp mode returns the correct parameters', function(done){
+ let prm = Gpgmejs.init({api_style:"gpgme_openpgpjs"});
+ prm.then(function(context){
+ expect(context).to.be.an('object');
+ expect(context.connection).to.be.undefined;
+ expect(context.Keyring).to.be.an('object');
+ expect(context.encrypt).to.be.a('function');
+ expect(context.decrypt).to.be.a('function');
+ done();
+ }, function(error){
+ expect(error).to.be.undefined;
+ done();
+ });
+ });
+});
+
+describe('GPGME does not start with invalid parameters', function(){
+ for (let i=0; i < inputvalues.init.invalid_startups.length; i++){
+ it('Parameter '+ i, function(done){
+ let prm = Gpgmejs.init(inputvalues.init.invalid_startups[i]);
+ prm.then(function(context){
+ expect(context).to.be.undefined;
+ done();
+ }, function(error){
+ expect(error).to.be.an.instanceof(Error);
+ expect(error.code).to.equal('PARAM_WRONG');
+ done();
+ });
+ })
+ }
+}); \ No newline at end of file