pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

commit 1d0d271068393c496f50738933fe6fe0debce0c1
parent 1882454319df0a4f6b2d53c4baa47a572558eae4
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Fri, 15 Nov 2024 19:37:14 +0000

Password character set argument in generate command
Diffstat:
MREADME.md | 3+++
Mspec/pashage_extra_spec.sh | 20++++++++++++++++++++
Mspec/usage_spec.sh | 19++++++++++++++++++-
Msrc/pashage.sh | 7++++---
4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -78,6 +78,9 @@ passwords. - The commands `copy` and `move` have new flags to control re-encryption (always, never, ask for each file). +- The `generate` command has a new command-line argument to specify +explicitly the character set. + - The `init` command has new flags to control re-encryption (never or ask for each file). diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh @@ -616,6 +616,26 @@ Describe 'Integrated Command Functions' OVERWRITE=no SHOW=text + It 'uses the character set given explicitly instead of environment' + CHARACTER_SET='[0-9]' + CHARACTER_SET_NO_SYMBOLS='[0-9]' + When call cmd_generate new 5 '[:upper:]' + The status should be success + The error should be blank + The lines of output should equal 2 + The line 1 of output should \ + equal '(B)The generated password for (U)new(!U) is:(N)' + The line 2 of output should match pattern '[A-Z][A-Z][A-Z][A-Z][A-Z]' + expected_log() { %text + #|Add generated password for new. + #| + #| new.age | 2 ++ + #| 1 file changed, 2 insertions(+) + setup_log + } + The result of function check_git_log should be successful + End + It 'overwrites after asking for confirmation' Data 'y' When call cmd_generate subdir/file 10 diff --git a/spec/usage_spec.sh b/spec/usage_spec.sh @@ -626,7 +626,8 @@ Describe 'Command-Line Parsing' usage_text() { %text #|Usage: prg generate [--no-symbols,-n] [--clip,-c | --qrcode,-q] - #| [--in-place,-i | --force,-f] pass-name [pass-length] + #| [--in-place,-i | --force,-f] + #| pass-name [pass-length [character-set]] } It 'generates a new entry with default length' @@ -661,6 +662,22 @@ Describe 'Command-Line Parsing' The error should equal "$(result)" End + It 'generates a new entry with explicit length and character set' + result() { + %text + #|$ check_sneaky_path secret + #|$ do_generate secret 12 [A-Z] + #|DECISION=default + #|OVERWRITE=no + #|SELECTED_LINE=1 + #|SHOW=text + } + When call cmd_generate secret 12 '[A-Z]' + The status should be success + The output should be blank + The error should equal "$(result)" + End + It 'generates a new flag-like entry' result() { %text diff --git a/src/pashage.sh b/src/pashage.sh @@ -1243,7 +1243,7 @@ cmd_generate() { esac done - if [ "${PARSE_ERROR}" = yes ] || [ $# -eq 0 ] || [ $# -gt 2 ] \ + if [ "${PARSE_ERROR}" = yes ] || [ $# -eq 0 ] || [ $# -gt 3 ] \ || [ "${DECISION}-${OVERWRITE}" = force-yes ] then cmd_usage 'Usage: ' generate >&2 @@ -1259,7 +1259,7 @@ cmd_generate() { [ "${LENGTH}" -gt 0 ] \ || die "Error: pass-length must be greater than zero." - do_generate "$1" "${LENGTH}" "${CHARSET}" + do_generate "$1" "${LENGTH}" "${3:-${CHARSET}}" unset CHARSET unset LENGTH @@ -1666,7 +1666,8 @@ EOF generate) cat <<EOF ${F}${PROGRAM} generate [--no-symbols,-n] [--clip,-c | --qrcode,-q] -${I}${BLANKPG} [--in-place,-i | --force,-f] pass-name [pass-length] +${I}${BLANKPG} [--in-place,-i | --force,-f] +${I}${BLANKPG} pass-name [pass-length [character-set]] EOF [ "${VERBOSE}" = yes ] && cat <<EOF ${I} Generate a new password of pass-length (or ${GENERATED_LENGTH:-25} if unspecified)