From cc138ad2f8eb519251d82c8c1e6e3e51c13aeb6f Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 20 Aug 2024 11:50:17 +0200 Subject: [PATCH 1/2] unit-test clap configuration `clap` provides an assertion ensuring that the config is well-formed. This removes the need to use bash unit tests. --- .github/workflows/rust.yml | 3 --- README.md | 18 -------------- src/cli.rs | 6 +++++ test.bats | 50 -------------------------------------- 4 files changed, 6 insertions(+), 71 deletions(-) delete mode 100755 test.bats diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6d948b5..b26e4c2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,8 +15,6 @@ jobs: runs-on: ubuntu-latest steps: - - uses: mig4/setup-bats@v1 - - uses: brokenpip3/setup-bats-libs@0.1.0 - uses: actions/checkout@v2 - name: Cache uses: actions/cache@v2 @@ -36,4 +34,3 @@ jobs: - name: Tests run: | cargo test - bats test.bats diff --git a/README.md b/README.md index 3c74609..3209c0e 100644 --- a/README.md +++ b/README.md @@ -145,21 +145,3 @@ cargo fmt --check # CI ensures that there are no outstanding clippy hints cargo clippy ``` - -### Integration tests - -To run integration tests locally, you will need `bats`. For now, only installation through `brew` and github actions is supported (`bats` needs to load its modules manually, and their installation path depends how they were installed). Feel free to add support for more systems as needed. - -```sh -bats test.bats -``` - -
-Installation with brew -```sh -brew install bats-core -brew tap kaos/shell -brew install bats-assert -brew install bats-file -``` -
diff --git a/src/cli.rs b/src/cli.rs index dc6cd76..32acf1d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -351,3 +351,9 @@ mod common_args { pub raw_input: bool, } } + +#[test] +fn verify_cli() { + use clap::CommandFactory; + Opts::command().debug_assert(); +} diff --git a/test.bats b/test.bats deleted file mode 100755 index 6a23c6b..0000000 --- a/test.bats +++ /dev/null @@ -1,50 +0,0 @@ -setup() { - if brew --prefix; then - TEST_BREW_PREFIX="$(brew --prefix)" - load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash" - load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash" - elif [ "${GITHUB_ACTIONS}" == "true" ]; then - load "/usr/lib/bats-support/load.bash" - load "/usr/lib/bats-assert/load.bash" - fi - cargo build - PATH="./target/debug:${PATH}" -} - -# this makes sure we're testing the correct biscuit executable -@test "the correct biscuit version is selected" { - run which biscuit - assert_output --partial "target/debug" -} - -# the following tests make sure that there is no clap configuration error -@test "biscuit --help runs without crashing" { - biscuit --help -} -@test "biscuit append-third-party-block --help runs without crashing" { - biscuit append-third-party-block --help -} -@test "biscuit attenuate --help runs without crashing" { - biscuit attenuate --help -} -@test "biscuit generate --help runs without crashing" { - biscuit generate --help -} -@test "biscuit generate-request --help runs without crashing" { - biscuit generate-request --help -} -@test "biscuit generate-third-party-block --help runs without crashing" { - biscuit generate-third-party-block --help -} -@test "biscuit inspect --help runs without crashing" { - biscuit inspect --help -} -@test "biscuit inspect-snapshot --help runs without crashing" { - biscuit inspect-snapshot --help -} -@test "biscuit keypair --help runs without crashing" { - biscuit keypair --help -} -@test "biscuit seal --help runs without crashing" { - biscuit seal --help -} From e75a7e3200d47ecf118489fced8400ecc38aefde Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Tue, 20 Aug 2024 11:52:10 +0200 Subject: [PATCH 2/2] fix: remove deprecated call --- src/inspect.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inspect.rs b/src/inspect.rs index 591db70..e096ed8 100644 --- a/src/inspect.rs +++ b/src/inspect.rs @@ -414,7 +414,7 @@ pub fn handle_inspect_inner(inspect: &Inspect) -> Result { if let Some(key_from) = public_key_from { let key = read_public_key_from(&key_from)?; - let sig_result = biscuit.check_signature(|_| key); + let sig_result = biscuit.verify(key); signatures_check = Some(sig_result.is_ok()); if let Ok(biscuit) = sig_result {