@@ -6,17 +6,20 @@ const test = require('tape');
66const { promisify} = require ( 'es6-promisify' ) ;
77const pullout = require ( 'pullout' ) ;
88const request = require ( 'request' ) ;
9+ const mockRequire = require ( 'mock-require' ) ;
10+ const clear = require ( 'clear-module' ) ;
911
1012const rootDir = '../..' ;
1113
1214const routePath = `${ rootDir } /server/route` ;
15+ const beforePath = '../before' ;
1316
1417const {
1518 _getIndexPath,
1619} = require ( routePath ) ;
1720
1821const route = require ( routePath ) ;
19- const { connect} = require ( '../before' ) ;
22+ const { connect} = require ( beforePath ) ;
2023
2124const warp = ( fn , ...a ) => ( ...b ) => fn ( ...b , ...a ) ;
2225const _pullout = promisify ( pullout ) ;
@@ -78,20 +81,6 @@ test('cloudcmd: route: buttons: console', async (t) => {
7881 done ( ) ;
7982} ) ;
8083
81- test ( 'cloudcmd: route: buttons: no terminal' , async ( t ) => {
82- const config = {
83- terminal : false
84- } ;
85-
86- const { port, done} = await connect ( { config} ) ;
87- const result = await getStr ( `http://localhost:${ port } ` ) ;
88-
89- t . ok ( / i c o n - t e r m i n a l n o n e / . test ( result ) , 'should hide terminal' ) ;
90- t . end ( ) ;
91-
92- done ( ) ;
93- } ) ;
94-
9584test ( 'cloudcmd: route: buttons: no config' , async ( t ) => {
9685 const config = {
9786 configDialog : false
@@ -286,8 +275,91 @@ test('cloudcmd: route: sendIndex: error', async (t) => {
286275 const data = await getStr ( `http://localhost:${ port } ` ) ;
287276
288277 t . equal ( data , error . message , 'should return error' ) ;
278+
279+ done ( ) ;
280+ t . end ( ) ;
281+ } ) ;
282+
283+ test ( 'cloudcmd: route: sendIndex: encode' , async ( t ) => {
284+ const name = '"><svg onload=alert(3);>' ;
285+ const nameEncoded = '"><svg onload=alert(3);>' ;
286+ const files = [ {
287+ name,
288+ } ] ;
289+
290+ const read = ( path , fn ) => fn ( null , {
291+ path,
292+ files,
293+ } ) ;
294+
295+ mockRequire ( 'flop' , {
296+ read
297+ } ) ;
298+
299+ clear ( routePath ) ;
300+ clear ( '../../server/cloudcmd' ) ;
301+ clear ( beforePath ) ;
302+
303+ const { connect} = require ( beforePath ) ;
304+ const { port, done} = await connect ( ) ;
305+ const data = await getStr ( `http://localhost:${ port } ` ) ;
306+
307+ t . ok ( data . includes ( nameEncoded ) , 'should encode name' ) ;
308+
309+ clear ( 'flop' ) ;
310+ clear ( routePath ) ;
311+ clear ( '../../server/cloudcmd' ) ;
312+ clear ( beforePath ) ;
313+
314+ done ( ) ;
289315 t . end ( ) ;
316+ } ) ;
317+
318+ test ( 'cloudcmd: route: sendIndex: encode' , async ( t ) => {
319+ const name = '"><svg onload=alert(3);>' ;
320+ const files = [ {
321+ name,
322+ } ] ;
323+
324+ const read = ( path , fn ) => fn ( null , {
325+ path,
326+ files,
327+ } ) ;
328+
329+ mockRequire ( 'flop' , {
330+ read
331+ } ) ;
332+
333+ clear ( routePath ) ;
334+ clear ( '../../server/cloudcmd' ) ;
335+ clear ( beforePath ) ;
336+
337+ const { connect} = require ( beforePath ) ;
338+ const { port, done} = await connect ( ) ;
339+ const data = await getStr ( `http://localhost:${ port } ` ) ;
340+
341+ t . notOk ( data . includes ( name ) , 'should put not encoded name' ) ;
342+
343+ clear ( 'flop' ) ;
344+ clear ( routePath ) ;
345+ clear ( '../../server/cloudcmd' ) ;
346+ clear ( beforePath ) ;
290347
291348 done ( ) ;
349+ t . end ( ) ;
350+ } ) ;
351+
352+ test ( 'cloudcmd: route: buttons: no terminal' , async ( t ) => {
353+ const config = {
354+ terminal : false
355+ } ;
356+
357+ const { port, done} = await connect ( { config} ) ;
358+ const result = await getStr ( `http://localhost:${ port } ` ) ;
359+
360+ t . ok ( / i c o n - t e r m i n a l n o n e / . test ( result ) , 'should hide terminal' ) ;
361+
362+ done ( ) ;
363+ t . end ( ) ;
292364} ) ;
293365
0 commit comments