diff --git a/.putout.json b/.putout.json index 9827b5e3..cbb9353c 100644 --- a/.putout.json +++ b/.putout.json @@ -6,6 +6,9 @@ "fontello.json" ], "match": { + "*.js": { + "convert-esm-to-commonjs": "on" + }, "*.md": { "convert-commonjs-to-esm": "on" }, diff --git a/server/route.spec.js b/server/route.spec.js index 0752cd80..1ce0266b 100644 --- a/server/route.spec.js +++ b/server/route.spec.js @@ -1,5 +1,7 @@ 'use strict'; +const {Readable} = require('stream'); + const path = require('path'); const fs = require('fs'); @@ -25,6 +27,10 @@ const {request} = serveOnce(cloudcmd, { config: defaultConfig, }); +const {stringify} = JSON; + +const {assign} = Object; + test('cloudcmd: route: buttons: no console', async (t) => { const options = { config: { @@ -222,15 +228,24 @@ test('cloudcmd: route: not found', async (t) => { test('cloudcmd: route: sendIndex: encode', async (t) => { const name = '">'; const nameEncoded = '"><svg onload=alert(3);>'; + const path = '/'; const files = [{ name, }]; - const read = stub().returns({ - type: 'directory', + const stream = Readable.from(stringify({ + path, files, + })); + + assign(stream, { + path, + files, + type: 'directory', }); + const read = stub().resolves(stream); + mockRequire('win32', { read, }); @@ -242,7 +257,8 @@ test('cloudcmd: route: sendIndex: encode', async (t) => { configManager: createConfigManager(), }); - const {body} = await request.get('/'); + const response = await request.get('/'); + const {body} = response; stopAll(); @@ -252,16 +268,25 @@ test('cloudcmd: route: sendIndex: encode', async (t) => { test('cloudcmd: route: sendIndex: encode: not encoded', async (t) => { const name = '">'; + const path = '/'; const files = [{ name, }]; - const read = async (path) => ({ + const stream = Readable.from(stringify({ path, files, + })); + + assign(stream, { + path, + files, + type: 'directory', }); - mockRequire('flop', { + const read = stub().resolves(stream); + + mockRequire('win32', { read, }); @@ -279,16 +304,25 @@ test('cloudcmd: route: sendIndex: encode: not encoded', async (t) => { test('cloudcmd: route: sendIndex: ddos: render', async (t) => { const name = '$$$\'"'; + const path = '/'; const files = [{ name, }]; - const read = async (path) => ({ + const stream = Readable.from(stringify({ path, files, + })); + + assign(stream, { + path, + files, + type: 'directory', }); - mockRequire('flop', { + const read = stub().resolves(stream); + + mockRequire('win32', { read, });