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

object.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. const normalize = require('../')
  2. const t = require('tap')
  3. t.test('benign object', async t => {
  4. // just clean up the ./ in the targets and remove anything weird
  5. const pkg = { name: 'hello', version: 'world', bin: {
  6. y: './x/y',
  7. z: './y/z',
  8. a: './a',
  9. } }
  10. const expect = { name: 'hello', version: 'world', bin: {
  11. y: 'x/y',
  12. z: 'y/z',
  13. a: 'a',
  14. } }
  15. t.strictSame(normalize(pkg), expect)
  16. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  17. })
  18. t.test('empty and non-string targets', async t => {
  19. // just clean up the ./ in the targets and remove anything weird
  20. const pkg = { name: 'hello', version: 'world', bin: {
  21. z: './././',
  22. y: '',
  23. './x': 'x.js',
  24. re: /asdf/,
  25. foo: { bar: 'baz' },
  26. false: false,
  27. null: null,
  28. array: [1,2,3],
  29. func: function () {},
  30. } }
  31. const expect = { name: 'hello', version: 'world', bin: {
  32. x: 'x.js',
  33. } }
  34. t.strictSame(normalize(pkg), expect)
  35. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  36. })
  37. t.test('slashy object', async t => {
  38. const pkg = { name: 'hello', version: 'world', bin: {
  39. '/path/foo': '/etc/passwd',
  40. 'bar': '/etc/passwd',
  41. '/etc/glorb/baz': '/etc/passwd',
  42. '/etc/passwd:/bin/usr/exec': '/etc/passwd',
  43. } }
  44. const expect = {
  45. name: 'hello',
  46. version: 'world',
  47. bin: {
  48. foo: 'etc/passwd',
  49. bar: 'etc/passwd',
  50. baz: 'etc/passwd',
  51. exec: 'etc/passwd',
  52. }
  53. }
  54. t.strictSame(normalize(pkg), expect)
  55. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  56. })
  57. t.test('dotty object', async t => {
  58. const pkg = {
  59. name: 'hello',
  60. version: 'world',
  61. bin: {
  62. 'nodots': '../../../../etc/passwd',
  63. '../../../../../../dots': '../../../../etc/passwd',
  64. '.././../\\./..//C:\\./': 'this is removed',
  65. '.././../\\./..//C:\\/': 'super safe programming language',
  66. '.././../\\./..//C:\\x\\y\\z/': 'xyz',
  67. } }
  68. const expect = { name: 'hello', version: 'world', bin: {
  69. nodots: 'etc/passwd',
  70. dots: 'etc/passwd',
  71. C: 'super safe programming language',
  72. z: 'xyz',
  73. } }
  74. t.strictSame(normalize(pkg), expect)
  75. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  76. })
  77. t.test('weird object', async t => {
  78. const pkg = { name: 'hello', version: 'world', bin: /asdf/ }
  79. const expect = { name: 'hello', version: 'world' }
  80. t.strictSame(normalize(pkg), expect)
  81. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  82. })
  83. t.test('oddball keys', async t => {
  84. const pkg = {
  85. bin: {
  86. '~': 'target',
  87. '£': 'target',
  88. 'ζ': 'target',
  89. 'ぎ': 'target',
  90. '操': 'target',
  91. '🎱': 'target',
  92. '💎': 'target',
  93. '💸': 'target',
  94. '🦉': 'target',
  95. 'сheck-dom': 'target',
  96. 'Ωpm': 'target',
  97. 'ζλ': 'target',
  98. 'мга': 'target',
  99. 'пше': 'target',
  100. 'тзч': 'target',
  101. 'тзь': 'target',
  102. 'нфкт': 'target',
  103. 'ссср': 'target',
  104. '君の名は': 'target',
  105. '君の名は': 'target',
  106. }
  107. }
  108. const expect = {
  109. bin: {
  110. '~': 'target',
  111. '£': 'target',
  112. 'ζ': 'target',
  113. 'ぎ': 'target',
  114. '操': 'target',
  115. '🎱': 'target',
  116. '💎': 'target',
  117. '💸': 'target',
  118. '🦉': 'target',
  119. 'сheck-dom': 'target',
  120. 'Ωpm': 'target',
  121. 'ζλ': 'target',
  122. 'мга': 'target',
  123. 'пше': 'target',
  124. 'тзч': 'target',
  125. 'тзь': 'target',
  126. 'нфкт': 'target',
  127. 'ссср': 'target',
  128. '君の名は': 'target',
  129. },
  130. }
  131. t.strictSame(normalize(pkg), expect)
  132. t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
  133. })