From 5d4cae1bd2b25a8e60a5224328c726627d1a1262 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Thu, 14 Nov 2024 15:14:28 +0000 Subject: [PATCH 1/3] test: merge build_rust.bash into rust.bash --- e2e/tests-dfx/build_rust.bash | 37 ----------------------------------- e2e/tests-dfx/rust.bash | 24 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 e2e/tests-dfx/build_rust.bash diff --git a/e2e/tests-dfx/build_rust.bash b/e2e/tests-dfx/build_rust.bash deleted file mode 100644 index 60dc5f19a1..0000000000 --- a/e2e/tests-dfx/build_rust.bash +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bats - -load ../utils/_ - -setup() { - standard_setup - - dfx_new -} - -teardown() { - dfx_stop - - standard_teardown -} - -@test "build without cargo-audit installed cannot check for vulnerabilities" { - assert_command rustup default stable - assert_command rustup target add wasm32-unknown-unknown - install_asset vulnerable_rust_deps - dfx_start - dfx canister create --all - assert_command dfx build - assert_match "Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed." -} - -@test "build with vulnerabilities in rust dependencies emits a warning" { - assert_command rustup default stable - assert_command rustup target add wasm32-unknown-unknown - assert_command cargo install cargo-audit --locked - assert_command cargo audit --version - install_asset vulnerable_rust_deps - dfx_start - dfx canister create --all - assert_command dfx build - assert_match "Audit found vulnerabilities" -} diff --git a/e2e/tests-dfx/rust.bash b/e2e/tests-dfx/rust.bash index 29f3f627fe..8b783f7fc9 100644 --- a/e2e/tests-dfx/rust.bash +++ b/e2e/tests-dfx/rust.bash @@ -75,3 +75,27 @@ teardown() { assert_command dfx canister call can3 id assert_contains '(3 : nat32)' } + +@test "build without cargo-audit installed cannot check for vulnerabilities" { + dfx_new + assert_command rustup default stable + assert_command rustup target add wasm32-unknown-unknown + install_asset vulnerable_rust_deps + dfx_start + dfx canister create --all + assert_command dfx build + assert_match "Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed." +} + +@test "build with vulnerabilities in rust dependencies emits a warning" { + dfx_new + assert_command rustup default stable + assert_command rustup target add wasm32-unknown-unknown + assert_command cargo install cargo-audit --locked + assert_command cargo audit --version + install_asset vulnerable_rust_deps + dfx_start + dfx canister create --all + assert_command dfx build + assert_match "Audit found vulnerabilities" +} From 1873241b23d2305af4e6127528ef86f68afe6f1e Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Thu, 14 Nov 2024 16:10:32 +0000 Subject: [PATCH 2/3] Revert "test: merge build_rust.bash into rust.bash" This reverts commit 5d4cae1bd2b25a8e60a5224328c726627d1a1262. --- e2e/tests-dfx/build_rust.bash | 37 +++++++++++++++++++++++++++++++++++ e2e/tests-dfx/rust.bash | 24 ----------------------- 2 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 e2e/tests-dfx/build_rust.bash diff --git a/e2e/tests-dfx/build_rust.bash b/e2e/tests-dfx/build_rust.bash new file mode 100644 index 0000000000..60dc5f19a1 --- /dev/null +++ b/e2e/tests-dfx/build_rust.bash @@ -0,0 +1,37 @@ +#!/usr/bin/env bats + +load ../utils/_ + +setup() { + standard_setup + + dfx_new +} + +teardown() { + dfx_stop + + standard_teardown +} + +@test "build without cargo-audit installed cannot check for vulnerabilities" { + assert_command rustup default stable + assert_command rustup target add wasm32-unknown-unknown + install_asset vulnerable_rust_deps + dfx_start + dfx canister create --all + assert_command dfx build + assert_match "Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed." +} + +@test "build with vulnerabilities in rust dependencies emits a warning" { + assert_command rustup default stable + assert_command rustup target add wasm32-unknown-unknown + assert_command cargo install cargo-audit --locked + assert_command cargo audit --version + install_asset vulnerable_rust_deps + dfx_start + dfx canister create --all + assert_command dfx build + assert_match "Audit found vulnerabilities" +} diff --git a/e2e/tests-dfx/rust.bash b/e2e/tests-dfx/rust.bash index 8b783f7fc9..29f3f627fe 100644 --- a/e2e/tests-dfx/rust.bash +++ b/e2e/tests-dfx/rust.bash @@ -75,27 +75,3 @@ teardown() { assert_command dfx canister call can3 id assert_contains '(3 : nat32)' } - -@test "build without cargo-audit installed cannot check for vulnerabilities" { - dfx_new - assert_command rustup default stable - assert_command rustup target add wasm32-unknown-unknown - install_asset vulnerable_rust_deps - dfx_start - dfx canister create --all - assert_command dfx build - assert_match "Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed." -} - -@test "build with vulnerabilities in rust dependencies emits a warning" { - dfx_new - assert_command rustup default stable - assert_command rustup target add wasm32-unknown-unknown - assert_command cargo install cargo-audit --locked - assert_command cargo audit --version - install_asset vulnerable_rust_deps - dfx_start - dfx canister create --all - assert_command dfx build - assert_match "Audit found vulnerabilities" -} From efce61582799f3a07bf7e20171806fa9a3e72218 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Thu, 14 Nov 2024 16:12:36 +0000 Subject: [PATCH 3/3] test: merge print.bash into usage.bash --- e2e/tests-dfx/print.bash | 27 --------------------------- e2e/tests-dfx/usage.bash | 12 ++++++++++++ 2 files changed, 12 insertions(+), 27 deletions(-) delete mode 100644 e2e/tests-dfx/print.bash diff --git a/e2e/tests-dfx/print.bash b/e2e/tests-dfx/print.bash deleted file mode 100644 index 7a1349921a..0000000000 --- a/e2e/tests-dfx/print.bash +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bats - -load ../utils/_ - -setup() { - standard_setup - - dfx_new -} - -teardown() { - dfx_stop - - standard_teardown -} - -@test "print_mo" { - install_asset print - dfx_start 2>stderr.txt - dfx canister create --all - dfx build - dfx canister install e2e_project - dfx canister call e2e_project hello - sleep 2 - run tail -2 stderr.txt - assert_match "Hello, World! from DFINITY" -} diff --git a/e2e/tests-dfx/usage.bash b/e2e/tests-dfx/usage.bash index cbfaeb11d1..0ece968beb 100644 --- a/e2e/tests-dfx/usage.bash +++ b/e2e/tests-dfx/usage.bash @@ -60,3 +60,15 @@ teardown() { assert_match "$(dfx identity get-principal --identity alice)" } +@test "print_mo" { + dfx_new + install_asset print + dfx_start 2>stderr.txt + dfx canister create --all + dfx build + dfx canister install e2e_project + dfx canister call e2e_project hello + sleep 2 + run tail -2 stderr.txt + assert_match "Hello, World! from DFINITY" +}