From 09861c20dbc25a5344f4ddb75a2d2c8275b12336 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 11 Jan 2021 15:16:18 -0800 Subject: [PATCH] symlink-related tests: accept either ELOOP or ENOTDIR when opening a symlink loop as directory, or nofollow opening a valid symlink as directory. --- .../wasi-tests/src/bin/dangling_symlink.rs | 13 ++++++++-- .../wasi-tests/src/bin/nofollow_errors.rs | 24 +++++++++---------- crates/wasi-c2/TEST_FAILURES | 6 ----- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs b/crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs index 3b67c5be10..47e2e3d580 100644 --- a/crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs +++ b/crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs @@ -6,9 +6,18 @@ unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) { wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); // Try to open it as a directory with O_NOFOLLOW. + let dir_open_errno = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) + .expect_err("opening a dangling symlink as a directory") + .raw_error(); + assert!( + dir_open_errno == wasi::ERRNO_NOTDIR || dir_open_errno == wasi::ERRNO_LOOP, + "errno should be ERRNO_NOTDIR or ERRNO_LOOP", + ); + + // Try to open it as a file with O_NOFOLLOW. assert_eq!( - wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) - .expect_err("opening a dangling symlink as a directory") + wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0) + .expect_err("opening a dangling symlink as a file") .raw_error(), wasi::ERRNO_LOOP, "errno should be ERRNO_LOOP", diff --git a/crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs b/crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs index e0c1797bb2..7b14c4692c 100644 --- a/crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs +++ b/crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs @@ -11,12 +11,12 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) { wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); // Try to open it as a directory with O_NOFOLLOW again. - assert_eq!( - wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) - .expect_err("opening a directory symlink as a directory should fail") - .raw_error(), - wasi::ERRNO_LOOP, - "errno should be ERRNO_LOOP", + let dir_open_errno = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) + .expect_err("opening a directory symlink as a directory should fail") + .raw_error(); + assert!( + dir_open_errno == wasi::ERRNO_LOOP || dir_open_errno == wasi::ERRNO_NOTDIR, + "errno should be ERRNO_LOOP or ERRNO_NOTDIR", ); // Try to open it with just O_NOFOLLOW. @@ -57,12 +57,12 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) { wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); // Try to open it as a directory with O_NOFOLLOW again. - assert_eq!( - wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) - .expect_err("opening a directory symlink as a directory should fail") - .raw_error(), - wasi::ERRNO_LOOP, - "errno should be ERRNO_LOOP", + let dir_open_errno = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) + .expect_err("opening a directory symlink as a directory should fail") + .raw_error(); + assert!( + dir_open_errno == wasi::ERRNO_LOOP || dir_open_errno == wasi::ERRNO_NOTDIR, + "errno should be ERRNO_LOOP or ERRNO_NOTDIR", ); // Try to open it with just O_NOFOLLOW. diff --git a/crates/wasi-c2/TEST_FAILURES b/crates/wasi-c2/TEST_FAILURES index 0c91841814..d751a5f421 100644 --- a/crates/wasi-c2/TEST_FAILURES +++ b/crates/wasi-c2/TEST_FAILURES @@ -1,22 +1,16 @@ TODOs: -* symlink following behavior, trailing slash behavior (closely related to - symlinks) in cap-std isnt ready yet. * path_filestat_set_times, fd_filestat_set_times: different types used to set times for a Dir vs a File, this is a fs_set_times vs cap_fs_ext divergence * File::set_fdflags is unimplemented, File::get_fdflags is lying - these are fcntl on unix, reopenfile / ?? on windows. Not implemented in system-interface yet. * async scheduling! -wasi_tests::dangling_symlink - - symlink following behavior not yet implemented wasi_tests::directory_seek - something weird about directory open rights / fdstat. need debug impl of Caps to see about this wasi_tests::fd_flags_set - set_fdflags is not implemented. test wanted to clear O_APPEND mode -wasi_tests::nofollow_errors - - symlink following behavior not yet implemented wasi_tests::path_filestat - fdstat.fs_flags is not populated correctly - APPEND | SYNC aren't present because File::get_fdflags isnt implemented correctly