aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/BrowserTestExtension/tests/inputvalues.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-08-01 10:51:12 +0000
committerMaximilian Krambach <[email protected]>2018-08-01 10:51:12 +0000
commit68a012deb3b501d7417778be12c88bd475a37cb5 (patch)
tree453fd5544589dbc51968f2138f7816b69ae83c66 /lang/js/BrowserTestExtension/tests/inputvalues.js
parentjs: fix confusion about loop in last commit (diff)
downloadgpgme-68a012deb3b501d7417778be12c88bd475a37cb5.tar.gz
gpgme-68a012deb3b501d7417778be12c88bd475a37cb5.zip
js: make init export immutable
-- * src/index.js: The export now uses a freezed Object, which does not allow for simply overwriting the init method by e.g. a third-party library. * BrowsertestExtension: Added some tests trying if decryption of bad data properly fails
Diffstat (limited to 'lang/js/BrowserTestExtension/tests/inputvalues.js')
-rw-r--r--lang/js/BrowserTestExtension/tests/inputvalues.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/lang/js/BrowserTestExtension/tests/inputvalues.js b/lang/js/BrowserTestExtension/tests/inputvalues.js
index 9d956b69..1e8f1544 100644
--- a/lang/js/BrowserTestExtension/tests/inputvalues.js
+++ b/lang/js/BrowserTestExtension/tests/inputvalues.js
@@ -248,3 +248,39 @@ const ImportablePublicKey = {// eslint-disable-line no-unused-vars
'=9WZ7\n' +
'-----END PGP PUBLIC KEY BLOCK-----\n'
};
+
+/**
+ * Changes base64 encoded gpg messages
+ * @param {String} msg input message
+ * @param {Number} rate of changes as percentage of message length.
+ * @param {[Number, Number]} p begin and end of the message left untouched (to
+ * preserve) header/footer
+ */
+// eslint-disable-next-line no-unused-vars
+function sabotageMsg(msg, rate = 0.01, p= [35,35]){
+ const iterations = Math.floor(Math.random() * msg.length * rate) + 1;
+ const base64_set =
+ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/';
+ for (let i=0; i < iterations; i++){
+ let str0, str1, str2;
+ const chosePosition = function(){
+ let position =
+ Math.floor( Math.random() * (msg.length - p[0] + p[1]))
+ + p[0];
+ str1 = msg.substring(position,position+1);
+ if (str1 === '\n'){
+ chosePosition();
+ } else {
+ str0 = msg.substring(0,position);
+ str2 = msg.substring(position +1);
+ }
+ };
+ chosePosition();
+ let new1 = function(){
+ let n = base64_set[Math.floor(Math.random() * 64)];
+ return (n === str1) ? new1() : n;
+ };
+ msg = str0.concat(new1()).concat(str2);
+ }
+ return msg;
+}