Debian Codegraph @

npm-normalize-package-bin/test/array.js

raw
1 const normalize = require('../')
2 const t = require('tap')
3
4 t.test('benign array', async t => {
5 const pkg = { name: 'hello', version: 'world', bin: ['./x/y', 'y/z', './a'] }
6 const expect = { name: 'hello',
7 version: 'world',
8 bin: {
9 y: 'x/y',
10 z: 'y/z',
11 a: 'a',
12 } }
13 t.strictSame(normalize(pkg), expect)
14 t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
15 })
16
17 t.test('conflicting array', async t => {
18 const pkg = { name: 'hello', version: 'world', bin: ['./x/y', 'z/y', './a'] }
19 const expect = { name: 'hello',
20 version: 'world',
21 bin: {
22 y: 'z/y',
23 a: 'a',
24 } }
25 t.strictSame(normalize(pkg), expect)
26 t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
27 })
28
29 t.test('slashy array', async t => {
30 const pkg = { name: 'hello', version: 'world', bin: ['/etc/passwd'] }
31 const expect = { name: 'hello', version: 'world', bin: { passwd: 'etc/passwd' } }
32 t.strictSame(normalize(pkg), expect)
33 t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
34 })
35
36 t.test('dotty array', async t => {
37 const pkg = { name: 'hello', version: 'world', bin: ['../../../../etc/passwd'] }
38 const expect = { name: 'hello', version: 'world', bin: { passwd: 'etc/passwd' } }
39 t.strictSame(normalize(pkg), expect)
40 t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
41 })