-
Notifications
You must be signed in to change notification settings - Fork 35
wasi:[email protected]: Add tests for symbolic links #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dirs": ["fs-tests.dir"] | ||
} |
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(); | ||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasmtime MacOS failure: STDERR: thread '' (1) panicked at src/bin/filesystem-symbolic-links.rs:92:5: |
||
// symlink-at: async func(old-path: string, new-path: string) -> result<_, error-code>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 anErr
value: ErrorCode { code: 30, name: "not-permitted", message: "Operation not permitted, similar toEPERM
in POSIX." }note: run with
RUST_BACKTRACE=1
environment variable to display a backtraceError: failed to run main module
tests\rust\testsuite\wasm32-wasip3\filesystem-symbolic-links.wasm