|
| 1 | +const assert = require('assert'); |
| 2 | +const tmp = require('../lib/tmp'); |
| 3 | + |
| 4 | +describe('GHSA-7c78-jf6q-g5cm', function () { |
| 5 | + describe('#fileSync with non-string `prefix`', function () { |
| 6 | + it('should reject an array prefix even when its element is "../foo"', function (done) { |
| 7 | + assert.throws(function () { |
| 8 | + tmp.fileSync({ prefix: ['../foo'] }); |
| 9 | + }, new RegExp('^Error: prefix option must be a string')); |
| 10 | + |
| 11 | + done(); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should reject a duck-typed object whose includes() returns false', function (done) { |
| 15 | + assert.throws(function () { |
| 16 | + tmp.fileSync({ |
| 17 | + prefix: { toString: function () { return '../foo'; }, includes: function () { return false; } } |
| 18 | + }); |
| 19 | + }, new RegExp('^Error: prefix option must be a string')); |
| 20 | + |
| 21 | + done(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should reject a number prefix', function (done) { |
| 25 | + assert.throws(function () { |
| 26 | + tmp.fileSync({ prefix: 42 }); |
| 27 | + }, new RegExp('^Error: prefix option must be a string')); |
| 28 | + |
| 29 | + done(); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('#fileSync with non-string `postfix`', function () { |
| 34 | + it('should reject an array postfix', function (done) { |
| 35 | + assert.throws(function () { |
| 36 | + tmp.fileSync({ postfix: ['/../foo'] }); |
| 37 | + }, new RegExp('^Error: postfix option must be a string')); |
| 38 | + |
| 39 | + done(); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('#fileSync with non-string `template`', function () { |
| 44 | + it('should reject an array template', function (done) { |
| 45 | + assert.throws(function () { |
| 46 | + tmp.fileSync({ template: ['XXXXXX/../foo'] }); |
| 47 | + }, new RegExp('^Error: template option must be a string')); |
| 48 | + |
| 49 | + done(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('#dirSync with non-string `prefix`', function () { |
| 54 | + it('should reject an array prefix', function (done) { |
| 55 | + assert.throws(function () { |
| 56 | + tmp.dirSync({ prefix: ['../escape'] }); |
| 57 | + }, new RegExp('^Error: prefix option must be a string')); |
| 58 | + |
| 59 | + done(); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('#tmpNameSync with non-string `prefix`', function () { |
| 64 | + it('should reject an array prefix', function (done) { |
| 65 | + assert.throws(function () { |
| 66 | + tmp.tmpNameSync({ prefix: ['../escape'] }); |
| 67 | + }, new RegExp('^Error: prefix option must be a string')); |
| 68 | + |
| 69 | + done(); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + describe('valid string prefixes still work', function () { |
| 74 | + it('should accept a normal string prefix', function (done) { |
| 75 | + const r = tmp.fileSync({ prefix: 'safe-prefix' }); |
| 76 | + assert.ok(r.name.indexOf('safe-prefix') !== -1); |
| 77 | + r.removeCallback(); |
| 78 | + done(); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments