From 64cd7ca9ccdefddfb6daa293dbc7775d1e48dacd Mon Sep 17 00:00:00 2001 From: muji Date: Sun, 18 Feb 2024 13:46:43 +0800 Subject: [PATCH 01/17] Prepare initial scripts and tasks. --- Makefile.toml | 36 +++++++++++++++++-- demos/.gitignore | 1 + tests/command_line/scripts/account/backup.sh | 2 ++ tests/command_line/scripts/account/info.sh | 3 ++ tests/command_line/scripts/account/list.sh | 2 ++ tests/command_line/scripts/account/stats.sh | 3 ++ .../scripts/demos/accounts-basic.sh | 20 +++++++++++ tests/command_line/scripts/demos/help.sh | 2 ++ .../scripts/demos/secrets-basic.sh | 21 +++++++++++ tests/command_line/scripts/demos/server.sh | 16 +++++++++ tests/command_line/scripts/demos/version.sh | 2 ++ tests/command_line/scripts/includes/screen.sh | 2 ++ tests/command_line/scripts/includes/signin.sh | 2 ++ tests/command_line/scripts/secret/add-note.sh | 8 +++++ tests/command_line/scripts/secret/copy.sh | 3 ++ tests/command_line/scripts/secret/get-note.sh | 3 ++ tests/command_line/scripts/secret/list.sh | 3 ++ tests/command_line/scripts/secret/rename.sh | 4 +++ tests/command_line/scripts/setup/account.sh | 10 ++++++ .../scripts/specs/secrets-basic.sh | 5 +++ 20 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 demos/.gitignore create mode 100644 tests/command_line/scripts/account/backup.sh create mode 100644 tests/command_line/scripts/account/info.sh create mode 100644 tests/command_line/scripts/account/list.sh create mode 100644 tests/command_line/scripts/account/stats.sh create mode 100644 tests/command_line/scripts/demos/accounts-basic.sh create mode 100644 tests/command_line/scripts/demos/help.sh create mode 100644 tests/command_line/scripts/demos/secrets-basic.sh create mode 100644 tests/command_line/scripts/demos/server.sh create mode 100644 tests/command_line/scripts/demos/version.sh create mode 100644 tests/command_line/scripts/includes/screen.sh create mode 100644 tests/command_line/scripts/includes/signin.sh create mode 100644 tests/command_line/scripts/secret/add-note.sh create mode 100644 tests/command_line/scripts/secret/copy.sh create mode 100644 tests/command_line/scripts/secret/get-note.sh create mode 100644 tests/command_line/scripts/secret/list.sh create mode 100644 tests/command_line/scripts/secret/rename.sh create mode 100644 tests/command_line/scripts/setup/account.sh create mode 100644 tests/command_line/scripts/specs/secrets-basic.sh diff --git a/Makefile.toml b/Makefile.toml index ccd70f0cc3..e6cf9ce3cf 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -118,9 +118,41 @@ args = ["test", "preferences_"] command = "cargo" args = ["test", "system_messages_"] -[tasks.test-cli] +[tasks.install-local] command = "cargo" -args = ["test", "command_line"] +args = ["install", "--path", "."] + +[tasks.clean-cli] +script = ''' +rm -rf target/accounts +''' + +[tasks.test-cli] +env = { "ACCOUNT_PASSWORD" = "demo-test-password-case", "SOS_DATA_DIR" = "target/accounts" } +script = ''' +anticipate \ + run \ + --parallel \ + --setup tests/command_line/scripts/setup/account.sh \ + --logs target \ + tests/command_line/scripts/specs/*.sh +''' +dependencies = ["clean-cli"] + +[tasks.demos] +env = { "ACCOUNT_PASSWORD" = "demo-test-password-case", "SOS_DATA_DIR" = "target/accounts" } +script = ''' +anticipate \ + record \ + --parallel \ + --overwrite \ + --print-comments \ + --logs target \ + demos \ + tests/command_line/scripts/demos/*.sh +''' +dependencies = ["clean-cli"] +#dependencies = ["install-local"] [tasks.integration] dependencies = [ diff --git a/demos/.gitignore b/demos/.gitignore new file mode 100644 index 0000000000..9f9b3db70f --- /dev/null +++ b/demos/.gitignore @@ -0,0 +1 @@ +*.cast diff --git a/tests/command_line/scripts/account/backup.sh b/tests/command_line/scripts/account/backup.sh new file mode 100644 index 0000000000..0108e88886 --- /dev/null +++ b/tests/command_line/scripts/account/backup.sh @@ -0,0 +1,2 @@ +sos account backup target/demo-backup.zip +#$ wait diff --git a/tests/command_line/scripts/account/info.sh b/tests/command_line/scripts/account/info.sh new file mode 100644 index 0000000000..81a54a2d72 --- /dev/null +++ b/tests/command_line/scripts/account/info.sh @@ -0,0 +1,3 @@ +sos account info -a Demo +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/account/list.sh b/tests/command_line/scripts/account/list.sh new file mode 100644 index 0000000000..93940986a2 --- /dev/null +++ b/tests/command_line/scripts/account/list.sh @@ -0,0 +1,2 @@ +sos account ls -v +#$ wait diff --git a/tests/command_line/scripts/account/stats.sh b/tests/command_line/scripts/account/stats.sh new file mode 100644 index 0000000000..f0632818ea --- /dev/null +++ b/tests/command_line/scripts/account/stats.sh @@ -0,0 +1,3 @@ +sos account stats -a Demo --json +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/demos/accounts-basic.sh b/tests/command_line/scripts/demos/accounts-basic.sh new file mode 100644 index 0000000000..97dad92b0a --- /dev/null +++ b/tests/command_line/scripts/demos/accounts-basic.sh @@ -0,0 +1,20 @@ +# create an account + +#$ include ../setup/account.sh +#$ include ../includes/screen.sh + +# list accounts +#$ include ../account/list.sh + +# create a backup archive +#$ include ../account/backup.sh + +# now we will always need to sign in + +# account info shows the folder list +#$ include ../account/info.sh + +#$ include ../includes/screen.sh + +# show account statistics +#$ include ../account/stats.sh diff --git a/tests/command_line/scripts/demos/help.sh b/tests/command_line/scripts/demos/help.sh new file mode 100644 index 0000000000..c246f2f5bc --- /dev/null +++ b/tests/command_line/scripts/demos/help.sh @@ -0,0 +1,2 @@ +sos --help +#$ expect Print version diff --git a/tests/command_line/scripts/demos/secrets-basic.sh b/tests/command_line/scripts/demos/secrets-basic.sh new file mode 100644 index 0000000000..067bd94a40 --- /dev/null +++ b/tests/command_line/scripts/demos/secrets-basic.sh @@ -0,0 +1,21 @@ +# create a new secret note +#$ include ../secret/add-note.sh +#$ include ../includes/screen.sh + +# now we can list the secrets in the folder +#$ include ../secret/list.sh + +# and view the secret +#$ include ../secret/get-note.sh + +#$ include ../includes/screen.sh + +# or copy it to the clipboard +#$ include ../secret/copy.sh + +#$ include ../includes/screen.sh + +# rename a secret +#$ include ../secret/rename.sh + +#$ include ../includes/screen.sh diff --git a/tests/command_line/scripts/demos/server.sh b/tests/command_line/scripts/demos/server.sh new file mode 100644 index 0000000000..6654060d06 --- /dev/null +++ b/tests/command_line/scripts/demos/server.sh @@ -0,0 +1,16 @@ +# create a directory to store account data +mkdir -p target/server/accounts +#$ readline + +# initialize a config file for the server +sos-server init target/config.toml --path server/accounts +#$ readline + +cat target/config.toml +#$ expect path = "server/accounts" + +# start the server +sos-server start target/config.toml +#$ regex tls + +#$ sendcontrol ^C diff --git a/tests/command_line/scripts/demos/version.sh b/tests/command_line/scripts/demos/version.sh new file mode 100644 index 0000000000..0f6b66c518 --- /dev/null +++ b/tests/command_line/scripts/demos/version.sh @@ -0,0 +1,2 @@ +sos --version +#$ readline diff --git a/tests/command_line/scripts/includes/screen.sh b/tests/command_line/scripts/includes/screen.sh new file mode 100644 index 0000000000..762909db96 --- /dev/null +++ b/tests/command_line/scripts/includes/screen.sh @@ -0,0 +1,2 @@ +#$ sleep 1000 +#$ clear diff --git a/tests/command_line/scripts/includes/signin.sh b/tests/command_line/scripts/includes/signin.sh new file mode 100644 index 0000000000..b0802548ab --- /dev/null +++ b/tests/command_line/scripts/includes/signin.sh @@ -0,0 +1,2 @@ +#$ regex (?i)password +$ACCOUNT_PASSWORD diff --git a/tests/command_line/scripts/secret/add-note.sh b/tests/command_line/scripts/secret/add-note.sh new file mode 100644 index 0000000000..a5470949d8 --- /dev/null +++ b/tests/command_line/scripts/secret/add-note.sh @@ -0,0 +1,8 @@ +sos secret add note +#$ include ../includes/signin.sh +#$ expect Name: +Example Note +#$ expect >> +This is the text for the secret note. +#$ sendcontrol ^D +#$ wait diff --git a/tests/command_line/scripts/secret/copy.sh b/tests/command_line/scripts/secret/copy.sh new file mode 100644 index 0000000000..94396f1ea0 --- /dev/null +++ b/tests/command_line/scripts/secret/copy.sh @@ -0,0 +1,3 @@ +sos secret copy "Example Note" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/get-note.sh b/tests/command_line/scripts/secret/get-note.sh new file mode 100644 index 0000000000..79d91fe274 --- /dev/null +++ b/tests/command_line/scripts/secret/get-note.sh @@ -0,0 +1,3 @@ +sos secret get "Example Note" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/list.sh b/tests/command_line/scripts/secret/list.sh new file mode 100644 index 0000000000..a4d450b0b3 --- /dev/null +++ b/tests/command_line/scripts/secret/list.sh @@ -0,0 +1,3 @@ +sos secret ls -f Documents +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/rename.sh b/tests/command_line/scripts/secret/rename.sh new file mode 100644 index 0000000000..7ead59ccba --- /dev/null +++ b/tests/command_line/scripts/secret/rename.sh @@ -0,0 +1,4 @@ +# rename a secret +sos secret rename --name "Demo Note" "Example Note" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/setup/account.sh b/tests/command_line/scripts/setup/account.sh new file mode 100644 index 0000000000..b49dff185d --- /dev/null +++ b/tests/command_line/scripts/setup/account.sh @@ -0,0 +1,10 @@ +sos account new Demo +#$ expect Choose a password +2 +#$ regex (?i)password +$ACCOUNT_PASSWORD +#$ regex (?i)password +$ACCOUNT_PASSWORD +#$ regex create a new account +y +#$ wait diff --git a/tests/command_line/scripts/specs/secrets-basic.sh b/tests/command_line/scripts/specs/secrets-basic.sh new file mode 100644 index 0000000000..166ce1c228 --- /dev/null +++ b/tests/command_line/scripts/specs/secrets-basic.sh @@ -0,0 +1,5 @@ +#$ include ../secret/add-note.sh +#$ include ../secret/list.sh +#$ include ../secret/get-note.sh +#$ include ../secret/copy.sh +#$ include ../secret/rename.sh From a09a435dcaa34a0dbf3839714ffdb2f4f88f26a7 Mon Sep 17 00:00:00 2001 From: muji Date: Sun, 18 Feb 2024 16:46:49 +0800 Subject: [PATCH 02/17] Add cli test specs to script definitions. --- .github/workflows/publish.yml | 2 +- Makefile.toml | 23 ++-------------- scripts/{ => ci}/find-executables.sh | 0 scripts/ci/prepare-executables.sh | 13 +++++++++ scripts/cli/demos.sh | 21 +++++++++++++++ scripts/cli/specs.sh | 15 +++++++++++ scripts/macos-codesign.sh | 11 -------- scripts/macos-notarize.sh | 18 ------------- scripts/prepare-executables.sh | 27 ------------------- src/cli/sos.rs | 2 +- src/cli/sos_server.rs | 2 +- src/commands/account.rs | 3 ++- tests/command_line/scripts/account/backup.sh | 3 ++- tests/command_line/scripts/account/restore.sh | 5 ++++ .../scripts/specs/account-info.sh | 6 +++++ .../scripts/specs/account-list.sh | 4 +++ .../scripts/specs/account-stats.sh | 0 .../scripts/specs/backup-restore.sh | 2 ++ 18 files changed, 75 insertions(+), 82 deletions(-) rename scripts/{ => ci}/find-executables.sh (100%) create mode 100755 scripts/ci/prepare-executables.sh create mode 100755 scripts/cli/demos.sh create mode 100755 scripts/cli/specs.sh delete mode 100755 scripts/macos-codesign.sh delete mode 100755 scripts/macos-notarize.sh delete mode 100755 scripts/prepare-executables.sh create mode 100644 tests/command_line/scripts/account/restore.sh create mode 100644 tests/command_line/scripts/specs/account-info.sh create mode 100644 tests/command_line/scripts/specs/account-list.sh create mode 100644 tests/command_line/scripts/specs/account-stats.sh create mode 100644 tests/command_line/scripts/specs/backup-restore.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 01c3a2a297..26d204a14b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -103,7 +103,7 @@ jobs: - name: Gather executables shell: bash run: | - ./scripts/prepare-executables.sh $(./scripts/find-executables.sh "$BUILD_DIR") + ./scripts/ci/prepare-executables.sh $(./scripts/ci/find-executables.sh "$BUILD_DIR") - name: Archive release uses: thedoctor0/zip-release@0.7.1 diff --git a/Makefile.toml b/Makefile.toml index e6cf9ce3cf..52e70283a3 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -128,31 +128,12 @@ rm -rf target/accounts ''' [tasks.test-cli] -env = { "ACCOUNT_PASSWORD" = "demo-test-password-case", "SOS_DATA_DIR" = "target/accounts" } -script = ''' -anticipate \ - run \ - --parallel \ - --setup tests/command_line/scripts/setup/account.sh \ - --logs target \ - tests/command_line/scripts/specs/*.sh -''' +script = { file = "./scripts/cli/specs.sh" } dependencies = ["clean-cli"] [tasks.demos] -env = { "ACCOUNT_PASSWORD" = "demo-test-password-case", "SOS_DATA_DIR" = "target/accounts" } -script = ''' -anticipate \ - record \ - --parallel \ - --overwrite \ - --print-comments \ - --logs target \ - demos \ - tests/command_line/scripts/demos/*.sh -''' +script = { file = "./scripts/cli/demos.sh" } dependencies = ["clean-cli"] -#dependencies = ["install-local"] [tasks.integration] dependencies = [ diff --git a/scripts/find-executables.sh b/scripts/ci/find-executables.sh similarity index 100% rename from scripts/find-executables.sh rename to scripts/ci/find-executables.sh diff --git a/scripts/ci/prepare-executables.sh b/scripts/ci/prepare-executables.sh new file mode 100755 index 0000000000..9156b7339c --- /dev/null +++ b/scripts/ci/prepare-executables.sh @@ -0,0 +1,13 @@ +#/usr/bin/env bash + +set -e + +EXES="$@" +BIN_DIR=${BIN_DIR:-target/bin} + +echo "$EXES" + +mkdir -p $BIN_DIR +cp -f $EXES $BIN_DIR +cp LICENSE-APACHE LICENSE-MIT COPYRIGHT $BIN_DIR +ls -la $BIN_DIR diff --git a/scripts/cli/demos.sh b/scripts/cli/demos.sh new file mode 100755 index 0000000000..b2d7a06823 --- /dev/null +++ b/scripts/cli/demos.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +export SOS_DATA_DIR="target/accounts" +export ACCOUNT_PASSWORD="demo-test-password-case" +export ACCOUNT_BACKUP="target/demo-backup.zip" + +scripts=tests/command_line/scripts/demos +anticipate \ + record \ + --parallel \ + --overwrite \ + --print-comments \ + --logs target \ + --setup $scripts/accounts-basic.sh \ + demos \ + $scripts/version.sh \ + $scripts/help.sh \ + $scripts/server.sh \ + $scripts/secrets-basic.sh diff --git a/scripts/cli/specs.sh b/scripts/cli/specs.sh new file mode 100755 index 0000000000..1828e4372b --- /dev/null +++ b/scripts/cli/specs.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +export SOS_DATA_DIR="target/accounts" +export ACCOUNT_PASSWORD="demo-test-password-case" +export ACCOUNT_BACKUP="target/demo-backup.zip" +export NO_COLOR=1 + +anticipate \ + run \ + --parallel \ + --setup tests/command_line/scripts/setup/account.sh \ + --logs target \ + tests/command_line/scripts/specs/*.sh diff --git a/scripts/macos-codesign.sh b/scripts/macos-codesign.sh deleted file mode 100755 index aaa830bffd..0000000000 --- a/scripts/macos-codesign.sh +++ /dev/null @@ -1,11 +0,0 @@ -#/usr/bin/env bash - -set -e - -DIR="$1" -EXES=$(./scripts/find-executables.sh $DIR) -ID=${MACOS_CERTIFICATE_NAME:-$SOS_MACOS_SIGN_CERTIFICATE_ID} - -for EXE in $EXES; do - codesign -s "$ID" --timestamp -o runtime -v "$EXE" --force -done diff --git a/scripts/macos-notarize.sh b/scripts/macos-notarize.sh deleted file mode 100755 index 3a4672e4c0..0000000000 --- a/scripts/macos-notarize.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -e - -DIR=${DIR:-target/release} -EXE=${EXE:-sos} -KEYCHAIN_PROFILE="$SOS_INSTALLER_KEYCHAIN_PROFILE" - -(cd $DIR && zip "$EXE.zip" "$EXE") -ZIP=${ZIP:-$DIR/$EXE.zip} - -xcrun notarytool submit $ZIP \ - --keychain-profile "$KEYCHAIN_PROFILE" \ - --wait - -cd $DIR -unzip -o "$EXE.zip" -spctl --assess -vvv --type install $EXE diff --git a/scripts/prepare-executables.sh b/scripts/prepare-executables.sh deleted file mode 100755 index 8efeba5d51..0000000000 --- a/scripts/prepare-executables.sh +++ /dev/null @@ -1,27 +0,0 @@ -#/usr/bin/env bash - -set -e - -EXES="$@" -BIN_DIR=${BIN_DIR:-target/bin} - -echo "$EXES" - -mkdir -p $BIN_DIR -cp -f $EXES $BIN_DIR -cp LICENSE-APACHE LICENSE-MIT COPYRIGHT $BIN_DIR -ls -la $BIN_DIR - -#OS="$(uname -s)" -#case "${OS}" in - #Darwin*) - #./scripts/macos-codesign.sh $BIN_DIR - - ## zip each executable for notarization - #for EXE in $EXES; do - #EXE_NAME=$(basename "$EXE") - #EXE_DIR=$(dirname "$EXE") - #DIR="$EXE_DIR" EXE="$EXE_NAME" ./scripts/macos-notarize.sh - #done - #;; -#esac diff --git a/src/cli/sos.rs b/src/cli/sos.rs index 094664b8ac..132ef9cb41 100644 --- a/src/cli/sos.rs +++ b/src/cli/sos.rs @@ -145,7 +145,7 @@ pub async fn run() -> Result<()> { if std::env::var("SOS_CLI_JSON").ok().is_some() { let cmd = Sos::command(); let tree: CommandTree = (&cmd).into(); - let output = serde_json::to_writer_pretty(std::io::stdout(), &tree)?; + serde_json::to_writer_pretty(std::io::stdout(), &tree)?; std::process::exit(0); } diff --git a/src/cli/sos_server.rs b/src/cli/sos_server.rs index 9737c19591..e036d9550f 100644 --- a/src/cli/sos_server.rs +++ b/src/cli/sos_server.rs @@ -36,7 +36,7 @@ pub async fn run() -> Result<()> { if std::env::var("SOS_CLI_JSON").ok().is_some() { let cmd = SosServer::command(); let tree: CommandTree = (&cmd).into(); - let output = serde_json::to_writer_pretty(std::io::stdout(), &tree)?; + serde_json::to_writer_pretty(std::io::stdout(), &tree)?; std::process::exit(0); } diff --git a/src/commands/account.rs b/src/commands/account.rs index 48c19311d7..b660eefb08 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -208,7 +208,7 @@ pub async fn run(cmd: Command) -> Result<()> { } Command::Restore { input } => { if let Some(account) = account_restore(input).await? { - success(format!("restored {} ({})", account.label(), account.address())); + success(format!("Account restored {}", account.label())); } } Command::Rename { name, account } => { @@ -396,6 +396,7 @@ async fn account_restore(input: PathBuf) -> Result> { let inventory: Inventory = AccountBackup::restore_archive_inventory(reader).await?; let account_ref = AccountRef::Address(inventory.manifest.address); + let account = find_account(&account_ref).await?; let mut owner = if let Some(account) = account { diff --git a/tests/command_line/scripts/account/backup.sh b/tests/command_line/scripts/account/backup.sh index 0108e88886..4aa20c4751 100644 --- a/tests/command_line/scripts/account/backup.sh +++ b/tests/command_line/scripts/account/backup.sh @@ -1,2 +1,3 @@ -sos account backup target/demo-backup.zip +sos account backup --force $ACCOUNT_BACKUP +#$ regex (?i)archive created #$ wait diff --git a/tests/command_line/scripts/account/restore.sh b/tests/command_line/scripts/account/restore.sh new file mode 100644 index 0000000000..09e4acf267 --- /dev/null +++ b/tests/command_line/scripts/account/restore.sh @@ -0,0 +1,5 @@ +sos account restore $ACCOUNT_BACKUP +#$ regex Overwrite all account +y +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/specs/account-info.sh b/tests/command_line/scripts/specs/account-info.sh new file mode 100644 index 0000000000..427689d311 --- /dev/null +++ b/tests/command_line/scripts/specs/account-info.sh @@ -0,0 +1,6 @@ +sos account info +#$ include ../includes/signin.sh +#$ wait +sos account info -v +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/specs/account-list.sh b/tests/command_line/scripts/specs/account-list.sh new file mode 100644 index 0000000000..b60a095b48 --- /dev/null +++ b/tests/command_line/scripts/specs/account-list.sh @@ -0,0 +1,4 @@ +sos account ls +#$ wait +sos account ls -v +#$ wait diff --git a/tests/command_line/scripts/specs/account-stats.sh b/tests/command_line/scripts/specs/account-stats.sh new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/command_line/scripts/specs/backup-restore.sh b/tests/command_line/scripts/specs/backup-restore.sh new file mode 100644 index 0000000000..a7a118060b --- /dev/null +++ b/tests/command_line/scripts/specs/backup-restore.sh @@ -0,0 +1,2 @@ +#$ include ../account/backup.sh +#$ include ../account/restore.sh From 286d9c02b035b7c8792b8e7efbbd62bd0ee8bfb2 Mon Sep 17 00:00:00 2001 From: muji Date: Tue, 20 Feb 2024 10:24:28 +0800 Subject: [PATCH 03/17] Don't run cli tests in parallel. --- scripts/cli/demos.sh | 1 - scripts/cli/specs.sh | 2 -- 2 files changed, 3 deletions(-) diff --git a/scripts/cli/demos.sh b/scripts/cli/demos.sh index b2d7a06823..12daac4766 100755 --- a/scripts/cli/demos.sh +++ b/scripts/cli/demos.sh @@ -12,7 +12,6 @@ anticipate \ --parallel \ --overwrite \ --print-comments \ - --logs target \ --setup $scripts/accounts-basic.sh \ demos \ $scripts/version.sh \ diff --git a/scripts/cli/specs.sh b/scripts/cli/specs.sh index 1828e4372b..6d9bd332c1 100755 --- a/scripts/cli/specs.sh +++ b/scripts/cli/specs.sh @@ -9,7 +9,5 @@ export NO_COLOR=1 anticipate \ run \ - --parallel \ --setup tests/command_line/scripts/setup/account.sh \ - --logs target \ tests/command_line/scripts/specs/*.sh From 28c1dfef8ab3e8b8aabd0211689e03d46d7c398d Mon Sep 17 00:00:00 2001 From: muji Date: Tue, 20 Feb 2024 13:18:14 +0800 Subject: [PATCH 04/17] Migrate folder cli test specs. --- scripts/cli/demos.sh | 4 +-- scripts/cli/env.sh | 18 ++++++++++ scripts/cli/specs.sh | 12 +++++-- src/commands/account.rs | 7 ++-- src/commands/folder.rs | 15 +++++--- tests/command_line/scripts/folder/commits.sh | 3 ++ .../scripts/folder/history/check.sh | 3 ++ .../scripts/folder/history/compact.sh | 5 +++ .../scripts/folder/history/list.sh | 3 ++ tests/command_line/scripts/folder/info.sh | 3 ++ tests/command_line/scripts/folder/keys.sh | 3 ++ tests/command_line/scripts/folder/list.sh | 3 ++ tests/command_line/scripts/folder/new.sh | 4 +++ tests/command_line/scripts/folder/remove.sh | 6 ++++ tests/command_line/scripts/folder/rename.sh | 7 ++++ tests/command_line/scripts/setup/account.sh | 2 +- .../scripts/specs/account-contacts.sh | 4 +++ .../scripts/specs/account-migrate.sh | 36 +++++++++++++++++++ .../scripts/specs/account-rename.sh | 7 ++++ .../scripts/specs/account-stats.sh | 3 ++ tests/command_line/scripts/specs/folder.sh | 12 +++++++ .../specs/{secrets-basic.sh => secrets.sh} | 0 22 files changed, 145 insertions(+), 15 deletions(-) create mode 100644 scripts/cli/env.sh create mode 100644 tests/command_line/scripts/folder/commits.sh create mode 100644 tests/command_line/scripts/folder/history/check.sh create mode 100644 tests/command_line/scripts/folder/history/compact.sh create mode 100644 tests/command_line/scripts/folder/history/list.sh create mode 100644 tests/command_line/scripts/folder/info.sh create mode 100644 tests/command_line/scripts/folder/keys.sh create mode 100644 tests/command_line/scripts/folder/list.sh create mode 100644 tests/command_line/scripts/folder/new.sh create mode 100644 tests/command_line/scripts/folder/remove.sh create mode 100644 tests/command_line/scripts/folder/rename.sh create mode 100644 tests/command_line/scripts/specs/account-contacts.sh create mode 100644 tests/command_line/scripts/specs/account-migrate.sh create mode 100644 tests/command_line/scripts/specs/account-rename.sh create mode 100644 tests/command_line/scripts/specs/folder.sh rename tests/command_line/scripts/specs/{secrets-basic.sh => secrets.sh} (100%) diff --git a/scripts/cli/demos.sh b/scripts/cli/demos.sh index 12daac4766..f9829a714e 100755 --- a/scripts/cli/demos.sh +++ b/scripts/cli/demos.sh @@ -2,9 +2,7 @@ set -e -export SOS_DATA_DIR="target/accounts" -export ACCOUNT_PASSWORD="demo-test-password-case" -export ACCOUNT_BACKUP="target/demo-backup.zip" +source scripts/cli/env.sh scripts=tests/command_line/scripts/demos anticipate \ diff --git a/scripts/cli/env.sh b/scripts/cli/env.sh new file mode 100644 index 0000000000..f28c229774 --- /dev/null +++ b/scripts/cli/env.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +export SOS_DATA_DIR="target/accounts" +export ACCOUNT_NAME="Demo" +export ACCOUNT_PASSWORD="demo-test-password-case" +export ACCOUNT_BACKUP="target/demo-backup.zip" +export ACCOUNT_CONTACTS="tests/fixtures/contacts.vcf" + +export FOLDER_NAME="mock-folder" +export NEW_FOLDER_NAME="mock-folder-renamed" + +export MIGRATE_1PASSWORD="tests/fixtures/migrate/1password-export.csv" +export MIGRATE_DASHLANE="tests/fixtures/migrate/dashlane-export.zip" +export MIGRATE_BITWARDEN="tests/fixtures/migrate/bitwarden-export.csv" +export MIGRATE_FIREFOX="tests/fixtures/migrate/firefox-export.csv" +export MIGRATE_MACOS="tests/fixtures/migrate/macos-export.csv" diff --git a/scripts/cli/specs.sh b/scripts/cli/specs.sh index 6d9bd332c1..54eafd83cb 100755 --- a/scripts/cli/specs.sh +++ b/scripts/cli/specs.sh @@ -2,11 +2,17 @@ set -e -export SOS_DATA_DIR="target/accounts" -export ACCOUNT_PASSWORD="demo-test-password-case" -export ACCOUNT_BACKUP="target/demo-backup.zip" +source scripts/cli/env.sh export NO_COLOR=1 +rm target/*.zip + +if [ -n "$DEBUG" ]; then + export PATH="target/debug:$PATH" +fi + +command -v sos + anticipate \ run \ --setup tests/command_line/scripts/setup/account.sh \ diff --git a/src/commands/account.rs b/src/commands/account.rs index b660eefb08..33134b1d9c 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -81,13 +81,12 @@ pub enum Command { }, /// Rename an account. Rename { - /// Name for the account. - #[clap(short, long)] - name: String, - /// Account name or address. #[clap(short, long)] account: Option, + + /// New name for the account. + name: String, }, /// Export and import unencrypted secrets. Migrate { diff --git a/src/commands/folder.rs b/src/commands/folder.rs index 6beab561af..c3865b88b3 100644 --- a/src/commands/folder.rs +++ b/src/commands/folder.rs @@ -40,6 +40,7 @@ pub enum Command { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, @@ -65,6 +66,7 @@ pub enum Command { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, /// Print secret keys for a folder. @@ -74,6 +76,7 @@ pub enum Command { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, /// Print commits for a folder. @@ -83,21 +86,22 @@ pub enum Command { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, /// Rename a folder. #[clap(alias = "mv")] Rename { - /// Name for the folder. - #[clap(short, long)] - name: String, - /// Account name or address. #[clap(short, long)] account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, + + /// New name for the folder. + name: String, }, /// Manage the history for a folder. History { @@ -116,6 +120,7 @@ pub enum History { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, /// Verify the integrity of the folder history. @@ -125,6 +130,7 @@ pub enum History { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, /// List history events. @@ -139,6 +145,7 @@ pub enum History { account: Option, /// Folder name or id. + #[clap(short, long)] folder: Option, }, } diff --git a/tests/command_line/scripts/folder/commits.sh b/tests/command_line/scripts/folder/commits.sh new file mode 100644 index 0000000000..9c30e32f83 --- /dev/null +++ b/tests/command_line/scripts/folder/commits.sh @@ -0,0 +1,3 @@ +sos folder commits -f $FOLDER_NAME +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/folder/history/check.sh b/tests/command_line/scripts/folder/history/check.sh new file mode 100644 index 0000000000..a6c5dded9c --- /dev/null +++ b/tests/command_line/scripts/folder/history/check.sh @@ -0,0 +1,3 @@ +sos folder history check -f $FOLDER_NAME +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/folder/history/compact.sh b/tests/command_line/scripts/folder/history/compact.sh new file mode 100644 index 0000000000..658938ef00 --- /dev/null +++ b/tests/command_line/scripts/folder/history/compact.sh @@ -0,0 +1,5 @@ +sos folder history compact -f $FOLDER_NAME +#$ include ../../includes/signin.sh +#$ regex (?i)remove history +y +#$ wait diff --git a/tests/command_line/scripts/folder/history/list.sh b/tests/command_line/scripts/folder/history/list.sh new file mode 100644 index 0000000000..08e988da1d --- /dev/null +++ b/tests/command_line/scripts/folder/history/list.sh @@ -0,0 +1,3 @@ +sos folder history list -f $FOLDER_NAME +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/folder/info.sh b/tests/command_line/scripts/folder/info.sh new file mode 100644 index 0000000000..3176501db6 --- /dev/null +++ b/tests/command_line/scripts/folder/info.sh @@ -0,0 +1,3 @@ +sos folder info -v +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/folder/keys.sh b/tests/command_line/scripts/folder/keys.sh new file mode 100644 index 0000000000..f050af44fc --- /dev/null +++ b/tests/command_line/scripts/folder/keys.sh @@ -0,0 +1,3 @@ +sos folder keys -f $FOLDER_NAME +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/folder/list.sh b/tests/command_line/scripts/folder/list.sh new file mode 100644 index 0000000000..3e15c8e210 --- /dev/null +++ b/tests/command_line/scripts/folder/list.sh @@ -0,0 +1,3 @@ +sos folder ls -v +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/folder/new.sh b/tests/command_line/scripts/folder/new.sh new file mode 100644 index 0000000000..2f9f520884 --- /dev/null +++ b/tests/command_line/scripts/folder/new.sh @@ -0,0 +1,4 @@ +sos folder new $FOLDER_NAME +#$ include ../includes/signin.sh +#$ regex (?i)created +#$ wait diff --git a/tests/command_line/scripts/folder/remove.sh b/tests/command_line/scripts/folder/remove.sh new file mode 100644 index 0000000000..6ccef8f8d9 --- /dev/null +++ b/tests/command_line/scripts/folder/remove.sh @@ -0,0 +1,6 @@ +sos folder remove -f $FOLDER_NAME +#$ include ../includes/signin.sh +#$ regex (?i)delete folder +y +#$ regex (?i)folder deleted +#$ wait diff --git a/tests/command_line/scripts/folder/rename.sh b/tests/command_line/scripts/folder/rename.sh new file mode 100644 index 0000000000..20a223dd9a --- /dev/null +++ b/tests/command_line/scripts/folder/rename.sh @@ -0,0 +1,7 @@ +sos folder rename -f $FOLDER_NAME $NEW_FOLDER_NAME +#$ include ../includes/signin.sh +#$ wait + +sos folder rename -f $NEW_FOLDER_NAME $FOLDER_NAME +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/setup/account.sh b/tests/command_line/scripts/setup/account.sh index b49dff185d..19f8c15713 100644 --- a/tests/command_line/scripts/setup/account.sh +++ b/tests/command_line/scripts/setup/account.sh @@ -1,4 +1,4 @@ -sos account new Demo +sos account new $ACCOUNT_NAME #$ expect Choose a password 2 #$ regex (?i)password diff --git a/tests/command_line/scripts/specs/account-contacts.sh b/tests/command_line/scripts/specs/account-contacts.sh new file mode 100644 index 0000000000..082f25d080 --- /dev/null +++ b/tests/command_line/scripts/specs/account-contacts.sh @@ -0,0 +1,4 @@ +sos account contacts import $ACCOUNT_CONTACTS +#$ include ../includes/signin.sh +#$ regex (?i)contacts imported +#$ wait diff --git a/tests/command_line/scripts/specs/account-migrate.sh b/tests/command_line/scripts/specs/account-migrate.sh new file mode 100644 index 0000000000..d62cb843d6 --- /dev/null +++ b/tests/command_line/scripts/specs/account-migrate.sh @@ -0,0 +1,36 @@ +sos account migrate export target/demo-export.zip +#$ include ../includes/signin.sh +#$ regex (?i)export unencrypted +y +#$ wait + +sos account migrate export --force target/demo-export.zip +#$ include ../includes/signin.sh +#$ regex (?i)export unencrypted +y +#$ wait + +sos account migrate import --format onepassword.csv $MIGRATE_1PASSWORD +#$ include ../includes/signin.sh +#$ regex (?i)imported +#$ wait + +sos account migrate import --format dashlane.zip $MIGRATE_DASHLANE +#$ include ../includes/signin.sh +#$ regex (?i)imported +#$ wait + +sos account migrate import --format bitwarden.csv $MIGRATE_BITWARDEN +#$ include ../includes/signin.sh +#$ regex (?i)imported +#$ wait + +sos account migrate import --format firefox.csv $MIGRATE_FIREFOX +#$ include ../includes/signin.sh +#$ regex (?i)imported +#$ wait + +sos account migrate import --format macos.csv $MIGRATE_MACOS +#$ include ../includes/signin.sh +#$ regex (?i)imported +#$ wait diff --git a/tests/command_line/scripts/specs/account-rename.sh b/tests/command_line/scripts/specs/account-rename.sh new file mode 100644 index 0000000000..7dc03c9ffd --- /dev/null +++ b/tests/command_line/scripts/specs/account-rename.sh @@ -0,0 +1,7 @@ +sos account rename -a $ACCOUNT_NAME NewDemo +#$ include ../includes/signin.sh +#$ wait + +sos account rename -a NewDemo $ACCOUNT_NAME +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/specs/account-stats.sh b/tests/command_line/scripts/specs/account-stats.sh index e69de29bb2..f0632818ea 100644 --- a/tests/command_line/scripts/specs/account-stats.sh +++ b/tests/command_line/scripts/specs/account-stats.sh @@ -0,0 +1,3 @@ +sos account stats -a Demo --json +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/specs/folder.sh b/tests/command_line/scripts/specs/folder.sh new file mode 100644 index 0000000000..311e0f4ac0 --- /dev/null +++ b/tests/command_line/scripts/specs/folder.sh @@ -0,0 +1,12 @@ +#$ include ../folder/new.sh +#$ include ../folder/list.sh +#$ include ../folder/info.sh +#$ include ../folder/keys.sh +#$ include ../folder/commits.sh +#$ include ../folder/rename.sh + +#$ include ../folder/history/compact.sh +#$ include ../folder/history/check.sh +#$ include ../folder/history/list.sh + +#$ include ../folder/remove.sh diff --git a/tests/command_line/scripts/specs/secrets-basic.sh b/tests/command_line/scripts/specs/secrets.sh similarity index 100% rename from tests/command_line/scripts/specs/secrets-basic.sh rename to tests/command_line/scripts/specs/secrets.sh From 151be11a407260b0fee640c823c215c3e6ca3bec Mon Sep 17 00:00:00 2001 From: muji Date: Tue, 20 Feb 2024 14:55:23 +0800 Subject: [PATCH 05/17] Improve account cli test specs. --- scripts/cli/env.sh | 1 + scripts/cli/specs.sh | 5 +++-- .../scripts/account/contacts/export.sh | 4 ++++ .../contacts/import.sh} | 2 +- tests/command_line/scripts/account/delete.sh | 6 +++++ .../account-stats.sh => account/info-json.sh} | 2 +- tests/command_line/scripts/account/info.sh | 2 +- .../scripts/account/migrate/export.sh | 12 ++++++++++ .../migrate/import.sh} | 22 +++++-------------- .../{setup/account.sh => account/new.sh} | 0 .../account-rename.sh => account/rename.sh} | 0 .../scripts/account/stats-json.sh | 3 +++ tests/command_line/scripts/account/stats.sh | 2 +- tests/command_line/scripts/setup.sh | 1 + .../scripts/specs/account-info.sh | 6 ----- .../scripts/specs/account-list.sh | 4 ---- tests/command_line/scripts/specs/account.sh | 16 ++++++++++++++ .../scripts/specs/backup-restore.sh | 2 -- .../scripts/specs/{secrets.sh => secret.sh} | 0 tests/command_line/scripts/teardown.sh | 1 + 20 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 tests/command_line/scripts/account/contacts/export.sh rename tests/command_line/scripts/{specs/account-contacts.sh => account/contacts/import.sh} (70%) create mode 100644 tests/command_line/scripts/account/delete.sh rename tests/command_line/scripts/{specs/account-stats.sh => account/info-json.sh} (55%) create mode 100644 tests/command_line/scripts/account/migrate/export.sh rename tests/command_line/scripts/{specs/account-migrate.sh => account/migrate/import.sh} (53%) rename tests/command_line/scripts/{setup/account.sh => account/new.sh} (100%) rename tests/command_line/scripts/{specs/account-rename.sh => account/rename.sh} (100%) create mode 100644 tests/command_line/scripts/account/stats-json.sh create mode 100644 tests/command_line/scripts/setup.sh delete mode 100644 tests/command_line/scripts/specs/account-info.sh delete mode 100644 tests/command_line/scripts/specs/account-list.sh create mode 100644 tests/command_line/scripts/specs/account.sh delete mode 100644 tests/command_line/scripts/specs/backup-restore.sh rename tests/command_line/scripts/specs/{secrets.sh => secret.sh} (100%) create mode 100644 tests/command_line/scripts/teardown.sh diff --git a/scripts/cli/env.sh b/scripts/cli/env.sh index f28c229774..1322278a82 100644 --- a/scripts/cli/env.sh +++ b/scripts/cli/env.sh @@ -7,6 +7,7 @@ export ACCOUNT_NAME="Demo" export ACCOUNT_PASSWORD="demo-test-password-case" export ACCOUNT_BACKUP="target/demo-backup.zip" export ACCOUNT_CONTACTS="tests/fixtures/contacts.vcf" +export CONTACTS_EXPORT="target/demo-contacts.vcf" export FOLDER_NAME="mock-folder" export NEW_FOLDER_NAME="mock-folder-renamed" diff --git a/scripts/cli/specs.sh b/scripts/cli/specs.sh index 54eafd83cb..116fee3774 100755 --- a/scripts/cli/specs.sh +++ b/scripts/cli/specs.sh @@ -5,7 +5,7 @@ set -e source scripts/cli/env.sh export NO_COLOR=1 -rm target/*.zip +rm target/*.{zip,vcf} if [ -n "$DEBUG" ]; then export PATH="target/debug:$PATH" @@ -15,5 +15,6 @@ command -v sos anticipate \ run \ - --setup tests/command_line/scripts/setup/account.sh \ + --setup tests/command_line/scripts/setup.sh \ + --teardown tests/command_line/scripts/teardown.sh \ tests/command_line/scripts/specs/*.sh diff --git a/tests/command_line/scripts/account/contacts/export.sh b/tests/command_line/scripts/account/contacts/export.sh new file mode 100644 index 0000000000..a4e94920f8 --- /dev/null +++ b/tests/command_line/scripts/account/contacts/export.sh @@ -0,0 +1,4 @@ +sos account contacts export $CONTACTS_EXPORT +#$ include ../../includes/signin.sh +#$ regex (?i)contacts exported +#$ wait diff --git a/tests/command_line/scripts/specs/account-contacts.sh b/tests/command_line/scripts/account/contacts/import.sh similarity index 70% rename from tests/command_line/scripts/specs/account-contacts.sh rename to tests/command_line/scripts/account/contacts/import.sh index 082f25d080..e777c47e61 100644 --- a/tests/command_line/scripts/specs/account-contacts.sh +++ b/tests/command_line/scripts/account/contacts/import.sh @@ -1,4 +1,4 @@ sos account contacts import $ACCOUNT_CONTACTS -#$ include ../includes/signin.sh +#$ include ../../includes/signin.sh #$ regex (?i)contacts imported #$ wait diff --git a/tests/command_line/scripts/account/delete.sh b/tests/command_line/scripts/account/delete.sh new file mode 100644 index 0000000000..555935c6eb --- /dev/null +++ b/tests/command_line/scripts/account/delete.sh @@ -0,0 +1,6 @@ +sos account delete -a $ACCOUNT_NAME +#$ include ../includes/signin.sh +#$ regex (?i)delete account +y +#$ regex (?i)account deleted +#$ wait diff --git a/tests/command_line/scripts/specs/account-stats.sh b/tests/command_line/scripts/account/info-json.sh similarity index 55% rename from tests/command_line/scripts/specs/account-stats.sh rename to tests/command_line/scripts/account/info-json.sh index f0632818ea..dfcbb5fdd2 100644 --- a/tests/command_line/scripts/specs/account-stats.sh +++ b/tests/command_line/scripts/account/info-json.sh @@ -1,3 +1,3 @@ -sos account stats -a Demo --json +sos account info --json #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/account/info.sh b/tests/command_line/scripts/account/info.sh index 81a54a2d72..bd2f40e39b 100644 --- a/tests/command_line/scripts/account/info.sh +++ b/tests/command_line/scripts/account/info.sh @@ -1,3 +1,3 @@ -sos account info -a Demo +sos account info -v #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/account/migrate/export.sh b/tests/command_line/scripts/account/migrate/export.sh new file mode 100644 index 0000000000..45465342fa --- /dev/null +++ b/tests/command_line/scripts/account/migrate/export.sh @@ -0,0 +1,12 @@ +sos account migrate export target/demo-export.zip +#$ include ../../includes/signin.sh +#$ regex (?i)export unencrypted +y +#$ wait + +sos account migrate export --force target/demo-export.zip +#$ include ../../includes/signin.sh +#$ regex (?i)export unencrypted +y +#$ wait + diff --git a/tests/command_line/scripts/specs/account-migrate.sh b/tests/command_line/scripts/account/migrate/import.sh similarity index 53% rename from tests/command_line/scripts/specs/account-migrate.sh rename to tests/command_line/scripts/account/migrate/import.sh index d62cb843d6..118c60ee13 100644 --- a/tests/command_line/scripts/specs/account-migrate.sh +++ b/tests/command_line/scripts/account/migrate/import.sh @@ -1,36 +1,24 @@ -sos account migrate export target/demo-export.zip -#$ include ../includes/signin.sh -#$ regex (?i)export unencrypted -y -#$ wait - -sos account migrate export --force target/demo-export.zip -#$ include ../includes/signin.sh -#$ regex (?i)export unencrypted -y -#$ wait - sos account migrate import --format onepassword.csv $MIGRATE_1PASSWORD -#$ include ../includes/signin.sh +#$ include ../../includes/signin.sh #$ regex (?i)imported #$ wait sos account migrate import --format dashlane.zip $MIGRATE_DASHLANE -#$ include ../includes/signin.sh +#$ include ../../includes/signin.sh #$ regex (?i)imported #$ wait sos account migrate import --format bitwarden.csv $MIGRATE_BITWARDEN -#$ include ../includes/signin.sh +#$ include ../../includes/signin.sh #$ regex (?i)imported #$ wait sos account migrate import --format firefox.csv $MIGRATE_FIREFOX -#$ include ../includes/signin.sh +#$ include ../../includes/signin.sh #$ regex (?i)imported #$ wait sos account migrate import --format macos.csv $MIGRATE_MACOS -#$ include ../includes/signin.sh +#$ include ../../includes/signin.sh #$ regex (?i)imported #$ wait diff --git a/tests/command_line/scripts/setup/account.sh b/tests/command_line/scripts/account/new.sh similarity index 100% rename from tests/command_line/scripts/setup/account.sh rename to tests/command_line/scripts/account/new.sh diff --git a/tests/command_line/scripts/specs/account-rename.sh b/tests/command_line/scripts/account/rename.sh similarity index 100% rename from tests/command_line/scripts/specs/account-rename.sh rename to tests/command_line/scripts/account/rename.sh diff --git a/tests/command_line/scripts/account/stats-json.sh b/tests/command_line/scripts/account/stats-json.sh new file mode 100644 index 0000000000..fb109de80c --- /dev/null +++ b/tests/command_line/scripts/account/stats-json.sh @@ -0,0 +1,3 @@ +sos account stats --json +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/account/stats.sh b/tests/command_line/scripts/account/stats.sh index f0632818ea..426b495d0b 100644 --- a/tests/command_line/scripts/account/stats.sh +++ b/tests/command_line/scripts/account/stats.sh @@ -1,3 +1,3 @@ -sos account stats -a Demo --json +sos account stats #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/setup.sh b/tests/command_line/scripts/setup.sh new file mode 100644 index 0000000000..af1ba57be3 --- /dev/null +++ b/tests/command_line/scripts/setup.sh @@ -0,0 +1 @@ +#$ include account/new.sh diff --git a/tests/command_line/scripts/specs/account-info.sh b/tests/command_line/scripts/specs/account-info.sh deleted file mode 100644 index 427689d311..0000000000 --- a/tests/command_line/scripts/specs/account-info.sh +++ /dev/null @@ -1,6 +0,0 @@ -sos account info -#$ include ../includes/signin.sh -#$ wait -sos account info -v -#$ include ../includes/signin.sh -#$ wait diff --git a/tests/command_line/scripts/specs/account-list.sh b/tests/command_line/scripts/specs/account-list.sh deleted file mode 100644 index b60a095b48..0000000000 --- a/tests/command_line/scripts/specs/account-list.sh +++ /dev/null @@ -1,4 +0,0 @@ -sos account ls -#$ wait -sos account ls -v -#$ wait diff --git a/tests/command_line/scripts/specs/account.sh b/tests/command_line/scripts/specs/account.sh new file mode 100644 index 0000000000..94b4d22e1f --- /dev/null +++ b/tests/command_line/scripts/specs/account.sh @@ -0,0 +1,16 @@ +#$ include ../account/list.sh +#$ include ../account/info.sh +#$ include ../account/info-json.sh +#$ include ../account/stats.sh +#$ include ../account/stats-json.sh + +#$ include ../account/backup.sh +#$ include ../account/restore.sh + +#$ include ../account/contacts/import.sh +#$ include ../account/contacts/export.sh + +#$ include ../account/migrate/export.sh +#$ include ../account/migrate/import.sh + +#$ include ../account/rename.sh diff --git a/tests/command_line/scripts/specs/backup-restore.sh b/tests/command_line/scripts/specs/backup-restore.sh deleted file mode 100644 index a7a118060b..0000000000 --- a/tests/command_line/scripts/specs/backup-restore.sh +++ /dev/null @@ -1,2 +0,0 @@ -#$ include ../account/backup.sh -#$ include ../account/restore.sh diff --git a/tests/command_line/scripts/specs/secrets.sh b/tests/command_line/scripts/specs/secret.sh similarity index 100% rename from tests/command_line/scripts/specs/secrets.sh rename to tests/command_line/scripts/specs/secret.sh diff --git a/tests/command_line/scripts/teardown.sh b/tests/command_line/scripts/teardown.sh new file mode 100644 index 0000000000..ba640dfdef --- /dev/null +++ b/tests/command_line/scripts/teardown.sh @@ -0,0 +1 @@ +#$ include account/delete.sh From 0eb31f329bd8d0396154fa7c02cad4d952a9d662 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 08:48:38 +0800 Subject: [PATCH 06/17] Add note to cli option. --- src/cli/sos.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cli/sos.rs b/src/cli/sos.rs index 132ef9cb41..19329d7fb3 100644 --- a/src/cli/sos.rs +++ b/src/cli/sos.rs @@ -39,7 +39,9 @@ pub struct Sos { /// Local storage directory. #[clap(long, env = "SOS_DATA_DIR", hide_env_values = true)] storage: Option, - + + // FIXME: remove this once we finish migrating the + // FIXME: CLI test specs to scripts /// Affirmative for all confirmation prompts. #[cfg(any(test, debug_assertions))] #[clap(long, env = "SOS_YES", hide_env_values = true)] From 09f4f7015fdee20ed62c8a061d8e0759d45af7ce Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 10:14:52 +0800 Subject: [PATCH 07/17] Migrate more secret test specs. --- Makefile.toml | 1 + scripts/cli/demos.sh | 2 ++ scripts/cli/env.sh | 7 +++++ scripts/cli/specs.sh | 2 -- tests/command_line/scripts/secret/add-file.sh | 4 +++ tests/command_line/scripts/secret/add-note.sh | 2 +- tests/command_line/scripts/secret/archive.sh | 4 +++ tests/command_line/scripts/secret/comment.sh | 7 +++++ tests/command_line/scripts/secret/copy.sh | 2 +- tests/command_line/scripts/secret/download.sh | 4 +++ tests/command_line/scripts/secret/favorite.sh | 3 ++ tests/command_line/scripts/secret/get-note.sh | 2 +- .../command_line/scripts/secret/info-json.sh | 3 ++ tests/command_line/scripts/secret/info.sh | 3 ++ tests/command_line/scripts/secret/move.sh | 9 ++++++ tests/command_line/scripts/secret/remove.sh | 6 ++++ tests/command_line/scripts/secret/rename.sh | 6 +++- tests/command_line/scripts/secret/tags/add.sh | 3 ++ .../command_line/scripts/secret/tags/clear.sh | 3 ++ .../command_line/scripts/secret/tags/list.sh | 3 ++ .../scripts/secret/tags/remove.sh | 3 ++ .../command_line/scripts/secret/unarchive.sh | 4 +++ tests/command_line/scripts/specs/secret.sh | 29 +++++++++++++++++++ 23 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 tests/command_line/scripts/secret/add-file.sh create mode 100644 tests/command_line/scripts/secret/archive.sh create mode 100644 tests/command_line/scripts/secret/comment.sh create mode 100644 tests/command_line/scripts/secret/download.sh create mode 100644 tests/command_line/scripts/secret/favorite.sh create mode 100644 tests/command_line/scripts/secret/info-json.sh create mode 100644 tests/command_line/scripts/secret/info.sh create mode 100644 tests/command_line/scripts/secret/move.sh create mode 100644 tests/command_line/scripts/secret/remove.sh create mode 100644 tests/command_line/scripts/secret/tags/add.sh create mode 100644 tests/command_line/scripts/secret/tags/clear.sh create mode 100644 tests/command_line/scripts/secret/tags/list.sh create mode 100644 tests/command_line/scripts/secret/tags/remove.sh create mode 100644 tests/command_line/scripts/secret/unarchive.sh diff --git a/Makefile.toml b/Makefile.toml index 52e70283a3..97ac754eef 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -125,6 +125,7 @@ args = ["install", "--path", "."] [tasks.clean-cli] script = ''' rm -rf target/accounts +rm -f target/*.{zip,vcf,heic} ''' [tasks.test-cli] diff --git a/scripts/cli/demos.sh b/scripts/cli/demos.sh index f9829a714e..5b6792c023 100755 --- a/scripts/cli/demos.sh +++ b/scripts/cli/demos.sh @@ -4,6 +4,8 @@ set -e source scripts/cli/env.sh +rm target/*.{zip,vcf,heic} + scripts=tests/command_line/scripts/demos anticipate \ record \ diff --git a/scripts/cli/env.sh b/scripts/cli/env.sh index 1322278a82..1fa6170e0c 100644 --- a/scripts/cli/env.sh +++ b/scripts/cli/env.sh @@ -9,9 +9,16 @@ export ACCOUNT_BACKUP="target/demo-backup.zip" export ACCOUNT_CONTACTS="tests/fixtures/contacts.vcf" export CONTACTS_EXPORT="target/demo-contacts.vcf" +export DEFAULT_FOLDER_NAME="Documents" export FOLDER_NAME="mock-folder" export NEW_FOLDER_NAME="mock-folder-renamed" +export FILE_INPUT="tests/fixtures/sample.heic" +export FILE_OUTPUT="target/sample-download.heic" + +export NOTE_NAME="mock note" +export FILE_NAME="mock file"; + export MIGRATE_1PASSWORD="tests/fixtures/migrate/1password-export.csv" export MIGRATE_DASHLANE="tests/fixtures/migrate/dashlane-export.zip" export MIGRATE_BITWARDEN="tests/fixtures/migrate/bitwarden-export.csv" diff --git a/scripts/cli/specs.sh b/scripts/cli/specs.sh index 116fee3774..edc317da9e 100755 --- a/scripts/cli/specs.sh +++ b/scripts/cli/specs.sh @@ -5,8 +5,6 @@ set -e source scripts/cli/env.sh export NO_COLOR=1 -rm target/*.{zip,vcf} - if [ -n "$DEBUG" ]; then export PATH="target/debug:$PATH" fi diff --git a/tests/command_line/scripts/secret/add-file.sh b/tests/command_line/scripts/secret/add-file.sh new file mode 100644 index 0000000000..ad753497ec --- /dev/null +++ b/tests/command_line/scripts/secret/add-file.sh @@ -0,0 +1,4 @@ +sos secret add file -n "$FILE_NAME" "$FILE_INPUT" +#$ include ../includes/signin.sh +#$ regex (?i)created +#$ wait diff --git a/tests/command_line/scripts/secret/add-note.sh b/tests/command_line/scripts/secret/add-note.sh index a5470949d8..fec3476b09 100644 --- a/tests/command_line/scripts/secret/add-note.sh +++ b/tests/command_line/scripts/secret/add-note.sh @@ -1,7 +1,7 @@ sos secret add note #$ include ../includes/signin.sh #$ expect Name: -Example Note +$NOTE_NAME #$ expect >> This is the text for the secret note. #$ sendcontrol ^D diff --git a/tests/command_line/scripts/secret/archive.sh b/tests/command_line/scripts/secret/archive.sh new file mode 100644 index 0000000000..205fbd7612 --- /dev/null +++ b/tests/command_line/scripts/secret/archive.sh @@ -0,0 +1,4 @@ +sos secret archive "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ regex (?i)moved to archive +#$ wait diff --git a/tests/command_line/scripts/secret/comment.sh b/tests/command_line/scripts/secret/comment.sh new file mode 100644 index 0000000000..673aecad78 --- /dev/null +++ b/tests/command_line/scripts/secret/comment.sh @@ -0,0 +1,7 @@ +sos secret comment --text 'Mock comment' "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ wait + +sos secret comment --text '' "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/copy.sh b/tests/command_line/scripts/secret/copy.sh index 94396f1ea0..2277d60b98 100644 --- a/tests/command_line/scripts/secret/copy.sh +++ b/tests/command_line/scripts/secret/copy.sh @@ -1,3 +1,3 @@ -sos secret copy "Example Note" +sos secret copy "$NOTE_NAME" #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/secret/download.sh b/tests/command_line/scripts/secret/download.sh new file mode 100644 index 0000000000..684ab5f173 --- /dev/null +++ b/tests/command_line/scripts/secret/download.sh @@ -0,0 +1,4 @@ +sos secret download "$FILE_NAME" "$FILE_OUTPUT" +#$ include ../includes/signin.sh +#$ regex (?i)download complete +#$ wait diff --git a/tests/command_line/scripts/secret/favorite.sh b/tests/command_line/scripts/secret/favorite.sh new file mode 100644 index 0000000000..638afbf15d --- /dev/null +++ b/tests/command_line/scripts/secret/favorite.sh @@ -0,0 +1,3 @@ +sos secret favorite "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/get-note.sh b/tests/command_line/scripts/secret/get-note.sh index 79d91fe274..2ac8d0a057 100644 --- a/tests/command_line/scripts/secret/get-note.sh +++ b/tests/command_line/scripts/secret/get-note.sh @@ -1,3 +1,3 @@ -sos secret get "Example Note" +sos secret get "$NOTE_NAME" #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/secret/info-json.sh b/tests/command_line/scripts/secret/info-json.sh new file mode 100644 index 0000000000..914c6d9e73 --- /dev/null +++ b/tests/command_line/scripts/secret/info-json.sh @@ -0,0 +1,3 @@ +sos secret info --json "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/info.sh b/tests/command_line/scripts/secret/info.sh new file mode 100644 index 0000000000..676a242b28 --- /dev/null +++ b/tests/command_line/scripts/secret/info.sh @@ -0,0 +1,3 @@ +sos secret info "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/move.sh b/tests/command_line/scripts/secret/move.sh new file mode 100644 index 0000000000..6aaeae170f --- /dev/null +++ b/tests/command_line/scripts/secret/move.sh @@ -0,0 +1,9 @@ +sos secret move --target "$FOLDER_NAME" "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ regex (?i)moved +#$ wait + +sos secret move --target "$DEFAULT_FOLDER_NAME" -f "$FOLDER_NAME" "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ regex (?i)moved +#$ wait diff --git a/tests/command_line/scripts/secret/remove.sh b/tests/command_line/scripts/secret/remove.sh new file mode 100644 index 0000000000..f172201ddb --- /dev/null +++ b/tests/command_line/scripts/secret/remove.sh @@ -0,0 +1,6 @@ +sos secret remove "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ regex (?i)delete secret +y +#$ regex (?i)secret deleted +#$ wait diff --git a/tests/command_line/scripts/secret/rename.sh b/tests/command_line/scripts/secret/rename.sh index 7ead59ccba..0b429903f4 100644 --- a/tests/command_line/scripts/secret/rename.sh +++ b/tests/command_line/scripts/secret/rename.sh @@ -1,4 +1,8 @@ # rename a secret -sos secret rename --name "Demo Note" "Example Note" +sos secret rename --name "Demo Note" "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ wait + +sos secret rename --name "$NOTE_NAME" "Demo Note" #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/secret/tags/add.sh b/tests/command_line/scripts/secret/tags/add.sh new file mode 100644 index 0000000000..2b62b96542 --- /dev/null +++ b/tests/command_line/scripts/secret/tags/add.sh @@ -0,0 +1,3 @@ +sos secret tags add --tags foo,bar,qux "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/tags/clear.sh b/tests/command_line/scripts/secret/tags/clear.sh new file mode 100644 index 0000000000..1f34234af1 --- /dev/null +++ b/tests/command_line/scripts/secret/tags/clear.sh @@ -0,0 +1,3 @@ +sos secret tags clear "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/tags/list.sh b/tests/command_line/scripts/secret/tags/list.sh new file mode 100644 index 0000000000..1309920cae --- /dev/null +++ b/tests/command_line/scripts/secret/tags/list.sh @@ -0,0 +1,3 @@ +sos secret tags list "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/tags/remove.sh b/tests/command_line/scripts/secret/tags/remove.sh new file mode 100644 index 0000000000..331cd66bc0 --- /dev/null +++ b/tests/command_line/scripts/secret/tags/remove.sh @@ -0,0 +1,3 @@ +sos secret tags rm --tags foo,bar "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/unarchive.sh b/tests/command_line/scripts/secret/unarchive.sh new file mode 100644 index 0000000000..028aaa4e12 --- /dev/null +++ b/tests/command_line/scripts/secret/unarchive.sh @@ -0,0 +1,4 @@ +sos secret unarchive "$NOTE_NAME" +#$ include ../includes/signin.sh +#$ regex (?i)restored from archive +#$ wait diff --git a/tests/command_line/scripts/specs/secret.sh b/tests/command_line/scripts/specs/secret.sh index 166ce1c228..731eeda841 100644 --- a/tests/command_line/scripts/specs/secret.sh +++ b/tests/command_line/scripts/specs/secret.sh @@ -1,5 +1,34 @@ + # secret::attach(&exe, &address, &password, ACCOUNT_NAME, None).await?; + #$ include ../secret/add-note.sh +#$ include ../secret/add-file.sh #$ include ../secret/list.sh #$ include ../secret/get-note.sh #$ include ../secret/copy.sh +#$ include ../secret/info.sh +#$ include ../secret/info-json.sh + +#$ include ../secret/download.sh + +# TODO: update secret + +#$ include ../folder/new.sh +#$ include ../secret/move.sh +#$ include ../folder/remove.sh + +#$ include ../secret/tags/add.sh +#$ include ../secret/tags/list.sh +#$ include ../secret/tags/remove.sh +#$ include ../secret/tags/clear.sh + +# Toggle favorite on then off again +#$ include ../secret/favorite.sh +#$ include ../secret/favorite.sh + +#$ include ../secret/archive.sh +#$ include ../secret/unarchive.sh + +#$ include ../secret/comment.sh #$ include ../secret/rename.sh + +#$ include ../secret/remove.sh From 31a60b7f5fbabc7f9bdba8a12b303d83c01945ab Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 12:28:08 +0800 Subject: [PATCH 08/17] Migrate secret attach test specs. --- Makefile.toml | 2 +- scripts/cli/env.sh | 11 ++++++++++- tests/command_line/scripts/secret/add-note.sh | 3 ++- tests/command_line/scripts/secret/attach/add-file.sh | 6 ++++++ tests/command_line/scripts/secret/attach/add-link.sh | 6 ++++++ tests/command_line/scripts/secret/attach/add-note.sh | 8 ++++++++ .../scripts/secret/attach/add-password.sh | 6 ++++++ tests/command_line/scripts/secret/attach/download.sh | 4 ++++ tests/command_line/scripts/secret/attach/get.sh | 3 +++ tests/command_line/scripts/secret/attach/list.sh | 3 +++ tests/command_line/scripts/secret/attach/remove.sh | 3 +++ tests/command_line/scripts/specs/secret.sh | 12 ++++++++++-- 12 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 tests/command_line/scripts/secret/attach/add-file.sh create mode 100644 tests/command_line/scripts/secret/attach/add-link.sh create mode 100644 tests/command_line/scripts/secret/attach/add-note.sh create mode 100644 tests/command_line/scripts/secret/attach/add-password.sh create mode 100644 tests/command_line/scripts/secret/attach/download.sh create mode 100644 tests/command_line/scripts/secret/attach/get.sh create mode 100644 tests/command_line/scripts/secret/attach/list.sh create mode 100644 tests/command_line/scripts/secret/attach/remove.sh diff --git a/Makefile.toml b/Makefile.toml index 97ac754eef..8eeaeb58e9 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -125,7 +125,7 @@ args = ["install", "--path", "."] [tasks.clean-cli] script = ''' rm -rf target/accounts -rm -f target/*.{zip,vcf,heic} +rm -f target/*.{zip,vcf,heic,txt} ''' [tasks.test-cli] diff --git a/scripts/cli/env.sh b/scripts/cli/env.sh index 1fa6170e0c..902636d659 100644 --- a/scripts/cli/env.sh +++ b/scripts/cli/env.sh @@ -14,11 +14,20 @@ export FOLDER_NAME="mock-folder" export NEW_FOLDER_NAME="mock-folder-renamed" export FILE_INPUT="tests/fixtures/sample.heic" -export FILE_OUTPUT="target/sample-download.heic" +export FILE_OUTPUT="target/file-download.heic" + +export ATTACH_INPUT="tests/fixtures/test-file.txt" +export ATTACH_OUTPUT="target/attachment-download.txt" export NOTE_NAME="mock note" export FILE_NAME="mock file"; +export FILE_ATTACHMENT="file-attachment"; +export NOTE_ATTACHMENT="note-attachment"; +export LINK_ATTACHMENT="link-attachment"; +export PASSWORD_ATTACHMENT="password-attachment"; +export LINK_VALUE="https://example.com"; + export MIGRATE_1PASSWORD="tests/fixtures/migrate/1password-export.csv" export MIGRATE_DASHLANE="tests/fixtures/migrate/dashlane-export.zip" export MIGRATE_BITWARDEN="tests/fixtures/migrate/bitwarden-export.csv" diff --git a/tests/command_line/scripts/secret/add-note.sh b/tests/command_line/scripts/secret/add-note.sh index fec3476b09..ae52f8c911 100644 --- a/tests/command_line/scripts/secret/add-note.sh +++ b/tests/command_line/scripts/secret/add-note.sh @@ -3,6 +3,7 @@ sos secret add note #$ expect Name: $NOTE_NAME #$ expect >> -This is the text for the secret note. +Text for the secret note. +#$ expect >> #$ sendcontrol ^D #$ wait diff --git a/tests/command_line/scripts/secret/attach/add-file.sh b/tests/command_line/scripts/secret/attach/add-file.sh new file mode 100644 index 0000000000..46fbf95a8b --- /dev/null +++ b/tests/command_line/scripts/secret/attach/add-file.sh @@ -0,0 +1,6 @@ +sos secret attach add file \ + --name "$FILE_ATTACHMENT" \ + --path "$ATTACH_INPUT" "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ regex (?i)updated +#$ wait diff --git a/tests/command_line/scripts/secret/attach/add-link.sh b/tests/command_line/scripts/secret/attach/add-link.sh new file mode 100644 index 0000000000..63f102b7dc --- /dev/null +++ b/tests/command_line/scripts/secret/attach/add-link.sh @@ -0,0 +1,6 @@ +sos secret attach add link --name "$LINK_ATTACHMENT" "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ expect URL: +$LINK_VALUE +#$ regex (?i)updated +#$ wait diff --git a/tests/command_line/scripts/secret/attach/add-note.sh b/tests/command_line/scripts/secret/attach/add-note.sh new file mode 100644 index 0000000000..031f632ce7 --- /dev/null +++ b/tests/command_line/scripts/secret/attach/add-note.sh @@ -0,0 +1,8 @@ +sos secret attach add note --name "$NOTE_ATTACHMENT" "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ expect >> +Text for the note attachment. +#$ expect >> +#$ sendcontrol ^D +#$ regex (?i)updated +#$ wait diff --git a/tests/command_line/scripts/secret/attach/add-password.sh b/tests/command_line/scripts/secret/attach/add-password.sh new file mode 100644 index 0000000000..c64905ab37 --- /dev/null +++ b/tests/command_line/scripts/secret/attach/add-password.sh @@ -0,0 +1,6 @@ +sos secret attach add password --name "$PASSWORD_ATTACHMENT" "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ expect Password: +$PASSWORD_ATTACHMENT +#$ regex (?i)updated +#$ wait diff --git a/tests/command_line/scripts/secret/attach/download.sh b/tests/command_line/scripts/secret/attach/download.sh new file mode 100644 index 0000000000..12975cd2c6 --- /dev/null +++ b/tests/command_line/scripts/secret/attach/download.sh @@ -0,0 +1,4 @@ +sos secret attach download "$NOTE_NAME" "$FILE_ATTACHMENT" "$ATTACH_OUTPUT" +#$ include ../../includes/signin.sh +#$ regex (?i)download complete +#$ wait diff --git a/tests/command_line/scripts/secret/attach/get.sh b/tests/command_line/scripts/secret/attach/get.sh new file mode 100644 index 0000000000..b94bf6a8c1 --- /dev/null +++ b/tests/command_line/scripts/secret/attach/get.sh @@ -0,0 +1,3 @@ +sos secret attach get "$NOTE_NAME" "$NOTE_ATTACHMENT" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/attach/list.sh b/tests/command_line/scripts/secret/attach/list.sh new file mode 100644 index 0000000000..f874d21890 --- /dev/null +++ b/tests/command_line/scripts/secret/attach/list.sh @@ -0,0 +1,3 @@ +sos secret attach ls -v "$NOTE_NAME" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/attach/remove.sh b/tests/command_line/scripts/secret/attach/remove.sh new file mode 100644 index 0000000000..0d62199659 --- /dev/null +++ b/tests/command_line/scripts/secret/attach/remove.sh @@ -0,0 +1,3 @@ +sos secret attach rm "$NOTE_NAME" "$NOTE_ATTACHMENT" +#$ include ../../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/specs/secret.sh b/tests/command_line/scripts/specs/secret.sh index 731eeda841..db7a0f1ce7 100644 --- a/tests/command_line/scripts/specs/secret.sh +++ b/tests/command_line/scripts/specs/secret.sh @@ -1,5 +1,3 @@ - # secret::attach(&exe, &address, &password, ACCOUNT_NAME, None).await?; - #$ include ../secret/add-note.sh #$ include ../secret/add-file.sh #$ include ../secret/list.sh @@ -10,6 +8,16 @@ #$ include ../secret/download.sh +#$ include ../secret/attach/add-file.sh +#$ include ../secret/attach/add-note.sh +#$ include ../secret/attach/add-link.sh +#$ include ../secret/attach/add-password.sh + +#$ include ../secret/attach/get.sh +#$ include ../secret/attach/list.sh +#$ include ../secret/attach/download.sh +#$ include ../secret/attach/remove.sh + # TODO: update secret #$ include ../folder/new.sh From 5d82285f0275e4145c1b81a5102e4cd7ad648287 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 13:49:50 +0800 Subject: [PATCH 09/17] Initial work migrating the interactive shell tests. --- Makefile.toml | 4 ++ scripts/cli/env.sh | 1 + scripts/cli/shell.sh | 19 ++++++ scripts/cli/specs.sh | 1 + src/commands/check.rs | 14 ++--- src/commands/shell/cli.rs | 18 +++--- tests/command_line/scripts/check/events.sh | 2 + tests/command_line/scripts/check/header.sh | 2 + tests/command_line/scripts/check/keys.sh | 2 + tests/command_line/scripts/check/vault.sh | 2 + tests/command_line/scripts/specs/check.sh | 4 ++ tests/command_line/scripts/specs/shell.sh | 70 ++++++++++++++++++++++ 12 files changed, 125 insertions(+), 14 deletions(-) create mode 100755 scripts/cli/shell.sh create mode 100644 tests/command_line/scripts/check/events.sh create mode 100644 tests/command_line/scripts/check/header.sh create mode 100644 tests/command_line/scripts/check/keys.sh create mode 100644 tests/command_line/scripts/check/vault.sh create mode 100644 tests/command_line/scripts/specs/check.sh create mode 100644 tests/command_line/scripts/specs/shell.sh diff --git a/Makefile.toml b/Makefile.toml index 8eeaeb58e9..7456aef366 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -132,6 +132,10 @@ rm -f target/*.{zip,vcf,heic,txt} script = { file = "./scripts/cli/specs.sh" } dependencies = ["clean-cli"] +[tasks.test-shell] +script = { file = "./scripts/cli/shell.sh" } +dependencies = ["clean-cli"] + [tasks.demos] script = { file = "./scripts/cli/demos.sh" } dependencies = ["clean-cli"] diff --git a/scripts/cli/env.sh b/scripts/cli/env.sh index 902636d659..540263953a 100644 --- a/scripts/cli/env.sh +++ b/scripts/cli/env.sh @@ -4,6 +4,7 @@ set -e export SOS_DATA_DIR="target/accounts" export ACCOUNT_NAME="Demo" +export ACCOUNT_NAME_ALT="Demo Account" export ACCOUNT_PASSWORD="demo-test-password-case" export ACCOUNT_BACKUP="target/demo-backup.zip" export ACCOUNT_CONTACTS="tests/fixtures/contacts.vcf" diff --git a/scripts/cli/shell.sh b/scripts/cli/shell.sh new file mode 100755 index 0000000000..8b67517bec --- /dev/null +++ b/scripts/cli/shell.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +source scripts/cli/env.sh +export NO_COLOR=1 +export SOS_PROMPT='➜ ' + +if [ -n "$DEBUG" ]; then + export PATH="target/debug:$PATH" +fi + +command -v sos + +anticipate \ + run \ + --setup tests/command_line/scripts/setup.sh \ + --teardown tests/command_line/scripts/teardown.sh \ + tests/command_line/scripts/specs/shell.sh diff --git a/scripts/cli/specs.sh b/scripts/cli/specs.sh index edc317da9e..f3da6bd4be 100755 --- a/scripts/cli/specs.sh +++ b/scripts/cli/specs.sh @@ -4,6 +4,7 @@ set -e source scripts/cli/env.sh export NO_COLOR=1 +export SOS_PROMPT='➜ ' if [ -n "$DEBUG" ]; then export PATH="target/debug:$PATH" diff --git a/src/commands/check.rs b/src/commands/check.rs index 7d9e7b9686..1c0e7bf15a 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -31,13 +31,13 @@ pub enum Command { /// Vault file path. file: PathBuf, }, - /// Verify log file checksums. - Log { + /// Verify event log checksums. + Events { /// Print more information. #[clap(short, long)] verbose: bool, - /// Log file path. + /// Event log file path. file: PathBuf, }, } @@ -49,8 +49,8 @@ pub async fn run(cmd: Command) -> Result<()> { } Command::Header { file } => header(file).await?, Command::Keys { file } => keys(file).await?, - Command::Log { verbose, file } => { - verify_log(file, verbose).await?; + Command::Events { verbose, file } => { + verify_events(file, verbose).await?; } } @@ -72,8 +72,8 @@ async fn verify_vault(file: PathBuf, verbose: bool) -> Result<()> { Ok(()) } -/// Verify the integrity of a log file. -async fn verify_log(file: PathBuf, verbose: bool) -> Result<()> { +/// Verify the integrity of an events log file. +async fn verify_events(file: PathBuf, verbose: bool) -> Result<()> { if !vfs::metadata(&file).await?.is_file() { return Err(Error::NotFile(file)); } diff --git a/src/commands/shell/cli.rs b/src/commands/shell/cli.rs index f66f4bca0c..28ddfff6dc 100644 --- a/src/commands/shell/cli.rs +++ b/src/commands/shell/cli.rs @@ -85,14 +85,18 @@ pub async fn run( let mut rl = readline::basic_editor()?; loop { let prompt_value = { - let owner = user.read().await; - let account_name = owner.account_label().await?; - let storage = owner.storage().await?; - let reader = storage.read().await; - if let Some(current) = reader.current_folder() { - format!("{}@{}> ", account_name, current.name()) + if let Ok(prompt) = std::env::var("SOS_PROMPT") { + prompt } else { - format!("{}> ", account_name) + let owner = user.read().await; + let account_name = owner.account_label().await?; + let storage = owner.storage().await?; + let reader = storage.read().await; + if let Some(current) = reader.current_folder() { + format!("{}@{}> ", account_name, current.name()) + } else { + format!("{}> ", account_name) + } } }; diff --git a/tests/command_line/scripts/check/events.sh b/tests/command_line/scripts/check/events.sh new file mode 100644 index 0000000000..969f5cb6d1 --- /dev/null +++ b/tests/command_line/scripts/check/events.sh @@ -0,0 +1,2 @@ +sos check events $(find target/accounts/identity -name '*.events') +#$ wait diff --git a/tests/command_line/scripts/check/header.sh b/tests/command_line/scripts/check/header.sh new file mode 100644 index 0000000000..988d9a7ab7 --- /dev/null +++ b/tests/command_line/scripts/check/header.sh @@ -0,0 +1,2 @@ +sos check header $(find target/accounts/identity -name '*.vault') +#$ wait diff --git a/tests/command_line/scripts/check/keys.sh b/tests/command_line/scripts/check/keys.sh new file mode 100644 index 0000000000..fe692b48b3 --- /dev/null +++ b/tests/command_line/scripts/check/keys.sh @@ -0,0 +1,2 @@ +sos check keys $(find target/accounts/identity -name '*.vault') +#$ wait diff --git a/tests/command_line/scripts/check/vault.sh b/tests/command_line/scripts/check/vault.sh new file mode 100644 index 0000000000..db0ae5383b --- /dev/null +++ b/tests/command_line/scripts/check/vault.sh @@ -0,0 +1,2 @@ +sos check vault $(find target/accounts/identity -name '*.vault') +#$ wait diff --git a/tests/command_line/scripts/specs/check.sh b/tests/command_line/scripts/specs/check.sh new file mode 100644 index 0000000000..88ee3e8afc --- /dev/null +++ b/tests/command_line/scripts/specs/check.sh @@ -0,0 +1,4 @@ +#$ include ../check/vault.sh +#$ include ../check/keys.sh +#$ include ../check/header.sh +#$ include ../check/events.sh diff --git a/tests/command_line/scripts/specs/shell.sh b/tests/command_line/scripts/specs/shell.sh new file mode 100644 index 0000000000..146dcf1b35 --- /dev/null +++ b/tests/command_line/scripts/specs/shell.sh @@ -0,0 +1,70 @@ +sos shell +#$ include ../includes/signin.sh +#$ wait + +############################################################# +# BASIC +############################################################# + +whoami +#$ wait +pwd +#$ wait +cd Archive +#$ wait +cd Documents +#$ wait + +############################################################# +# SWITCH +############################################################# + +account new "$ACCOUNT_NAME_ALT" +#$ expect Choose a password +2 +#$ regex (?i)password +$ACCOUNT_PASSWORD +#$ regex (?i)password +$ACCOUNT_PASSWORD +#$ regex create a new account +y +#$ wait + +switch "$ACCOUNT_NAME_ALT" +#$ include ../includes/signin.sh +#$ wait + +switch "$ACCOUNT_NAME" +#$ include ../includes/signin.sh +#$ wait + +############################################################# +# ACCOUNT +############################################################# + +account ls -v +#$ wait + +account backup --force $ACCOUNT_BACKUP +#$ regex (?i)archive created +#$ wait + +account restore $ACCOUNT_BACKUP +#$ regex Overwrite all account +y +#$ include ../includes/signin.sh +#$ wait + +account info -v +#$ wait + +account stats +#$ wait + +account stats --json +#$ wait + +account migrate export --force target/demo-export.zip +#$ regex (?i)export unencrypted +y +#$ wait From 3203b3a5fa6576b4bbf141081d1c6c002ec26ff0 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 14:05:11 +0800 Subject: [PATCH 10/17] Improve shell test spec. --- tests/command_line/scripts/specs/shell.sh | 100 ++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/tests/command_line/scripts/specs/shell.sh b/tests/command_line/scripts/specs/shell.sh index 146dcf1b35..6d831f9104 100644 --- a/tests/command_line/scripts/specs/shell.sh +++ b/tests/command_line/scripts/specs/shell.sh @@ -64,7 +64,107 @@ account stats account stats --json #$ wait +account rename -a $ACCOUNT_NAME NewDemo +#$ wait + +account rename -a NewDemo $ACCOUNT_NAME +#$ wait + +############################################################# +# MIGRATE +############################################################# + account migrate export --force target/demo-export.zip #$ regex (?i)export unencrypted y #$ wait + +account migrate import --format onepassword.csv $MIGRATE_1PASSWORD +#$ regex (?i)imported +#$ wait + +account migrate import --format dashlane.zip $MIGRATE_DASHLANE +#$ regex (?i)imported +#$ wait + +account migrate import --format bitwarden.csv $MIGRATE_BITWARDEN +#$ regex (?i)imported +#$ wait + +account migrate import --format firefox.csv $MIGRATE_FIREFOX +#$ regex (?i)imported +#$ wait + +account migrate import --format macos.csv $MIGRATE_MACOS +#$ regex (?i)imported +#$ wait + +############################################################# +# CONTACTS +############################################################# + +account contacts export --force $CONTACTS_EXPORT +#$ regex (?i)contacts exported +#$ wait + +account contacts import $ACCOUNT_CONTACTS +#$ regex (?i)contacts imported +#$ wait + +############################################################# +# FOLDER +############################################################# + +folder new $FOLDER_NAME +#$ regex (?i)created +#$ wait + +folder ls -v +#$ wait + +folder info -v +#$ wait + +folder keys -f $FOLDER_NAME +#$ wait + +folder commits -f $FOLDER_NAME +#$ wait + +folder rename -f $FOLDER_NAME $NEW_FOLDER_NAME +#$ wait + +folder rename -f $NEW_FOLDER_NAME $FOLDER_NAME +#$ wait + +folder history compact -f $FOLDER_NAME +#$ regex (?i)remove history +y +#$ wait + +folder history check -f $FOLDER_NAME +#$ wait + +folder history list -f $FOLDER_NAME +#$ wait + +folder remove -f $FOLDER_NAME +#$ regex (?i)delete folder +y +#$ regex (?i)folder deleted +#$ wait + +############################################################# +# TEARDOWN +############################################################# + +switch "$ACCOUNT_NAME_ALT" +#$ include ../includes/signin.sh +#$ wait + +account delete +#$ include ../includes/signin.sh +#$ regex (?i)delete account +y +#$ regex (?i)account deleted +#$ wait From 6ff26568b187d0c220124678dc219f1d55b57d82 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 15:31:28 +0800 Subject: [PATCH 11/17] Update secret and shell cli test specs. --- scripts/cli/env.sh | 14 +- src/commands/shell/repl.rs | 11 -- tests/command_line/scripts/secret/add-list.sh | 16 ++ .../command_line/scripts/secret/add-login.sh | 10 ++ tests/command_line/scripts/secret/get-file.sh | 3 + tests/command_line/scripts/secret/get-list.sh | 3 + .../command_line/scripts/secret/get-login.sh | 3 + tests/command_line/scripts/secret/list.sh | 14 +- tests/command_line/scripts/secret/rename.sh | 1 - tests/command_line/scripts/specs/secret.sh | 5 + tests/command_line/scripts/specs/shell.sh | 166 ++++++++++++++++++ 11 files changed, 232 insertions(+), 14 deletions(-) create mode 100644 tests/command_line/scripts/secret/add-list.sh create mode 100644 tests/command_line/scripts/secret/add-login.sh create mode 100644 tests/command_line/scripts/secret/get-file.sh create mode 100644 tests/command_line/scripts/secret/get-list.sh create mode 100644 tests/command_line/scripts/secret/get-login.sh diff --git a/scripts/cli/env.sh b/scripts/cli/env.sh index 540263953a..6e44a22516 100644 --- a/scripts/cli/env.sh +++ b/scripts/cli/env.sh @@ -21,7 +21,19 @@ export ATTACH_INPUT="tests/fixtures/test-file.txt" export ATTACH_OUTPUT="target/attachment-download.txt" export NOTE_NAME="mock note" -export FILE_NAME="mock file"; +export FILE_NAME="mock file" +export LOGIN_NAME="mock login" +export LIST_NAME="mock list" + +export LOGIN_SERVICE_NAME="mock-service" +export LOGIN_URL="https://example.com" +export LOGIN_PASSWORD="mock-login-password" + +export LIST_NAME="mock-list"; +export LIST_KEY_1="SERVICE_1_API"; +export LIST_VALUE_1="mock-key-1"; +export LIST_KEY_2="SERVICE_2_API"; +export LIST_VALUE_2="mock-key-2"; export FILE_ATTACHMENT="file-attachment"; export NOTE_ATTACHMENT="note-attachment"; diff --git a/src/commands/shell/repl.rs b/src/commands/shell/repl.rs index 35512c0490..68a984bf1d 100644 --- a/src/commands/shell/repl.rs +++ b/src/commands/shell/repl.rs @@ -59,11 +59,6 @@ enum ShellCommand { #[clap(subcommand)] cmd: FileCommand, }, - /* - /// Change encryption password for the selected vault. - #[clap(alias = "passwd")] - Password, - */ /// Set a folder as the current working directory. Cd { /// Folder name or id. @@ -75,11 +70,6 @@ enum ShellCommand { /// Account name or address. account: AccountRef, }, - /// Check file status and integrity. - Check { - #[clap(subcommand)] - cmd: CheckCommand, - }, /// Print the current identity. Whoami, /// Print the current folder. @@ -343,7 +333,6 @@ async fn exec_program(program: Shell, user: Owner) -> Result<()> { Ok(()) } - ShellCommand::Check { cmd } => crate::commands::check::run(cmd).await, ShellCommand::Whoami => { let owner = user.read().await; println!("{} {}", owner.account_label().await?, owner.address()); diff --git a/tests/command_line/scripts/secret/add-list.sh b/tests/command_line/scripts/secret/add-list.sh new file mode 100644 index 0000000000..3fb3e321ef --- /dev/null +++ b/tests/command_line/scripts/secret/add-list.sh @@ -0,0 +1,16 @@ +sos secret add list --name "$LIST_NAME" +#$ include ../includes/signin.sh +#$ expect Key: +$LIST_KEY_1 +#$ expect Value: +$LIST_VALUE_1 +#$ expect Add more +y +#$ expect Key: +$LIST_KEY_2 +#$ expect Value: +$LIST_VALUE_2 +#$ expect Add more +n +#$ regex (?i)created +#$ wait diff --git a/tests/command_line/scripts/secret/add-login.sh b/tests/command_line/scripts/secret/add-login.sh new file mode 100644 index 0000000000..be4c9891f3 --- /dev/null +++ b/tests/command_line/scripts/secret/add-login.sh @@ -0,0 +1,10 @@ +sos secret add login --name "$LOGIN_NAME" +#$ include ../includes/signin.sh +#$ expect Username: +$LOGIN_SERVICE_NAME +#$ expect Website: +$LOGIN_URL +#$ expect Password: +$LOGIN_PASSWORD +#$ regex (?i)created +#$ wait diff --git a/tests/command_line/scripts/secret/get-file.sh b/tests/command_line/scripts/secret/get-file.sh new file mode 100644 index 0000000000..498fb3f649 --- /dev/null +++ b/tests/command_line/scripts/secret/get-file.sh @@ -0,0 +1,3 @@ +sos secret get "$FILE_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/get-list.sh b/tests/command_line/scripts/secret/get-list.sh new file mode 100644 index 0000000000..b5bb2e3b72 --- /dev/null +++ b/tests/command_line/scripts/secret/get-list.sh @@ -0,0 +1,3 @@ +sos secret get "$LIST_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/get-login.sh b/tests/command_line/scripts/secret/get-login.sh new file mode 100644 index 0000000000..b90b11fa35 --- /dev/null +++ b/tests/command_line/scripts/secret/get-login.sh @@ -0,0 +1,3 @@ +sos secret get "$LOGIN_NAME" +#$ include ../includes/signin.sh +#$ wait diff --git a/tests/command_line/scripts/secret/list.sh b/tests/command_line/scripts/secret/list.sh index a4d450b0b3..a8b6f7188a 100644 --- a/tests/command_line/scripts/secret/list.sh +++ b/tests/command_line/scripts/secret/list.sh @@ -1,3 +1,15 @@ -sos secret ls -f Documents +sos secret ls +#$ include ../includes/signin.sh +#$ wait + +sos secret ls --verbose +#$ include ../includes/signin.sh +#$ wait + +sos secret ls --all +#$ include ../includes/signin.sh +#$ wait + +sos secret ls --favorites #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/secret/rename.sh b/tests/command_line/scripts/secret/rename.sh index 0b429903f4..6e8884fc15 100644 --- a/tests/command_line/scripts/secret/rename.sh +++ b/tests/command_line/scripts/secret/rename.sh @@ -1,4 +1,3 @@ -# rename a secret sos secret rename --name "Demo Note" "$NOTE_NAME" #$ include ../includes/signin.sh #$ wait diff --git a/tests/command_line/scripts/specs/secret.sh b/tests/command_line/scripts/specs/secret.sh index db7a0f1ce7..fa0a147ec3 100644 --- a/tests/command_line/scripts/specs/secret.sh +++ b/tests/command_line/scripts/specs/secret.sh @@ -1,7 +1,12 @@ #$ include ../secret/add-note.sh #$ include ../secret/add-file.sh +#$ include ../secret/add-login.sh +#$ include ../secret/add-list.sh #$ include ../secret/list.sh #$ include ../secret/get-note.sh +#$ include ../secret/get-file.sh +#$ include ../secret/get-login.sh +#$ include ../secret/get-list.sh #$ include ../secret/copy.sh #$ include ../secret/info.sh #$ include ../secret/info-json.sh diff --git a/tests/command_line/scripts/specs/shell.sh b/tests/command_line/scripts/specs/shell.sh index 6d831f9104..c8410f669e 100644 --- a/tests/command_line/scripts/specs/shell.sh +++ b/tests/command_line/scripts/specs/shell.sh @@ -154,6 +154,172 @@ y #$ regex (?i)folder deleted #$ wait +############################################################# +# SECRET +############################################################# + +secret add note +#$ expect Name: +$NOTE_NAME +#$ expect >> +Text for the secret note. +#$ expect >> +#$ sendcontrol ^D +#$ wait + +secret add file -n "$FILE_NAME" "$FILE_INPUT" +#$ regex (?i)created +#$ wait + +secret add login --name "$LOGIN_NAME" +#$ expect Username: +$LOGIN_SERVICE_NAME +#$ expect Website: +$LOGIN_URL +#$ expect Password: +$LOGIN_PASSWORD +#$ regex (?i)created +#$ wait + +secret add list --name "$LIST_NAME" +#$ expect Key: +$LIST_KEY_1 +#$ expect Value: +$LIST_VALUE_1 +#$ expect Add more +y +#$ expect Key: +$LIST_KEY_2 +#$ expect Value: +$LIST_VALUE_2 +#$ expect Add more +n +#$ regex (?i)created +#$ wait + +secret ls -f Documents +#$ wait + +secret get "$NOTE_NAME" +#$ wait + +secret get "$FILE_NAME" +#$ wait + +secret get "$LOGIN_NAME" +#$ wait + +secret get "$LIST_NAME" +#$ wait + +secret copy "$NOTE_NAME" +#$ wait + +secret info "$NOTE_NAME" +#$ wait + +secret info --json "$NOTE_NAME" +#$ wait + +secret download --force "$FILE_NAME" "$FILE_OUTPUT" +#$ regex (?i)download complete +#$ wait + +secret attach add file --name "$FILE_ATTACHMENT" --path "$ATTACH_INPUT" "$NOTE_NAME" +#$ regex (?i)updated +#$ wait + +secret attach add note --name "$NOTE_ATTACHMENT" "$NOTE_NAME" +#$ expect >> +Text for the note attachment. +#$ expect >> +#$ sendcontrol ^D +#$ regex (?i)updated +#$ wait + +secret attach add link --name "$LINK_ATTACHMENT" "$NOTE_NAME" +#$ expect URL: +$LINK_VALUE +#$ regex (?i)updated +#$ wait + +secret attach add password --name "$PASSWORD_ATTACHMENT" "$NOTE_NAME" +#$ expect Password: +$PASSWORD_ATTACHMENT +#$ regex (?i)updated +#$ wait + +secret attach get "$NOTE_NAME" "$NOTE_ATTACHMENT" +#$ wait + +secret attach ls -v "$NOTE_NAME" +#$ wait + +secret attach rm "$NOTE_NAME" "$NOTE_ATTACHMENT" +#$ wait + +folder new $FOLDER_NAME +#$ regex (?i)created +#$ wait + +secret move --target "$FOLDER_NAME" "$NOTE_NAME" +#$ regex (?i)moved +#$ wait + +secret move --target "$DEFAULT_FOLDER_NAME" -f "$FOLDER_NAME" "$NOTE_NAME" +#$ regex (?i)moved +#$ wait + +folder remove -f $FOLDER_NAME +#$ regex (?i)delete folder +y +#$ regex (?i)folder deleted +#$ wait + +secret tags add --tags foo,bar,qux "$NOTE_NAME" +#$ wait + +secret tags list "$NOTE_NAME" +#$ wait + +secret tags rm --tags foo,bar "$NOTE_NAME" +#$ wait + +secret tags clear "$NOTE_NAME" +#$ wait + +secret favorite "$NOTE_NAME" +#$ wait + +secret favorite "$NOTE_NAME" +#$ wait + +secret archive "$NOTE_NAME" +#$ regex (?i)moved to archive +#$ wait + +secret unarchive "$NOTE_NAME" +#$ regex (?i)restored from archive +#$ wait + +secret comment --text 'Mock comment' "$NOTE_NAME" +#$ wait + +secret comment --text '' "$NOTE_NAME" +#$ wait + +secret rename --name "Demo Note" "$NOTE_NAME" +#$ wait + +secret rename --name "$NOTE_NAME" "Demo Note" +#$ wait + +secret remove "$NOTE_NAME" +#$ regex (?i)delete secret +y +#$ regex (?i)secret deleted +#$ wait + ############################################################# # TEARDOWN ############################################################# From 57766c98360c39a0612c154cf36ecdbd260b7149 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 16:25:10 +0800 Subject: [PATCH 12/17] Use anticipate for CLI test specs. --- .github/workflows/checks.yml | 2 +- Cargo.lock | 148 +++- Cargo.toml | 2 + Makefile.toml | 41 +- RELEASE.md | 2 +- TEST.md | 27 +- coverage_grcov.makefile.toml => coverage.toml | 0 src/cli/sos.rs | 9 +- src/cli/sos_server.rs | 4 +- src/commands/account.rs | 2 +- src/commands/security_report.rs | 5 +- src/helpers/account.rs | 1 - src/lib.rs | 2 +- tests/command_line/cli/account.rs | 466 ------------ tests/command_line/cli/check.rs | 77 -- tests/command_line/cli/folder.rs | 188 ----- tests/command_line/cli/helpers.rs | 106 --- tests/command_line/cli/mod.rs | 690 ----------------- tests/command_line/cli/secret.rs | 701 ------------------ tests/command_line/main.rs | 105 ++- tests/command_line/scripts/specs/shell.sh | 7 + 21 files changed, 298 insertions(+), 2287 deletions(-) rename coverage_grcov.makefile.toml => coverage.toml (100%) delete mode 100644 tests/command_line/cli/account.rs delete mode 100644 tests/command_line/cli/check.rs delete mode 100644 tests/command_line/cli/folder.rs delete mode 100644 tests/command_line/cli/helpers.rs delete mode 100644 tests/command_line/cli/mod.rs delete mode 100644 tests/command_line/cli/secret.rs diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5fabbd1d22..aeac470f66 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -63,4 +63,4 @@ jobs: - name: Run tests run: | - cargo make test-ci + cargo make test-lite diff --git a/Cargo.lock b/Cargo.lock index 71fb63359a..896c22e9af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,6 +127,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + [[package]] name = "allocator-api2" version = "0.2.16" @@ -196,6 +202,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anticipate-core" +version = "0.3.0" +dependencies = [ + "comma", + "expectrl", + "logos", + "ouroboros", + "probability", + "rand", + "thiserror", + "tracing", + "unicode-segmentation", +] + [[package]] name = "anyhow" version = "1.0.79" @@ -828,6 +849,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335" +[[package]] +name = "conpty" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b72b06487a0d4683349ad74d62e87ad639b09667082b3c495c5b6bab7d84b3da" +dependencies = [ + "windows", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -1435,6 +1465,16 @@ dependencies = [ "uint", ] +[[package]] +name = "expectrl" +version = "0.7.1" +dependencies = [ + "conpty", + "nix 0.26.4", + "ptyprocess", + "regex", +] + [[package]] name = "fancy-regex" version = "0.11.0" @@ -2312,6 +2352,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" @@ -2430,6 +2479,12 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "line-wrap" version = "0.1.1" @@ -2655,6 +2710,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "memoffset 0.7.1", + "pin-utils", ] [[package]] @@ -2822,6 +2878,31 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ouroboros" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b7be5a8a3462b752f4be3ff2b2bf2f7f1d00834902e46be2a4d68b87b0573c" +dependencies = [ + "aliasable", + "ouroboros_macro", + "static_assertions", +] + +[[package]] +name = "ouroboros_macro" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b645dcde5f119c2c454a92d0dfa271a2a3b205da92e4292a68ead4bdbfde1f33" +dependencies = [ + "heck", + "itertools 0.12.1", + "proc-macro2 1.0.78", + "proc-macro2-diagnostics", + "quote 1.0.35", + "syn 2.0.48", +] + [[package]] name = "overload" version = "0.1.1" @@ -3043,7 +3124,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" dependencies = [ "diff", - "yansi", + "yansi 0.5.1", ] [[package]] @@ -3059,6 +3140,16 @@ dependencies = [ "uint", ] +[[package]] +name = "probability" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42746b805e424b759d46c22c65dc66ccca057a2db96e9db4fda6c337a287e485" +dependencies = [ + "random", + "special", +] + [[package]] name = "probly-search" version = "2.0.0" @@ -3120,6 +3211,28 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.48", + "version_check", + "yansi 1.0.0-rc.1", +] + +[[package]] +name = "ptyprocess" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e05aef7befb11a210468a2d77d978dde2c6381a0381e33beb575e91f57fe8cf" +dependencies = [ + "nix 0.26.4", +] + [[package]] name = "qrcodegen" version = "1.8.0" @@ -3216,6 +3329,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "random" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "474c42c904f04dfe2a595a02f71e1a0e5e92ffb5761cc9a4c02140b93b8dd504" + [[package]] name = "redox_syscall" version = "0.4.1" @@ -3997,6 +4116,7 @@ dependencies = [ name = "sos" version = "0.10.1" dependencies = [ + "anticipate-core", "anyhow", "arboard", "async-recursion", @@ -4215,6 +4335,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "special" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b89cf0d71ae639fdd8097350bfac415a41aabf1d5ddd356295fdc95f09760382" +dependencies = [ + "libm", +] + [[package]] name = "spin" version = "0.9.8" @@ -5338,6 +5467,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5619,6 +5757,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "yansi" +version = "1.0.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1367295b8f788d371ce2dbc842c7b709c73ee1364d30351dd300ec2203b12377" + [[package]] name = "zerocopy" version = "0.7.32" @@ -5667,7 +5811,7 @@ checksum = "103fa851fff70ea29af380e87c25c48ff7faac5c530c70bd0e65366d4e0c94e4" dependencies = [ "derive_builder 0.12.0", "fancy-regex", - "itertools", + "itertools 0.10.5", "js-sys", "lazy_static", "quick-error", diff --git a/Cargo.toml b/Cargo.toml index 9df1be121b..d466b82778 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ members = [ [features] default = [] +enable-cli-tests = [] mem-fs = ["sos-net/mem-fs"] test-utils = ["sos-net/test-utils"] @@ -115,6 +116,7 @@ copy_dir = "0.1" maplit2 = "1" sos_test_utils = { path = "workspace/test_utils" } pretty_assertions = "1.4" +anticipate-core = { path = "../../anticipate/core" } [target.'cfg(not(target_os = "windows"))'.dev-dependencies] rexpect = "0.5" diff --git a/Makefile.toml b/Makefile.toml index 7456aef366..a81628fc16 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,5 +1,5 @@ extend= [ - { path = "coverage_grcov.makefile.toml" } + { path = "coverage.toml" } ] [config] @@ -140,40 +140,15 @@ dependencies = ["clean-cli"] script = { file = "./scripts/cli/demos.sh" } dependencies = ["clean-cli"] -[tasks.integration] -dependencies = [ - "test-audit-trail", - "test-backup-archive", - "test-event-log", - "test-diff-merge", - "test-local-account", - "test-network-account", - "test-pairing", - "test-access-control", - "test-file-transfers", - "test-preferences", - "test-system-messages", - "test-cli", -] - [tasks.test] -dependencies = ["unit", "integration"] +command = "cargo" +args = ["test", "--features", "enable-cli-tests"] +dependencies = ["clean-cli"] -[tasks.test-ci] -dependencies = [ - "unit", - "test-audit-trail", - "test-backup-archive", - "test-event-log", - "test-diff-merge", - "test-local-account", - "test-network-account", - "test-pairing", - "test-access-control", - "test-file-transfers", - "test-preferences", - "test-system-messages", -] +[tasks.test-lite] +command = "cargo" +args = ["test"] +dependencies = ["clean-cli"] [tasks.dev] dependencies = ["check-wasm", "test", "format"] diff --git a/RELEASE.md b/RELEASE.md index 51ede50f47..aad5548ffc 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -3,7 +3,7 @@ Check all the tests first. ``` -cargo make test-ci +cargo make test ``` Check the security audits. diff --git a/TEST.md b/TEST.md index a1e00ecddd..74ac5d5bb8 100644 --- a/TEST.md +++ b/TEST.md @@ -1,28 +1,37 @@ # Test -Generate a test keypair. +Run all the tests. ``` -cargo make gen-test-key +cargo make test ``` -Run the unit tests. +The CLI test specs can take a long time with the debug build so if you want to skip them use: ``` -cargo make unit +cargo make test-lite ``` -Run the integration tests. +To just test the CLI run: ``` -cargo make integration +cargo make test-cli ``` -## Notes +Or to just test the shell command: + +``` +cargo make test-shell +``` -### Command Line Tests +If you need to debug the CLI tests enable echo to see the I/O, for example: -The command line tests wait for very specific output in order to complete, inadvertently having a rogue `println!` in the code will cause the command line tests to fail. +``` +ANTICIPATE_ECHO=true cargo make test-cli +ANTICIPATE_ECHO=true cargo make test-shell +``` + +## Notes ### MacOS ulimit diff --git a/coverage_grcov.makefile.toml b/coverage.toml similarity index 100% rename from coverage_grcov.makefile.toml rename to coverage.toml diff --git a/src/cli/sos.rs b/src/cli/sos.rs index 19329d7fb3..9ef4d63469 100644 --- a/src/cli/sos.rs +++ b/src/cli/sos.rs @@ -1,4 +1,4 @@ -use clap::{Parser, Subcommand, CommandFactory}; +use clap::{CommandFactory, Parser, Subcommand}; use sos_net::sdk::{identity::AccountRef, vault::FolderRef, Paths}; use std::path::PathBuf; @@ -11,8 +11,7 @@ use crate::{ SecretCommand, ServerCommand, SyncCommand, }, helpers::{PROGRESS_MONITOR, USER}, - CommandTree, - Result, + CommandTree, Result, }; #[derive(Parser, Debug)] @@ -39,8 +38,8 @@ pub struct Sos { /// Local storage directory. #[clap(long, env = "SOS_DATA_DIR", hide_env_values = true)] storage: Option, - - // FIXME: remove this once we finish migrating the + + // FIXME: remove this once we finish migrating the // FIXME: CLI test specs to scripts /// Affirmative for all confirmation prompts. #[cfg(any(test, debug_assertions))] diff --git a/src/cli/sos_server.rs b/src/cli/sos_server.rs index e036d9550f..2bf5d99b59 100644 --- a/src/cli/sos_server.rs +++ b/src/cli/sos_server.rs @@ -1,5 +1,5 @@ -use crate::{Result, CommandTree}; -use clap::{Parser, Subcommand, CommandFactory}; +use crate::{CommandTree, Result}; +use clap::{CommandFactory, Parser, Subcommand}; use std::path::PathBuf; #[derive(Parser, Debug)] diff --git a/src/commands/account.rs b/src/commands/account.rs index 33134b1d9c..aafb03a08f 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -395,7 +395,7 @@ async fn account_restore(input: PathBuf) -> Result> { let inventory: Inventory = AccountBackup::restore_archive_inventory(reader).await?; let account_ref = AccountRef::Address(inventory.manifest.address); - + let account = find_account(&account_ref).await?; let mut owner = if let Some(account) = account { diff --git a/src/commands/security_report.rs b/src/commands/security_report.rs index a0e66e378d..0f2e201e6f 100644 --- a/src/commands/security_report.rs +++ b/src/commands/security_report.rs @@ -1,4 +1,7 @@ -use crate::{helpers::{account::resolve_user, messages::success}, Error, Result}; +use crate::{ + helpers::{account::resolve_user, messages::success}, + Error, Result, +}; use sos_net::{ client::hashcheck, sdk::{ diff --git a/src/helpers/account.rs b/src/helpers/account.rs index c5a72e2b67..659c7e2710 100644 --- a/src/helpers/account.rs +++ b/src/helpers/account.rs @@ -241,7 +241,6 @@ pub async fn new_account( account_name: String, folder_name: Option, ) -> Result<()> { - let account = AccountRef::Name(account_name.clone()); let account = find_account(&account).await?; diff --git a/src/lib.rs b/src/lib.rs index 7fad15c78c..0ec7ea98d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ pub type Result = std::result::Result; pub use helpers::USER; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; /// Command tree used to print help output for the website. #[doc(hidden)] diff --git a/tests/command_line/cli/account.rs b/tests/command_line/cli/account.rs deleted file mode 100644 index 8838daeb8d..0000000000 --- a/tests/command_line/cli/account.rs +++ /dev/null @@ -1,466 +0,0 @@ -use super::*; -use anyhow::Result; -use rexpect::{session::PtySession, spawn}; -use secrecy::SecretString; -use sos_net::sdk::{ - constants::DEFAULT_VAULT_NAME, migrate::import::ImportFormat, - secrecy::ExposeSecret, Paths, -}; -use std::{ - ops::DerefMut, - path::PathBuf, - sync::{Arc, Mutex}, -}; - -/// Create a new account. -pub fn new( - exe: &str, - password: &SecretString, - name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} account new {}", exe, name); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - if !is_ci() { - ps.exp_regex("2[)] Choose a password")?; - ps.send_line("2")?; - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - ps.exp_regex("Confirm password:")?; - ps.send_line(password.expose_secret())?; - ps.exp_regex("you want to create a new account")?; - ps.send_line("y")?; - } - Ok(()) - }); - - Ok(()) -} - -/// List accounts. -pub fn list( - exe: &str, - name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} account ls", exe); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - ps.exp_string(name)?; - Ok(()) - }); - - let cmd = format!("{} account ls -v", exe); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - ps.exp_regex(name)?; - Ok(()) - }); - - Ok(()) -} - -pub fn backup_restore( - exe: &str, - address: &str, - password: &SecretString, - account_name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - let data_dir = Paths::data_dir().unwrap(); - let backup_file = data_dir.join(format!("{}-backup.zip", address)); - - let cmd = format!( - "{} account backup -a {} -o {}", - exe, - address, - backup_file.to_string_lossy() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - ps.exp_regex("backup archive created")?; - Ok(()) - }); - - let cmd = format!( - "{} account restore -i {}", - exe, - backup_file.to_string_lossy() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - if !is_ci() { - ps.exp_regex("Overwrite all account")?; - ps.send_line("y")?; - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - - ps.exp_regex(&format!("restored {}", account_name))?; - Ok(()) - }); - - Ok(()) -} - -pub fn info( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} account info -a {}", exe, address); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - Ok(()) - }); - - let cmd = format!("{} account info -a {} -v", exe, address); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - Ok(()) - }); - - let cmd = format!("{} account info -a {} --json", exe, address); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - Ok(()) - }); - - Ok(()) -} - -pub fn statistics( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} account statistics -a {}", exe, address); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} account statistics --tags --folders --types -a {}", - exe, address - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} account statistics --json -a {}", exe, address); - read_until_eof(cmd, Some(password), repl) -} - -pub fn rename( - exe: &str, - address: &str, - password: &SecretString, - account_name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - // Must update expected prompt - let new_prompt = format_prompt(NEW_ACCOUNT_NAME, DEFAULT_VAULT_NAME); - let renamed = repl.clone().map(|(s, _p)| (s, &new_prompt[..])); - - // Rename account - let cmd = format!( - "{} account rename -a {} --name {}", - exe, address, NEW_ACCOUNT_NAME - ); - run!(renamed, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("account renamed")?; - Ok(()) - }); - - // Rename again to revert - let cmd = format!( - "{} account rename -a {} --name {}", - exe, address, account_name - ); - - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("account renamed")?; - Ok(()) - }); - - Ok(()) -} - -pub fn migrate( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let data_dir = Paths::data_dir().unwrap(); - let export_file = data_dir.join(format!("{}-export.zip", address)); - let fixtures = PathBuf::from("tests/fixtures/migrate"); - - let cmd = format!( - "{} account migrate -a {} export {}", - exe, - address, - export_file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex("Export UNENCRYPTED account")?; - ps.send_line("y")?; - } - ps.exp_regex("account exported")?; - Ok(()) - }); - - let cmd = format!( - "{} account migrate -a {} export --force {}", - exe, - address, - export_file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex("Export UNENCRYPTED account")?; - ps.send_line("y")?; - } - ps.exp_regex("account exported")?; - Ok(()) - }); - - let file = fixtures.join("1password-export.csv"); - let cmd = format!( - "{} account migrate -a {} import --format {} {}", - exe, - address, - ImportFormat::OnePasswordCsv, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("file imported")?; - Ok(()) - }); - - let file = fixtures.join("dashlane-export.zip"); - let cmd = format!( - "{} account migrate -a {} import --format {} {}", - exe, - address, - ImportFormat::DashlaneZip, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("file imported")?; - Ok(()) - }); - - let file = fixtures.join("bitwarden-export.csv"); - let cmd = format!( - "{} account migrate -a {} import --format {} {}", - exe, - address, - ImportFormat::BitwardenCsv, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("file imported")?; - Ok(()) - }); - - let file = fixtures.join("chrome-export.csv"); - let cmd = format!( - "{} account migrate -a {} import --format {} {}", - exe, - address, - ImportFormat::ChromeCsv, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("file imported")?; - Ok(()) - }); - - let file = fixtures.join("firefox-export.csv"); - let cmd = format!( - "{} account migrate -a {} import --format {} {}", - exe, - address, - ImportFormat::FirefoxCsv, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("file imported")?; - Ok(()) - }); - - let file = fixtures.join("macos-export.csv"); - let cmd = format!( - "{} account migrate -a {} import --format {} {}", - exe, - address, - ImportFormat::MacosCsv, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("file imported")?; - Ok(()) - }); - - Ok(()) -} - -pub fn contacts( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let import_file = PathBuf::from("tests/fixtures/contacts.vcf"); - - let data_dir = Paths::data_dir().unwrap(); - let export_file = data_dir.join(format!("{}-contacts.vcf", address)); - - let cmd = format!( - "{} account contacts -a {} import {}", - exe, - address, - import_file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("contacts imported")?; - Ok(()) - }); - - let cmd = format!( - "{} account contacts -a {} export {}", - exe, - address, - export_file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("contacts exported")?; - Ok(()) - }); - - Ok(()) -} - -pub fn delete( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = if repl.is_some() { - format!("{} account delete", exe) - } else { - format!("{} account delete -a {}", exe, address) - }; - run!(repl, cmd, false, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - if !is_ci() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - ps.exp_regex("Delete account")?; - ps.send_line("y")?; - } - - ps.exp_regex("account deleted")?; - // Delete the account kills the process - // so now we expect EOF for the shell and - // normal execution - ps.exp_eof()?; - Ok(()) - }); - Ok(()) -} diff --git a/tests/command_line/cli/check.rs b/tests/command_line/cli/check.rs deleted file mode 100644 index 9cf73ef4bb..0000000000 --- a/tests/command_line/cli/check.rs +++ /dev/null @@ -1,77 +0,0 @@ -use super::*; -use anyhow::Result; -use rexpect::{session::PtySession, spawn, ReadUntil}; -use sos_net::sdk::{vault::VaultId, Paths}; -use std::{ - ops::DerefMut, - sync::{Arc, Mutex}, -}; - -pub fn vault( - exe: &str, - address: &str, - vault_id: &VaultId, - repl: Option<(Session, &str)>, -) -> Result<()> { - let paths = Paths::new(Paths::data_dir()?, address); - let vault_path = paths.vault_path(vault_id); - - let cmd = format!("{} check vault {}", exe, vault_path.display()); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - ps.exp_any(vec![ReadUntil::String(String::from("Verified"))])?; - Ok(()) - }); - - let cmd = - format!("{} check vault --verbose {}", exe, vault_path.display()); - run!(repl, cmd, true, |ps: &mut PtySession, - _prompt: Option<&str>| - -> Result<()> { - ps.exp_any(vec![ReadUntil::String(String::from("Verified"))])?; - Ok(()) - }); - - Ok(()) -} - -pub fn keys( - exe: &str, - address: &str, - vault_id: &VaultId, - repl: Option<(Session, &str)>, -) -> Result<()> { - let paths = Paths::new(Paths::data_dir()?, address); - let vault_path = paths.vault_path(vault_id); - let cmd = format!("{} check keys {}", exe, vault_path.display()); - read_until_eof(cmd, None, repl) -} - -pub fn header( - exe: &str, - address: &str, - vault_id: &VaultId, - repl: Option<(Session, &str)>, -) -> Result<()> { - let paths = Paths::new(Paths::data_dir()?, address); - let vault_path = paths.vault_path(vault_id); - let cmd = format!("{} check header {}", exe, vault_path.display()); - read_until_eof(cmd, None, repl) -} - -pub fn log( - exe: &str, - address: &str, - vault_id: &VaultId, - repl: Option<(Session, &str)>, -) -> Result<()> { - let paths = Paths::new(Paths::data_dir()?, address); - let log_path = paths.event_log_path(vault_id); - - let cmd = format!("{} check log {}", exe, log_path.display()); - read_until_eof(cmd, None, repl.clone())?; - - let cmd = format!("{} check log --verbose {}", exe, log_path.display()); - read_until_eof(cmd, None, repl) -} diff --git a/tests/command_line/cli/folder.rs b/tests/command_line/cli/folder.rs deleted file mode 100644 index 0b637af375..0000000000 --- a/tests/command_line/cli/folder.rs +++ /dev/null @@ -1,188 +0,0 @@ -use super::*; -use anyhow::Result; -use rexpect::{session::PtySession, spawn}; -use secrecy::SecretString; -use sos_net::sdk::secrecy::ExposeSecret; -use std::{ - ops::DerefMut, - sync::{Arc, Mutex}, -}; - -pub fn new( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} folder new -a {} {}", exe, address, FOLDER_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Folder created")?; - Ok(()) - }); - - Ok(()) -} - -pub fn list( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} folder list -a {}", exe, address); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} folder list --verbose -a {}", exe, address); - read_until_eof(cmd, Some(password), repl) -} - -pub fn info( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} folder info -a {} {}", exe, address, FOLDER_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} folder info --verbose -a {} {}", - exe, address, FOLDER_NAME - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn keys( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} folder keys -a {} {}", exe, address, FOLDER_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn commits( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = - format!("{} folder commits -a {} {}", exe, address, FOLDER_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn rename( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!( - "{} folder rename -a {} -n {} {}", - exe, address, NEW_FOLDER_NAME, FOLDER_NAME - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} folder rename -a {} -n {} {}", - exe, address, FOLDER_NAME, NEW_FOLDER_NAME - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn history_compact( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!( - "{} folder history compact -a {} {}", - exe, address, FOLDER_NAME - ); - run!(repl, cmd, false, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - - if !is_ci() { - ps.exp_regex("Compaction will remove history")?; - ps.send_line("y")?; - } - - if let Some(prompt) = prompt { - wait_for_prompt(ps, prompt)?; - } else { - wait_for_eof(ps)?; - } - Ok(()) - }); - - Ok(()) -} - -pub fn history_check( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!( - "{} folder history check -a {} {}", - exe, address, FOLDER_NAME - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn history_list( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = - format!("{} folder history list -a {} {}", exe, address, FOLDER_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} folder history list --verbose -a {} {}", - exe, address, FOLDER_NAME - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn remove( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} folder remove -a {} {}", exe, address, FOLDER_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex("Delete folder")?; - ps.send_line("y")?; - } - ps.exp_regex("Folder deleted")?; - Ok(()) - }); - - Ok(()) -} diff --git a/tests/command_line/cli/helpers.rs b/tests/command_line/cli/helpers.rs deleted file mode 100644 index 7e3b56182b..0000000000 --- a/tests/command_line/cli/helpers.rs +++ /dev/null @@ -1,106 +0,0 @@ -use super::*; -use anyhow::Result; -use rexpect::spawn; -use secrecy::SecretString; -use sos_net::sdk::{ - constants::DEFAULT_VAULT_NAME, secrecy::ExposeSecret, - signer::ecdsa::Address, vault::VaultId, -}; - -/// Get the id of the default folder so we can -/// use it to execute the check subcommand which requires -/// paths to the files to check. -pub fn default_folder_id( - exe: &str, - address: &str, - password: &SecretString, -) -> Result { - let cmd = - format!("{} folder info -a {} {}", exe, address, DEFAULT_VAULT_NAME); - let mut p = spawn(&cmd, TIMEOUT)?; - if !is_ci() { - p.exp_regex("Password:")?; - p.send_line(password.expose_secret())?; - p.read_line()?; - } - - let result = p.read_line()?; - p.exp_eof()?; - - Ok(result.parse()?) -} - -/// Parse the address from the first account in the accounts list. -pub fn first_account_address(exe: &str, name: &str) -> Result { - let cmd = format!("{} account ls -v", exe); - let mut p = spawn(&cmd, TIMEOUT)?; - let result = p.read_line()?; - p.exp_eof()?; - - let mut parts: Vec<&str> = result.split(' ').collect(); - let address: &str = parts.remove(0); - let account_name: &str = parts.remove(0); - - assert!(address.parse::
().is_ok()); - assert_eq!(name, account_name); - Ok(address.to_owned()) -} - -pub fn set_note_ci_vars() { - std::env::set_var("SOS_NOTE", NOTE_VALUE.to_string()); -} - -pub fn clear_note_ci_vars() { - std::env::remove_var("SOS_NOTE"); -} - -pub fn set_login_ci_vars(account_password: &SecretString) { - std::env::set_var("SOS_LOGIN_USERNAME", LOGIN_SERVICE_NAME.to_string()); - std::env::set_var("SOS_LOGIN_URL", LOGIN_URL.to_string()); - std::env::set_var( - "SOS_LOGIN_PASSWORD", - account_password.expose_secret().to_string(), - ); -} - -pub fn clear_login_ci_vars() { - std::env::remove_var("SOS_LOGIN_USERNAME"); - std::env::remove_var("SOS_LOGIN_URL"); - std::env::remove_var("SOS_LOGIN_PASSWORD"); -} - -pub fn set_list_ci_vars(value_1: &SecretString, value_2: &SecretString) { - std::env::set_var( - "SOS_LIST", - format!( - "{}={}\n{}={}\n", - LIST_KEY_1, - value_1.expose_secret(), - LIST_KEY_2, - value_2.expose_secret() - ), - ); -} - -pub fn clear_list_ci_vars() { - std::env::remove_var("SOS_LIST"); -} - -pub fn set_link_ci_vars() { - std::env::set_var("SOS_LINK", LINK_VALUE.to_string()); -} - -pub fn clear_link_ci_vars() { - std::env::remove_var("SOS_LINK"); -} - -pub fn set_password_ci_vars(attachment_password: &SecretString) { - std::env::set_var( - "SOS_PASSWORD_VALUE", - attachment_password.expose_secret().to_string(), - ); -} - -pub fn clear_password_ci_vars() { - std::env::remove_var("SOS_PASSWORD_VALUE"); -} diff --git a/tests/command_line/cli/mod.rs b/tests/command_line/cli/mod.rs deleted file mode 100644 index fc98f7fc1e..0000000000 --- a/tests/command_line/cli/mod.rs +++ /dev/null @@ -1,690 +0,0 @@ -use anyhow::Result; -use rexpect::{session::PtySession, spawn, ReadUntil}; -use secrecy::SecretString; -use sos_net::sdk::{ - constants::{DEFAULT_ARCHIVE_VAULT_NAME, DEFAULT_VAULT_NAME}, - passwd::diceware::generate_passphrase, - secrecy::ExposeSecret, - vfs, Paths, -}; -use std::{ - ops::DerefMut, - path::PathBuf, - sync::{Arc, Mutex}, -}; - -mod account; -mod check; -mod folder; -mod helpers; -mod secret; - -type Session = Arc>; - -const TIMEOUT: Option = Some(30000); - -const ACCOUNT_NAME: &str = "mock"; -const SHELL_ACCOUNT_NAME: &str = "shell"; - -// Note we choose a name that sorts after all the -// other account names otherwise this account may -// appear first in the list as we parse the account -// address from the first in the list so if it sorts -// beforehand there be dragons. -const ALT_SHELL_ACCOUNT_NAME: &str = "zshell"; - -const NEW_ACCOUNT_NAME: &str = "mock-account-renamed"; -const FOLDER_NAME: &str = "mock-folder"; -const NEW_FOLDER_NAME: &str = "mock-folder-renamed"; - -const NOTE_NAME: &str = "mock-note"; -const NOTE_VALUE: &str = "Mock note value\n"; - -const NEW_NOTE_NAME: &str = "mock-note-renamed"; - -const FILE_NAME: &str = "mock-file"; - -const LOGIN_NAME: &str = "mock-login"; -const LOGIN_SERVICE_NAME: &str = "mock-service"; -const LOGIN_URL: &str = "https://example.com"; - -const LIST_NAME: &str = "mock-list"; -const LIST_KEY_1: &str = "SERVICE_1_API"; -const LIST_KEY_2: &str = "SERVICE_2_API"; - -const FILE_ATTACHMENT: &str = "file-attachment"; -const NOTE_ATTACHMENT: &str = "note-attachment"; -const LINK_ATTACHMENT: &str = "link-attachment"; -const PASSWORD_ATTACHMENT: &str = "password-attachment"; -const LINK_VALUE: &str = "https://example.com"; - -// Run a test spec handling the differences between -// executing a process and entering a line in a shell session. -macro_rules! run { - ($launch:ident, $cmd:ident, $eof:expr, $spec:expr) => {{ - // Get a PtySession which is either an existing session - // in the case of the shell command otherwise we spawn - // a new process/session - let is_shell = $launch.is_some(); - - println!( - "{}{}", - if is_shell { "$ " } else { "" }, - if is_shell { - strip_exe(&$cmd) - } else { - $cmd.clone() - } - ); - - let (process, prompt) = if let Some((session, prompt)) = &$launch { - (Arc::clone(session), Some(prompt)) - } else { - (Arc::new(Mutex::new(spawn(&$cmd, TIMEOUT).unwrap())), None) - }; - - let mut p = process.lock().expect("to acquire lock"); - - // Run the shell command - if is_shell { - p.send_line(&strip_exe(&$cmd))?; - } - - // Execute the test spec - $spec(p.deref_mut(), prompt.copied())?; - - // Wait for the prompt (shell) or expect EOF - if $eof { - if let Some(prompt) = prompt { - p.exp_regex(prompt)?; - } else { - p.exp_eof()?; - } - } - - if is_shell { - // Leave a little time for data to flush otherwise - // some tests will fail - std::thread::sleep(std::time::Duration::from_millis(10)); - } - }}; -} - -pub(crate) use run; - -pub(crate) fn format_prompt(account: &str, folder: &str) -> String { - format!("{}@{}>", account, folder) -} - -/// Strip executable name from a command, used when executing -/// in the context of a shell. -pub(crate) fn strip_exe(cmd: &str) -> String { - let mut parts: Vec<_> = cmd.split(" ").collect(); - parts.remove(0); - parts.join(" ") -} - -pub(crate) fn wait_for_prompt( - ps: &mut PtySession, - prompt: &str, -) -> Result<()> { - ps.exp_any(vec![ReadUntil::String(prompt.to_string())])?; - Ok(()) -} - -pub(crate) fn wait_for_eof(ps: &mut PtySession) -> Result<()> { - ps.exp_any(vec![ReadUntil::EOF])?; - Ok(()) -} - -pub(crate) fn is_coverage() -> bool { - env_is_set("COVERAGE") && env_is_set("COVERAGE_BINARIES") -} - -pub(crate) fn is_ci() -> bool { - env_is_set("CI") -} - -pub(crate) fn env_is_set(name: &str) -> bool { - std::env::var(name).is_ok() && !std::env::var(name).unwrap().is_empty() -} - -pub(crate) fn read_until_eof( - cmd: String, - password: Option<&SecretString>, - repl: Option<(Session, &str)>, -) -> Result<()> { - run!(repl, cmd, false, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if let Some(password) = password { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - } - if let Some(prompt) = prompt { - wait_for_prompt(ps, prompt)?; - } else { - wait_for_eof(ps)?; - } - Ok(()) - }); - - Ok(()) -} - -#[tokio::test] -async fn command_line() -> Result<()> { - let (password, _) = generate_passphrase()?; - - let data_dir = PathBuf::from("target/command_line_test"); - let _ = vfs::remove_dir_all(&data_dir).await; - - // Set cache directory for child processes - std::env::set_var("SOS_DATA_DIR", data_dir.clone()); - - // Set so test functions can access - Paths::set_data_dir(data_dir.clone()); - Paths::scaffold(Some(data_dir)).await?; - - if is_ci() { - std::env::set_var("SOS_YES", true.to_string()); - std::env::set_var("SOS_PASSWORD", password.expose_secret()); - } - - let exe = if is_coverage() { - PathBuf::from(std::env::var("COVERAGE_BINARIES")?) - .join("sos") - .to_string_lossy() - .into_owned() - } else { - "target/debug/sos".to_owned() - }; - - // Run tests in the context of a shell session - shell(&exe, &password).await?; - - account::new(&exe, &password, ACCOUNT_NAME, None)?; - - let address = helpers::first_account_address(&exe, ACCOUNT_NAME)?; - let default_id = helpers::default_folder_id(&exe, &address, &password)?; - - // These are the tests that execute each command line - // and therefore are much slower than the shell execution - // as we need to spawn the debug executable for each command - - check::vault(&exe, &address, &default_id, None)?; - check::keys(&exe, &address, &default_id, None)?; - check::header(&exe, &address, &default_id, None)?; - check::log(&exe, &address, &default_id, None)?; - - account::list(&exe, ACCOUNT_NAME, None)?; - account::backup_restore(&exe, &address, &password, ACCOUNT_NAME, None)?; - account::info(&exe, &address, &password, None)?; - account::statistics(&exe, &address, &password, None)?; - account::rename(&exe, &address, &password, ACCOUNT_NAME, None)?; - account::migrate(&exe, &address, &password, None)?; - account::contacts(&exe, &address, &password, None)?; - - folder::new(&exe, &address, &password, None)?; - folder::list(&exe, &address, &password, None)?; - folder::info(&exe, &address, &password, None)?; - folder::keys(&exe, &address, &password, None)?; - folder::commits(&exe, &address, &password, None)?; - folder::rename(&exe, &address, &password, None)?; - folder::history_compact(&exe, &address, &password, None)?; - folder::history_check(&exe, &address, &password, None)?; - folder::history_list(&exe, &address, &password, None)?; - folder::remove(&exe, &address, &password, None)?; - - secret::add_note(&exe, &address, &password, None)?; - secret::add_file(&exe, &address, &password, None)?; - secret::add_login(&exe, &address, &password, None)?; - secret::add_list(&exe, &address, &password, None)?; - - secret::list(&exe, &address, &password, None)?; - secret::get(&exe, &address, &password, None)?; - secret::cp(&exe, &address, &password, None)?; - secret::info(&exe, &address, &password, None)?; - secret::tags(&exe, &address, &password, None)?; - secret::favorite(&exe, &address, &password, None)?; - secret::rename(&exe, &address, &password, None)?; - secret::mv(&exe, &address, &password, ACCOUNT_NAME, None)?; - secret::comment(&exe, &address, &password, None)?; - secret::archive_unarchive(&exe, &address, &password, None)?; - secret::download(&exe, &address, &password, ACCOUNT_NAME, None).await?; - - // TODO: update - - secret::attach(&exe, &address, &password, ACCOUNT_NAME, None).await?; - secret::remove(&exe, &address, &password, None)?; - - account::delete(&exe, &address, &password, None)?; - - Paths::clear_data_dir(); - - std::env::remove_var("SOS_DATA_DIR"); - std::env::remove_var("SOS_YES"); - std::env::remove_var("SOS_PASSWORD"); - Ok(()) -} - -/// Login to a shell session. -fn login( - exe: &str, - address: &str, - password: &SecretString, - prompt: &str, -) -> Result { - let cmd = format!("{} shell {}", exe, address); - let ps = spawn(&cmd, TIMEOUT)?; - let process = Arc::new(Mutex::new(ps)); - - // Authenticate the user - if !is_ci() { - let mut p = process.lock().expect("to acquire lock"); - p.exp_regex("Password:")?; - p.send_line(password.expose_secret())?; - } - - // Wait for initial prompt - { - let mut p = process.lock().expect("to acquire lock"); - p.exp_regex(prompt)?; - } - - Ok(process) -} - -/// Run a shell session. -async fn shell(exe: &str, password: &SecretString) -> Result<()> { - // Prepare variables for CI input - helpers::set_note_ci_vars(); - let (account_password, _) = generate_passphrase()?; - helpers::set_login_ci_vars(&account_password); - let (value_1, _) = generate_passphrase()?; - let (value_2, _) = generate_passphrase()?; - helpers::set_list_ci_vars(&value_1, &value_2); - - helpers::set_link_ci_vars(); - let (attachment_password, _) = generate_passphrase()?; - helpers::set_password_ci_vars(&attachment_password); - - account::new(&exe, &password, SHELL_ACCOUNT_NAME, None)?; - - let address = helpers::first_account_address(&exe, SHELL_ACCOUNT_NAME)?; - let default_id = helpers::default_folder_id(&exe, &address, &password)?; - - let prompt = format_prompt(SHELL_ACCOUNT_NAME, DEFAULT_VAULT_NAME); - - let process = login(exe, &address, password, &prompt)?; - - // Login shell specific commands - whoami(exe, &password, Some((Arc::clone(&process), &prompt)))?; - pwd(exe, &password, Some((Arc::clone(&process), &prompt)))?; - cd(exe, &password, Some((Arc::clone(&process), &prompt)))?; - - // Create alternative account so we can test the switch command - account::new(&exe, &password, ALT_SHELL_ACCOUNT_NAME, None)?; - switch(exe, &password, Some((Arc::clone(&process), &prompt)))?; - - // Check - check::vault( - &exe, - &address, - &default_id, - Some((Arc::clone(&process), &prompt)), - )?; - check::keys( - &exe, - &address, - &default_id, - Some((Arc::clone(&process), &prompt)), - )?; - check::header( - &exe, - &address, - &default_id, - Some((Arc::clone(&process), &prompt)), - )?; - check::log( - &exe, - &address, - &default_id, - Some((Arc::clone(&process), &prompt)), - )?; - - // Account - account::list( - &exe, - SHELL_ACCOUNT_NAME, - Some((Arc::clone(&process), &prompt)), - )?; - account::backup_restore( - &exe, - &address, - &password, - SHELL_ACCOUNT_NAME, - Some((Arc::clone(&process), &prompt)), - )?; - account::info( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - account::statistics( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - account::rename( - &exe, - &address, - &password, - SHELL_ACCOUNT_NAME, - Some((Arc::clone(&process), &prompt)), - )?; - account::migrate( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - account::contacts( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - - // Folder - folder::new( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::list( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::info( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::keys( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::commits( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::rename( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::history_compact( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::history_check( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::history_list( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - folder::remove( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - - // Secret - secret::add_note( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::add_file( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::add_login( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::add_list( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::list( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::get( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::cp( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::info( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::tags( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::favorite( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::rename( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::mv( - &exe, - &address, - &password, - SHELL_ACCOUNT_NAME, - Some((Arc::clone(&process), &prompt)), - )?; - secret::comment( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::archive_unarchive( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - secret::download( - &exe, - &address, - &password, - SHELL_ACCOUNT_NAME, - Some((Arc::clone(&process), &prompt)), - ) - .await?; - - // TODO: update - - secret::attach( - &exe, - &address, - &password, - SHELL_ACCOUNT_NAME, - Some((Arc::clone(&process), &prompt)), - ) - .await?; - secret::remove( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - - helpers::clear_note_ci_vars(); - helpers::clear_login_ci_vars(); - helpers::clear_list_ci_vars(); - helpers::clear_link_ci_vars(); - helpers::clear_password_ci_vars(); - - // Quit the shell session - { - let mut p = process.lock().expect("to acquire lock"); - p.send_line("quit")?; - p.exp_eof()?; - } - - /* DELETE ACCOUNT */ - { - let process = login(exe, &address, password, &prompt)?; - account::delete( - &exe, - &address, - &password, - Some((Arc::clone(&process), &prompt)), - )?; - } - - Ok(()) -} - -fn whoami( - exe: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} whoami", exe); - read_until_eof(cmd, Some(password), repl) -} - -fn pwd( - exe: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} pwd", exe); - read_until_eof(cmd, Some(password), repl) -} - -fn cd( - exe: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - // Must update expected prompt - let new_prompt = - format_prompt(SHELL_ACCOUNT_NAME, DEFAULT_ARCHIVE_VAULT_NAME); - let renamed = repl.clone().map(|(s, _p)| (s, &new_prompt[..])); - - let cmd = format!("{} cd {}", exe, DEFAULT_ARCHIVE_VAULT_NAME); - read_until_eof(cmd, Some(password), renamed)?; - - cd_default_folder(exe, password, repl) -} - -fn cd_default_folder( - exe: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} cd {}", exe, DEFAULT_VAULT_NAME); - read_until_eof(cmd, Some(password), repl) -} - -fn switch( - exe: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - // Must update expected prompt - let new_prompt = - format_prompt(ALT_SHELL_ACCOUNT_NAME, DEFAULT_VAULT_NAME); - let renamed = repl.clone().map(|(s, _p)| (s, &new_prompt[..])); - - let cmd = format!("{} switch {}", exe, ALT_SHELL_ACCOUNT_NAME); - run!(renamed, cmd, false, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if let Some(prompt) = prompt { - wait_for_prompt(ps, prompt)?; - } else { - wait_for_eof(ps)?; - } - Ok(()) - }); - - let cmd = format!("{} switch {}", exe, SHELL_ACCOUNT_NAME); - run!(repl, cmd, false, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if let Some(prompt) = prompt { - wait_for_prompt(ps, prompt)?; - } else { - wait_for_eof(ps)?; - } - Ok(()) - }); - - Ok(()) -} diff --git a/tests/command_line/cli/secret.rs b/tests/command_line/cli/secret.rs deleted file mode 100644 index 2dc9197ca2..0000000000 --- a/tests/command_line/cli/secret.rs +++ /dev/null @@ -1,701 +0,0 @@ -use super::*; -use anyhow::Result; -use rexpect::spawn; -use secrecy::SecretString; -use sos_net::sdk::{ - constants::DEFAULT_VAULT_NAME, passwd::diceware::generate_passphrase, - secrecy::ExposeSecret, vfs, Paths, -}; -use std::{ops::DerefMut, path::PathBuf}; - -pub fn add_note( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - if is_ci() && repl.is_none() { - helpers::set_note_ci_vars(); - } - - let cmd = - format!("{} secret add note -a {} -n {}", exe, address, NOTE_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex(">> ")?; - ps.send_line(NOTE_VALUE)?; - ps.exp_regex(">> ")?; - ps.send_control('d')?; - } - ps.exp_regex("Secret created")?; - Ok(()) - }); - - if is_ci() && repl.is_none() { - helpers::clear_note_ci_vars(); - } - - Ok(()) -} - -pub fn add_file( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let file = PathBuf::from("tests/fixtures/sample.heic").canonicalize()?; - let cmd = format!( - "{} secret add file -a {} -n {} {}", - exe, - address, - FILE_NAME, - file.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Secret created")?; - Ok(()) - }); - - Ok(()) -} - -pub fn add_login( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let (account_password, _) = generate_passphrase()?; - - if is_ci() && repl.is_none() { - helpers::set_login_ci_vars(&account_password); - } - - let cmd = - format!("{} secret add login -a {} -n {}", exe, address, LOGIN_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex("Username:")?; - ps.send_line(LOGIN_SERVICE_NAME)?; - - ps.exp_regex("Website:")?; - ps.send_line(LOGIN_URL)?; - - ps.exp_regex("Password:")?; - ps.send_line(account_password.expose_secret())?; - } - ps.exp_regex("Secret created")?; - Ok(()) - }); - - if is_ci() && repl.is_none() { - helpers::clear_login_ci_vars(); - } - - Ok(()) -} - -pub fn add_list( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let (value_1, _) = generate_passphrase()?; - let (value_2, _) = generate_passphrase()?; - - if is_ci() && repl.is_none() { - helpers::set_list_ci_vars(&value_1, &value_2); - } - - let cmd = - format!("{} secret add list -a {} -n {}", exe, address, LIST_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex("Key:")?; - ps.send_line(LIST_KEY_1)?; - - ps.exp_regex("Value:")?; - ps.send_line(value_1.expose_secret())?; - - ps.exp_regex("Add more")?; - ps.send_line("y")?; - - ps.exp_regex("Key:")?; - ps.send_line(LIST_KEY_2)?; - - ps.exp_regex("Value:")?; - ps.send_line(value_2.expose_secret())?; - - ps.exp_regex("Add more")?; - ps.send_line("n")?; - } - ps.exp_regex("Secret created")?; - Ok(()) - }); - - if is_ci() && repl.is_none() { - helpers::clear_list_ci_vars(); - } - - Ok(()) -} - -pub fn list( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} secret list -a {}", exe, address); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret list --verbose -a {}", exe, address); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret list --all -a {}", exe, address); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret list --favorites -a {}", exe, address); - read_until_eof(cmd, Some(password), repl) -} - -pub fn get( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} secret get -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret get -a {} {}", exe, address, FILE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret get -a {} {}", exe, address, LOGIN_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret get -a {} {}", exe, address, LIST_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn cp( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} secret cp -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!("{} secret cp -a {} {}", exe, address, FILE_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn info( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} secret info -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = - format!("{} secret info --debug -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = - format!("{} secret info --json -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn tags( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let tags = "foo,bar,qux"; - - let cmd = format!( - "{} secret tags add -a {} --tags {} {}", - exe, address, tags, NOTE_NAME - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = - format!("{} secret tags list -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} secret tags rm -a {} --tags {} {}", - exe, address, "foo,bar", NOTE_NAME - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = - format!("{} secret tags clear -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn favorite( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - // Add to favorites with first toggle - let cmd = format!("{} secret favorite -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl.clone())?; - - // Remove from favorites with second toggle - let cmd = format!("{} secret favorite -a {} {}", exe, address, NOTE_NAME); - read_until_eof(cmd, Some(password), repl) -} - -pub fn rename( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!( - "{} secret rename -a {} --name {} {}", - exe, address, NEW_NOTE_NAME, NOTE_NAME - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} secret rename -a {} --name {} {}", - exe, address, NOTE_NAME, NEW_NOTE_NAME - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn mv( - exe: &str, - address: &str, - password: &SecretString, - account_name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - let target_folder = "moved-secret-folder"; - - let new_prompt = format_prompt(account_name, target_folder); - let renamed = repl.clone().map(|(s, _p)| (s, &new_prompt[..])); - - // Create temporary folder - let cmd = format!("{} folder new -a {} {}", exe, address, target_folder); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Folder created")?; - Ok(()) - }); - - // Move to the new folder - let cmd = format!( - "{} secret move -a {} --target {} {}", - exe, address, target_folder, NOTE_NAME - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Secret moved")?; - Ok(()) - }); - - // Move back to the default folder - let cmd = format!( - "{} secret move -a {} --target {} --folder {} {}", - exe, address, DEFAULT_VAULT_NAME, target_folder, NOTE_NAME - ); - run!(renamed, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Secret moved")?; - Ok(()) - }); - - // Clean up the temporary folder - let cmd = - format!("{} folder remove -a {} {}", exe, address, target_folder); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - - if !is_ci() { - ps.exp_regex("Delete folder")?; - ps.send_line("y")?; - } - - ps.exp_regex("Folder deleted")?; - Ok(()) - }); - - Ok(()) -} - -pub fn comment( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - // Set a comment - let cmd = format!( - "{} secret comment -a {} --text {} {}", - exe, address, "mock-comment", NOTE_NAME - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - // Clear the comment - let cmd = format!( - "{} secret comment -a {} --text '' {}", - exe, address, NOTE_NAME - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn archive_unarchive( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - // Move to archive - let cmd = format!("{} secret archive -a {} {}", exe, address, NOTE_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Moved to archive")?; - Ok(()) - }); - - // Restore from archive - let cmd = - format!("{} secret unarchive -a {} {}", exe, address, NOTE_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Restored from archive")?; - Ok(()) - }); - - Ok(()) -} - -pub async fn download( - exe: &str, - address: &str, - password: &SecretString, - account_name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - let data_dir = Paths::data_dir()?; - let output = data_dir.join(format!("sample-{}.heic", account_name)); - - let cmd = format!( - "{} secret download -a {} {} {}", - exe, - address, - FILE_NAME, - output.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Download complete")?; - Ok(()) - }); - assert!(vfs::try_exists(&output).await?); - - let cmd = format!( - "{} secret download -a {} --force {} {}", - exe, - address, - FILE_NAME, - output.display() - ); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Download complete")?; - Ok(()) - }); - assert!(vfs::try_exists(&output).await?); - - Ok(()) -} - -pub async fn attach( - exe: &str, - address: &str, - password: &SecretString, - account_name: &str, - repl: Option<(Session, &str)>, -) -> Result<()> { - let data_dir = Paths::data_dir()?; - let input = PathBuf::from("tests/fixtures/sample.heic").canonicalize()?; - let output = - data_dir.join(format!("sample-attachment-{}.heic", account_name)); - - // Create file attachment - let cmd = format!( - "{} secret attach add file -a {} --name {} --path {} {}", - exe, - address, - FILE_ATTACHMENT, - input.display(), - NOTE_NAME - ); - { - let repl = repl.clone(); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Secret updated")?; - Ok(()) - }); - } - - // Create note attachment - if is_ci() && repl.is_none() { - helpers::set_note_ci_vars(); - } - let cmd = format!( - "{} secret attach add note -a {} --name {} {}", - exe, address, NOTE_ATTACHMENT, NOTE_NAME - ); - { - let repl = repl.clone(); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - - if !is_ci() { - ps.exp_regex(">> ")?; - ps.send_line(NOTE_VALUE)?; - ps.exp_regex(">> ")?; - ps.send_control('d')?; - } - - ps.exp_regex("Secret updated")?; - Ok(()) - }); - } - - if is_ci() { - helpers::clear_note_ci_vars(); - } - - // Create link attachment - if is_ci() { - helpers::set_link_ci_vars(); - } - let cmd = format!( - "{} secret attach add link -a {} --name {} {}", - exe, address, LINK_ATTACHMENT, NOTE_NAME - ); - - { - let repl = repl.clone(); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - - if !is_ci() { - ps.exp_regex("URL:")?; - ps.send_line(LINK_VALUE)?; - } - - ps.exp_regex("Secret updated")?; - Ok(()) - }); - } - - if is_ci() { - helpers::clear_link_ci_vars(); - } - - // Create password attachment - let (attachment_password, _) = generate_passphrase()?; - if is_ci() { - helpers::set_password_ci_vars(&attachment_password); - } - let cmd = format!( - "{} secret attach add password -a {} --name {} {}", - exe, address, PASSWORD_ATTACHMENT, NOTE_NAME - ); - - { - let repl = repl.clone(); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - - // Hack for this test failing (incorrectly) sporadically - std::thread::sleep(std::time::Duration::from_millis(25)); - - if !is_ci() { - ps.exp_regex("Password:")?; - ps.send_line(attachment_password.expose_secret())?; - } - - ps.exp_regex("Secret updated")?; - Ok(()) - }); - } - - if is_ci() { - helpers::clear_password_ci_vars(); - } - - // Get an attachment - let cmd = format!( - "{} secret attach get -a {} {} {}", - exe, address, NOTE_NAME, NOTE_ATTACHMENT, - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - // List attachments - let cmd = - format!("{} secret attach ls -a {} {}", exe, address, NOTE_NAME,); - read_until_eof(cmd, Some(password), repl.clone())?; - - let cmd = format!( - "{} secret attach ls --verbose -a {} {}", - exe, address, NOTE_NAME, - ); - read_until_eof(cmd, Some(password), repl.clone())?; - - // Download file attachment - let cmd = format!( - "{} secret attach download -a {} {} {} {}", - exe, - address, - NOTE_NAME, - FILE_ATTACHMENT, - output.display() - ); - { - let repl = repl.clone(); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - ps.exp_regex("Download complete")?; - Ok(()) - }); - } - assert!(vfs::try_exists(&output).await?); - - // Remove an attachment - let cmd = format!( - "{} secret attach remove -a {} {} {}", - exe, address, NOTE_NAME, NOTE_ATTACHMENT, - ); - read_until_eof(cmd, Some(password), repl) -} - -pub fn remove( - exe: &str, - address: &str, - password: &SecretString, - repl: Option<(Session, &str)>, -) -> Result<()> { - let cmd = format!("{} secret remove -a {} {}", exe, address, NOTE_NAME); - run!(repl, cmd, true, |ps: &mut PtySession, - prompt: Option<&str>| - -> Result<()> { - if !is_ci() && prompt.is_none() { - ps.exp_regex("Password:")?; - ps.send_line(password.expose_secret())?; - } - if !is_ci() { - ps.exp_regex("Delete secret")?; - ps.send_line("y")?; - } - ps.exp_regex("Secret deleted")?; - Ok(()) - }); - - Ok(()) -} diff --git a/tests/command_line/main.rs b/tests/command_line/main.rs index 8fbd592f05..c14ffa976f 100644 --- a/tests/command_line/main.rs +++ b/tests/command_line/main.rs @@ -1,5 +1,106 @@ -#[cfg(all(not(target_arch = "wasm32"), not(target_os = "windows")))] -mod cli; +#[cfg(feature = "enable-cli-tests")] +mod cli { + use anticipate_core::{InterpreterOptions, ScriptFile}; + use anyhow::Result; + use std::{env::set_var, path::Path}; + + #[test] + fn command_line() -> Result<()> { + prepare_env(); + + let specs = vec![ + "tests/command_line/scripts/setup.sh", + "tests/command_line/scripts/specs/account.sh", + "tests/command_line/scripts/specs/check.sh", + "tests/command_line/scripts/specs/folder.sh", + "tests/command_line/scripts/specs/secret.sh", + "tests/command_line/scripts/specs/shell.sh", + "tests/command_line/scripts/teardown.sh", + ]; + + for spec in specs { + run_spec(spec)?; + } + + Ok(()) + } + + fn run_spec(input_file: impl AsRef) -> Result<()> { + let file_name = input_file + .as_ref() + .file_name() + .unwrap() + .to_string_lossy() + .into_owned(); + let echo = std::env::var("ANTICIPATE_ECHO").is_ok(); + let script = ScriptFile::parse(input_file)?; + let mut options = InterpreterOptions::new(5000, echo, false, false); + options.id = Some(file_name.to_owned()); + script.run(options)?; + Ok(()) + } + + fn prepare_env() { + set_var("NO_COLOR", "1"); + set_var("SOS_DATA_DIR", "target/accounts"); + set_var("SOS_PROMPT", "➜ "); + set_var("ACCOUNT_NAME", "Demo"); + set_var("ACCOUNT_NAME_ALT", "Demo Account"); + set_var("ACCOUNT_PASSWORD", "demo-test-password-case"); + set_var("ACCOUNT_BACKUP", "target/demo-backup.zip"); + set_var("ACCOUNT_CONTACTS", "tests/fixtures/contacts.vcf"); + set_var("CONTACTS_EXPORT", "target/demo-contacts.vcf"); + + set_var("DEFAULT_FOLDER_NAME", "Documents"); + set_var("FOLDER_NAME", "mock-folder"); + set_var("NEW_FOLDER_NAME", "mock-folder-renamed"); + + set_var("FILE_INPUT", "tests/fixtures/sample.heic"); + set_var("FILE_OUTPUT", "target/file-download.heic"); + + set_var("ATTACH_INPUT", "tests/fixtures/test-file.txt"); + set_var("ATTACH_OUTPUT", "target/attachment-download.txt"); + + set_var("NOTE_NAME", "mock note"); + set_var("FILE_NAME", "mock file"); + set_var("LOGIN_NAME", "mock login"); + set_var("LIST_NAME", "mock list"); + + set_var("LOGIN_SERVICE_NAME", "mock-service"); + set_var("LOGIN_URL", "https://example.com"); + set_var("LOGIN_PASSWORD", "mock-login-password"); + + set_var("LIST_NAME", "mock-list"); + set_var("LIST_KEY_1", "SERVICE_1_API"); + set_var("LIST_VALUE_1", "mock-key-1"); + set_var("LIST_KEY_2", "SERVICE_2_API"); + set_var("LIST_VALUE_2", "mock-key-2"); + + set_var("FILE_ATTACHMENT", "file-attachment"); + set_var("NOTE_ATTACHMENT", "note-attachment"); + set_var("LINK_ATTACHMENT", "link-attachment"); + set_var("PASSWORD_ATTACHMENT", "password-attachment"); + set_var("LINK_VALUE", "https://example.com"); + + set_var( + "MIGRATE_1PASSWORD", + "tests/fixtures/migrate/1password-export.csv", + ); + set_var( + "MIGRATE_DASHLANE", + "tests/fixtures/migrate/dashlane-export.zip", + ); + set_var( + "MIGRATE_BITWARDEN", + "tests/fixtures/migrate/bitwarden-export.csv", + ); + set_var( + "MIGRATE_FIREFOX", + "tests/fixtures/migrate/firefox-export.csv", + ); + set_var("MIGRATE_MACOS", "tests/fixtures/migrate/macos-export.csv"); + } +} #[cfg(not(target_arch = "wasm32"))] pub use sos_test_utils as test_utils; diff --git a/tests/command_line/scripts/specs/shell.sh b/tests/command_line/scripts/specs/shell.sh index c8410f669e..704efa24ae 100644 --- a/tests/command_line/scripts/specs/shell.sh +++ b/tests/command_line/scripts/specs/shell.sh @@ -2,6 +2,13 @@ sos shell #$ include ../includes/signin.sh #$ wait +quit +#$ wait + +sos shell +#$ include ../includes/signin.sh +#$ wait + ############################################################# # BASIC ############################################################# From 71ed397c4a31796ea1efb963fd7a0e7ebe3f6716 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 16:27:23 +0800 Subject: [PATCH 13/17] Remove obsolete SOS_YES env var. --- src/cli/sos.rs | 7 ------- src/commands/shell/repl.rs | 2 +- src/helpers/readline.rs | 4 ---- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/cli/sos.rs b/src/cli/sos.rs index 9ef4d63469..23a63d7953 100644 --- a/src/cli/sos.rs +++ b/src/cli/sos.rs @@ -39,13 +39,6 @@ pub struct Sos { #[clap(long, env = "SOS_DATA_DIR", hide_env_values = true)] storage: Option, - // FIXME: remove this once we finish migrating the - // FIXME: CLI test specs to scripts - /// Affirmative for all confirmation prompts. - #[cfg(any(test, debug_assertions))] - #[clap(long, env = "SOS_YES", hide_env_values = true)] - yes: bool, - #[clap(subcommand)] cmd: Command, } diff --git a/src/commands/shell/repl.rs b/src/commands/shell/repl.rs index 68a984bf1d..412b1844f7 100644 --- a/src/commands/shell/repl.rs +++ b/src/commands/shell/repl.rs @@ -8,7 +8,7 @@ use sos_net::sdk::{ use crate::{ commands::{ - AccountCommand, CheckCommand, FileCommand, FolderCommand, + AccountCommand, FileCommand, FolderCommand, SecretCommand, ServerCommand, SyncCommand, }, helpers::account::{cd_folder, switch, Owner}, diff --git a/src/helpers/readline.rs b/src/helpers/readline.rs index 5427da2480..3e650cad8e 100644 --- a/src/helpers/readline.rs +++ b/src/helpers/readline.rs @@ -146,10 +146,6 @@ pub fn read_option(prompt: Option<&str>) -> Result> { /// Read a flag value (y/n). pub fn read_flag(prompt: Option<&str>) -> Result { - if std::env::var("SOS_YES").is_ok() { - return Ok(true); - } - let mut rl = basic_editor()?; let readline = rl.readline(prompt.unwrap_or(DEFAULT_PROMPT)); match readline { From aa3bba5330aa2a3badfdea7b9eb02d2279bb4a0e Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 17:28:08 +0800 Subject: [PATCH 14/17] Configure PATH for cli tests. --- Cargo.lock | 39 +------------------------------------- Cargo.toml | 3 --- Makefile.toml | 2 ++ coverage.toml | 2 +- tests/command_line/main.rs | 12 ++++++++++-- 5 files changed, 14 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 896c22e9af..90b063b1d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2591,15 +2591,6 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.7.1" @@ -2686,20 +2677,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "nix" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if 1.0.0", - "libc", - "memoffset 0.6.5", - "pin-utils", -] - [[package]] name = "nix" version = "0.26.4" @@ -2709,7 +2686,7 @@ dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", "libc", - "memoffset 0.7.1", + "memoffset", "pin-utils", ] @@ -3434,19 +3411,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "rexpect" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ff60778f96fb5a48adbe421d21bf6578ed58c0872d712e7e08593c195adff8" -dependencies = [ - "comma", - "nix 0.25.1", - "regex", - "tempfile", - "thiserror", -] - [[package]] name = "rfc6979" version = "0.4.0" @@ -4137,7 +4101,6 @@ dependencies = [ "once_cell", "parking_lot", "pretty_assertions", - "rexpect", "rustyline", "rustyline-derive", "secrecy", diff --git a/Cargo.toml b/Cargo.toml index d466b82778..73d2b56d5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,9 +118,6 @@ sos_test_utils = { path = "workspace/test_utils" } pretty_assertions = "1.4" anticipate-core = { path = "../../anticipate/core" } -[target.'cfg(not(target_os = "windows"))'.dev-dependencies] -rexpect = "0.5" - [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3" wasm-bindgen = { version = "0.2.80", features = ["serde-serialize"] } diff --git a/Makefile.toml b/Makefile.toml index a81628fc16..c1b92e4b85 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -210,7 +210,9 @@ command = "cargo" args = ["clean", "--target-dir", "target/cover"] [tasks.cover] +env = { "COVER" = "1" } dependencies = [ + "clean-cli", "clean-cover", "clean-coverage", "coverage", diff --git a/coverage.toml b/coverage.toml index 97101bec72..4e4e937f1d 100644 --- a/coverage.toml +++ b/coverage.toml @@ -51,7 +51,7 @@ args = ["build"] condition = { rust_version = { min = "1.60.0" } } private=true command = "cargo" -args = ["test", "--all", "--", "--nocapture"] +args = ["test", "--all", "--features", "enable-cli-tests", "--", "--nocapture"] [tasks.coverage_grcov_run_test_stable.env] "COVERAGE" = "1" diff --git a/tests/command_line/main.rs b/tests/command_line/main.rs index c14ffa976f..601d47c31b 100644 --- a/tests/command_line/main.rs +++ b/tests/command_line/main.rs @@ -2,7 +2,7 @@ mod cli { use anticipate_core::{InterpreterOptions, ScriptFile}; use anyhow::Result; - use std::{env::set_var, path::Path}; + use std::{env::{set_var, var}, path::Path}; #[test] fn command_line() -> Result<()> { @@ -32,7 +32,7 @@ mod cli { .unwrap() .to_string_lossy() .into_owned(); - let echo = std::env::var("ANTICIPATE_ECHO").is_ok(); + let echo = var("ANTICIPATE_ECHO").is_ok(); let script = ScriptFile::parse(input_file)?; let mut options = InterpreterOptions::new(5000, echo, false, false); options.id = Some(file_name.to_owned()); @@ -41,6 +41,14 @@ mod cli { } fn prepare_env() { + let path = var("PATH").ok().unwrap_or_default(); + let prefix = if var("COVER").ok().is_some() { + "target/cover/debug" + } else { + "target/debug" + }; + set_var("PATH", format!("{}:{}", prefix, path)); + set_var("NO_COLOR", "1"); set_var("SOS_DATA_DIR", "target/accounts"); set_var("SOS_PROMPT", "➜ "); From ed4db870a0d3a6e9919e896c8802c123389262c4 Mon Sep 17 00:00:00 2001 From: muji Date: Wed, 21 Feb 2024 17:32:58 +0800 Subject: [PATCH 15/17] Update test docs. --- Makefile.toml | 4 ---- TEST.md | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index c1b92e4b85..ca78413d4a 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -118,10 +118,6 @@ args = ["test", "preferences_"] command = "cargo" args = ["test", "system_messages_"] -[tasks.install-local] -command = "cargo" -args = ["install", "--path", "."] - [tasks.clean-cli] script = ''' rm -rf target/accounts diff --git a/TEST.md b/TEST.md index 74ac5d5bb8..18c7ead0df 100644 --- a/TEST.md +++ b/TEST.md @@ -12,7 +12,9 @@ The CLI test specs can take a long time with the debug build so if you want to s cargo make test-lite ``` -To just test the CLI run: +## Test Scripts + +To run the CLI test specs using the first version of `sos` in `PATH`: ``` cargo make test-cli @@ -31,6 +33,8 @@ ANTICIPATE_ECHO=true cargo make test-cli ANTICIPATE_ECHO=true cargo make test-shell ``` +Run `cargo install --path .` to install a release version and make these tests much faster. + ## Notes ### MacOS ulimit From 39461476542518924a4bd15cd9cd40b9417c0e41 Mon Sep 17 00:00:00 2001 From: muji Date: Thu, 22 Feb 2024 09:04:06 +0800 Subject: [PATCH 16/17] Switch to anticipate-runner crate. --- Cargo.lock | 428 ++++++++++++++++++------------------- Cargo.toml | 2 +- Makefile.toml | 5 +- TEST.md | 12 ++ coverage.toml | 3 +- tests/command_line/main.rs | 2 +- 6 files changed, 223 insertions(+), 229 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90b063b1d9..cb7f58ff5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,9 +29,9 @@ dependencies = [ [[package]] name = "aes" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if 1.0.0", "cipher", @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" dependencies = [ "cfg-if 1.0.0", "once_cell", @@ -156,9 +156,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" dependencies = [ "anstyle", "anstyle-parse", @@ -203,11 +203,21 @@ dependencies = [ ] [[package]] -name = "anticipate-core" -version = "0.3.0" +name = "anticipate" +version = "0.8.1" +dependencies = [ + "conpty", + "nix 0.26.4", + "ptyprocess", + "regex", +] + +[[package]] +name = "anticipate-runner" +version = "0.4.0" dependencies = [ + "anticipate", "comma", - "expectrl", "logos", "ouroboros", "probability", @@ -219,9 +229,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" [[package]] name = "app_dirs2" @@ -237,11 +247,11 @@ dependencies = [ [[package]] name = "arboard" -version = "3.3.0" +version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafb29b107435aa276664c1db8954ac27a6e105cdad3c88287a199eb0e313c08" +checksum = "1faa3c733d9a3dd6fbaf85da5d162a2e03b2e0033a90dceb0e2a90fdd1e5380a" dependencies = [ - "clipboard-win 4.5.0", + "clipboard-win", "core-graphics", "image", "log", @@ -250,7 +260,7 @@ dependencies = [ "objc_id", "parking_lot", "thiserror", - "winapi", + "windows-sys 0.48.0", "x11rb", ] @@ -305,7 +315,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -327,7 +337,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -338,7 +348,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -376,7 +386,7 @@ dependencies = [ "http 1.0.0", "http-body 1.0.0", "http-body-util", - "hyper 1.1.0", + "hyper 1.2.0", "hyper-util", "itoa", "matchit", @@ -451,7 +461,7 @@ dependencies = [ "heck", "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -466,11 +476,11 @@ dependencies = [ "http 1.0.0", "http-body 1.0.0", "http-body-util", - "hyper 1.1.0", + "hyper 1.2.0", "hyper-util", "pin-project-lite", "rustls 0.21.10", - "rustls-pemfile 2.0.0", + "rustls-pemfile 2.1.0", "tokio", "tokio-rustls 0.24.1", "tower", @@ -622,22 +632,11 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" -[[package]] -name = "bstr" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" -dependencies = [ - "memchr", - "regex-automata 0.4.5", - "serde", -] - [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "a3b1be7772ee4501dba05acbe66bb1e8760f6a6c474a36035631638e4415f130" [[package]] name = "byte-slice-cast" @@ -665,12 +664,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "7f9fa1897e4325be0d68d48df6aa1a71ac2ed4d27723887e7754192705350730" [[package]] name = "cesu8" @@ -728,9 +724,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", @@ -752,9 +748,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" dependencies = [ "clap_builder", "clap_derive", @@ -762,9 +758,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.0" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" dependencies = [ "anstream", "anstyle", @@ -782,7 +778,7 @@ dependencies = [ "heck", "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -793,22 +789,11 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clipboard-win" -version = "4.5.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" +checksum = "12f9a0700e0127ba15d1d52dd742097f821cd9c65939303a44d970465040a297" dependencies = [ - "error-code 2.3.1", - "str-buf", - "winapi", -] - -[[package]] -name = "clipboard-win" -version = "5.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec832972fefb8cf9313b45a0d1945e29c9c251f1d4c6eafc5fe2124c02d2e81" -dependencies = [ - "error-code 3.0.0", + "error-code", ] [[package]] @@ -913,14 +898,14 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "core-graphics" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.5.0", "libc", ] @@ -946,9 +931,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if 1.0.0", ] @@ -1009,11 +994,10 @@ dependencies = [ [[package]] name = "csv-async" -version = "1.2.6" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71933d3f2d0481d5111cb2817b15b6961961458ec58adf8008194e6c850046f4" +checksum = "d37fe5b0d07f4a8260ce1e9a81413e88f459af0f2dfc55c15e96868a2f99c0f0" dependencies = [ - "bstr", "cfg-if 1.0.0", "csv-core", "futures", @@ -1077,7 +1061,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1102,12 +1086,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" +checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955" dependencies = [ - "darling_core 0.20.5", - "darling_macro 0.20.5", + "darling_core 0.20.6", + "darling_macro 0.20.6", ] [[package]] @@ -1140,16 +1124,16 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" +checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855" dependencies = [ "fnv", "ident_case", "proc-macro2 1.0.78", "quote 1.0.35", "strsim 0.10.0", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1176,13 +1160,13 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" +checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" dependencies = [ - "darling_core 0.20.5", + "darling_core 0.20.6", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1323,7 +1307,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1367,9 +1351,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "elliptic-curve" @@ -1422,16 +1406,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "error-code" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" -dependencies = [ - "libc", - "str-buf", -] - [[package]] name = "error-code" version = "3.0.0" @@ -1465,16 +1439,6 @@ dependencies = [ "uint", ] -[[package]] -name = "expectrl" -version = "0.7.1" -dependencies = [ - "conpty", - "nix 0.26.4", - "ptyprocess", - "regex", -] - [[package]] name = "fancy-regex" version = "0.11.0" @@ -1637,7 +1601,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared 0.3.1", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.50", ] [[package]] @@ -1646,6 +1631,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1730,7 +1721,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -1776,12 +1767,12 @@ dependencies = [ [[package]] name = "gethostname" -version = "0.3.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb65d4ba3173c56a500b555b532f72c42e8d1fe64962b518897f8959fae2c177" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" dependencies = [ "libc", - "winapi", + "windows-targets 0.48.5", ] [[package]] @@ -1836,7 +1827,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.11", - "indexmap 2.2.2", + "indexmap 2.2.3", "slab", "tokio", "tokio-util", @@ -1855,7 +1846,7 @@ dependencies = [ "futures-sink", "futures-util", "http 1.0.0", - "indexmap 2.2.2", + "indexmap 2.2.3", "slab", "tokio", "tokio-util", @@ -1910,9 +1901,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" +checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" [[package]] name = "hex" @@ -2050,9 +2041,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" dependencies = [ "bytes", "futures-channel", @@ -2064,6 +2055,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", + "smallvec", "tokio", ] @@ -2104,7 +2096,7 @@ dependencies = [ "futures-util", "http 1.0.0", "http-body 1.0.0", - "hyper 1.1.0", + "hyper 1.2.0", "pin-project-lite", "socket2", "tokio", @@ -2162,7 +2154,7 @@ dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", "strsim 0.10.0", - "syn 2.0.48", + "syn 2.0.50", "unic-langid", ] @@ -2176,7 +2168,7 @@ dependencies = [ "i18n-config", "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2283,9 +2275,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" dependencies = [ "equivalent", "hashbrown 0.14.3", @@ -2436,7 +2428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5e25f9b861a88faa9d272ca4376e1a13c9a37d36de623f013c7bbb0ae2baa1" dependencies = [ "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2543,7 +2535,7 @@ dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", "regex-syntax 0.8.2", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2754,9 +2746,9 @@ dependencies = [ [[package]] name = "num_threads" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" dependencies = [ "libc", ] @@ -2813,13 +2805,13 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.63" +version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ "bitflags 2.4.2", "cfg-if 1.0.0", - "foreign-types", + "foreign-types 0.3.2", "libc", "once_cell", "openssl-macros", @@ -2834,7 +2826,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2845,9 +2837,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.99" +version = "0.9.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +checksum = "ae94056a791d0e1217d18b6cbdccb02c61e3054fc69893607f4067e3bb0b1fd1" dependencies = [ "cc", "libc", @@ -2877,7 +2869,7 @@ dependencies = [ "proc-macro2 1.0.78", "proc-macro2-diagnostics", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -2995,7 +2987,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3022,9 +3014,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platforms" @@ -3039,7 +3031,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5699cc8a63d1aa2b1ee8e12b9ad70ac790d65788cd36101fa37f87ea46c4cef" dependencies = [ "base64", - "indexmap 2.2.2", + "indexmap 2.2.3", "line-wrap", "quick-xml", "serde", @@ -3048,9 +3040,9 @@ dependencies = [ [[package]] name = "png" -version = "0.17.11" +version = "0.17.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f6c3c3e617595665b8ea2ff95a86066be38fb121ff920a9c0eb282abcd1da5a" +checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -3196,7 +3188,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", "version_check", "yansi 1.0.0-rc.1", ] @@ -3423,16 +3415,17 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.7" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if 1.0.0", "getrandom", "libc", "spin", "untrusted", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3474,7 +3467,7 @@ dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", "rust-embed-utils", - "syn 2.0.48", + "syn 2.0.50", "walkdir", ] @@ -3575,7 +3568,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" dependencies = [ "openssl-probe", - "rustls-pemfile 2.0.0", + "rustls-pemfile 2.1.0", "rustls-pki-types", "schannel", "security-framework", @@ -3592,9 +3585,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e4980fa29e4c4b212ffb3db068a564cbf560e51d3944b7c88bd8bf5bec64f4" +checksum = "3c333bb734fcdedcea57de1602543590f545f127dc8b533324318fd492c5c70b" dependencies = [ "base64", "rustls-pki-types", @@ -3602,9 +3595,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a716eb65e3158e90e17cd93d855216e27bde02745ab842f2cab4a39dba1bacf" +checksum = "048a63e5b3ac996d78d402940b5fa47973d2d080c6c6fffa1d0f19c4445310b7" [[package]] name = "rustls-webpki" @@ -3641,7 +3634,7 @@ checksum = "02a2d683a4ac90aeef5b1013933f6d977bd37d51ff3f4dad829d4931a7e6be86" dependencies = [ "bitflags 2.4.2", "cfg-if 1.0.0", - "clipboard-win 5.1.0", + "clipboard-win", "fd-lock", "home", "libc", @@ -3663,14 +3656,14 @@ checksum = "e5af959c8bf6af1aff6d2b463a57f71aae53d1332da58419e30ad8dc7011d951" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "safemem" @@ -3812,38 +3805,38 @@ checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba" [[package]] name = "semver" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", @@ -3891,7 +3884,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.2.2", + "indexmap 2.2.3", "serde", "serde_derive", "serde_json", @@ -3905,10 +3898,10 @@ version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "865f9743393e638991566a8b7a479043c2c8da94a33e0a31f18214c9cae0a64d" dependencies = [ - "darling 0.20.5", + "darling 0.20.6", "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -3933,7 +3926,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -4080,7 +4073,7 @@ dependencies = [ name = "sos" version = "0.10.1" dependencies = [ - "anticipate-core", + "anticipate-runner", "anyhow", "arboard", "async-recursion", @@ -4154,7 +4147,7 @@ dependencies = [ "futures", "hex", "http 1.0.0", - "indexmap 2.2.2", + "indexmap 2.2.3", "once_cell", "parking_lot", "rand", @@ -4212,7 +4205,7 @@ dependencies = [ "getrandom", "hex", "http 1.0.0", - "indexmap 2.2.2", + "indexmap 2.2.3", "k256", "keychain_parser", "mime_guess", @@ -4329,12 +4322,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "str-buf" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" - [[package]] name = "strsim" version = "0.10.0" @@ -4377,9 +4364,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", @@ -4464,9 +4451,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ "smawk", "terminal_size 0.2.6", @@ -4476,22 +4463,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -4516,9 +4503,9 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" dependencies = [ "cfg-if 1.0.0", "once_cell", @@ -4629,7 +4616,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -4723,7 +4710,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.4", + "toml_edit 0.22.6", ] [[package]] @@ -4741,22 +4728,22 @@ version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" dependencies = [ - "indexmap 2.2.2", + "indexmap 2.2.3", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] name = "toml_edit" -version = "0.22.4" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9ffdf896f8daaabf9b66ba8e77ea1ed5ed0f72821b398aba62352e95062951" +checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6" dependencies = [ - "indexmap 2.2.2", + "indexmap 2.2.3", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.2", ] [[package]] @@ -4842,7 +4829,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -4998,9 +4985,9 @@ checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] @@ -5095,7 +5082,7 @@ version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "272ebdfbc99111033031d2f10e018836056e4d2c8e2acda76450ec7974269fa7" dependencies = [ - "indexmap 2.2.2", + "indexmap 2.2.3", "serde", "serde_json", "utoipa-gen", @@ -5110,7 +5097,7 @@ dependencies = [ "proc-macro-error", "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", "uuid", ] @@ -5237,7 +5224,7 @@ dependencies = [ "once_cell", "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", "wasm-bindgen-shared", ] @@ -5271,7 +5258,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5304,7 +5291,7 @@ checksum = "a5211b7550606857312bba1d978a8ec75692eae187becc5e680444fffc5e6f89" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -5415,15 +5402,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "winapi-wsapoll" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -5648,9 +5626,18 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.39" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5389a154b01683d28c77f8f68f49dea75f0a4da32557a58f68ee51ebba472d29" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "winnow" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178" dependencies = [ "memchr", ] @@ -5676,25 +5663,20 @@ dependencies = [ [[package]] name = "x11rb" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" +checksum = "f8f25ead8c7e4cba123243a6367da5d3990e0d3affa708ea19dce96356bd9f1a" dependencies = [ "gethostname", - "nix 0.26.4", - "winapi", - "winapi-wsapoll", + "rustix 0.38.31", "x11rb-protocol", ] [[package]] name = "x11rb-protocol" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82d6c3f9a0fb6701fab8f6cea9b0c0bd5d6876f1f89f7fada07e558077c344bc" -dependencies = [ - "nix 0.26.4", -] +checksum = "e63e71c4b8bd9ffec2c963173a4dc4cbde9ee96961d4fcb4429db9929b606c34" [[package]] name = "x25519-dalek" @@ -5743,7 +5725,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] @@ -5763,7 +5745,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2 1.0.78", "quote 1.0.35", - "syn 2.0.48", + "syn 2.0.50", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 73d2b56d5a..0a67065b93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,7 +116,7 @@ copy_dir = "0.1" maplit2 = "1" sos_test_utils = { path = "workspace/test_utils" } pretty_assertions = "1.4" -anticipate-core = { path = "../../anticipate/core" } +anticipate-runner = { version = "0.4", path = "../../anticipate/runner" } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3" diff --git a/Makefile.toml b/Makefile.toml index ca78413d4a..092705dbda 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -138,12 +138,12 @@ dependencies = ["clean-cli"] [tasks.test] command = "cargo" -args = ["test", "--features", "enable-cli-tests"] +args = ["test", "--all", "--features", "enable-cli-tests"] dependencies = ["clean-cli"] [tasks.test-lite] command = "cargo" -args = ["test"] +args = ["test", "--all"] dependencies = ["clean-cli"] [tasks.dev] @@ -206,7 +206,6 @@ command = "cargo" args = ["clean", "--target-dir", "target/cover"] [tasks.cover] -env = { "COVER" = "1" } dependencies = [ "clean-cli", "clean-cover", diff --git a/TEST.md b/TEST.md index 18c7ead0df..5ba79c917c 100644 --- a/TEST.md +++ b/TEST.md @@ -6,6 +6,18 @@ Run all the tests. cargo make test ``` +To skip integration tests and just run unit tests: + +``` +cargo make unit +``` + +To generate a code coverage report in `target/coverage` run: + +``` +cargo make cover +``` + The CLI test specs can take a long time with the debug build so if you want to skip them use: ``` diff --git a/coverage.toml b/coverage.toml index 4e4e937f1d..7bd2013514 100644 --- a/coverage.toml +++ b/coverage.toml @@ -43,6 +43,7 @@ command = "cargo" args = ["build"] [tasks.coverage_grcov_build_stable.env] +"COVER"="1" "CARGO_BUILD_TARGET_DIR"="${COVERAGE_TARGET_DIRECTORY}" "RUSTFLAGS"= "-Cinstrument-coverage -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off" "RUSTDOCFLAGS"="-Cpanic=abort" @@ -54,7 +55,7 @@ command = "cargo" args = ["test", "--all", "--features", "enable-cli-tests", "--", "--nocapture"] [tasks.coverage_grcov_run_test_stable.env] -"COVERAGE" = "1" +"COVER" = "1" "CARGO_BUILD_TARGET_DIR"="${COVERAGE_TARGET_DIRECTORY}" "LLVM_PROFILE_FILE"="${COVERAGE_PROF_OUTPUT}/coverage-%p-%m.profraw" diff --git a/tests/command_line/main.rs b/tests/command_line/main.rs index 601d47c31b..c7a2c71099 100644 --- a/tests/command_line/main.rs +++ b/tests/command_line/main.rs @@ -1,6 +1,6 @@ #[cfg(feature = "enable-cli-tests")] mod cli { - use anticipate_core::{InterpreterOptions, ScriptFile}; + use anticipate_runner::{InterpreterOptions, ScriptFile}; use anyhow::Result; use std::{env::{set_var, var}, path::Path}; From 2481f6606c651e193b4aec7460e591f32a4bd45e Mon Sep 17 00:00:00 2001 From: muji Date: Thu, 22 Feb 2024 09:05:53 +0800 Subject: [PATCH 17/17] Use published version of anticipate-runner. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0a67065b93..091fe2fc51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,7 +116,7 @@ copy_dir = "0.1" maplit2 = "1" sos_test_utils = { path = "workspace/test_utils" } pretty_assertions = "1.4" -anticipate-runner = { version = "0.4", path = "../../anticipate/runner" } +anticipate-runner = { version = "0.4" } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3"