├── tests ├── gnupg │ ├── .gpg-v21-migrated │ ├── pubring.gpg │ ├── secring.gpg │ ├── trustdb.gpg │ ├── gpg.conf │ └── private-keys-v1.d │ │ ├── 0606FE40527B8F47BFD30238709F895642EEF303.key │ │ ├── 06278846A35FE4416E8701DDCF6B60E93F8BCB63.key │ │ ├── 615FC2A5B2CBFD58B7FFA0A140D43B74AB9748B0.key │ │ ├── 63D607EC5C89163B473708E7B3E5115301CF06E4.key │ │ ├── A5CEE9554AA7090ADD97D97E0DA902764E6C2111.key │ │ ├── AD20D0B45D263DD5AE866FDB98E04A0D20070F68.key │ │ ├── C93858C40FA9E117DA4E7F336580B8B12354EB83.key │ │ ├── C93F70CA322D4F42E7FC7D54F6367E65C23E5CA3.key │ │ ├── CDA6EE91E62A15AB9F6A3041FE01CC123B7E9D23.key │ │ └── FFED3C5A6A52B200BCCE3F41593EA51D6054649F.key ├── .gitignore ├── pass-code.sh ├── t0000-skeleton.sh ├── t9999-code-test.sh ├── t0100-insert-tests.sh ├── t2400-code-edit.sh ├── t0200-edit-tests.sh ├── t0001-sanity-checks.sh ├── t0020-show-tests.sh ├── t2600-code-rm.sh ├── t0500-find.sh ├── t0010-generate-tests.sh ├── t2300-code-generate.sh ├── t0400-grep.sh ├── t0060-rm-tests.sh ├── fake-editor-change-password.sh ├── t2500-code-mv-cp.sh ├── t2001-code-ls.sh ├── aggregate-results.sh ├── Makefile ├── t0050-mv-tests.sh ├── t2100-code-show-manual.sh ├── setup.sh ├── t2200-code-insert-manual.sh ├── t2000-code-ls-manual.sh ├── t0300-reencryption.sh └── sharness.sh ├── Makefile ├── DESIGN.rst ├── README.rst ├── code.bash └── LICENSE /tests/gnupg/.gpg-v21-migrated: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | /gnupg/random_seed 2 | /trash directory* 3 | /test-results 4 | /.prove 5 | -------------------------------------------------------------------------------- /tests/gnupg/pubring.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/pubring.gpg -------------------------------------------------------------------------------- /tests/gnupg/secring.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/secring.gpg -------------------------------------------------------------------------------- /tests/gnupg/trustdb.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/trustdb.gpg -------------------------------------------------------------------------------- /tests/pass-code.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # Simple redirection to pass-code extension 4 | pass code "$@" 5 | -------------------------------------------------------------------------------- /tests/gnupg/gpg.conf: -------------------------------------------------------------------------------- 1 | group group1 = E4691410 D774A374 2 | group group2 = E4691410 3 | group big group = CF90C77B D774A374 EB7D54A8 E4691410 39E5020C 4 | -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/0606FE40527B8F47BFD30238709F895642EEF303.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/0606FE40527B8F47BFD30238709F895642EEF303.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/06278846A35FE4416E8701DDCF6B60E93F8BCB63.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/06278846A35FE4416E8701DDCF6B60E93F8BCB63.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/615FC2A5B2CBFD58B7FFA0A140D43B74AB9748B0.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/615FC2A5B2CBFD58B7FFA0A140D43B74AB9748B0.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/63D607EC5C89163B473708E7B3E5115301CF06E4.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/63D607EC5C89163B473708E7B3E5115301CF06E4.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/A5CEE9554AA7090ADD97D97E0DA902764E6C2111.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/A5CEE9554AA7090ADD97D97E0DA902764E6C2111.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/AD20D0B45D263DD5AE866FDB98E04A0D20070F68.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/AD20D0B45D263DD5AE866FDB98E04A0D20070F68.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/C93858C40FA9E117DA4E7F336580B8B12354EB83.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/C93858C40FA9E117DA4E7F336580B8B12354EB83.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/C93F70CA322D4F42E7FC7D54F6367E65C23E5CA3.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/C93F70CA322D4F42E7FC7D54F6367E65C23E5CA3.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/CDA6EE91E62A15AB9F6A3041FE01CC123B7E9D23.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/CDA6EE91E62A15AB9F6A3041FE01CC123B7E9D23.key -------------------------------------------------------------------------------- /tests/gnupg/private-keys-v1.d/FFED3C5A6A52B200BCCE3F41593EA51D6054649F.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpernebbi/pass-code/HEAD/tests/gnupg/private-keys-v1.d/FFED3C5A6A52B200BCCE3F41593EA51D6054649F.key -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @echo "pass-code is a shell script, so there is nothing to do." 3 | 4 | test: 5 | $(MAKE) -C tests 6 | 7 | lint: 8 | shellcheck -s bash code.bash 9 | 10 | .PHONY: all test lint 11 | -------------------------------------------------------------------------------- /tests/t0000-skeleton.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code test skeleton' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'successful test example' ' 8 | "$PASS" --help || true 9 | ' 10 | 11 | test_done 12 | -------------------------------------------------------------------------------- /tests/t9999-code-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code internal testing' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'run pass-code internal tests' ' 8 | "$PASS" init $KEY1 && 9 | "$PASS" code test || test_pause 10 | ' 11 | 12 | test_done 13 | -------------------------------------------------------------------------------- /tests/t0100-insert-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Test insert' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Test "insert" command' ' 9 | "$PASS" init $KEY1 && 10 | echo "Hello world" | "$PASS" insert -e cred1 && 11 | [[ $("$PASS" show cred1) == "Hello world" ]] 12 | ' 13 | 14 | test_done 15 | -------------------------------------------------------------------------------- /tests/t2400-code-edit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code test skeleton' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'set up password store' ' 8 | "$PASS" init $KEY1 && 9 | "$PASS" code generate a 32 10 | ' 11 | 12 | test_expect_success 'pass-code edit password works' ' 13 | export FAKE_PASSWORD=".Gob<9sl)N[(~Xu2#DZV3v?CDt*2sM]w" && 14 | EDITOR=tee "$PASS" code edit a <<< "$FAKE_PASSWORD" && 15 | diff -U99 - <("$PASS" code show a) <<< "$FAKE_PASSWORD" 16 | ' 17 | 18 | test_done 19 | -------------------------------------------------------------------------------- /tests/t0200-edit-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Test edit' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Test "edit" command' ' 9 | "$PASS" init $KEY1 && 10 | "$PASS" generate cred1 90 && 11 | export FAKE_EDITOR_PASSWORD="big fat fake password" && 12 | export PATH="$TEST_HOME:$PATH" 13 | export EDITOR="fake-editor-change-password.sh" && 14 | "$PASS" edit cred1 && 15 | [[ $("$PASS" show cred1) == "$FAKE_EDITOR_PASSWORD" ]] 16 | ' 17 | 18 | test_done 19 | -------------------------------------------------------------------------------- /tests/t0001-sanity-checks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Sanity checks' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'Make sure we can run pass' ' 8 | "$PASS" --help | grep "pass: the standard unix password manager" 9 | ' 10 | 11 | test_expect_success 'Make sure we can initialize our test store' ' 12 | "$PASS" init $KEY1 && 13 | [[ -e "$PASSWORD_STORE_DIR/.gpg-id" ]] && 14 | [[ $(cat "$PASSWORD_STORE_DIR/.gpg-id") == "$KEY1" ]] 15 | ' 16 | 17 | test_expect_success 'Make sure pass-code can run' ' 18 | "$PASS" code version | grep "pass-code version" 19 | ' 20 | 21 | test_done 22 | -------------------------------------------------------------------------------- /tests/t0020-show-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Test show' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Test "show" command' ' 9 | "$PASS" init $KEY1 && 10 | "$PASS" generate cred1 20 && 11 | "$PASS" show cred1 12 | ' 13 | 14 | test_expect_success 'Test "show" command with spaces' ' 15 | "$PASS" insert -e "I am a cred with lots of spaces"<<<"BLAH!!" && 16 | [[ $("$PASS" show "I am a cred with lots of spaces") == "BLAH!!" ]] 17 | ' 18 | 19 | test_expect_success 'Test "show" of nonexistant password' ' 20 | test_must_fail "$PASS" show cred2 21 | ' 22 | 23 | test_done 24 | -------------------------------------------------------------------------------- /tests/t2600-code-rm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code rm tests' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'set up password-store' ' 8 | "$PASS" init $KEY1 9 | ' 10 | 11 | test_expect_success 'pass-code rm file works' ' 12 | "$PASS" code generate a && 13 | "$PASS" code rm a <<< "Y" && 14 | test_must_fail "$PASS" code show a 15 | ' 16 | 17 | test_expect_success 'pass-code rm folder requires --recursive' ' 18 | "$PASS" code generate b/1 && 19 | "$PASS" code generate b/2 && 20 | "$PASS" code generate b/3 && 21 | test_must_fail "$PASS" code rm b && 22 | "$PASS" code rm b --recursive && 23 | test_must_fail "$PASS" code show b/3 24 | ' 25 | 26 | test_done 27 | -------------------------------------------------------------------------------- /tests/t0500-find.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Find check' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Make sure find resolves correct files' ' 9 | "$PASS" init $KEY1 && 10 | "$PASS" generate Something/neat 19 && 11 | "$PASS" generate Anotherthing/okay 38 && 12 | "$PASS" generate Fish 12 && 13 | "$PASS" generate Fishthings 122 && 14 | "$PASS" generate Fishies/stuff 21 && 15 | "$PASS" generate Fishies/otherstuff 1234 && 16 | [[ $("$PASS" find fish | sed "s/^[ \`|-]*//g;s/$(printf \\x1b)\\[[0-9;]*[a-zA-Z]//g" | tr "\\n" -) == "Search Terms: fish-Fish-Fishies-otherstuff-stuff-Fishthings-" ]] 17 | ' 18 | 19 | test_done 20 | -------------------------------------------------------------------------------- /tests/t0010-generate-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Test generate' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Test "generate" command' ' 9 | "$PASS" init $KEY1 && 10 | "$PASS" generate cred 19 && 11 | [[ $("$PASS" show cred | wc -m) -eq 20 ]] 12 | ' 13 | 14 | test_expect_success 'Test replacement of first line' ' 15 | "$PASS" insert -m cred2 <<<"$(printf "this is a big\\npassword\\nwith\\nmany\\nlines\\nin it bla bla")" && 16 | "$PASS" generate -i cred2 23 && 17 | [[ $("$PASS" show cred2) == "$(printf "%s\\npassword\\nwith\\nmany\\nlines\\nin it bla bla" "$("$PASS" show cred2 | head -n 1)")" ]] 18 | ' 19 | 20 | test_done 21 | -------------------------------------------------------------------------------- /tests/t2300-code-generate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code generate tests' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'setup password store' ' 8 | "$PASS" init $KEY1 9 | ' 10 | 11 | test_expect_success 'pass-code generate' ' 12 | "$PASS" code generate alpha 32 13 | ' 14 | 15 | test_expect_success 'pass-code generate --force' ' 16 | "$PASS" code generate --force alpha 32 17 | ' 18 | 19 | test_expect_success 'pass-code generated password has correct length' ' 20 | password=$("$PASS" code show alpha) && 21 | [[ "${#password}" -eq 32 ]] 22 | ' 23 | 24 | test_expect_success 'pass-code generate encodes filename' ' 25 | test_must_fail "$PASS" ls alpha 26 | ' 27 | 28 | test_done 29 | -------------------------------------------------------------------------------- /tests/t0400-grep.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Grep check' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Make sure grep prints normal lines' ' 9 | "$PASS" init $KEY1 && 10 | "$PASS" insert -e blah1 <<<"hello" && 11 | "$PASS" insert -e blah2 <<<"my name is" && 12 | "$PASS" insert -e folder/blah3 <<<"I hate computers" && 13 | "$PASS" insert -e blah4 <<<"me too!" && 14 | "$PASS" insert -e folder/where/blah5 <<<"They are hell" && 15 | results="$("$PASS" grep hell)" && 16 | [[ $(wc -l <<<"$results") -eq 4 ]] && 17 | grep -q blah5 <<<"$results" && 18 | grep -q blah1 <<<"$results" && 19 | grep -q "They are" <<<"$results" 20 | ' 21 | 22 | test_done 23 | -------------------------------------------------------------------------------- /tests/t0060-rm-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Test rm' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | test_expect_success 'Test "rm" command' ' 9 | "$PASS" init $KEY1 && 10 | "$PASS" generate cred1 43 && 11 | "$PASS" rm cred1 && 12 | test_must_fail "$PASS" show cred1 13 | ' 14 | 15 | test_expect_success 'Test "rm" command with spaces' ' 16 | "$PASS" generate "hello i have spaces" 43 && 17 | "$PASS" show "hello i have spaces" && 18 | "$PASS" rm "hello i have spaces" && 19 | test_must_fail "$PASS" show "hello i have spaces" 20 | ' 21 | 22 | test_expect_success 'Test "rm" of non-existent password' ' 23 | test_must_fail "$PASS" rm does-not-exist 24 | ' 25 | 26 | test_done 27 | -------------------------------------------------------------------------------- /tests/fake-editor-change-password.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fake editor program for testing 'pass edit'. 3 | # Changes password to 'Hello World', leaving rest of file intact. 4 | # 5 | # Intended use: 6 | # export FAKE_EDITOR_PASSWORD="blah blah blah" 7 | # export EDITOR=fake-editor-change-password.sh 8 | # $EDITOR 9 | # 10 | # Arguments: 11 | # Returns: 0 on success, 1 on error 12 | 13 | if [[ $# -ne 1 ]]; then 14 | echo "Usage: $0 " 15 | exit 1 16 | fi 17 | 18 | filename=$1 ; shift ; 19 | new_password="${FAKE_EDITOR_PASSWORD:-Hello World}" 20 | 21 | # And change only first line of file 22 | # -i.tmp allows editing file in place. Extension needed on Mac OSX 23 | sed -i.tmp "1 s/^.*\$/$new_password/g" "$filename" 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /tests/t2500-code-mv-cp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code mv and pass-code cp tests' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'set up password-store' ' 8 | "$PASS" init $KEY1 && 9 | "$PASS" code generate a 10 | ' 11 | 12 | test_expect_success 'pass-code mv moves files around' ' 13 | "$PASS" code mv a b && 14 | test_must_fail "$PASS" code show a && 15 | "$PASS" code show b 16 | ' 17 | 18 | test_expect_success 'pass-code cp results in identical content' ' 19 | "$PASS" code generate a 32 && 20 | "$PASS" code cp --force a b && 21 | diff -U99 <("$PASS" code show a) <("$PASS" code show b) 22 | ' 23 | 24 | test_expect_success 'pass-code cp filenames are still encoded' ' 25 | test_must_fail "$PASS" show a 26 | test_must_fail "$PASS" show b 27 | ' 28 | 29 | test_expect_success 'pass-code mv force with files' ' 30 | "$PASS" code mv b a --force && 31 | test_must_fail "$PASS" code show b 32 | ' 33 | 34 | test_done 35 | -------------------------------------------------------------------------------- /tests/t2001-code-ls.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code ls tests' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'setup password store' ' 8 | "$PASS" init $KEY1 9 | ' 10 | 11 | remove_colors() { sed -e "s/\x1B\[[0-9;]*m//g"; } 12 | 13 | test_expect_success 'pass-code ls file with spaces' ' 14 | "$PASS" code generate "a long name with spaces" && 15 | diff -U99 - \ 16 | <("$PASS" code ls | remove_colors) \ 17 | <<- "_EOF_" 18 | Password Store 19 | `-- a long name with spaces 20 | _EOF_ 21 | ' 22 | 23 | test_expect_success 'pass-code ls directory with spaces' ' 24 | "$PASS" code generate "a long dir with spaces"/"other file" && 25 | diff -U99 - \ 26 | <("$PASS" code ls | remove_colors) \ 27 | <<- "_EOF_" 28 | Password Store 29 | |-- a long dir with spaces 30 | | `-- other file 31 | `-- a long name with spaces 32 | _EOF_ 33 | ' 34 | 35 | test_expect_success 'pass-code ls more folders with spaces' ' 36 | "$PASS" code generate "dir a/dir b/dir c/cred c" && 37 | "$PASS" code generate "dir a/dir b/dir d/cred d" && 38 | diff -U99 - \ 39 | <("$PASS" code ls | remove_colors) \ 40 | <<- "_EOF_" 41 | Password Store 42 | |-- a long dir with spaces 43 | | `-- other file 44 | |-- a long name with spaces 45 | `-- dir a 46 | `-- dir b 47 | |-- dir c 48 | | `-- cred c 49 | `-- dir d 50 | `-- cred d 51 | _EOF_ 52 | ' 53 | 54 | test_expect_success 'pass-code ls subfolders with spaces' ' 55 | diff -U99 - \ 56 | <("$PASS" code ls "dir a/dir b" | remove_colors) \ 57 | <<- "_EOF_" 58 | dir a/dir b 59 | |-- dir c 60 | | `-- cred c 61 | `-- dir d 62 | `-- cred d 63 | _EOF_ 64 | ' 65 | 66 | test_done 67 | -------------------------------------------------------------------------------- /tests/aggregate-results.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2008-2012 Git project 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see http://www.gnu.org/licenses/ . 17 | 18 | failed_tests= 19 | fixed=0 20 | success=0 21 | failed=0 22 | broken=0 23 | total=0 24 | 25 | while read file; do 26 | while read type value; do 27 | case $type in 28 | '') 29 | continue ;; 30 | fixed) 31 | fixed=$(($fixed + $value)) ;; 32 | success) 33 | success=$(($success + $value)) ;; 34 | failed) 35 | failed=$(($failed + $value)) 36 | if test $value != 0; then 37 | test_name=$(expr "$file" : 'test-results/\(.*\)\.[0-9]*\.counts') 38 | failed_tests="$failed_tests $test_name" 39 | fi 40 | ;; 41 | broken) 42 | broken=$(($broken + $value)) ;; 43 | total) 44 | total=$(($total + $value)) ;; 45 | esac 46 | done <"$file" 47 | done 48 | 49 | if test -n "$failed_tests"; then 50 | printf "\nfailed test(s):$failed_tests\n\n" 51 | fi 52 | 53 | printf "%-8s%d\n" fixed $fixed 54 | printf "%-8s%d\n" success $success 55 | printf "%-8s%d\n" failed $failed 56 | printf "%-8s%d\n" broken $broken 57 | printf "%-8s%d\n" total $total 58 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | # Run tests 2 | # 3 | # Copyright (c) 2011-2012 Mathias Lafeldt 4 | # Copyright (c) 2005-2012 Git project 5 | # Copyright (c) 2005-2012 Junio C Hamano 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see http://www.gnu.org/licenses/ . 19 | 20 | SHELL := $(shell which bash) 21 | SHELL_PATH ?= $(SHELL) 22 | SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) 23 | RM ?= rm -f 24 | PROVE ?= prove 25 | AGGREGATE_SCRIPT ?= aggregate-results.sh 26 | DEFAULT_TEST_TARGET ?= test 27 | 28 | T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) 29 | 30 | all: $(DEFAULT_TEST_TARGET) 31 | 32 | test: pre-clean 33 | $(MAKE) aggregate-results-and-cleanup 34 | 35 | prove: pre-clean 36 | @echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(PROVE_OPTS) $(T) :: $(TEST_OPTS) 37 | $(MAKE) clean-except-prove-cache 38 | 39 | $(T): 40 | @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(TEST_OPTS) 41 | 42 | pre-clean: 43 | $(RM) -r test-results 44 | 45 | clean-except-prove-cache: 46 | $(RM) -r 'trash directory'.* test-results 47 | 48 | clean: clean-except-prove-cache 49 | $(RM) .prove 50 | 51 | aggregate-results-and-cleanup: $(T) 52 | $(MAKE) aggregate-results 53 | $(MAKE) clean 54 | 55 | aggregate-results: 56 | for f in test-results/*.counts; do \ 57 | echo "$$f"; \ 58 | done | '$(SHELL_PATH_SQ)' '$(AGGREGATE_SCRIPT)' 59 | 60 | .PHONY: all test prove $(T) pre-clean clean 61 | .PHONY: aggregate-results-and-cleanup aggregate-results 62 | -------------------------------------------------------------------------------- /tests/t0050-mv-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Test mv command' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | INITIAL_PASSWORD="bla bla bla will we make it!!" 9 | 10 | test_expect_success 'Basic move command' ' 11 | "$PASS" init $KEY1 && 12 | "$PASS" git init && 13 | "$PASS" insert -e cred1 <<<"$INITIAL_PASSWORD" && 14 | "$PASS" mv cred1 cred2 && 15 | test_must_fail "$PASS" show cred1 && 16 | "$PASS" show cred2 17 | ' 18 | 19 | test_expect_success 'Directory creation' ' 20 | "$PASS" mv cred2 directory/ && 21 | test_must_fail "$PASS" show cred2 && 22 | "$PASS" show directory/cred2 23 | ' 24 | 25 | test_expect_success 'Directory creation with file rename and empty directory removal' ' 26 | "$PASS" mv directory/cred2 "new directory with spaces"/cred && 27 | test_must_fail "$PASS" show directory/cred2 && 28 | "$PASS" show "new directory with spaces"/cred 29 | ' 30 | 31 | test_expect_success 'Directory rename' ' 32 | "$PASS" mv "new directory with spaces" anotherdirectory && 33 | test_must_fail "$PASS" show "new directory with spaces"/cred && 34 | "$PASS" show anotherdirectory/cred 35 | ' 36 | 37 | test_expect_success 'Directory move into new directory' ' 38 | "$PASS" mv anotherdirectory "new directory with spaces"/ && 39 | test_must_fail "$PASS" show anotherdirectory/cred && 40 | "$PASS" show "new directory with spaces"/anotherdirectory/cred 41 | ' 42 | 43 | test_expect_success 'Multi-directory creation and multi-directory empty removal' ' 44 | "$PASS" mv "new directory with spaces"/anotherdirectory/cred new1/new2/new3/new4/thecred && 45 | "$PASS" mv new1/new2/new3/new4/thecred cred && 46 | test_must_fail "$PASS" show "new directory with spaces"/anotherdirectory/cred && 47 | test_must_fail "$PASS" show new1/new2/new3/new4/thecred && 48 | "$PASS" show cred 49 | ' 50 | 51 | test_expect_success 'Password made it until the end' ' 52 | [[ $("$PASS" show cred) == "$INITIAL_PASSWORD" ]] 53 | ' 54 | 55 | test_expect_success 'Git is consistent' ' 56 | [[ -z $(git status --porcelain 2>&1) ]] 57 | ' 58 | 59 | test_done 60 | -------------------------------------------------------------------------------- /tests/t2100-code-show-manual.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code show with manually written .passcode' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'setup .passcode.gpg manually' ' 8 | "$PASS" init $KEY1 9 | "$PASS" insert --multiline .passcode <<- "_EOF_" >/dev/null 10 | puap5y6t5nq6r75v:a/a/a/a 11 | niozt3shbhobwjit:a/a/b 12 | 6qjue4yxea7a2bfy:a/b/a 13 | frp6mxk35daczom6:a/c 14 | na6afjbulshsnket:b/a 15 | aksqm5aw4lbn5fmp:d/d/a 16 | jlkgltkeh5pmfogs:d/d/b 17 | s3bhz3rmtjo5ugai:d/d/c 18 | dz4bbay7a55q65ie:e/f 19 | r3orhjgnwrixi6gg:g 20 | _EOF_ 21 | ' 22 | 23 | test_expect_success 'setup encoded filenames' ' 24 | "$PASS" insert --echo puap5y6t5nq6r75v <<< "a/a/a/a" 25 | "$PASS" insert --echo niozt3shbhobwjit <<< "a/a/b" 26 | "$PASS" insert --echo 6qjue4yxea7a2bfy <<< "a/b/a" 27 | "$PASS" insert --echo frp6mxk35daczom6 <<< "a/c" 28 | "$PASS" insert --echo na6afjbulshsnket <<< "b/a" 29 | "$PASS" insert --echo aksqm5aw4lbn5fmp <<< "d/d/a" 30 | "$PASS" insert --echo jlkgltkeh5pmfogs <<< "d/d/b" 31 | "$PASS" insert --echo s3bhz3rmtjo5ugai <<< "d/d/c" 32 | "$PASS" insert --echo dz4bbay7a55q65ie <<< "e/f" 33 | "$PASS" insert --echo r3orhjgnwrixi6gg <<< "g" 34 | ' 35 | 36 | 37 | test_expect_success 'pass code show output matches pass show output' ' 38 | diff -U99 \ 39 | <("$PASS" show puap5y6t5nq6r75v) \ 40 | <("$PASS" code show a/a/a/a) && 41 | diff -U99 \ 42 | <("$PASS" show niozt3shbhobwjit) \ 43 | <("$PASS" code show a/a/b) && 44 | diff -U99 \ 45 | <("$PASS" show 6qjue4yxea7a2bfy) \ 46 | <("$PASS" code show a/b/a) && 47 | diff -U99 \ 48 | <("$PASS" show frp6mxk35daczom6) \ 49 | <("$PASS" code show a/c) && 50 | diff -U99 \ 51 | <("$PASS" show na6afjbulshsnket) \ 52 | <("$PASS" code show b/a) && 53 | diff -U99 \ 54 | <("$PASS" show aksqm5aw4lbn5fmp) \ 55 | <("$PASS" code show d/d/a) && 56 | diff -U99 \ 57 | <("$PASS" show jlkgltkeh5pmfogs) \ 58 | <("$PASS" code show d/d/b) && 59 | diff -U99 \ 60 | <("$PASS" show s3bhz3rmtjo5ugai) \ 61 | <("$PASS" code show d/d/c) && 62 | diff -U99 \ 63 | <("$PASS" show dz4bbay7a55q65ie) \ 64 | <("$PASS" code show e/f) && 65 | diff -U99 \ 66 | <("$PASS" show r3orhjgnwrixi6gg) \ 67 | <("$PASS" code show g) 68 | ' 69 | 70 | test_done 71 | -------------------------------------------------------------------------------- /DESIGN.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Notes to self 3 | ============= 4 | ``pass-code`` assumes the ``pass`` hierarchy will be flat, so the 5 | ``--path=sub-folder`` argument to ``pass init`` is not supported now. 6 | Can probably be implemented by putting a .passcode file in the folder, 7 | checking whether the paths from arguments refer to a folder that exist 8 | and using the .passcode from those folder. Makes things quite 9 | complicated. 10 | 11 | Since the original pass commands are used whenever possible and the 12 | file names passed to those are encrypted, ``git`` history is mostly 13 | undecipherable. It would be possible to translate encoded/decoded values 14 | in ``pass code git`` but I don't think that's a good idea. 15 | 16 | When ``pass-code`` moves/removes/copies a folder, a ``git`` commit 17 | is issued for every file in that folder. When moving, I can just 18 | modify the filenames in the .passcode, but I feel that would make 19 | merge conflicts harder to resolve. 20 | 21 | I haven't tested what happens when you have to merge two differing 22 | ``git`` histories, but I guess there will be a conflict every time 23 | you try to do so (at least on the .passcode file). Is a merge driver 24 | possible? Could I get by with doing union merges for .passcode 25 | and verifying referred encrypted files exist while reading it? 26 | 27 | From ``{a, b}`` have branch ``x`` do ``cp a c``, and have branch ``y`` 28 | do ``cp b c``. Now the merge has two new encoded files, both of which 29 | refer to ``c`` and have different content. Only conflicting file is 30 | the .passcode, so merge driver can't remove one of the encoded ones. 31 | I could do union, and prompt to manually delete one of the conflicting 32 | files. 33 | 34 | pass code init 35 | -------------- 36 | I should make ``pass code init`` convert an existing password-store 37 | to ``pass-code`` automatically. 38 | 39 | - Fail if ``pass init`` not run already. 40 | - Create ``.passcode`` if doesn't exist. 41 | - Encode current passwords if they exist. 42 | - Check ``.passcode`` and skip encoded ones 43 | - If git repo, make a new branch and do ``git filter-branch`` magic. 44 | - Don't forget to change filenames in commit messages 45 | - ``pass init --path=sub-folder`` is going to cause problems 46 | - Maybe preserve folder structure with ``encoded:*/decoded`` in 47 | ``.passcode`` ? 48 | -------------------------------------------------------------------------------- /tests/setup.sh: -------------------------------------------------------------------------------- 1 | # This file should be sourced by all test-scripts 2 | # 3 | # This scripts sets the following: 4 | # $PASS Full path to system password-store script 5 | # $GPG Name of gpg executable 6 | # $KEY{1..5} GPG key ids of testing keys 7 | # $TEST_HOME This folder 8 | # $EXT_HOME Folder containing pass extensions to be tested 9 | 10 | 11 | # Unset config vars 12 | unset PASSWORD_STORE_DIR 13 | unset PASSWORD_STORE_KEY 14 | unset PASSWORD_STORE_GIT 15 | unset PASSWORD_STORE_GPG_OPTS 16 | unset PASSWORD_STORE_X_SELECTION 17 | unset PASSWORD_STORE_CLIP_TIME 18 | unset PASSWORD_STORE_UMASK 19 | unset PASSWORD_STORE_GENERATED_LENGTH 20 | unset PASSWORD_STORE_CHARACTER_SET 21 | unset PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS 22 | unset PASSWORD_STORE_ENABLE_EXTENSIONS 23 | unset PASSWORD_STORE_EXTENSIONS_DIR 24 | unset PASSWORD_STORE_SIGNING_KEY 25 | unset EDITOR 26 | 27 | # We must be called from tests/ 28 | TEST_HOME="$(pwd)" 29 | 30 | . ./sharness.sh --verbose 31 | 32 | export PASSWORD_STORE_DIR="$SHARNESS_TRASH_DIRECTORY/test-store/" 33 | rm -rf "$PASSWORD_STORE_DIR" 34 | mkdir -p "$PASSWORD_STORE_DIR" 35 | if [[ ! -d $PASSWORD_STORE_DIR ]]; then 36 | echo "Could not create $PASSWORD_STORE_DIR" 37 | exit 1 38 | fi 39 | 40 | export GIT_DIR="$PASSWORD_STORE_DIR/.git" 41 | export GIT_WORK_TREE="$PASSWORD_STORE_DIR" 42 | export GIT_AUTHOR_EMAIL="Pass-Automated-Testing-Suite@zx2c4.com" 43 | export GIT_AUTHOR_NAME="Pass Automated Testing Suite" 44 | 45 | 46 | # Test using system pass binary 47 | PASS="$(which pass)" 48 | if [[ ! -e $PASS ]]; then 49 | echo "Could not find password-store installation." 50 | exit 1 51 | fi 52 | 53 | # Note: the assumption is the test key is unencrypted. 54 | export GNUPGHOME="$TEST_HOME/gnupg/" 55 | chmod 700 "$GNUPGHOME" 56 | GPG="gpg" 57 | which gpg2 &>/dev/null && GPG="gpg2" 58 | 59 | # We don't want any currently running agent to conflict. 60 | unset GPG_AGENT_INFO 61 | 62 | KEY1="CF90C77B" # pass test key 1 63 | KEY2="D774A374" # pass test key 2 64 | KEY3="EB7D54A8" # pass test key 3 65 | KEY4="E4691410" # pass test key 4 66 | KEY5="39E5020C" # pass test key 5 67 | 68 | # Enable extensions, load own extensions 69 | # $TEST_HOME is /path/to/git-repo/tests/ 70 | EXT_HOME="$(dirname $TEST_HOME)" 71 | export PASSWORD_STORE_ENABLE_EXTENSIONS=true 72 | export PASSWORD_STORE_EXTENSIONS_DIR="$EXT_HOME" 73 | -------------------------------------------------------------------------------- /tests/t2200-code-insert-manual.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code ls with manually written .passcode' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'setup password store' ' 8 | "$PASS" init $KEY1 9 | ' 10 | 11 | test_expect_success 'pass-code insert --echo succeeds' ' 12 | "$PASS" code insert --echo a/a/a/a <<< "a/a/a/a" && 13 | "$PASS" code insert --echo a/a/b <<< "a/a/b" && 14 | "$PASS" code insert --echo a/b/a <<< "a/b/a" && 15 | "$PASS" code insert --echo a/c <<< "a/c" && 16 | "$PASS" code insert --echo b/a <<< "b/a" && 17 | "$PASS" code insert --echo d/d/a <<< "d/d/a" && 18 | "$PASS" code insert --echo d/d/b <<< "d/d/b" && 19 | "$PASS" code insert --echo d/d/c <<< "d/d/c" && 20 | "$PASS" code insert --echo e/f <<< "e/f" && 21 | "$PASS" code insert --echo g <<< "g" 22 | ' 23 | 24 | remove_colors() { sed -e "s/\x1B\[[0-9;]*m//g"; } 25 | 26 | test_expect_success 'pass-code insert folder hierarchy is correct' ' 27 | diff -U99 - \ 28 | <("$PASS" code ls | remove_colors) \ 29 | <<- "_EOF_" 30 | Password Store 31 | |-- a 32 | | |-- a 33 | | | |-- a 34 | | | | `-- a 35 | | | `-- b 36 | | |-- b 37 | | | `-- a 38 | | `-- c 39 | |-- b 40 | | `-- a 41 | |-- d 42 | | `-- d 43 | | |-- a 44 | | |-- b 45 | | `-- c 46 | |-- e 47 | | `-- f 48 | `-- g 49 | _EOF_ 50 | ' 51 | 52 | test_expect_success 'pass-code inserted passwords are correct' ' 53 | diff -U99 - <("$PASS" code show a/a/a/a) <<< "a/a/a/a" && 54 | diff -U99 - <("$PASS" code show a/a/b) <<< "a/a/b" && 55 | diff -U99 - <("$PASS" code show a/b/a) <<< "a/b/a" && 56 | diff -U99 - <("$PASS" code show a/c) <<< "a/c" && 57 | diff -U99 - <("$PASS" code show b/a) <<< "b/a" && 58 | diff -U99 - <("$PASS" code show d/d/a) <<< "d/d/a" && 59 | diff -U99 - <("$PASS" code show d/d/b) <<< "d/d/b" && 60 | diff -U99 - <("$PASS" code show d/d/c) <<< "d/d/c" && 61 | diff -U99 - <("$PASS" code show e/f) <<< "e/f" && 62 | diff -U99 - <("$PASS" code show g) <<< "g" 63 | ' 64 | 65 | test_expect_success 'pass-code insert --multiline succeeds' ' 66 | "$PASS" code insert --multiline mul/ti/line <<- _EOF_ 67 | First line. 68 | Second line. 69 | Third line. 70 | Fourth line. 71 | Fifth line. 72 | _EOF_ 73 | ' 74 | 75 | test_expect_success 'pass-code insert --multiline value is correct' ' 76 | diff -U99 - <("$PASS" code show mul/ti/line) <<- _EOF_ 77 | First line. 78 | Second line. 79 | Third line. 80 | Fourth line. 81 | Fifth line. 82 | _EOF_ 83 | ' 84 | 85 | test_done 86 | -------------------------------------------------------------------------------- /tests/t2000-code-ls-manual.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='pass-code ls with manually written .passcode' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | 7 | test_expect_success 'setup .passcode.gpg manually' ' 8 | "$PASS" init $KEY1 9 | "$PASS" insert --multiline .passcode <<- "_EOF_" >/dev/null 10 | puap5y6t5nq6r75v:a/a/a/a 11 | niozt3shbhobwjit:a/a/b 12 | 6qjue4yxea7a2bfy:a/b/a 13 | frp6mxk35daczom6:a/c 14 | na6afjbulshsnket:b/a 15 | aksqm5aw4lbn5fmp:d/d/a 16 | jlkgltkeh5pmfogs:d/d/b 17 | s3bhz3rmtjo5ugai:d/d/c 18 | dz4bbay7a55q65ie:e/f 19 | r3orhjgnwrixi6gg:g 20 | _EOF_ 21 | ' 22 | 23 | test_expect_success 'setup encoded filenames' ' 24 | "$PASS" insert --echo puap5y6t5nq6r75v <<< "a/a/a/a" 25 | "$PASS" insert --echo niozt3shbhobwjit <<< "a/a/b" 26 | "$PASS" insert --echo 6qjue4yxea7a2bfy <<< "a/b/a" 27 | "$PASS" insert --echo frp6mxk35daczom6 <<< "a/c" 28 | "$PASS" insert --echo na6afjbulshsnket <<< "b/a" 29 | "$PASS" insert --echo aksqm5aw4lbn5fmp <<< "d/d/a" 30 | "$PASS" insert --echo jlkgltkeh5pmfogs <<< "d/d/b" 31 | "$PASS" insert --echo s3bhz3rmtjo5ugai <<< "d/d/c" 32 | "$PASS" insert --echo dz4bbay7a55q65ie <<< "e/f" 33 | "$PASS" insert --echo r3orhjgnwrixi6gg <<< "g" 34 | ' 35 | 36 | test_expect_success 'pass ls output should be scrambled' ' 37 | diff -U99 - <("$PASS" ls) <<- "_EOF_" 38 | Password Store 39 | |-- 6qjue4yxea7a2bfy 40 | |-- aksqm5aw4lbn5fmp 41 | |-- dz4bbay7a55q65ie 42 | |-- frp6mxk35daczom6 43 | |-- jlkgltkeh5pmfogs 44 | |-- na6afjbulshsnket 45 | |-- niozt3shbhobwjit 46 | |-- puap5y6t5nq6r75v 47 | |-- r3orhjgnwrixi6gg 48 | `-- s3bhz3rmtjo5ugai 49 | _EOF_ 50 | ' 51 | 52 | remove_colors() { sed -e "s/\x1B\[[0-9;]*m//g"; } 53 | 54 | test_expect_success 'pass-code ls output should be decoded' ' 55 | diff -U99 - \ 56 | <("$PASS" code ls | remove_colors) \ 57 | <<- "_EOF_" 58 | Password Store 59 | |-- a 60 | | |-- a 61 | | | |-- a 62 | | | | `-- a 63 | | | `-- b 64 | | |-- b 65 | | | `-- a 66 | | `-- c 67 | |-- b 68 | | `-- a 69 | |-- d 70 | | `-- d 71 | | |-- a 72 | | |-- b 73 | | `-- c 74 | |-- e 75 | | `-- f 76 | `-- g 77 | _EOF_ 78 | ' 79 | 80 | test_expect_success 'pass-code ls subfolder 1' ' 81 | diff -U99 - \ 82 | <("$PASS" code ls a | remove_colors) \ 83 | <<- "_EOF_" 84 | a 85 | |-- a 86 | | |-- a 87 | | | `-- a 88 | | `-- b 89 | |-- b 90 | | `-- a 91 | `-- c 92 | _EOF_ 93 | ' 94 | 95 | test_expect_success 'pass-code ls subfolder 2' ' 96 | diff -U99 - \ 97 | <("$PASS" code ls a/a | remove_colors) \ 98 | <<- "_EOF_" 99 | a/a 100 | |-- a 101 | | `-- a 102 | `-- b 103 | _EOF_ 104 | ' 105 | 106 | test_expect_success 'pass-code ls subfolder 3' ' 107 | diff -U99 - \ 108 | <("$PASS" code ls a/a/a | remove_colors) \ 109 | <<- "_EOF_" 110 | a/a/a 111 | `-- a 112 | _EOF_ 113 | ' 114 | 115 | test_expect_success 'pass-code ls subfolder 4' ' 116 | diff -U99 - \ 117 | <("$PASS" code ls d | remove_colors) \ 118 | <<- "_EOF_" 119 | d 120 | `-- d 121 | |-- a 122 | |-- b 123 | `-- c 124 | _EOF_ 125 | ' 126 | 127 | test_done 128 | -------------------------------------------------------------------------------- /tests/t0300-reencryption.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | test_description='Reencryption consistency' 4 | cd "$(dirname "$0")" 5 | . ./setup.sh 6 | PASS="$SHARNESS_TEST_DIRECTORY/pass-code.sh" 7 | 8 | INITIAL_PASSWORD="will this password live? a big question indeed..." 9 | 10 | canonicalize_gpg_keys() { 11 | $GPG --list-keys --with-colons "$@" | sed -n 's/sub:[^:]*:[^:]*:[^:]*:\([^:]*\):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[a-zA-Z]*e[a-zA-Z]*:.*/\1/p' | LC_ALL=C sort -u 12 | } 13 | 14 | gpg_keys_from_encrypted_file() { 15 | $GPG -v --no-secmem-warning --no-permission-warning --decrypt --list-only --keyid-format long "$1" 2>&1 | cut -d ' ' -f 5 | LC_ALL=C sort -u 16 | } 17 | 18 | gpg_file_from_code() { 19 | local enc="$("$PASS" show .passcode | grep ":$1$" | cut -d ':' -f 1)" 20 | echo "$PASSWORD_STORE_DIR/$enc.gpg" 21 | } 22 | 23 | gpg_keys_from_code() { 24 | gpg_keys_from_encrypted_file "$(gpg_file_from_code "$1")" 25 | } 26 | 27 | gpg_keys_from_group() { 28 | local output="$($GPG --list-config --with-colons | sed -n "s/^cfg:group:$1:\\(.*\\)/\\1/p" | head -n 1)" 29 | local saved_ifs="$IFS" 30 | IFS=";" 31 | local keys=( $output ) 32 | IFS="$saved_ifs" 33 | canonicalize_gpg_keys "${keys[@]}" 34 | } 35 | 36 | test_expect_success 'Setup initial key and git' ' 37 | "$PASS" init $KEY1 && "$PASS" git init 38 | ' 39 | 40 | test_expect_success 'Root key encryption' ' 41 | "$PASS" insert -e folder/cred1 <<<"$INITIAL_PASSWORD" && 42 | [[ $(canonicalize_gpg_keys "$KEY1") == "$(gpg_keys_from_code "folder/cred1")" ]] 43 | ' 44 | 45 | test_expect_success 'Reencryption root single key' ' 46 | "$PASS" init $KEY2 && 47 | [[ $(canonicalize_gpg_keys "$KEY2") == "$(gpg_keys_from_code "folder/cred1")" ]] 48 | ' 49 | 50 | test_expect_success 'Reencryption root multiple key' ' 51 | "$PASS" init $KEY2 $KEY3 $KEY1 && 52 | [[ $(canonicalize_gpg_keys $KEY2 $KEY3 $KEY1) == "$(gpg_keys_from_code "folder/cred1")" ]] 53 | ' 54 | 55 | test_expect_success 'Reencryption root multiple key with string' ' 56 | "$PASS" init $KEY2 $KEY3 $KEY1 "pass test key 4" && 57 | [[ $(canonicalize_gpg_keys $KEY2 $KEY3 $KEY1 $KEY4) == "$(gpg_keys_from_code "folder/cred1")" ]] 58 | ' 59 | 60 | test_expect_success 'Reencryption root group' ' 61 | "$PASS" init group1 && 62 | [[ $(gpg_keys_from_group group1) == "$(gpg_keys_from_code "folder/cred1")" ]] 63 | ' 64 | 65 | test_expect_success 'Reencryption root group with spaces' ' 66 | "$PASS" init "big group" && 67 | [[ $(gpg_keys_from_group "big group") == "$(gpg_keys_from_code "folder/cred1")" ]] 68 | ' 69 | 70 | test_expect_success 'Reencryption root group with spaces and other keys' ' 71 | "$PASS" init "big group" $KEY3 $KEY1 $KEY2 && 72 | [[ $(canonicalize_gpg_keys $KEY3 $KEY1 $KEY2 $(gpg_keys_from_group "big group")) == "$(gpg_keys_from_code "folder/cred1")" ]] 73 | ' 74 | 75 | test_expect_success 'Reencryption root group and other keys' ' 76 | "$PASS" init group2 $KEY3 $KEY1 $KEY2 && 77 | [[ $(canonicalize_gpg_keys $KEY3 $KEY1 $KEY2 $(gpg_keys_from_group group2)) == "$(gpg_keys_from_code "folder/cred1")" ]] 78 | ' 79 | 80 | test_expect_success 'Reencryption root group to identical individual with no file change' ' 81 | oldfile="$SHARNESS_TRASH_DIRECTORY/$RANDOM.$RANDOM.$RANDOM.$RANDOM.$RANDOM" && 82 | "$PASS" init group1 && 83 | cp "$(gpg_file_from_code "folder/cred1")" "$oldfile" && 84 | "$PASS" init $KEY4 $KEY2 && 85 | test_cmp "$(gpg_file_from_code "folder/cred1")" "$oldfile" 86 | ' 87 | 88 | test_expect_failure 'Reencryption subfolder multiple keys, copy' ' 89 | "$PASS" init -p anotherfolder $KEY3 $KEY1 && 90 | "$PASS" cp folder/cred1 anotherfolder/ && 91 | [[ $(canonicalize_gpg_keys $KEY1 $KEY3) == "$(gpg_keys_from_code "anotherfolder/cred1")" ]] 92 | ' 93 | 94 | test_expect_failure 'Reencryption subfolder multiple keys, move, deinit' ' 95 | "$PASS" init -p anotherfolder2 $KEY3 $KEY4 $KEY2 && 96 | "$PASS" mv -f anotherfolder anotherfolder2/ && 97 | [[ $(canonicalize_gpg_keys $KEY1 $KEY3) == "$(gpg_keys_from_code "anotherfolder2/anotherfolder/cred1")" ]] && 98 | "$PASS" init -p anotherfolder2/anotherfolder "" && 99 | [[ $(canonicalize_gpg_keys $KEY3 $KEY4 $KEY2) == "$(gpg_keys_from_code "anotherfolder2/anotherfolder/cred1")" ]] 100 | ' 101 | 102 | #TODO: test with more varieties of move and copy! 103 | 104 | test_expect_success 'Password lived through all transformations' ' 105 | [[ $("$PASS" show anotherfolder2/anotherfolder/cred1) == "$INITIAL_PASSWORD" ]] 106 | ' 107 | 108 | test_expect_success 'Git picked up all changes throughout' ' 109 | [[ -z $(git status --porcelain 2>&1) ]] 110 | ' 111 | 112 | test_done 113 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | pass-code 3 | ========= 4 | A pass_ extension that obscures the filenames and folder hierarchy 5 | within your password store. 6 | 7 | .. _pass: https://www.passwordstore.org/ 8 | 9 | Desciption 10 | ---------- 11 | In normal operation, ``pass`` stores the passwords in encrypted form, 12 | but the filenames that you use to access these passwords are 13 | unencrypted. These filenames would usually include the names of the 14 | websites and sometimes the names of the accounts. This is a security 15 | concern for some people, and filename encryption has been requested 16 | as a feature in the password-store mailing list repeatedly `[1]`_ 17 | `[2]`_ `[3]`_. Another extension that fulfils this purpose is 18 | pass-tomb_ which stores your entire password storage in an encrypted 19 | volume. 20 | 21 | .. _[1]: https://lists.zx2c4.com/pipermail/password-store/2017-February/002700.html 22 | .. _[2]: https://lists.zx2c4.com/pipermail/password-store/2017-February/002737.html 23 | .. _[3]: https://lists.zx2c4.com/pipermail/password-store/2016-January/001880.html 24 | .. _pass-tomb: https://github.com/roddhjav/pass-tomb 25 | 26 | ``pass-code`` generates random filenames for each file in the password 27 | store and keeps the mapping in an encrypted file. This way, no valuable 28 | information is accessible even if your password store is leaked to the 29 | public (unless your GPG private keys were also leaked). Nevertheless, 30 | you should always ensure proper protection of your password store. 31 | 32 | ``pass-code`` is designed to behave as closely to ``pass`` as possible, 33 | to the point that it currently passes all but two tests from the 34 | original ``pass`` test suite with appropriate modifications. 35 | 36 | Example 37 | ------- 38 | 39 | For someone who doesn't have your GPG keys, your password-store looks 40 | like this:: 41 | 42 | $ pass ls 43 | Password Store 44 | ├── 5jv1d009jg3ihfz7 45 | ├── dn9n5icjgj2gvx7k 46 | ├── pjpg9m9ryx4m6ic8 47 | ├── rig4xd9t90ypq3ah 48 | ├── u35k4x1q68n3lvbg 49 | ├── ws54wjtfuhc6wbq0 50 | └── yaskztsk3ceuomir 51 | 52 | With the ``pass-code`` extension (and your GPG keys), you can see 53 | the true form of the password store:: 54 | 55 | $ pass code ls 56 | Password Store 57 | ├── Business 58 | │ ├── some-silly-business-site.com 59 | │ └── another-business-site.net 60 | ├── Email 61 | │ ├── donenfeld.com 62 | │ └── zx2c4.com 63 | └── France 64 | ├── bank 65 | ├── freebox 66 | └── mobilephone 67 | 68 | The mappings between the two is stored in a ``.passcode.gpg`` file 69 | with a very simple, human-readable format:: 70 | 71 | $ pass show .passcode 72 | pjpg9m9ryx4m6ic8:Business/some-silly-business-site.com 73 | ws54wjtfuhc6wbq0:Business/another-business-site.net 74 | rig4xd9t90ypq3ah:Email/donenfeld.com 75 | 5jv1d009jg3ihfz7:Email/zx2c4.com 76 | dn9n5icjgj2gvx7k:France/bank 77 | yaskztsk3ceuomir:France/freebox 78 | u35k4x1q68n3lvbg:France/mobilephone 79 | 80 | Usage 81 | ----- 82 | Almost all ``pass`` commands are supported with the same argument lists, 83 | the exceptions being ``pass code init`` and ``pass code git`` which 84 | only pass their arguments directly to their ``pass`` counterparts). 85 | See the `man page for pass`_. 86 | 87 | .. _man page for pass: https://git.zx2c4.com/password-store/about/ 88 | 89 | :: 90 | 91 | pass code init [args...] 92 | No pass-code specific initialization is done, instead 93 | passes the options to "pass init" unconditionally. 94 | The pass-code extension does not support encrypted 95 | subfolders (with the --path option), but still passes 96 | these options through. 97 | 98 | pass code git [args...] 99 | No pass-code specific manipulation is done to the 100 | arguments, stdin or the stdout. Instead, the given 101 | options are simply passed to "pass git". 102 | 103 | pass code pass-command [args...] 104 | See help text for "pass pass-command". When 105 | necessary, the pass-names are encoded/decoded, file 106 | mappings are created/changed/removed and written to the 107 | ".passcode" pass-name in the password storage. 108 | 109 | pass code encode pass-code-name... 110 | List whichever pass-names in the password storage 111 | correspond to the given encoded names. Outputs one line 112 | with the encoded name (or an empty line) per argument. 113 | 114 | pass code decode pass-name... 115 | List whichever pass-code-names in the .passcode file 116 | correspond to the given decoded names. Outputs one line 117 | with the decoded name (or an empty line) per argument. 118 | 119 | pass code [help] [pass] 120 | Show this message, or the "pass help" message. 121 | 122 | pass code version [pass] 123 | Show version information for pass-code or pass. 124 | 125 | Installation 126 | ------------ 127 | First, ensure that ``pass version`` reports ``v1.7`` or later, which 128 | is needed for extension support. If so, copy the ``code.bash`` file to 129 | ``~/.password-store/.extensions/``. You also need to set the 130 | ``PASSWORD_STORE_ENABLE_EXTENSIONS`` environment variable to ``true`` 131 | for ``pass`` to execute extensions. 132 | 133 | Caveats 134 | ------- 135 | See ``DESIGN.rst`` for notes I keep about issues and things to 136 | implement. 137 | -------------------------------------------------------------------------------- /code.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # pass-code, an extension for pass ( https://www.passwordstore.org/ ) 4 | # Copyright (C) 2017 Alper Nebi Yasak 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | declare -A codec 20 | codec_modified=false 21 | 22 | # Decrypt the .passcode file and put it to an associative array so we 23 | # don't need to re-decrpyt it every time we encode/decode something. 24 | code_decrypt() { 25 | local passcode 26 | if passcode="$(cmd_show .passcode 2>/dev/null)" ; then 27 | while read -r pair; do 28 | codec["Dx${pair##*:}"]="${pair%%:*}" 29 | codec["Ex${pair%%:*}"]="${pair##*:}" 30 | done <<< "$passcode" 31 | else 32 | die "Could not decrypt pass-code store" 33 | fi 34 | } 35 | 36 | # Will not print anything if code_decrypt not run or key not in mapping 37 | code_encode() { while read -r dec; do echo "${codec[Dx$dec]}"; done; } 38 | code_decode() { while read -r enc; do echo "${codec[Ex$enc]}"; done; } 39 | 40 | # $1 is decoded, $2 is encoded 41 | code_add() { 42 | codec["Dx$1"]="$2" 43 | codec["Ex$2"]="$1" 44 | codec_modified=true 45 | } 46 | 47 | code_remove() { 48 | unset codec["Dx$1"] 49 | unset codec["Ex$2"] 50 | codec_modified=true 51 | } 52 | 53 | # Generate a random encoded filename and map it to given decoded $1 54 | code_add_random() { 55 | local dec="$1" 56 | local enc="" 57 | 58 | if [[ -z "$dec" ]]; then 59 | return 1 60 | fi 61 | 62 | until code_is_file "$dec"; do 63 | read -r -n 16 enc \ 64 | < <(LC_ALL=C tr -dc "0-9a-z" < /dev/urandom) 65 | 66 | if [[ ${#enc} -ne 16 ]]; then 67 | die "Could not generate a random filename." 68 | fi 69 | 70 | # Don't break one-to-one mapping 71 | if [[ -z "${codec[Ex$enc]+x}" ]]; then 72 | code_add "$dec" "$enc" 73 | else 74 | # Don't overload the CPU 75 | sleep 0.1 76 | fi 77 | done 78 | } 79 | 80 | # Lists decoded files, assuming encoded hierarchy is flat 81 | code_list_files() { 82 | cmd_show \ 83 | | tail -n +2 \ 84 | | cut -d ' ' -f 2 \ 85 | | code_decode \ 86 | | sort 87 | } 88 | 89 | # Check if file/directory exists in codec 90 | code_is_directory() { 91 | [[ -n "$1" ]] && (code_list_files | grep "^${1%/}/" > /dev/null) 92 | } 93 | 94 | code_is_file() { 95 | [[ -n "$1" && -n "${codec[Dx$1]+x}" ]] 96 | } 97 | 98 | # Check if codec is in valid format. 99 | # Only [ExENC]=DEC and [DxDEC]=ENC are allowed. 100 | # One-to-one mapping, so [Dx[ExENC]]=ENC and [Ex[DxDEC]]=DEC. 101 | code_validate() { 102 | for key in "${!codec[@]}"; do 103 | if [[ "${key#Ex}" != "${key#Dx}" && ( 104 | "${codec[Dx${codec[$key]}]}" = "${key#Ex}" || 105 | "${codec[Ex${codec[$key]}]}" = "${key#Dx}" 106 | ) ]]; then 107 | continue 108 | else 109 | die "pass-code internal mapping is invalid." 110 | fi 111 | done 112 | } 113 | 114 | # Print ENC:DEC pairs 115 | code_as_colons() { 116 | for key in "${!codec[@]}"; do 117 | if [[ -n "${key#Ex}" && "${key#Ex}" != "$key" ]]; then 118 | echo "${key#Ex}:${codec[$key]}" 119 | fi 120 | done | sort -t ':' -k 2 121 | } 122 | 123 | # If we have modified the mappings, rewrite the .passcode file and 124 | # put it back into the password-store. 125 | code_encrypt() { 126 | if [[ "$codec_modified" = false ]]; then 127 | return 128 | fi 129 | 130 | code_validate 131 | code_as_colons \ 132 | | cmd_insert ".passcode" --multiline --force \ 133 | >/dev/null 134 | } 135 | 136 | # Enable colors if we have LS_COLORS 137 | declare -A colors 138 | for pair in $(tr ':' '\n' <<< "$LS_COLORS"); do 139 | colors["${pair%%=*}"]="\x1B[${pair##*=}m" 140 | done 141 | 142 | code_colorize_dir() { 143 | if [[ "$1" == */ ]]; then 144 | echo -e -n "${colors["di"]}${1%/}${colors["rs"]}" 145 | else 146 | echo -n "$1" 147 | fi 148 | } 149 | 150 | code_format_as_tree() { 151 | # Thing to print before this line, used in recursion 152 | local prefix="$1" 153 | 154 | # Print box-drawing chars if $LANG supports it 155 | local brnc pipe crnr blnk 156 | if [[ "${LANG,,}" == *utf8* || "${LANG,,}" == *utf-8* ]]; then 157 | brnc='├──' 158 | pipe='│ ' 159 | crnr='└──' 160 | blnk=' ' 161 | else 162 | brnc='|--' 163 | pipe='| ' 164 | crnr='`--' 165 | blnk=' ' 166 | fi 167 | 168 | # Sorted list of files, and first-level items 169 | local -a all_files fs 170 | readarray all_files -t 171 | 172 | # Figure out first-level items, with dirs/ and files 173 | for f in "${all_files[@]}"; do 174 | if [[ "${#fs}" -eq 0 || "${fs[-1]}" != "${f%%/*}/" ]] 175 | then 176 | if [[ -z "${f##*/*}" ]]; then 177 | fs+=("${f%%/*}/") 178 | else 179 | fs+=("${f%%/*}") 180 | fi 181 | fi 182 | done 183 | 184 | 185 | # Print the first-level items as if only they exist, but print 186 | # the sub-trees via recursion (with the appropriate prefixes) 187 | # in-between them. 188 | # 189 | # Recursion level 1 190 | # ----------------- 191 | # |-- a 192 | # {"| " tree a} 193 | # |-- b 194 | # {"| " tree b} 195 | # `-- c 196 | # {" " tree d} 197 | # 198 | # Recursion level 2 199 | # ----------------- 200 | # |-- a 201 | # | |-- a 202 | # {"| | " tree a/a} 203 | # | `-- b 204 | # |-- b 205 | # | `-- a 206 | # {"| " tree b/a} 207 | # `-- c 208 | # |-- a 209 | # {" | " tree c/a} 210 | # `-- b 211 | # {" " tree c/b} 212 | 213 | local pre 214 | for x in "${!fs[@]}"; do 215 | local f="${fs[$x]}" 216 | 217 | # Only the trees after the last element of the current 218 | # level get the " " prefix, others get the "| " 219 | # prefix. Also, the last elements have "`-- " instead 220 | # of "|-- " 221 | if [[ "$f" != "${fs[-1]}" ]]; then 222 | echo "$prefix$brnc $(code_colorize_dir "$f")" 223 | pre="$pipe" 224 | else 225 | echo "$prefix$crnr $(code_colorize_dir "$f")" 226 | pre="$blnk" 227 | fi 228 | 229 | # If this is a folder, recurse down a level 230 | if [[ "$f" == */ ]]; then 231 | for y in "${all_files[@]}"; do 232 | echo "$y" 233 | done | code_filter_subfolder "$f" "yes" \ 234 | | code_format_as_tree "$prefix$pre " 235 | fi 236 | done 237 | } 238 | 239 | # Take newline seperated list of files, choose those in path/to/sub/ 240 | code_filter_subfolder() { 241 | # Accept "path/to/sub/" and "path/to/sub" as inputs 242 | local sub="${1%/}" 243 | local remove="$2" 244 | 245 | if [[ -z "$sub" ]]; then 246 | cat 247 | else 248 | while read -r line; do 249 | if [[ "${line#$sub/}" != "${line}" ]]; then 250 | if [[ -n "$remove" ]]; then 251 | echo "${line#$sub/}" 252 | else 253 | echo "${line}" 254 | fi 255 | fi 256 | done 257 | fi 258 | } 259 | 260 | code_filter() { 261 | local lowline 262 | while read -r line; do 263 | lowline="${line,,}" 264 | for arg in "$@"; do 265 | if [[ -z "${lowline##*${arg,,}*}" ]]; then 266 | echo "$line" 267 | break 268 | fi 269 | done 270 | done 271 | 272 | } 273 | 274 | code_decode_grep_output() { 275 | local enc dec x1b 276 | 277 | # Escape code 278 | x1b="$(echo -en '\x1B')" 279 | 280 | while read -r line; do 281 | enc="${line##*$PREFIX}" 282 | 283 | # Delete color control codes (e.g. "\x1B[0m") 284 | enc="${enc#${x1b}*m}" 285 | enc="${enc%${x1b}*}" 286 | 287 | dec="${codec["Ex$enc"]}" 288 | if [[ -n "$dec" ]]; then 289 | echo "${line//$enc/$enc ($dec)}" 290 | else 291 | echo "$line" 292 | fi 293 | done 294 | } 295 | 296 | # Encodes all encodable arguments, but leaves others intact. 297 | # code_encode_args "$@" 298 | # set -- "${encoded_args[@]}" 299 | declare -a encoded_args 300 | code_encode_args() { 301 | encoded_args=() 302 | 303 | for arg in "$@"; do 304 | encoded_args+=("${codec[Dx$arg]-$arg}") 305 | done 306 | } 307 | 308 | # Strip options (i.e. anything that starts with a dash) 309 | # code_positional_args "$@" 310 | # set -- "${positional_args[@]}" 311 | declare -a positional_args 312 | code_positional_args() { 313 | positional_args=() 314 | 315 | for arg in "$@"; do 316 | if [[ "${arg#-}" = "$arg" ]]; then 317 | positional_args+=("$arg") 318 | fi 319 | done 320 | } 321 | 322 | cmd_code_usage() { 323 | if [[ "$1" = "$PROGRAM" ]]; then 324 | shift 325 | cmd_usage "$@" 326 | return 327 | fi 328 | 329 | cmd_code_version 330 | echo 331 | cat <<- _EOF_ 332 | Usage: 333 | $PROGRAM code init [args...] 334 | No pass-code specific initialization is done, instead 335 | passes the options to "$PROGRAM init" unconditionally. 336 | The pass-code extension does not support encrypted 337 | subfolders (with the --path option), but still passes 338 | these options through. 339 | $PROGRAM code git [args...] 340 | No pass-code specific manipulation is done to the 341 | arguments, stdin or the stdout. Instead, the given 342 | options are simply passed to "$PROGRAM git". 343 | $PROGRAM code pass-command [args...] 344 | See help text for "$PROGRAM pass-command". When 345 | necessary, the pass-names are encoded/decoded, file 346 | mappings are created/changed/removed and written to the 347 | ".passcode" pass-name in the password storage. 348 | $PROGRAM code encode pass-code-name... 349 | List whichever pass-names in the password storage 350 | correspond to the given encoded names. Outputs one line 351 | with the encoded name (or an empty line) per argument. 352 | $PROGRAM code decode pass-name... 353 | List whichever pass-code-names in the .passcode file 354 | correspond to the given decoded names. Outputs one line 355 | with the decoded name (or an empty line) per argument. 356 | $PROGRAM code [help] [$PROGRAM] 357 | Show this message, or the "$PROGRAM help" message. 358 | $PROGRAM code version [$PROGRAM] 359 | Show version information for pass-code or $PROGRAM. 360 | _EOF_ 361 | } 362 | 363 | cmd_code_version() { 364 | if [[ "$1" = "$PROGRAM" ]]; then 365 | shift 366 | cmd_version "$@" 367 | return 368 | fi 369 | 370 | cat <<- EOF 371 | $PROGRAM-code version 0.1.0 372 | EOF 373 | } 374 | 375 | cmd_code_ls() { 376 | local sub="$1" 377 | check_sneaky_paths "$sub" 378 | code_decrypt 379 | 380 | if [[ -z "$sub" ]]; then 381 | echo "Password Store" 382 | elif code_is_directory "$sub"; then 383 | echo "$sub" 384 | else 385 | return 386 | fi 387 | 388 | code_list_files \ 389 | | code_filter_subfolder "$sub" "yes" \ 390 | | code_format_as_tree 391 | } 392 | 393 | cmd_code_show() { 394 | code_decrypt 395 | code_encode_args "$@" 396 | set -- "${encoded_args[@]}" 397 | cmd_show "$@" 398 | } 399 | 400 | cmd_code_find() { 401 | code_decrypt 402 | 403 | # First line, IFS doesn't leak out of the subshell 404 | (IFS=','; echo "Search Terms: $*") 405 | 406 | code_list_files \ 407 | | code_filter "$@" \ 408 | | code_format_as_tree 409 | } 410 | 411 | cmd_code_grep() { 412 | code_decrypt 413 | 414 | rs="$(echo -e "\x1B[0m")" 415 | 416 | cmd_grep "$@" \ 417 | | code_decode_grep_output 418 | } 419 | 420 | cmd_code_insert() { 421 | code_decrypt 422 | 423 | # One positional arg, possibly not in codec 424 | code_positional_args "$@" 425 | local dec="${positional_args[0]}" 426 | code_is_file "$dec" || code_add_random "$dec" 427 | 428 | code_encode_args "$@" 429 | set -- "${encoded_args[@]}" 430 | cmd_insert "$@" 431 | code_encrypt 432 | } 433 | 434 | cmd_code_edit() { 435 | code_decrypt 436 | 437 | # One positional arg, maybe not in codec 438 | code_positional_args "$@" 439 | local dec="${positional_args[0]}" 440 | code_is_file "$dec" || code_add_random "$dec" 441 | 442 | code_encode_args "$@" 443 | set -- "${encoded_args[@]}" 444 | cmd_edit "$@" 445 | code_encrypt 446 | } 447 | 448 | cmd_code_generate() { 449 | code_decrypt 450 | 451 | # One (maybe two) positional args, first possibly not in codec 452 | # Second is a number or empty, irrelevant in both cases 453 | code_positional_args "$@" 454 | local dec="${positional_args[0]}" 455 | code_is_file "$dec" || code_add_random "$dec" 456 | 457 | code_encode_args "$@" 458 | set -- "${encoded_args[@]}" 459 | cmd_generate "$@" 460 | code_encrypt 461 | } 462 | 463 | cmd_code_cpmvrm() { 464 | code_decrypt 465 | 466 | # Prepended an action in the case statement, take that out 467 | local action="$1" 468 | shift 469 | 470 | # Check --force/-f since we have to do conflict handling 471 | local force=false recursive=false 472 | for arg in "$@"; do 473 | if [[ "$arg" = "--recursive" || "$arg" = "-r" ]]; then 474 | recursive=true 475 | elif [[ "$arg" = "--force" || "$arg" = "-f" ]]; then 476 | force=true 477 | fi 478 | done 479 | 480 | # Two positional args, first must be in codec; second may be. 481 | # If we're removing, second arg should not exist at all. 482 | # Both might exist _both_ as a folder and as a file, since 483 | # pass uses .gpg suffixes. (i.e. x.gpg and x/ are both x) 484 | code_positional_args "$@" 485 | local from="${positional_args[0]}" from_is_dir=false 486 | local to="${positional_args[1]}" to_is_dir=false 487 | 488 | # codec | a | a/ | d? a/ | f a | is_dir | 489 | # ---------|--------|--------|-------------|--------| 490 | # {a, a/*} | file | folder | y | y | a/ | 491 | # {a/*} | folder | folder | y | n | a a/ | 492 | # {a} | file | error | n | y | | 493 | # {} | error | error | n | n | | 494 | if code_is_directory "$from" && code_is_file "${from%/}"; then 495 | [[ "$from" == */ ]] && from_is_dir=true 496 | elif code_is_directory "$from"; then 497 | from_is_dir=true 498 | elif [[ "$from" == */ ]] || ! code_is_file "$from"; then 499 | die "Error: \`$from\` not in pass-code store." 500 | fi 501 | from="${from%/}" 502 | 503 | # codec | b | b/ | d? b/ | f b | is_dir | 504 | # ---------|--------|---------|-------------|--------| 505 | # {b, b/*} | file | folder | y | y | b/ | 506 | # {b/*} | folder | folder | y | n | b b/ | 507 | # {b} | file | folder+ | n | y | b/ | 508 | # {} | file+ | folder+ | n | n | b/ | 509 | if [[ "$action" = "delete" ]]; then 510 | [[ -n "$to" ]] && die "cp takes one positional arg" 511 | elif [[ "$to" == */ ]]; then 512 | to_is_dir=true 513 | elif code_is_directory "$to" && ! code_is_file "${to%/}"; then 514 | to_is_dir=true 515 | fi 516 | to="${to%/}" 517 | 518 | # Decide on what exactly needs to be done. 519 | local from_name to_dir to_name 520 | local -a from_files 521 | local -A pass_thru 522 | 523 | from_name="${from##*/}" 524 | 525 | # Array of things to copy. The false case is a single "$from" 526 | # file, which I copy to a single "$to" later on using another 527 | # if "$from_is_dir" branch. 528 | if [[ "$from_is_dir" = true ]]; then 529 | readarray -t from_files < <(code_list_files \ 530 | | code_filter_subfolder "$from") 531 | else 532 | from_files=("$from") 533 | fi 534 | 535 | # If we're copying into a directory, go into it 536 | if [[ "$to_is_dir" = true ]]; then 537 | to_dir="$to" 538 | to_name="$from_name" 539 | to="$to_dir/$to_name" 540 | else 541 | to_dir="${to%/*}" 542 | to_name="${to##*/}" 543 | fi 544 | 545 | # ``mv a x`` on {a/a, a/b, a/c, x/a/b} asks if we want 546 | # to overwrite x/a and doesn't move anything if we abort. 547 | # But it still doesn't copy anything if we --force, since mv 548 | # complains x/a isn't empty. However, ``cp a x`` in the same 549 | # situation copies all it can, asks whenever it needs to 550 | # overwrite and overwrites if you say so (or give --force). If 551 | # you reject the overwrite, it continues copying other files. 552 | 553 | # Hence, don't merge folders if we're on mv. 554 | [[ "$action" = "move" && "$from_is_dir" = true ]] && \ 555 | code_is_directory "$to" && \ 556 | die "Cannot move $from_name to $to: Directory not empty" 557 | 558 | # Need to set recursive to delete folders 559 | [[ "$action" = "delete" && "$from_is_dir" = true ]] && \ 560 | [[ "$recursive" = false ]] && \ 561 | die "Cannot remove $from: Directory not empty" 562 | 563 | # ``pass rm --recursive x`` on {x/*} only asks confirmation 564 | # for x, so ask it and set force if approved, die otherwise. 565 | [[ "$action" = "delete" && "$recursive" = true ]] && \ 566 | [[ "$force" = false ]] && yesno "remove $from?" && \ 567 | force=true 568 | 569 | local fenc tenc fdec tdec 570 | for fdec in "${from_files[@]}"; do 571 | fenc="${codec[Dx$fdec]}" 572 | 573 | # if "$from_is_dir" is true, 574 | # from="old/dir", fdec="old/dir/*" 575 | # tdec="new/dir/*" or tdec="new/old/dir/*" 576 | # depending on "$to_is_dir" manipulation above 577 | # 578 | # if "$from_is_dir" is false, 579 | # from="old/file", fdec="old/file", to="new/file" 580 | # 581 | # if deleting, to="", so tdec="", this is fine 582 | if [[ "$from_is_dir" = true ]]; then 583 | tdec="$to/${fdec#$from/}" 584 | else 585 | tdec="$to" 586 | fi 587 | 588 | # Ask on conflicts if not force 589 | if code_is_file "$tdec" && [[ "$force" != true ]]; then 590 | (yesno "overwrite $tdec?") || continue 591 | fi 592 | 593 | # Remove asks to delete files 594 | # If we're deleting a folder, force is already true 595 | if [[ "$action" = "delete" && "$force" != true ]]; then 596 | (yesno "remove $fdec?") || continue 597 | fi 598 | 599 | # No need to change mapping if one exists 600 | # Just overwrite the encoded file 601 | # If deleting, need to add "Fx$fenc" to the associative 602 | # array somehow, so map it to itself 603 | if [[ "$action" = "delete" ]]; then 604 | pass_thru["Fx$fenc"]="$fenc" 605 | else 606 | code_is_file "$tdec" || code_add_random "$tdec" 607 | pass_thru["Fx$fenc"]="${codec[Dx$tdec]}" 608 | fi 609 | 610 | # Need to remove from-file mapping if we're moving 611 | # or deleting 612 | if [[ "$action" = "delete" ]]; then 613 | code_remove "$fdec" "$fenc" 614 | elif [[ "$action" = "move" ]]; then 615 | code_remove "$fdec" "$fenc" 616 | fi 617 | done 618 | 619 | # Since we haven't been interrupted out of running yet, 620 | # we can commit to our changes. Force everything since we 621 | # filtered out unwanted changes earlier. 622 | for fxfenc in "${!pass_thru[@]}"; do 623 | fenc="${fxfenc#Fx}" 624 | tenc="${pass_thru[Fx$fenc]}" 625 | if [[ "$action" = "move" || "$action" = "copy" ]]; then 626 | cmd_copy_move "$action" --force "$fenc" "$tenc" 627 | elif [[ "$action" = "delete" ]]; then 628 | cmd_delete --force "$fenc" 629 | fi 630 | done 631 | 632 | code_encrypt 633 | } 634 | 635 | # For testing internal functions. 636 | # Exit with non-zero status to pause sharness and inspect manually. 637 | cmd_code_test() { 638 | exit 0 639 | } 640 | 641 | cmd_code_lookup() { 642 | code_decrypt 643 | mode="$1" 644 | shift 645 | 646 | for x in "$@"; do 647 | echo "${codec["$mode$x"]}" 648 | done 649 | } 650 | 651 | case "$1" in 652 | init) shift; cmd_init "$@" ;; 653 | help|--help) shift; cmd_code_usage "$@" ;; 654 | version|--version) shift; cmd_code_version "$@" ;; 655 | list|ls) shift; cmd_code_ls "$@" ;; 656 | show) shift; cmd_code_show "$@" ;; 657 | find|search) shift; cmd_code_find "$@" ;; 658 | grep) shift; cmd_code_grep "$@" ;; 659 | insert|add) shift; cmd_code_insert "$@" ;; 660 | edit) shift; cmd_code_edit "$@" ;; 661 | generate) shift; cmd_code_generate "$@" ;; 662 | delete|rm|remove) shift; cmd_code_cpmvrm "delete" "$@" ;; 663 | rename|mv) shift; cmd_code_cpmvrm "move" "$@" ;; 664 | copy|cp) shift; cmd_code_cpmvrm "copy" "$@" ;; 665 | git) shift; cmd_git "$@" ;; 666 | test) shift; cmd_code_test "$@" ;; 667 | encode|enc) shift; cmd_code_lookup "Dx" "$@";; 668 | decode|dec) shift; cmd_code_lookup "Ex" "$@";; 669 | *) cmd_code_usage "$@" ;; 670 | esac 671 | -------------------------------------------------------------------------------- /tests/sharness.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2011-2012 Mathias Lafeldt 4 | # Copyright (c) 2005-2012 Git project 5 | # Copyright (c) 2005-2012 Junio C Hamano 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 2 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see http://www.gnu.org/licenses/ . 19 | 20 | # Public: Current version of Sharness. 21 | SHARNESS_VERSION="1.0.0" 22 | export SHARNESS_VERSION 23 | 24 | # Public: The file extension for tests. By default, it is set to "t". 25 | : ${SHARNESS_TEST_EXTENSION:=t} 26 | export SHARNESS_TEST_EXTENSION 27 | 28 | # Reset TERM to original terminal if found, otherwise save orignal TERM 29 | [ "x" = "x$SHARNESS_ORIG_TERM" ] && 30 | SHARNESS_ORIG_TERM="$TERM" || 31 | TERM="$SHARNESS_ORIG_TERM" 32 | # Public: The unsanitized TERM under which sharness is originally run 33 | export SHARNESS_ORIG_TERM 34 | 35 | # Export SHELL_PATH 36 | : ${SHELL_PATH:=$SHELL} 37 | export SHELL_PATH 38 | 39 | # For repeatability, reset the environment to a known state. 40 | # TERM is sanitized below, after saving color control sequences. 41 | LANG=C 42 | LC_ALL=C 43 | PAGER=cat 44 | TZ=UTC 45 | EDITOR=: 46 | export LANG LC_ALL PAGER TZ EDITOR 47 | unset VISUAL CDPATH GREP_OPTIONS 48 | 49 | # Line feed 50 | LF=' 51 | ' 52 | 53 | [ "x$TERM" != "xdumb" ] && ( 54 | [ -t 1 ] && 55 | tput bold >/dev/null 2>&1 && 56 | tput setaf 1 >/dev/null 2>&1 && 57 | tput sgr0 >/dev/null 2>&1 58 | ) && 59 | color=t 60 | 61 | while test "$#" -ne 0; do 62 | case "$1" in 63 | -d|--d|--de|--deb|--debu|--debug) 64 | debug=t; shift ;; 65 | -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) 66 | immediate=t; shift ;; 67 | -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) 68 | TEST_LONG=t; export TEST_LONG; shift ;; 69 | --in|--int|--inte|--inter|--intera|--interac|--interact|--interacti|--interactiv|--interactive|--interactive-|--interactive-t|--interactive-te|--interactive-tes|--interactive-test|--interactive-tests): 70 | TEST_INTERACTIVE=t; export TEST_INTERACTIVE; verbose=t; shift ;; 71 | -h|--h|--he|--hel|--help) 72 | help=t; shift ;; 73 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) 74 | verbose=t; shift ;; 75 | -q|--q|--qu|--qui|--quie|--quiet) 76 | # Ignore --quiet under a TAP::Harness. Saying how many tests 77 | # passed without the ok/not ok details is always an error. 78 | test -z "$HARNESS_ACTIVE" && quiet=t; shift ;; 79 | --chain-lint) 80 | chain_lint=t; shift ;; 81 | --no-chain-lint) 82 | chain_lint=; shift ;; 83 | --no-color) 84 | color=; shift ;; 85 | --root=*) 86 | root=$(expr "z$1" : 'z[^=]*=\(.*\)') 87 | shift ;; 88 | *) 89 | echo "error: unknown test option '$1'" >&2; exit 1 ;; 90 | esac 91 | done 92 | 93 | if test -n "$color"; then 94 | # Save the color control sequences now rather than run tput 95 | # each time say_color() is called. This is done for two 96 | # reasons: 97 | # * TERM will be changed to dumb 98 | # * HOME will be changed to a temporary directory and tput 99 | # might need to read ~/.terminfo from the original HOME 100 | # directory to get the control sequences 101 | # Note: This approach assumes the control sequences don't end 102 | # in a newline for any terminal of interest (command 103 | # substitutions strip trailing newlines). Given that most 104 | # (all?) terminals in common use are related to ECMA-48, this 105 | # shouldn't be a problem. 106 | say_color_error=$(tput bold; tput setaf 1) # bold red 107 | say_color_skip=$(tput setaf 4) # blue 108 | say_color_warn=$(tput setaf 3) # brown/yellow 109 | say_color_pass=$(tput setaf 2) # green 110 | say_color_info=$(tput setaf 6) # cyan 111 | say_color_reset=$(tput sgr0) 112 | say_color_="" # no formatting for normal text 113 | say_color() { 114 | test -z "$1" && test -n "$quiet" && return 115 | eval "say_color_color=\$say_color_$1" 116 | shift 117 | printf "%s\\n" "$say_color_color$*$say_color_reset" 118 | } 119 | else 120 | say_color() { 121 | test -z "$1" && test -n "$quiet" && return 122 | shift 123 | printf "%s\n" "$*" 124 | } 125 | fi 126 | 127 | TERM=dumb 128 | export TERM 129 | 130 | error() { 131 | say_color error "error: $*" 132 | EXIT_OK=t 133 | exit 1 134 | } 135 | 136 | say() { 137 | say_color info "$*" 138 | } 139 | 140 | test -n "$test_description" || error "Test script did not set test_description." 141 | 142 | if test "$help" = "t"; then 143 | echo "$test_description" 144 | exit 0 145 | fi 146 | 147 | exec 5>&1 148 | exec 6<&0 149 | if test "$verbose" = "t"; then 150 | exec 4>&2 3>&1 151 | else 152 | exec 4>/dev/null 3>/dev/null 153 | fi 154 | 155 | test_failure=0 156 | test_count=0 157 | test_fixed=0 158 | test_broken=0 159 | test_success=0 160 | 161 | die() { 162 | code=$? 163 | if test -n "$EXIT_OK"; then 164 | exit $code 165 | else 166 | echo >&5 "FATAL: Unexpected exit with code $code" 167 | exit 1 168 | fi 169 | } 170 | 171 | EXIT_OK= 172 | trap 'die' EXIT 173 | 174 | # Public: Define that a test prerequisite is available. 175 | # 176 | # The prerequisite can later be checked explicitly using test_have_prereq or 177 | # implicitly by specifying the prerequisite name in calls to test_expect_success 178 | # or test_expect_failure. 179 | # 180 | # $1 - Name of prerequiste (a simple word, in all capital letters by convention) 181 | # 182 | # Examples 183 | # 184 | # # Set PYTHON prerequisite if interpreter is available. 185 | # command -v python >/dev/null && test_set_prereq PYTHON 186 | # 187 | # # Set prerequisite depending on some variable. 188 | # test -z "$NO_GETTEXT" && test_set_prereq GETTEXT 189 | # 190 | # Returns nothing. 191 | test_set_prereq() { 192 | satisfied_prereq="$satisfied_prereq$1 " 193 | } 194 | satisfied_prereq=" " 195 | 196 | # Public: Check if one or more test prerequisites are defined. 197 | # 198 | # The prerequisites must have previously been set with test_set_prereq. 199 | # The most common use of this is to skip all the tests if some essential 200 | # prerequisite is missing. 201 | # 202 | # $1 - Comma-separated list of test prerequisites. 203 | # 204 | # Examples 205 | # 206 | # # Skip all remaining tests if prerequisite is not set. 207 | # if ! test_have_prereq PERL; then 208 | # skip_all='skipping perl interface tests, perl not available' 209 | # test_done 210 | # fi 211 | # 212 | # Returns 0 if all prerequisites are defined or 1 otherwise. 213 | test_have_prereq() { 214 | # prerequisites can be concatenated with ',' 215 | save_IFS=$IFS 216 | IFS=, 217 | set -- $* 218 | IFS=$save_IFS 219 | 220 | total_prereq=0 221 | ok_prereq=0 222 | missing_prereq= 223 | 224 | for prerequisite; do 225 | case "$prerequisite" in 226 | !*) 227 | negative_prereq=t 228 | prerequisite=${prerequisite#!} 229 | ;; 230 | *) 231 | negative_prereq= 232 | esac 233 | 234 | total_prereq=$(($total_prereq + 1)) 235 | case "$satisfied_prereq" in 236 | *" $prerequisite "*) 237 | satisfied_this_prereq=t 238 | ;; 239 | *) 240 | satisfied_this_prereq= 241 | esac 242 | 243 | case "$satisfied_this_prereq,$negative_prereq" in 244 | t,|,t) 245 | ok_prereq=$(($ok_prereq + 1)) 246 | ;; 247 | *) 248 | # Keep a list of missing prerequisites; restore 249 | # the negative marker if necessary. 250 | prerequisite=${negative_prereq:+!}$prerequisite 251 | if test -z "$missing_prereq"; then 252 | missing_prereq=$prerequisite 253 | else 254 | missing_prereq="$prerequisite,$missing_prereq" 255 | fi 256 | esac 257 | done 258 | 259 | test $total_prereq = $ok_prereq 260 | } 261 | 262 | # You are not expected to call test_ok_ and test_failure_ directly, use 263 | # the text_expect_* functions instead. 264 | 265 | test_ok_() { 266 | test_success=$(($test_success + 1)) 267 | say_color "" "ok $test_count - $@" 268 | } 269 | 270 | test_failure_() { 271 | test_failure=$(($test_failure + 1)) 272 | say_color error "not ok $test_count - $1" 273 | shift 274 | echo "$@" | sed -e 's/^/# /' 275 | test "$immediate" = "" || { EXIT_OK=t; exit 1; } 276 | } 277 | 278 | test_known_broken_ok_() { 279 | test_fixed=$(($test_fixed + 1)) 280 | say_color error "ok $test_count - $@ # TODO known breakage vanished" 281 | } 282 | 283 | test_known_broken_failure_() { 284 | test_broken=$(($test_broken + 1)) 285 | say_color warn "not ok $test_count - $@ # TODO known breakage" 286 | } 287 | 288 | # Public: Execute commands in debug mode. 289 | # 290 | # Takes a single argument and evaluates it only when the test script is started 291 | # with --debug. This is primarily meant for use during the development of test 292 | # scripts. 293 | # 294 | # $1 - Commands to be executed. 295 | # 296 | # Examples 297 | # 298 | # test_debug "cat some_log_file" 299 | # 300 | # Returns the exit code of the last command executed in debug mode or 0 301 | # otherwise. 302 | test_debug() { 303 | test "$debug" = "" || eval "$1" 304 | } 305 | 306 | # Public: Stop execution and start a shell. 307 | # 308 | # This is useful for debugging tests and only makes sense together with "-v". 309 | # Be sure to remove all invocations of this command before submitting. 310 | test_pause() { 311 | if test "$verbose" = t; then 312 | "$SHELL_PATH" <&6 >&3 2>&4 313 | else 314 | error >&5 "test_pause requires --verbose" 315 | fi 316 | } 317 | 318 | test_eval_() { 319 | # This is a separate function because some tests use 320 | # "return" to end a test_expect_success block early. 321 | case ",$test_prereq," in 322 | *,INTERACTIVE,*) 323 | eval "$*" 324 | ;; 325 | *) 326 | eval &3 2>&4 "$*" 327 | ;; 328 | esac 329 | } 330 | 331 | test_run_() { 332 | test_cleanup=: 333 | expecting_failure=$2 334 | test_eval_ "$1" 335 | eval_ret=$? 336 | 337 | if test "$chain_lint" = "t"; then 338 | test_eval_ "(exit 117) && $1" 339 | if test "$?" != 117; then 340 | error "bug in the test script: broken &&-chain: $1" 341 | fi 342 | fi 343 | 344 | if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"; then 345 | test_eval_ "$test_cleanup" 346 | fi 347 | if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then 348 | echo "" 349 | fi 350 | return "$eval_ret" 351 | } 352 | 353 | test_skip_() { 354 | test_count=$(($test_count + 1)) 355 | to_skip= 356 | for skp in $SKIP_TESTS; do 357 | case $this_test.$test_count in 358 | $skp) 359 | to_skip=t 360 | break 361 | esac 362 | done 363 | if test -z "$to_skip" && test -n "$test_prereq" && ! test_have_prereq "$test_prereq"; then 364 | to_skip=t 365 | fi 366 | case "$to_skip" in 367 | t) 368 | of_prereq= 369 | if test "$missing_prereq" != "$test_prereq"; then 370 | of_prereq=" of $test_prereq" 371 | fi 372 | 373 | say_color skip >&3 "skipping test: $@" 374 | say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" 375 | : true 376 | ;; 377 | *) 378 | false 379 | ;; 380 | esac 381 | } 382 | 383 | # Public: Run test commands and expect them to succeed. 384 | # 385 | # When the test passed, an "ok" message is printed and the number of successful 386 | # tests is incremented. When it failed, a "not ok" message is printed and the 387 | # number of failed tests is incremented. 388 | # 389 | # With --immediate, exit test immediately upon the first failed test. 390 | # 391 | # Usually takes two arguments: 392 | # $1 - Test description 393 | # $2 - Commands to be executed. 394 | # 395 | # With three arguments, the first will be taken to be a prerequisite: 396 | # $1 - Comma-separated list of test prerequisites. The test will be skipped if 397 | # not all of the given prerequisites are set. To negate a prerequisite, 398 | # put a "!" in front of it. 399 | # $2 - Test description 400 | # $3 - Commands to be executed. 401 | # 402 | # Examples 403 | # 404 | # test_expect_success \ 405 | # 'git-write-tree should be able to write an empty tree.' \ 406 | # 'tree=$(git-write-tree)' 407 | # 408 | # # Test depending on one prerequisite. 409 | # test_expect_success TTY 'git --paginate rev-list uses a pager' \ 410 | # ' ... ' 411 | # 412 | # # Multiple prerequisites are separated by a comma. 413 | # test_expect_success PERL,PYTHON 'yo dawg' \ 414 | # ' test $(perl -E 'print eval "1 +" . qx[python -c "print 2"]') == "4" ' 415 | # 416 | # Returns nothing. 417 | test_expect_success() { 418 | test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= 419 | test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_success" 420 | export test_prereq 421 | if ! test_skip_ "$@"; then 422 | say >&3 "expecting success: $2" 423 | if test_run_ "$2"; then 424 | test_ok_ "$1" 425 | else 426 | test_failure_ "$@" 427 | fi 428 | fi 429 | echo >&3 "" 430 | } 431 | 432 | # Public: Run test commands and expect them to fail. Used to demonstrate a known 433 | # breakage. 434 | # 435 | # This is NOT the opposite of test_expect_success, but rather used to mark a 436 | # test that demonstrates a known breakage. 437 | # 438 | # When the test passed, an "ok" message is printed and the number of fixed tests 439 | # is incremented. When it failed, a "not ok" message is printed and the number 440 | # of tests still broken is incremented. 441 | # 442 | # Failures from these tests won't cause --immediate to stop. 443 | # 444 | # Usually takes two arguments: 445 | # $1 - Test description 446 | # $2 - Commands to be executed. 447 | # 448 | # With three arguments, the first will be taken to be a prerequisite: 449 | # $1 - Comma-separated list of test prerequisites. The test will be skipped if 450 | # not all of the given prerequisites are set. To negate a prerequisite, 451 | # put a "!" in front of it. 452 | # $2 - Test description 453 | # $3 - Commands to be executed. 454 | # 455 | # Returns nothing. 456 | test_expect_failure() { 457 | test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= 458 | test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_failure" 459 | export test_prereq 460 | if ! test_skip_ "$@"; then 461 | say >&3 "checking known breakage: $2" 462 | if test_run_ "$2" expecting_failure; then 463 | test_known_broken_ok_ "$1" 464 | else 465 | test_known_broken_failure_ "$1" 466 | fi 467 | fi 468 | echo >&3 "" 469 | } 470 | 471 | # Public: Run command and ensure that it fails in a controlled way. 472 | # 473 | # Use it instead of "! ". For example, when dies due to a 474 | # segfault, test_must_fail diagnoses it as an error, while "! " would 475 | # mistakenly be treated as just another expected failure. 476 | # 477 | # This is one of the prefix functions to be used inside test_expect_success or 478 | # test_expect_failure. 479 | # 480 | # $1.. - Command to be executed. 481 | # 482 | # Examples 483 | # 484 | # test_expect_success 'complain and die' ' 485 | # do something && 486 | # do something else && 487 | # test_must_fail git checkout ../outerspace 488 | # ' 489 | # 490 | # Returns 1 if the command succeeded (exit code 0). 491 | # Returns 1 if the command died by signal (exit codes 130-192) 492 | # Returns 1 if the command could not be found (exit code 127). 493 | # Returns 0 otherwise. 494 | test_must_fail() { 495 | "$@" 496 | exit_code=$? 497 | if test $exit_code = 0; then 498 | echo >&2 "test_must_fail: command succeeded: $*" 499 | return 1 500 | elif test $exit_code -gt 129 -a $exit_code -le 192; then 501 | echo >&2 "test_must_fail: died by signal: $*" 502 | return 1 503 | elif test $exit_code = 127; then 504 | echo >&2 "test_must_fail: command not found: $*" 505 | return 1 506 | fi 507 | return 0 508 | } 509 | 510 | # Public: Run command and ensure that it succeeds or fails in a controlled way. 511 | # 512 | # Similar to test_must_fail, but tolerates success too. Use it instead of 513 | # " || :" to catch failures caused by a segfault, for instance. 514 | # 515 | # This is one of the prefix functions to be used inside test_expect_success or 516 | # test_expect_failure. 517 | # 518 | # $1.. - Command to be executed. 519 | # 520 | # Examples 521 | # 522 | # test_expect_success 'some command works without configuration' ' 523 | # test_might_fail git config --unset all.configuration && 524 | # do something 525 | # ' 526 | # 527 | # Returns 1 if the command died by signal (exit codes 130-192) 528 | # Returns 1 if the command could not be found (exit code 127). 529 | # Returns 0 otherwise. 530 | test_might_fail() { 531 | "$@" 532 | exit_code=$? 533 | if test $exit_code -gt 129 -a $exit_code -le 192; then 534 | echo >&2 "test_might_fail: died by signal: $*" 535 | return 1 536 | elif test $exit_code = 127; then 537 | echo >&2 "test_might_fail: command not found: $*" 538 | return 1 539 | fi 540 | return 0 541 | } 542 | 543 | # Public: Run command and ensure it exits with a given exit code. 544 | # 545 | # This is one of the prefix functions to be used inside test_expect_success or 546 | # test_expect_failure. 547 | # 548 | # $1 - Expected exit code. 549 | # $2.. - Command to be executed. 550 | # 551 | # Examples 552 | # 553 | # test_expect_success 'Merge with d/f conflicts' ' 554 | # test_expect_code 1 git merge "merge msg" B master 555 | # ' 556 | # 557 | # Returns 0 if the expected exit code is returned or 1 otherwise. 558 | test_expect_code() { 559 | want_code=$1 560 | shift 561 | "$@" 562 | exit_code=$? 563 | if test $exit_code = $want_code; then 564 | return 0 565 | fi 566 | 567 | echo >&2 "test_expect_code: command exited with $exit_code, we wanted $want_code $*" 568 | return 1 569 | } 570 | 571 | # Public: Compare two files to see if expected output matches actual output. 572 | # 573 | # The TEST_CMP variable defines the command used for the comparision; it 574 | # defaults to "diff -u". Only when the test script was started with --verbose, 575 | # will the command's output, the diff, be printed to the standard output. 576 | # 577 | # This is one of the prefix functions to be used inside test_expect_success or 578 | # test_expect_failure. 579 | # 580 | # $1 - Path to file with expected output. 581 | # $2 - Path to file with actual output. 582 | # 583 | # Examples 584 | # 585 | # test_expect_success 'foo works' ' 586 | # echo expected >expected && 587 | # foo >actual && 588 | # test_cmp expected actual 589 | # ' 590 | # 591 | # Returns the exit code of the command set by TEST_CMP. 592 | test_cmp() { 593 | ${TEST_CMP:-diff -u} "$@" 594 | } 595 | 596 | # Public: portably print a sequence of numbers. 597 | # 598 | # seq is not in POSIX and GNU seq might not be available everywhere, 599 | # so it is nice to have a seq implementation, even a very simple one. 600 | # 601 | # $1 - Starting number. 602 | # $2 - Ending number. 603 | # 604 | # Examples 605 | # 606 | # test_expect_success 'foo works 10 times' ' 607 | # for i in $(test_seq 1 10) 608 | # do 609 | # foo || return 610 | # done 611 | # ' 612 | # 613 | # Returns 0 if all the specified numbers can be displayed. 614 | test_seq() { 615 | i="$1" 616 | j="$2" 617 | while test "$i" -le "$j" 618 | do 619 | echo "$i" || return 620 | i=$(expr "$i" + 1) 621 | done 622 | } 623 | 624 | # Public: Check if the file expected to be empty is indeed empty, and barfs 625 | # otherwise. 626 | # 627 | # $1 - File to check for emptyness. 628 | # 629 | # Returns 0 if file is empty, 1 otherwise. 630 | test_must_be_empty() { 631 | if test -s "$1" 632 | then 633 | echo "'$1' is not empty, it contains:" 634 | cat "$1" 635 | return 1 636 | fi 637 | } 638 | 639 | # Public: Schedule cleanup commands to be run unconditionally at the end of a 640 | # test. 641 | # 642 | # If some cleanup command fails, the test will not pass. With --immediate, no 643 | # cleanup is done to help diagnose what went wrong. 644 | # 645 | # This is one of the prefix functions to be used inside test_expect_success or 646 | # test_expect_failure. 647 | # 648 | # $1.. - Commands to prepend to the list of cleanup commands. 649 | # 650 | # Examples 651 | # 652 | # test_expect_success 'test core.capslock' ' 653 | # git config core.capslock true && 654 | # test_when_finished "git config --unset core.capslock" && 655 | # do_something 656 | # ' 657 | # 658 | # Returns the exit code of the last cleanup command executed. 659 | test_when_finished() { 660 | test_cleanup="{ $* 661 | } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup" 662 | } 663 | 664 | # Public: Schedule cleanup commands to be run unconditionally when all tests 665 | # have run. 666 | # 667 | # This can be used to clean up things like test databases. It is not needed to 668 | # clean up temporary files, as test_done already does that. 669 | # 670 | # Examples: 671 | # 672 | # cleanup mysql -e "DROP DATABASE mytest" 673 | # 674 | # Returns the exit code of the last cleanup command executed. 675 | final_cleanup= 676 | cleanup() { 677 | final_cleanup="{ $* 678 | } && (exit \"\$eval_ret\"); eval_ret=\$?; $final_cleanup" 679 | } 680 | 681 | # Public: Summarize test results and exit with an appropriate error code. 682 | # 683 | # Must be called at the end of each test script. 684 | # 685 | # Can also be used to stop tests early and skip all remaining tests. For this, 686 | # set skip_all to a string explaining why the tests were skipped before calling 687 | # test_done. 688 | # 689 | # Examples 690 | # 691 | # # Each test script must call test_done at the end. 692 | # test_done 693 | # 694 | # # Skip all remaining tests if prerequisite is not set. 695 | # if ! test_have_prereq PERL; then 696 | # skip_all='skipping perl interface tests, perl not available' 697 | # test_done 698 | # fi 699 | # 700 | # Returns 0 if all tests passed or 1 if there was a failure. 701 | test_done() { 702 | EXIT_OK=t 703 | 704 | if test -z "$HARNESS_ACTIVE"; then 705 | test_results_dir="$SHARNESS_TEST_DIRECTORY/test-results" 706 | mkdir -p "$test_results_dir" 707 | test_results_path="$test_results_dir/$this_test.$$.counts" 708 | 709 | cat >>"$test_results_path" <<-EOF 710 | total $test_count 711 | success $test_success 712 | fixed $test_fixed 713 | broken $test_broken 714 | failed $test_failure 715 | 716 | EOF 717 | fi 718 | 719 | if test "$test_fixed" != 0; then 720 | say_color error "# $test_fixed known breakage(s) vanished; please update test(s)" 721 | fi 722 | if test "$test_broken" != 0; then 723 | say_color warn "# still have $test_broken known breakage(s)" 724 | fi 725 | if test "$test_broken" != 0 || test "$test_fixed" != 0; then 726 | test_remaining=$(( $test_count - $test_broken - $test_fixed )) 727 | msg="remaining $test_remaining test(s)" 728 | else 729 | test_remaining=$test_count 730 | msg="$test_count test(s)" 731 | fi 732 | 733 | case "$test_failure" in 734 | 0) 735 | # Maybe print SKIP message 736 | if test -n "$skip_all" && test $test_count -gt 0; then 737 | error "Can't use skip_all after running some tests" 738 | fi 739 | [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all" 740 | 741 | if test $test_remaining -gt 0; then 742 | say_color pass "# passed all $msg" 743 | fi 744 | say "1..$test_count$skip_all" 745 | 746 | test_eval_ "$final_cleanup" 747 | 748 | test -d "$remove_trash" && 749 | cd "$(dirname "$remove_trash")" && 750 | rm -rf "$(basename "$remove_trash")" 751 | 752 | exit 0 ;; 753 | 754 | *) 755 | say_color error "# failed $test_failure among $msg" 756 | say "1..$test_count" 757 | 758 | exit 1 ;; 759 | 760 | esac 761 | } 762 | 763 | # Public: Root directory containing tests. Tests can override this variable, 764 | # e.g. for testing Sharness itself. 765 | : ${SHARNESS_TEST_DIRECTORY:=$(pwd)} 766 | export SHARNESS_TEST_DIRECTORY 767 | 768 | # Public: Source directory of test code and sharness library. 769 | # This directory may be different from the directory in which tests are 770 | # being run. 771 | : ${SHARNESS_TEST_SRCDIR:=$(cd $(dirname $0) && pwd)} 772 | export SHARNESS_TEST_SRCDIR 773 | 774 | # Public: Build directory that will be added to PATH. By default, it is set to 775 | # the parent directory of SHARNESS_TEST_DIRECTORY. 776 | : ${SHARNESS_BUILD_DIRECTORY:="$SHARNESS_TEST_DIRECTORY/.."} 777 | PATH="$SHARNESS_BUILD_DIRECTORY:$PATH" 778 | export PATH SHARNESS_BUILD_DIRECTORY 779 | 780 | # Public: Path to test script currently executed. 781 | SHARNESS_TEST_FILE="$0" 782 | export SHARNESS_TEST_FILE 783 | 784 | # Prepare test area. 785 | SHARNESS_TRASH_DIRECTORY="trash directory.$(basename "$SHARNESS_TEST_FILE" ".$SHARNESS_TEST_EXTENSION")" 786 | test -n "$root" && SHARNESS_TRASH_DIRECTORY="$root/$SHARNESS_TRASH_DIRECTORY" 787 | case "$SHARNESS_TRASH_DIRECTORY" in 788 | /*) ;; # absolute path is good 789 | *) SHARNESS_TRASH_DIRECTORY="$SHARNESS_TEST_DIRECTORY/$SHARNESS_TRASH_DIRECTORY" ;; 790 | esac 791 | test "$debug" = "t" || remove_trash="$SHARNESS_TRASH_DIRECTORY" 792 | rm -rf "$SHARNESS_TRASH_DIRECTORY" || { 793 | EXIT_OK=t 794 | echo >&5 "FATAL: Cannot prepare test area" 795 | exit 1 796 | } 797 | 798 | 799 | # 800 | # Load any extensions in $srcdir/sharness.d/*.sh 801 | # 802 | if test -d "${SHARNESS_TEST_SRCDIR}/sharness.d" 803 | then 804 | for file in "${SHARNESS_TEST_SRCDIR}"/sharness.d/*.sh 805 | do 806 | # Ensure glob was not an empty match: 807 | test -e "${file}" || break 808 | 809 | if test -n "$debug" 810 | then 811 | echo >&5 "sharness: loading extensions from ${file}" 812 | fi 813 | . "${file}" 814 | if test $? != 0 815 | then 816 | echo >&5 "sharness: Error loading ${file}. Aborting." 817 | exit 1 818 | fi 819 | done 820 | fi 821 | 822 | # Public: Empty trash directory, the test area, provided for each test. The HOME 823 | # variable is set to that directory too. 824 | export SHARNESS_TRASH_DIRECTORY 825 | 826 | HOME="$SHARNESS_TRASH_DIRECTORY" 827 | export HOME 828 | 829 | mkdir -p "$SHARNESS_TRASH_DIRECTORY" || exit 1 830 | # Use -P to resolve symlinks in our working directory so that the cwd 831 | # in subprocesses like git equals our $PWD (for pathname comparisons). 832 | cd -P "$SHARNESS_TRASH_DIRECTORY" || exit 1 833 | 834 | this_test=${SHARNESS_TEST_FILE##*/} 835 | this_test=${this_test%.$SHARNESS_TEST_EXTENSION} 836 | for skp in $SKIP_TESTS; do 837 | case "$this_test" in 838 | $skp) 839 | say_color info >&3 "skipping test $this_test altogether" 840 | skip_all="skip all tests in $this_test" 841 | test_done 842 | esac 843 | done 844 | 845 | test -n "$TEST_LONG" && test_set_prereq EXPENSIVE 846 | test -n "$TEST_INTERACTIVE" && test_set_prereq INTERACTIVE 847 | 848 | # Make sure this script ends with code 0 849 | : 850 | 851 | # vi: set ts=4 sw=4 noet : 852 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------