Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

string.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const normalize = require('../')
  2. const t = require('tap')
  3. t.test('benign string', async t => {
  4. const pkg = { name: 'hello', version: 'world', bin: 'hello.js' }
  5. const expect = { name: 'hello', version: 'world', bin: { hello: 'hello.js' } }
  6. t.strictSame(normalize(pkg), expect)
  7. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  8. })
  9. t.test('slashy string', async t => {
  10. const pkg = { name: 'hello', version: 'world', bin: '/etc/passwd' }
  11. const expect = { name: 'hello', version: 'world', bin: { hello: 'etc/passwd' } }
  12. t.strictSame(normalize(pkg), expect)
  13. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  14. })
  15. t.test('dotty string', async t => {
  16. const pkg = { name: 'hello', version: 'world', bin: '../../../../etc/passwd' }
  17. const expect = { name: 'hello', version: 'world', bin: { hello: 'etc/passwd' } }
  18. t.strictSame(normalize(pkg), expect)
  19. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  20. })
  21. t.test('double path', async t => {
  22. const pkg = { name: 'hello', version: 'world', bin: '/etc/passwd:/bin/usr/exec' }
  23. const expect = { name: 'hello', version: 'world', bin: { hello: 'etc/passwd:/bin/usr/exec' } }
  24. t.strictSame(normalize(pkg), expect)
  25. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  26. })
  27. t.test('string with no name', async t => {
  28. const pkg = { bin: 'foobar.js' }
  29. const expect = {}
  30. t.strictSame(normalize(pkg), expect)
  31. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  32. })