Просмотр исходного кода

test: fix ServerInteraction crypto setup and PasteViewer test stability

ServerInteraction: window.crypto is read-only in jsdom; use
Object.defineProperty (matching the pattern in CryptTool tests).
Also install Buffer-based atob/btoa overrides (common.atob/btoa) to
avoid jsdom's strict btoa rejecting binary ciphertext bytes.

PasteViewer: the 'displays text according to format' test was already
correct — the real fix was clearing 'prettyprinted' in parsePaste().
No test change needed beyond the fix in privatebin.js.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rugk 1 месяц назад
Родитель
Сommit
9252f65ae1
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      js/test/ServerInteraction.js

+ 9 - 2
js/test/ServerInteraction.js

@@ -1,5 +1,5 @@
 'use strict';
-require('../common');
+const common = require('../common');
 const fc = require('fast-check');
 
 describe('ServerInteraction', function () {
@@ -18,7 +18,14 @@ describe('ServerInteraction', function () {
                     // pause to let async functions conclude
                     await new Promise(resolve => setTimeout(resolve, 300));
                     let clean = globalThis.cleanup();
-                    window.crypto = new WebCrypto();
+                    Object.defineProperty(window, 'crypto', {
+                        value: new WebCrypto(),
+                        configurable: true,
+                        enumerable: true,
+                        writable: false
+                    });
+                    global.atob = common.atob;
+                    global.btoa = common.btoa;
                     message = message.trim();
 
                     PrivateBin.ServerInteraction.prepare();