From 5652a43d1d639fd94fba24eec173131a11c31e24 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 16 Apr 2019 07:45:04 +0200 Subject: [PATCH] adding js test to generate v2 example pastes to be used in the development of the server side logic, adding one of these into the helper class of the php tests --- js/privatebin.js | 11 ++++++++++ js/test/ServerInteraction.js | 40 ++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- tst/Bootstrap.php | 32 ++++++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 js/test/ServerInteraction.js diff --git a/js/privatebin.js b/js/privatebin.js index 766e6124..4a0ee3d2 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -3736,6 +3736,17 @@ jQuery.PrivateBin = (function($, RawDeflate) { }); }; + /** + * return currently set data, used in unit testing + * + * @name ServerInteraction.getData + * @function + */ + me.getData = function() + { + return data; + }; + /** * set success function * diff --git a/js/test/ServerInteraction.js b/js/test/ServerInteraction.js new file mode 100644 index 00000000..64377379 --- /dev/null +++ b/js/test/ServerInteraction.js @@ -0,0 +1,40 @@ +'use strict'; +require('../common'); + +describe('ServerInteraction', function () { + describe('prepare', function () { + afterEach(async function () { + // pause to let async functions conclude + await new Promise(resolve => setTimeout(resolve, 1900)); + }); + this.timeout(30000); + it('can prepare an encrypted paste', function () { + jsc.check(jsc.forall( + 'string', + 'string', + 'string', + async function (key, password, message) { + // pause to let async functions conclude + await new Promise(resolve => setTimeout(resolve, 300)); + let clean = jsdom(); + window.crypto = new WebCrypto(); + message = message.trim(); + + $.PrivateBin.ServerInteraction.prepare(); + $.PrivateBin.ServerInteraction.setCryptParameters(password, key); + $.PrivateBin.ServerInteraction.setUnencryptedData('adata', [ + // encryption parameters defined by CryptTool, format, discussion, burn after reading + null, 'plaintext', 0, 0 + ]); + $.PrivateBin.ServerInteraction.setUnencryptedData('meta', {'expire': '5min'}); + await $.PrivateBin.ServerInteraction.setCipherMessage({'paste': message}); + //console.log($.PrivateBin.ServerInteraction.getData()); + clean(); + // TODO currently not testing anything and just used to generate v2 pastes for starting development of server side v2 implementation + return true; + } + ), + {tests: 3}); + }); + }); +}); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 25dbf1af..311893f1 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -71,7 +71,7 @@ if ($MARKDOWN): endif; ?> - + diff --git a/tpl/page.php b/tpl/page.php index 4165e727..eb6bea00 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -49,7 +49,7 @@ if ($MARKDOWN): endif; ?> - + diff --git a/tst/Bootstrap.php b/tst/Bootstrap.php index 3ef80fb6..a79c24b7 100644 --- a/tst/Bootstrap.php +++ b/tst/Bootstrap.php @@ -31,11 +31,11 @@ class Helper private static $pasteid = '5e9bc25c89fb3bf9'; /** - * example paste + * example paste version 1 * * @var array */ - private static $paste = array( + private static $pasteV1 = array( 'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}', 'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}', 'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}', @@ -46,6 +46,32 @@ class Helper ), ); + /** + * example paste version 2 + * + * @var array + */ + private static $pasteV2 = array( + 'adata' => array( + array( + 'gMSNoLOk4z0RnmsYwXZ8mw==', + 'TZO+JWuIuxs=', + 100000, + 256, + 128, + 'aes', + 'gcm', + 'zlib' + ), + 'plaintext', + 0, + 0 + ), + 'meta' => array( 'expire' => '5min' ), + 'v' => 2, + 'ct' => 'ME5JF/YBEijp2uYMzLZozbKtWc5wfy6R59NBb7SmRig=' + ); + /** * example ID of a comment * @@ -103,7 +129,7 @@ class Helper */ public static function getPasteWithAttachment($meta = array()) { - $example = self::$paste; + $example = self::$pasteV1; $example['meta']['salt'] = ServerSalt::generate(); $example['meta'] = array_merge($example['meta'], $meta); return $example;