Skip to content

Commit 04c48da

Browse files
committed
More testing.
1 parent 82887cc commit 04c48da

File tree

1 file changed

+145
-2
lines changed

1 file changed

+145
-2
lines changed

tests/fs_additional.rs

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,29 @@ fn dotdot_in_middle_of_symlink() {
10581058
assert_eq!(data, foo);
10591059
}
10601060

1061+
/// Like `dotdot_in_middle_of_symlink` but with a `/.` at the end.
1062+
#[test]
1063+
fn dotdot_slashdot_in_middle_of_symlink() {
1064+
let tmpdir = tmpdir();
1065+
1066+
let foo = b"foo";
1067+
check!(tmpdir.write("target", foo));
1068+
check!(tmpdir.create_dir("b"));
1069+
let b = check!(tmpdir.open_dir("b"));
1070+
check!(symlink_dir("../.", &b, "up"));
1071+
1072+
let path = "b/up/target";
1073+
let mut file = check!(tmpdir.open(path));
1074+
let mut data = Vec::new();
1075+
check!(file.read_to_end(&mut data));
1076+
assert_eq!(data, foo);
1077+
}
1078+
10611079
/// Same as `dotdot_in_middle_of_symlink`, but use two levels of `..`.
10621080
///
10631081
/// This fails on Windows for unknown reasons. Patches welcome.
10641082
#[test]
1065-
#[cfg(not(windows))]
1083+
//#[cfg(not(windows))]
10661084
fn dotdot_more_in_middle_of_symlink() {
10671085
let tmpdir = tmpdir();
10681086

@@ -1079,12 +1097,31 @@ fn dotdot_more_in_middle_of_symlink() {
10791097
assert_eq!(data, foo);
10801098
}
10811099

1100+
/// Like `dotdot_more_in_middle_of_symlink`, but with a `/.` at the end.
1101+
#[test]
1102+
//#[cfg(not(windows))]
1103+
fn dotdot_slashdot_more_in_middle_of_symlink() {
1104+
let tmpdir = tmpdir();
1105+
1106+
let foo = b"foo";
1107+
check!(tmpdir.write("target", foo));
1108+
check!(tmpdir.create_dir_all("b/c"));
1109+
let b = check!(tmpdir.open_dir("b"));
1110+
check!(symlink_dir("c/../../.", &b, "up"));
1111+
1112+
let path = "b/up/target";
1113+
let mut file = check!(tmpdir.open(path));
1114+
let mut data = Vec::new();
1115+
check!(file.read_to_end(&mut data));
1116+
assert_eq!(data, foo);
1117+
}
1118+
10821119
/// Same as `dotdot_more_in_middle_of_symlink`, but the symlink doesn't
10831120
/// include `c`.
10841121
///
10851122
/// This fails on Windows for unknown reasons. Patches welcome.
10861123
#[test]
1087-
#[cfg(not(windows))]
1124+
//#[cfg(not(windows))]
10881125
fn dotdot_other_in_middle_of_symlink() {
10891126
let tmpdir = tmpdir();
10901127

@@ -1101,6 +1138,25 @@ fn dotdot_other_in_middle_of_symlink() {
11011138
assert_eq!(data, foo);
11021139
}
11031140

1141+
/// Like `dotdot_other_in_middle_of_symlink`, but with `/.` at the end.
1142+
#[test]
1143+
//#[cfg(not(windows))]
1144+
fn dotdot_slashdot_other_in_middle_of_symlink() {
1145+
let tmpdir = tmpdir();
1146+
1147+
let foo = b"foo";
1148+
check!(tmpdir.write("target", foo));
1149+
check!(tmpdir.create_dir_all("b/c"));
1150+
let c = check!(tmpdir.open_dir("b/c"));
1151+
check!(symlink_dir("../../.", &c, "up"));
1152+
1153+
let path = "b/c/up/target";
1154+
let mut file = check!(tmpdir.open(path));
1155+
let mut data = Vec::new();
1156+
check!(file.read_to_end(&mut data));
1157+
assert_eq!(data, foo);
1158+
}
1159+
11041160
/// Same as `dotdot_more_in_middle_of_symlink`, but use a symlink that
11051161
/// doesn't end with `..`.
11061162
#[test]
@@ -1120,6 +1176,24 @@ fn dotdot_even_more_in_middle_of_symlink() {
11201176
assert_eq!(data, foo);
11211177
}
11221178

1179+
/// Like `dotdot_even_more_in_middle_of_symlink`, but with a `/.` at the end.
1180+
#[test]
1181+
fn dotdot_slashdot_even_more_in_middle_of_symlink() {
1182+
let tmpdir = tmpdir();
1183+
1184+
let foo = b"foo";
1185+
check!(tmpdir.create_dir_all("b/c"));
1186+
check!(tmpdir.write("b/target", foo));
1187+
let b = check!(tmpdir.open_dir("b"));
1188+
check!(symlink_dir("c/../../b/.", &b, "up"));
1189+
1190+
let path = "b/up/target";
1191+
let mut file = check!(tmpdir.open(path));
1192+
let mut data = Vec::new();
1193+
check!(file.read_to_end(&mut data));
1194+
assert_eq!(data, foo);
1195+
}
1196+
11231197
/// Same as `dotdot_even_more_in_middle_of_symlink`, but the symlink doesn't
11241198
/// include `c`.
11251199
#[test]
@@ -1139,6 +1213,24 @@ fn dotdot_even_other_in_middle_of_symlink() {
11391213
assert_eq!(data, foo);
11401214
}
11411215

1216+
/// Like `dotdot_even_other_in_middle_of_symlink`, but with a `/.` at the end.
1217+
#[test]
1218+
fn dotdot_slashdot_even_other_in_middle_of_symlink() {
1219+
let tmpdir = tmpdir();
1220+
1221+
let foo = b"foo";
1222+
check!(tmpdir.create_dir_all("b/c"));
1223+
check!(tmpdir.write("b/target", foo));
1224+
let c = check!(tmpdir.open_dir("b/c"));
1225+
check!(symlink_dir("../../b/.", &c, "up"));
1226+
1227+
let path = "b/c/up/target";
1228+
let mut file = check!(tmpdir.open(path));
1229+
let mut data = Vec::new();
1230+
check!(file.read_to_end(&mut data));
1231+
assert_eq!(data, foo);
1232+
}
1233+
11421234
/// Similar to `dotdot_in_middle_of_symlink`, but this time the symlink to
11431235
/// `..` does happen to be the end of the path, so we need to make sure
11441236
/// the implementation doesn't just do a stack pop when it sees the `..`
@@ -1167,6 +1259,31 @@ fn dotdot_at_end_of_symlink() {
11671259
}
11681260
}
11691261

1262+
/// Like `dotdot_at_end_of_symlink`, but with a `/.` at the end.
1263+
#[test]
1264+
fn dotdot_slashdot_at_end_of_symlink() {
1265+
let tmpdir = tmpdir();
1266+
1267+
let foo = b"foo";
1268+
check!(tmpdir.write("target", foo));
1269+
check!(tmpdir.create_dir("b"));
1270+
let b = check!(tmpdir.open_dir("b"));
1271+
check!(symlink_dir("../.", &b, "up"));
1272+
1273+
// Do some things with `path` that might break with an `O_PATH` fd.
1274+
// On Linux, the `permissions` part doesn't because cap-std uses
1275+
// /proc/self/fd. But the `read_dir` part does.
1276+
let path = "b/up";
1277+
1278+
let perms = check!(tmpdir.metadata(path)).permissions();
1279+
check!(tmpdir.set_permissions(path, perms));
1280+
1281+
let contents = check!(tmpdir.read_dir(path));
1282+
for entry in contents {
1283+
let _entry = check!(entry);
1284+
}
1285+
}
1286+
11701287
/// Like `dotdot_at_end_of_symlink`, but do everything inside a new directory,
11711288
/// so that `MaybeOwnedFile` doesn't reopen `.` which would artificially give
11721289
/// us a non-`O_PATH` fd.
@@ -1194,3 +1311,29 @@ fn dotdot_at_end_of_symlink_all_inside_dir() {
11941311
let _entry = check!(entry);
11951312
}
11961313
}
1314+
1315+
/// `dotdot_at_end_of_symlink_all_inside_dir`, but with a `/.` at the end.
1316+
#[test]
1317+
fn dotdot_slashdot_at_end_of_symlink_all_inside_dir() {
1318+
let tmpdir = tmpdir();
1319+
1320+
let foo = b"foo";
1321+
check!(tmpdir.create_dir("dir"));
1322+
check!(tmpdir.write("dir/target", foo));
1323+
check!(tmpdir.create_dir("dir/b"));
1324+
let b = check!(tmpdir.open_dir("dir/b"));
1325+
check!(symlink_dir("../.", &b, "up"));
1326+
1327+
// Do some things with `path` that might break with an `O_PATH` fd.
1328+
// On Linux, the `permissions` part doesn't because cap-std uses
1329+
// /proc/self/fd. But the `read_dir` part does.
1330+
let path = "dir/b/up";
1331+
1332+
let perms = check!(tmpdir.metadata(path)).permissions();
1333+
check!(tmpdir.set_permissions(path, perms));
1334+
1335+
let contents = check!(tmpdir.read_dir(path));
1336+
for entry in contents {
1337+
let _entry = check!(entry);
1338+
}
1339+
}

0 commit comments

Comments
 (0)