Skip to content
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

Fix filesystem rights on WASI, add integration test for file permissions #3240

Merged
merged 23 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a9482ac
Add fd_rights integration test
fschutt Oct 19, 2022
798d27a
Added --nightly option to wasi-wast test generator
fschutt Oct 19, 2022
ec92613
Generate WASI tests on nightly, see which ones fail in CI
fschutt Oct 19, 2022
00d5053
Try triggering CI
fschutt Oct 20, 2022
5a4596f
Undo CI trigger
fschutt Oct 20, 2022
66b2ae3
Rename CurrentNightly to Nightly_2022_10_18
fschutt Oct 20, 2022
ea83bf3
Ignore already-failing tests in CI
fschutt Oct 20, 2022
35d1b96
Debug lib/wasi/src/syscalls/mod/path_open function
fschutt Oct 20, 2022
fdda18d
Implement fix for fd_rights test
fschutt Oct 20, 2022
508b96f
Added proper fix for fd_rights issue
fschutt Oct 24, 2022
fe34d46
Merge branch 'master' into wasi-fs-rights-2
fschutt Oct 24, 2022
5c49c45
Fix style issues, make lint
fschutt Oct 24, 2022
2fb2226
Ignore failing test cases that fail for no reason (maybe debug later)
fschutt Oct 24, 2022
dc33e1b
Adress review comment (code style)
fschutt Oct 24, 2022
cae9f8e
Properly ignore the failing test cases
fschutt Oct 24, 2022
a7c849f
Fix mistake in fd_rights integration test
fschutt Oct 24, 2022
58f184e
Correct file permission diff between create() and create_new()
fschutt Oct 24, 2022
e5a6082
Bug: permissions should be set from OpenOptions, not working dir
fschutt Oct 24, 2022
8c21ba0
Remove check if directory is empty
fschutt Oct 24, 2022
72d49b3
Fix slight bug in adjusted_rights
fschutt Oct 24, 2022
28645c1
Fix bug in mem_fs: parent of foo.txt is root dir
fschutt Oct 24, 2022
5c132f4
Undo wrong inheritance of rights for directories
fschutt Oct 25, 2022
f06d0e9
Revert https://github.com/wasmerio/wasmer/commit/72d49b3d1a5597765581…
fschutt Oct 25, 2022
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
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fn main() -> anyhow::Result<()> {
.expect("Can't get directory");
build_deps::rerun_if_changed_paths("tests/wasi-wast/wasi/snapshot1/*")
.expect("Can't get directory");
build_deps::rerun_if_changed_paths("tests/wasi-wast/wasi/nightly-2022-10-18/*")
.expect("Can't get directory");

let out_dir = PathBuf::from(
env::var_os("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
Expand Down Expand Up @@ -66,7 +68,7 @@ fn main() -> anyhow::Result<()> {
};

with_test_module(&mut wasitests, "wasitests", |wasitests| {
for wasi_version in &["unstable", "snapshot1"] {
for wasi_version in &["unstable", "snapshot1", "nightly_2022_10_18"] {
with_test_module(wasitests, wasi_version, |wasitests| {
for (wasi_filesystem_test_name, wasi_filesystem_kind) in &[
("host_fs", "WasiFileSystemKind::Host"),
Expand Down
9 changes: 8 additions & 1 deletion tests/wasi-wast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ mod wasi_version;
mod wasitests;

pub use crate::set_up_toolchain::install_toolchains;
pub use crate::wasi_version::{WasiVersion, ALL_WASI_VERSIONS, LATEST_WASI_VERSION};
pub use crate::wasi_version::{
WasiVersion, ALL_WASI_VERSIONS, LATEST_WASI_VERSION, NIGHTLY_VERSION,
};
pub use crate::wasitests::{build, WasiOptions, WasiTest};

use gumdrop::Options;
Expand All @@ -17,6 +19,8 @@ pub struct TestGenOptions {
/// if you want to specify specific tests to generate
#[options(free)]
free: Vec<String>,
/// Whether to use the current nightly instead of the latest snapshot0 compiler
nightly: bool,
/// Whether or not to do operations for all versions of WASI or just the latest.
all_versions: bool,
/// Whether or not the Wasm will be generated.
Expand All @@ -38,8 +42,11 @@ fn main() {
let generate_all = opts.all_versions;
let set_up_toolchain = opts.set_up_toolchain;
let generate_wasm = opts.generate_wasm;
let nightly = opts.nightly;
let wasi_versions = if generate_all {
ALL_WASI_VERSIONS
} else if nightly {
NIGHTLY_VERSION
} else {
LATEST_WASI_VERSION
};
Expand Down
10 changes: 10 additions & 0 deletions tests/wasi-wast/src/wasi_version.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
pub static ALL_WASI_VERSIONS: &[WasiVersion] = &[WasiVersion::Unstable, WasiVersion::Snapshot1];
pub static LATEST_WASI_VERSION: &[WasiVersion] = &[WasiVersion::get_latest()];
pub static NIGHTLY_VERSION: &[WasiVersion] = &[WasiVersion::current_nightly()];

#[derive(Debug, Clone, Copy)]
pub enum WasiVersion {
/// A.K.A. Snapshot0
Unstable,
Snapshot1,
/// This is for making tests pass on Apple M1 while
/// still keeping the old test for compatibility reasons
CurrentNightly,
fschutt marked this conversation as resolved.
Show resolved Hide resolved
}

impl WasiVersion {
pub const fn get_latest() -> Self {
Self::Snapshot1
}

pub const fn current_nightly() -> Self {
Self::CurrentNightly
}

pub fn get_compiler_toolchain(&self) -> &'static str {
match self {
WasiVersion::Unstable => "nightly-2019-09-13",
WasiVersion::Snapshot1 => "1.53.0",
WasiVersion::CurrentNightly => "nightly-2022-10-18",
}
}

pub fn get_directory_name(&self) -> &'static str {
match self {
WasiVersion::Unstable => "unstable",
WasiVersion::Snapshot1 => "snapshot1",
WasiVersion::CurrentNightly => "nightly_2022_10_18",
}
}
}
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/close_preopen_fd.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "close_preopen_fd.wasm"
(map_dirs "hamlet:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "accessing preopen fd was a success\nClosing preopen fd was a success\naccessing closed preopen fd was an EBADF error: true\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/create_dir.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "create_dir.wasm"
(preopens "test_fs")
(assert_return (i64.const 0))
(assert_stdout "Test file exists: false\nDir exists: false\nDir exists: false\nDir exists: false\nSuccess\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/envvar.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "envvar.wasm"
(envs "DOG=1" "CAT=2")
(assert_return (i64.const 0))
(assert_stdout "Env vars:\nCAT=2\nDOG=1\nDOG Ok(\"1\")\nDOG_TYPE Err(NotPresent)\nSET VAR Ok(\"HELLO\")\n")
)
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_allocate.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_allocate.wasm"
(temp_dirs ".")
(assert_return (i64.const 0))
(assert_stdout "171\n1405\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_append.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_append.wasm"
(temp_dirs ".")
(assert_return (i64.const 101))
(assert_stderr "thread 'main' panicked at 'Couldn't create file: Os { code: 2, kind: NotFound, message: \"No such file or directory\" }', /Users/fs/Development/wasmer/tests/wasi-wast/wasi/tests/fd_append.rs:27:14\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n")
)
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_close.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_close.wasm"
(map_dirs ".:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "Successfully closed file!\nSuccessfully closed stderr!\nSuccessfully closed stdin!\n")
)
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_pread.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_pread.wasm"
(preopens "test_fs")
(assert_return (i64.const 0))
(assert_stdout " POLONIUS\n\n He will come straight. Look you lay home to him:\n\n POLONIUS\n\n He will come straight. Look you lay home to him:\n\nRead the same data? true\n")
)
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_read.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_read.wasm"
(map_dirs ".:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "SCENE IV. The Queen's closet.\n\n Enter QUEEN GERTRUDE and POLO\n")
)
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_rename_path.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_rename_path.wasm"
(preopens "test_fs")
(assert_return (i64.const 0))
)
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_rights.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_rights.wasm"
(assert_return (i64.const 101))
(assert_stderr "thread 'main' panicked at 'assertion failed: files.is_empty()', /Users/fs/Development/wasmer/tests/wasi-wast/wasi/tests/fd_rights.rs:6:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fd_sync.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fd_sync.wasm"
(temp_dirs ".")
(assert_return (i64.const 0))
(assert_stdout "170\n1404\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/file_metadata.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "file_metadata.wasm"
(preopens "test_fs")
(assert_return (i64.const 0))
(assert_stdout "is dir: false\nfiletype: false true false\nfile info: 8866\n")
)
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fs_sandbox_test.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fs_sandbox_test.wasm"
(assert_return (i64.const 0))
(assert_stdout "Reading the parent directory was okay? false\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/fseek.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "fseek.wasm"
(map_dirs ".:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "SCENE III. A room in Polonius' h\nouse.\n\n Enter LAERTES and OPH\n And, sister, as the winds gi\nr talk with the Lord Hamlet.\n \nuits,\n Breathing like sanctif\nis is for all:\n I would not, \n")
)
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/hello.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "hello.wasm"
(assert_return (i64.const 0))
(assert_stdout "Hello, world!\n")
)
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/isatty.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "isatty.wasm"
(assert_return (i64.const 0))
(assert_stdout "stdin: 1\nstdout: 1\nstderr: 1\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/mapdir.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "mapdir.wasm"
(map_dirs ".:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "\"./README.md\"\n\"./act1\"\n\"./act2\"\n\"./act3\"\n\"./act4\"\n\"./act5\"\n\"./bookmarks\"\n")
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "mapdir_with_leading_slash.wasm"
(map_dirs "/hamlet:test_fs/hamlet")
(assert_return (i64.const 0))
(assert_stdout "File exists? true\nSCENE III. A room in the castle.\n\n Enter KING CLAUDIUS, ROSENCRANTZ, and GUILDENSTERN \n\nKING CLAUDIUS\n\n I like him not, nor stands it safe with us\n To let his madness range. Therefore prepare you;\n I your commission will forthwith dispatch,\n \n")
)
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/path_link.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "path_link.wasm"
(map_dirs "act5:test_fs/hamlet/act5")
(temp_dirs "temp")
(assert_return (i64.const 0))
(assert_stdout "ACT V\nSCENE I. A churchyard.\n\n Enter two Clowns, with spades,\nACT V\nSCENE I. A churchyard.\n\n Enter two Clowns, with spades,\nPath still exists\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/path_rename.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "path_rename.wasm"
(temp_dirs "temp")
(assert_return (i64.const 0))
(assert_stdout "The original file does not still exist!\nFound item: path_renamed_file.txt\n柴犬\nThe original file does not still exist!\nFound item: path_renamed_file.txt\n柴犬\nrun_with_sub_dir: The original file does not still exist!\nrun_with_different_sub_dirs: The original file does not still exist!\n")
)
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/path_symlink.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "path_symlink.wasm"
(map_dirs "hamlet:test_fs/hamlet")
(temp_dirs "temp")
(assert_return (i64.const 101))
(assert_stderr "thread 'main' panicked at 'Could not open file: Os { code: 2, kind: NotFound, message: \"No such file or directory\" }', /Users/fs/Development/wasmer/tests/wasi-wast/wasi/tests/path_symlink.rs:21:44\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n")
)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/pipe_reverse.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "pipe_reverse.wasm"
(assert_return (i64.const 0))
(stdin "Hello, world!")
(assert_stdout "!dlrow ,olleH\n")
)
8 changes: 8 additions & 0 deletions tests/wasi-wast/wasi/nightly_2022_10_18/poll_oneoff.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "poll_oneoff.wasm"
(map_dirs "hamlet:test_fs/hamlet")
(temp_dirs "temp")
(assert_return (i64.const 101))
(assert_stderr "thread 'main' panicked at 'Could not open file: Os { code: 2, kind: NotFound, message: \"No such file or directory\" }', /Users/fs/Development/wasmer/tests/wasi-wast/wasi/tests/poll_oneoff.rs:155:14\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n")
)
Binary file not shown.
Loading