| 31 | |
| 32 | |
| 33 | def validate_manifest(manifest): |
| 34 | if not manifest['files']: |
| 35 | raise ValueError('empty manifest') |
| 36 | tip = manifest['git_tip'] |
| 37 | if len(tip) not in (40, 64) or any(char not in '0123456789abcdef' for char in tip): |
| 38 | raise ValueError('invalid pinned Git tip') |
| 39 | paths = set() |
| 40 | for file in manifest['files']: |
| 41 | name = file['path'] |
| 42 | path = PurePosixPath(name) |
| 43 | if not name or not path.parts or path.is_absolute() or '..' in path.parts or path.parts[0] in ('.git', '.atomic') or str(path) != name: |
| 44 | raise ValueError('unsafe or noncanonical fixture path: ' + name) |
| 45 | if name in paths or file['mode'] not in ('100644', '100755', '120000'): |
| 46 | raise ValueError('duplicate path or unsupported mode') |
| 47 | if len(file['sha256']) != 64 or any(char not in '0123456789abcdef' for char in file['sha256']): |
| 48 | raise ValueError('invalid expected content hash') |
| 49 | paths.add(name) |
| 50 | |
| 51 | |
| 52 | def isolated_env(root): |