test / unit + widget + golden + a11y (push) Failing after 32s
test / integration_test (xvfb) (push) Has been skipped
test / bundle smoke (xvfb 5s) (push) Has been skipped
test / daemon subprocess + web WASM smoke (push) Has been skipped
test / dart doc (lib API) (push) Failing after 1m2s
Three small foundational test additions: - test/files/watcher_test.dart (new, 8 tests): FileChangeKind fromEvent across every FileSystemEvent.type + wire getter, FileChange.toJson, FileWatcher end-to-end (created event, ignored-path filtering, idempotent start, stop teardown). - ignore_test: trailing /**, bare **, ? glob-pattern branches in the regex compiler. - path_safety_test: PathOutsideRoot.toString embeds the three fields. - ipc/errno_mapping_test: ENOTDIR / ENOMEM / EAGAIN branches in errnoToIpcError that weren't previously hit. - panes/registry_test: RecordingEventSink.ofSubsystem filter. Coverage: src/files/watcher.dart 10/36 -> ~ all; ignore.dart + path_safety.dart residuals closed; ipc/errno_mapping.dart 3 added branches; panes/event_sink.dart 100%. Total coverage 90.53% -> 90.99%. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
2.3 KiB
Dart
68 lines
2.3 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:clide/src/files/path_safety.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
late Directory root;
|
|
|
|
setUp(() {
|
|
root = Directory.systemTemp.createTempSync('clide_path_safety_');
|
|
});
|
|
|
|
tearDown(() {
|
|
if (root.existsSync()) root.deleteSync(recursive: true);
|
|
});
|
|
|
|
group('resolveUnderRoot', () {
|
|
test('plain relative path resolves under root', () {
|
|
final out = resolveUnderRoot(root, 'file.txt');
|
|
expect(out, '${root.absolute.path}/file.txt');
|
|
});
|
|
|
|
test('nested relative path resolves under root', () {
|
|
final out = resolveUnderRoot(root, 'src/main.dart');
|
|
expect(out, '${root.absolute.path}/src/main.dart');
|
|
});
|
|
|
|
test('empty relative path resolves to root itself', () {
|
|
final out = resolveUnderRoot(root, '');
|
|
expect(out, root.absolute.path);
|
|
});
|
|
|
|
test('rejects ../etc/passwd traversal', () {
|
|
expect(() => resolveUnderRoot(root, '../../../etc/passwd'), throwsA(isA<PathOutsideRoot>()));
|
|
});
|
|
|
|
test('rejects traversal that lands at filesystem root', () {
|
|
expect(() => resolveUnderRoot(root, '../'), throwsA(isA<PathOutsideRoot>()));
|
|
});
|
|
|
|
test('rejects sibling-directory traversal', () {
|
|
expect(() => resolveUnderRoot(root, '../sibling/file'), throwsA(isA<PathOutsideRoot>()));
|
|
});
|
|
|
|
test('allows internal `..` that stays under root', () {
|
|
final out = resolveUnderRoot(root, 'a/b/../c');
|
|
expect(out, '${root.absolute.path}/a/c');
|
|
});
|
|
|
|
test('rejects path that prefix-matches root but is outside', () {
|
|
// Sibling dir whose name starts with the root's last segment.
|
|
// resolveUnderRoot must not be fooled by string-prefix matching.
|
|
final twin = Directory('${root.parent.path}/${root.uri.pathSegments.where((s) => s.isNotEmpty).last}_twin');
|
|
try {
|
|
twin.createSync();
|
|
expect(() => resolveUnderRoot(root, '../${twin.uri.pathSegments.where((s) => s.isNotEmpty).last}/file'), throwsA(isA<PathOutsideRoot>()));
|
|
} finally {
|
|
if (twin.existsSync()) twin.deleteSync(recursive: true);
|
|
}
|
|
});
|
|
|
|
test('PathOutsideRoot.toString embeds requested + resolved + root', () {
|
|
final e = PathOutsideRoot('r', '/abs', '/root');
|
|
expect(e.toString(), allOf(contains('r'), contains('/abs'), contains('/root')));
|
|
});
|
|
});
|
|
}
|