mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { buildFileCheckCmd } from './commands.js'
|
|
|
|
describe('buildFileCheckCmd function', () => {
|
|
it('builds the file check command correctly', () => {
|
|
const testcases = [
|
|
{
|
|
input: { path: '/etc/passwd', type: 'file' },
|
|
output: ['test', '-f', '/etc/passwd'],
|
|
},
|
|
{
|
|
input: { path: '/etc', type: 'folder' },
|
|
output: ['test', '-d', '/etc'],
|
|
},
|
|
{
|
|
input: { path: '/tmp/socket', type: 'socket' },
|
|
output: ['test', '-S', '/tmp/socket'],
|
|
},
|
|
{
|
|
input: { path: '/tmp/link', type: 'link' },
|
|
output: ['test', '-L', '/tmp/link'],
|
|
},
|
|
{
|
|
input: { path: '/unknown', type: 'unknown' },
|
|
output: ['test', '-e', '/unknown'],
|
|
},
|
|
// Add some injection tests
|
|
{
|
|
input: { path: '/etc/passwd;ls', type: 'file' },
|
|
output: ['test', '-f', '/etc/passwdls'],
|
|
},
|
|
{
|
|
input: { path: '/etc/passwd && ls', type: 'file' },
|
|
output: ['test', '-f', '/etc/passwdls'],
|
|
},
|
|
]
|
|
|
|
testcases.forEach(({ input, output }) => {
|
|
expect(buildFileCheckCmd(input)).toStrictEqual(output)
|
|
})
|
|
})
|
|
})
|