Skip to content
Snippets Groups Projects
Select Git revision
  • 73506f90439c070fa0948931055d352c86627db3
  • main default protected
  • renovate/main-vitest-monorepo
  • next
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • renovate/main-redis-5.x
  • renovate/main-xmldoc-2.x
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • 41.13.1
  • 41.13.0
  • 41.12.1
  • 41.12.0
  • 41.11.1
  • 41.11.0
  • 41.10.1
  • 41.10.0
  • 41.9.0
  • 41.8.0
  • 41.7.2
  • 41.7.1
  • 41.7.0
  • 41.6.4
  • 41.6.3
  • 41.6.2
  • 41.6.1
  • 41.6.0
  • 41.5.0
  • 41.4.0
41 results

validation.js

Blame
  • util.spec.ts 2.34 KiB
    import upath from 'upath';
    import { GlobalConfig } from '../../config/global';
    import { FILE_ACCESS_VIOLATION_ERROR } from '../../constants/error-messages';
    import { ensureCachePath, ensureLocalPath, isValidPath } from './util';
    
    describe('util/fs/util', () => {
      const localDir = upath.resolve('/foo');
      const cacheDir = upath.resolve('/bar');
    
      beforeAll(() => {
        GlobalConfig.set({ localDir, cacheDir });
      });
    
      test.each`
        path     | fullPath
        ${''}    | ${`${localDir}`}
        ${'baz'} | ${`${localDir}/baz`}
      `(`ensureLocalPath('$path', '$fullPath')`, ({ path, fullPath }) => {
        expect(ensureLocalPath(path)).toBe(fullPath);
      });
    
      test.each`
        path
        ${'..'}
        ${'../etc/passwd'}
        ${'/foo/../bar'}
        ${'/foo/../../etc/passwd'}
        ${'/baz'}
      `(`ensureLocalPath('$path', '${localDir}') - throws`, ({ path }) => {
        expect(() => ensureLocalPath(path)).toThrow(FILE_ACCESS_VIOLATION_ERROR);
      });
    
      test.each`
        path     | fullPath
        ${''}    | ${`${cacheDir}`}
        ${'baz'} | ${`${cacheDir}/baz`}
      `(`ensureCachePath('$path', '$fullPath')`, ({ path, fullPath }) => {
        expect(ensureCachePath(path)).toBe(fullPath);
      });
    
      test.each`
        path
        ${'..'}
        ${'../etc/passwd'}
        ${'/bar/../foo'}
        ${'/bar/../../etc/passwd'}
        ${'/baz'}
        ${'/baz"'}
      `(`ensureCachePath('$path', '${cacheDir}') - throws`, ({ path }) => {
        expect(() => ensureCachePath(path)).toThrow(FILE_ACCESS_VIOLATION_ERROR);
      });
    
      it.each`
        value               | expected
        ${'.'}              | ${true}
        ${'./...'}          | ${true}
        ${'foo'}            | ${true}
        ${'foo/bar'}        | ${true}
        ${'./foo/bar'}      | ${true}
        ${'./foo/bar/...'}  | ${true}
        ${'..'}             | ${false}
        ${'....'}           | ${true}
        ${'./foo/..'}       | ${true}
        ${'./foo/..../bar'} | ${true}
        ${'./..'}           | ${false}
        ${'\\foo'}          | ${false}
        ${"foo'"}           | ${false}
        ${'fo"o'}           | ${false}
        ${'fo&o'}           | ${false}
        ${'f;oo'}           | ${true}
        ${'f o o'}          | ${true}
        ${'/'}              | ${false}
        ${'/foo'}           | ${false}
        ${'&&'}             | ${false}
        ${';'}              | ${true}
        ${'./[foo]/bar'}    | ${true}
      `('isValidPath($value) == $expected', ({ value, expected }) => {
        expect(isValidPath(value, 'cacheDir')).toBe(expected);
      });
    });