Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dirs": ["fs-tests.dir"]
}
115 changes: 115 additions & 0 deletions tests/rust/wasm32-wasip3/src/bin/filesystem-symbolic-links.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use std::process;
extern crate wit_bindgen;

wit_bindgen::generate!({
inline: r"
package test:test;

world test {
include wasi:filesystem/[email protected];
include wasi:cli/[email protected];
}
",
additional_derives: [PartialEq, Eq, Hash, Clone],
// Work around https://github.com/bytecodealliance/wasm-tools/issues/2285.
features:["clocks-timezone"],
generate_all
});

use wasi::filesystem::types::Descriptor;
use wasi::filesystem::types::{DescriptorFlags, ErrorCode, OpenFlags, PathFlags};

async fn test_symbolic_links(dir: &Descriptor) {
let ln_s = |from: &str, to: &str| -> _ { dir.symlink_at(from.to_string(), to.to_string()) };
let readlink = |path: &str| dir.readlink_at(path.to_string());
let stat_with_flags = |flags: PathFlags, path: &str| dir.stat_at(flags, path.to_string());
let stat_follow = |path: &str| stat_with_flags(PathFlags::SYMLINK_FOLLOW, path);
let open_r_follow = |path: &str| -> _ {
dir.open_at(
PathFlags::SYMLINK_FOLLOW,
path.to_string(),
OpenFlags::empty(),
DescriptorFlags::READ,
)
};
let open_r = |path: &str| -> _ {
dir.open_at(
PathFlags::empty(),
path.to_string(),
OpenFlags::empty(),
DescriptorFlags::READ,
)
};
let rm = |path: &str| dir.unlink_file_at(path.to_string());

// readlink-at: async func(path: string) -> result<string, error-code>;
assert_eq!(readlink("").await, Err(ErrorCode::NoEntry));
assert_eq!(readlink(".").await, Err(ErrorCode::Invalid));
assert_eq!(readlink("a.txt").await, Err(ErrorCode::Invalid));
assert_eq!(readlink("z.txt").await, Err(ErrorCode::NoEntry));
assert_eq!(readlink("./../").await, Err(ErrorCode::NotPermitted));
assert_eq!(readlink("..").await, Err(ErrorCode::NotPermitted));
assert_eq!(readlink("/").await, Err(ErrorCode::NotPermitted));
assert_eq!(readlink("parent").await, Ok("..".to_string()));

let afd = open_r("a.txt").await.unwrap();
assert_eq!(
afd.readlink_at(".".to_string()).await,
Err(ErrorCode::NotDirectory)
);

// https://github.com/WebAssembly/wasi-filesystem/issues/186
assert_eq!(
open_r("parent")
.await
.expect_err("open symlink with NOFOLLOW"),
ErrorCode::Loop
);

ln_s("parent", "parent-link").await.unwrap();
Copy link
Collaborator Author

@wingo wingo Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows Wasmtime failure:
Test filesystem-symbolic-links failed
[exit_code] 0 == 3
STDOUT:

STDERR:

thread '' (1) panicked at src/bin/filesystem-symbolic-links.rs:69:41:
called Result::unwrap() on an Err value: ErrorCode { code: 30, name: "not-permitted", message: "Operation not permitted, similar to EPERM in POSIX." }
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to run main module tests\rust\testsuite\wasm32-wasip3\filesystem-symbolic-links.wasm

assert_eq!(open_r("parent-link").await.unwrap_err(), ErrorCode::Loop);
assert_eq!(
open_r_follow("parent-link").await.unwrap_err(),
ErrorCode::NotPermitted
);
assert_eq!(
stat_follow("parent-link").await.unwrap_err(),
ErrorCode::NotPermitted
);
assert_eq!(open_r("parent-link").await.unwrap_err(), ErrorCode::Loop);
assert_eq!(
ln_s("a.txt", "parent-link/a.txt").await,
Err(ErrorCode::NotPermitted)
);
rm("parent-link").await.unwrap();

ln_s("self", "self").await.unwrap();
assert_eq!(open_r_follow("self").await.unwrap_err(), ErrorCode::Loop);
assert_eq!(stat_follow("self").await.unwrap_err(), ErrorCode::Loop);
rm("self").await.unwrap();

assert_eq!(ln_s("whatever", "").await, Err(ErrorCode::NoEntry));
assert_eq!(ln_s("", "whatever").await, Err(ErrorCode::NoEntry));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasmtime MacOS failure:
Test filesystem-symbolic-links failed
[exit_code] 0 == 134
STDOUT:

STDERR:

thread '' (1) panicked at src/bin/filesystem-symbolic-links.rs:92:5:
assertion left == right failed
left: Ok(())
right: Err(ErrorCode { code: 19, name: "no-entry", message: "No such file or directory, similar to ENOENT in POSIX." })
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to run main module tests/rust/testsuite/wasm32-wasip3/filesystem-symbolic-links.wasm

// symlink-at: async func(old-path: string, new-path: string) -> result<_, error-code>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this belong up at line 68?

}

struct Component;
export!(Component);
impl exports::wasi::cli::run::Guest for Component {
async fn run() -> Result<(), ()> {
match &wasi::filesystem::preopens::get_directories()[..] {
[(dir, dirname)] if dirname == "fs-tests.dir" => {
test_symbolic_links(dir).await;
}
[..] => {
eprintln!("usage: run with one open dir named 'fs-tests.dir'");
process::exit(1)
}
};
Ok(())
}
}

fn main() {
unreachable!("main is a stub");
}
Loading