commit 0835b9c3af3c45c9b7553a6798254be6a6c87b05
parent 7b7f7d3f0c9deb34513dd90a08ecfeb2d2245d56
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Sat, 2 Nov 2024 09:28:12 +0000
Insert command is fully covered by integrated suites
Diffstat:
2 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh
@@ -143,6 +143,7 @@ Describe 'Integrated Command Functions'
diff() { @diff "$@"; }
dirname() { @dirname "$@"; }
git() { @git "$@"; }
+ head() { @head "$@"; }
mkdir() { @mkdir "$@"; }
mktemp() { @mktemp "$@"; }
mv() { @mv "$@"; }
@@ -575,7 +576,81 @@ Describe 'Integrated Command Functions'
End
End
-# Describe 'cmd_insert'
+ Describe 'cmd_insert'
+ ECHO=no
+ MULTILINE=no
+ OVERWRITE=no
+
+ It 'inserts a new single-line entry on the second try'
+ stty() { :; }
+ Data
+ #|first try
+ #|First Try
+ #|pass-word
+ #|pass-word
+ End
+ When call cmd_insert newdir/newpass
+ The status should be success
+ The error should be blank
+ expected_out() { %text | @sed 's/\$$//'
+ #|Enter password for newdir/newpass: $
+ #|Retype password for newdir/newpass: $
+ #|Passwords don't match$
+ #|Enter password for newdir/newpass: $
+ #|Retype password for newdir/newpass: $
+ }
+ The output should equal "$(expected_out)"
+ The contents of file "${PREFIX}/newdir/newpass.age" \
+ should include "age:pass-word"
+ expected_log() { %text
+ #|Add given password for newdir/newpass to store.
+ #|
+ #| newdir/newpass.age | 2 ++
+ #| 1 file changed, 2 insertions(+)
+ setup_log
+ }
+ The result of function check_git_log should be successful
+ End
+
+ It 'overwrites an entry after confirmation'
+ Data
+ #|y
+ #|pass-word
+ End
+ When call cmd_insert -e subdir/file
+ The status should be success
+ The error should be blank
+ The output should equal 'An entry already exists for subdir/file. Overwrite it? [y/n]Enter password for subdir/file: '
+ expected_file() { %text
+ #|ageRecipient:myself
+ #|age:pass-word
+ }
+ The contents of file "${PREFIX}/subdir/file.age" \
+ should equal "$(expected_file)"
+ expected_log() { %text
+ #|Add given password for subdir/file to store.
+ #|
+ #| subdir/file.age | 2 +-
+ #| 1 file changed, 1 insertion(+), 1 deletion(-)
+ setup_log
+ }
+ The result of function check_git_log should be successful
+ End
+
+ It 'does not overwrite an entry without confirmation'
+ Data
+ #|n
+ #|pass-word
+ End
+ When call cmd_insert -e subdir/file
+ The status should be success
+ The error should be blank
+ The output should equal \
+ 'An entry already exists for subdir/file. Overwrite it? [y/n]'
+ The result of function check_git_log should be successful
+ End
+ End
+
# Describe 'cmd_list_or_show'
# Describe 'cmd_move' is not needed (covered by 'cmd_copy_move')
# Describe 'cmd_random'
diff --git a/spec/pass_spec.sh b/spec/pass_spec.sh
@@ -883,6 +883,9 @@ Describe 'Pass-like command'
It 'inserts a new single-line entry'
Skip if 'pass(age) needs bash' check_skip $2
+ Mock stty
+ true
+ End
Data
#|pass-word
#|pass-word
@@ -1030,6 +1033,17 @@ Describe 'Pass-like command'
The contents of file "${GITLOG}" should equal "$(setup_log)"
End
+ It 'displays usage when called with incompatible arguments'
+ Skip if 'pass(age) needs bash' check_skip $2
+ When run script $1 insert -em new-secret
+ The status should equal 1
+ The output should be blank
+ The error should include 'Usage:'
+ The error should include ' insert '
+ The result of function git_log should be successful
+ The contents of file "${GITLOG}" should equal "$(setup_log)"
+ End
+
It 'rejects a path containing ..'
Skip if 'pass(age) needs bash' check_skip $2
When run script $1 insert -e fluff/../new-secret