leak.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var test = require('tap').test;
  4. var path = require('path');
  5. var through = require('through2');
  6. var os = require('os');
  7. var tmpdir = (os.tmpdir || os.tmpDir)();
  8. var dir = path.join(
  9. tmpdir,
  10. 'browserify-test-' + Math.random(),
  11. 'aaabbbzzz'
  12. );
  13. var dirstring = dir.split(path.sep).slice(-2).join(path.sep);
  14. if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; };
  15. test('leaking information about system paths (process)', function (t) {
  16. t.plan(4);
  17. var b = browserify({ basedir: dir });
  18. var stream = through();
  19. stream.push('process.nextTick(function () {'
  20. + 't.ok(true)'
  21. + '})'
  22. );
  23. stream.push(null);
  24. b.add(stream);
  25. b.bundle(function (err, buf) {
  26. var src = buf.toString('utf8');
  27. t.equal(src.indexOf(dirstring), -1, 'temp directory visible');
  28. t.equal(src.indexOf(process.cwd()), -1, 'cwd directory visible');
  29. t.equal(src.indexOf('/home'), -1, 'home directory visible');
  30. vm.runInNewContext(src, {
  31. t: t,
  32. setTimeout: setTimeout,
  33. clearTimeout: clearTimeout
  34. });
  35. });
  36. });
  37. test('leaking information about system paths (Buffer)', function (t) {
  38. t.plan(4);
  39. var b = browserify({ basedir: dir });
  40. var stream = through();
  41. stream.push('t.equal(Buffer("eHl6", "base64").toString(), "xyz")');
  42. stream.push(null);
  43. b.add(stream);
  44. b.bundle(function (err, buf) {
  45. var src = buf.toString('utf8');
  46. t.equal(src.indexOf(dirstring), -1, 'temp directory visible');
  47. t.equal(src.indexOf(process.cwd()), -1, 'cwd directory visible');
  48. t.equal(src.indexOf('/home'), -1, 'home directory visible');
  49. vm.runInNewContext(src, { t: t, setTimeout: setTimeout, Uint8Array: Uint8Array, ArrayBuffer: ArrayBuffer });
  50. });
  51. });