ServerInteraction.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. const common = require('../common');
  3. const fc = require('fast-check');
  4. describe('ServerInteraction', function () {
  5. describe('prepare', function () {
  6. afterEach(async function () {
  7. // pause to let async functions conclude
  8. await new Promise(resolve => setTimeout(resolve, 1900));
  9. });
  10. this.timeout(30000);
  11. it('can prepare an encrypted document', async function () {
  12. await fc.assert(fc.asyncProperty(
  13. fc.string(),
  14. fc.string(),
  15. fc.string(),
  16. async function (key, password, message) {
  17. // pause to let async functions conclude
  18. await new Promise(resolve => setTimeout(resolve, 300));
  19. let clean = globalThis.cleanup();
  20. Object.defineProperty(window, 'crypto', {
  21. value: new WebCrypto(),
  22. configurable: true,
  23. enumerable: true,
  24. writable: false
  25. });
  26. global.atob = common.atob;
  27. global.btoa = common.btoa;
  28. message = message.trim();
  29. PrivateBin.ServerInteraction.prepare();
  30. PrivateBin.ServerInteraction.setCryptParameters(password, key);
  31. PrivateBin.ServerInteraction.setUnencryptedData('adata', [
  32. // encryption parameters defined by CryptTool, format, discussion, burn after reading
  33. null, 'plaintext', 0, 0
  34. ]);
  35. PrivateBin.ServerInteraction.setUnencryptedData('meta', {'expire': '5min'});
  36. await PrivateBin.ServerInteraction.setCipherMessage({'paste': message});
  37. //console.log(PrivateBin.ServerInteraction.getData());
  38. clean();
  39. // TODO currently not testing anything and just used to generate v2 pastes for starting development of server side v2 implementation
  40. return true;
  41. }
  42. ),
  43. {numRuns: 3});
  44. });
  45. });
  46. });