ServerInteraction.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. 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. window.crypto = new WebCrypto();
  21. message = message.trim();
  22. PrivateBin.ServerInteraction.prepare();
  23. PrivateBin.ServerInteraction.setCryptParameters(password, key);
  24. PrivateBin.ServerInteraction.setUnencryptedData('adata', [
  25. // encryption parameters defined by CryptTool, format, discussion, burn after reading
  26. null, 'plaintext', 0, 0
  27. ]);
  28. PrivateBin.ServerInteraction.setUnencryptedData('meta', {'expire': '5min'});
  29. await PrivateBin.ServerInteraction.setCipherMessage({'paste': message});
  30. //console.log(PrivateBin.ServerInteraction.getData());
  31. clean();
  32. // TODO currently not testing anything and just used to generate v2 pastes for starting development of server side v2 implementation
  33. return true;
  34. }
  35. ),
  36. {numRuns: 3});
  37. });
  38. });
  39. });