# HG changeset patch # User Guido Berhoerster # Date 1565170087 -7200 # Node ID f9501248b6bd48ea2346c670b310d184bf921f55 # Parent 2a8298bafec202db62d384b9b900e6db3de126b0 Add tests diff -r 2a8298bafec2 -r f9501248b6bd Makefile --- a/Makefile Tue Aug 06 11:21:04 2019 +0200 +++ b/Makefile Wed Aug 07 11:28:07 2019 +0200 @@ -51,6 +51,8 @@ DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \ --stringparam man.copyright.section.enabled 0 +TESTS_OUTPUT_PATH = ./tests/output + define generate-manpage-rule = $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl $$(XSLTPROC) \ @@ -179,7 +181,7 @@ .DEFAULT_TARGET = all -.PHONY: all clean clobber dist install +.PHONY: all check clean clobber dist install all: $(PWM_BIN) $(PWM_CLIP_BIN) $(MANPAGES) @@ -275,6 +277,11 @@ fi \ done +check: $(PWM_BIN) + rm -rf $(TESTS_OUTPUT_PATH); \ + SHELL=$(SHELL) PWM=./$(PWM_BIN) \ + TESTS_OUTPUT_PATH=$(TESTS_OUTPUT_PATH) $(SHELL) tests/run-tests.sh + clean: rm -f $(LIBCOMPAT_LIB) $(LIBPWM_LIB) $(PWM_CLIP_BIN) $(PWM_BIN) \ $(OBJS) $(MANPAGES) diff -r 2a8298bafec2 -r f9501248b6bd tests/corrupt.psafe3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/corrupt.psafe3 Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,1 @@ +PWS3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file diff -r 2a8298bafec2 -r f9501248b6bd tests/password.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/password.txt Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,1 @@ +PaSsWoRd diff -r 2a8298bafec2 -r f9501248b6bd tests/run-tests.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/run-tests.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,72 @@ +#!/bin/sh +# +# Copyright (C) 2019 Guido Berhoerster +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +export PWM="${PWM:-pwm}" + +export LC_ALL=C + +l="$(locale -a | sort | grep -E '^(C|en_US)\.([uU][tT][fF]-?8)$' | head -1)" +if [ -z "$l" ]; then + printf 'no suitable UTF-8 locale found\n' >&2 + exit 1 +fi + +export LC_ALL="$l" +export TESTS_PATH="$(dirname "$0")" +export TESTS_OUTPUT_PATH="${TESTS_OUTPUT_PATH:-${TESTS_PATH}/output}" + +tests_passed=0 +tests_failed=0 + +mkdir -p "${TESTS_OUTPUT_PATH}" || exit 1 + +for t in "${TESTS_PATH}"/test-*.sh; do + [ -r "${t}" ] || break + + export LOGFILE="${TESTS_OUTPUT_PATH}/$(basename "${t}" .sh).log" + export TEST_NAME="$(basename "${t}" .sh)" + + [ -t 1 ] && printf "Running %s" "${t}" + if ${SHELL:-/bin/sh} "$t" >/dev/null 2>"${LOGFILE}"; then + tests_passed=$(( tests_passed + 1 )) + if [ -t 1 ]; then + printf "\rOK " + else + printf "OK %s" "${t}" + fi + else + tests_failed=$(( tests_failed + 1 )) + if [ -t 1 ]; then + printf "\rFAILED " + else + printf "FAILED %s" "${t}" + fi + fi + printf "%s\n" "${t}" +done + +printf -- "-----------\npassed: %3d\nfailed: %3d\ntotal: %3d\n" $tests_passed \ + $tests_failed $(( tests_failed + tests_passed )) + +[ $tests_failed -eq 0 ] diff -r 2a8298bafec2 -r f9501248b6bd tests/test-001-non-existing-home.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-001-non-existing-home.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,4 @@ +# non-existing home directory + +HOME=/nonexistent/home $PWM -P "${TESTS_PATH}/password.txt" < /dev/null +grep 'failed to create directory' "${LOGFILE}" diff -r 2a8298bafec2 -r f9501248b6bd tests/test-002-missing-master-password-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-002-missing-master-password-file.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,4 @@ +# missing master password file + +$PWM "${TESTS_OUTPUT_PATH}/test.psafe3" < /dev/null +grep 'master password file must be specified' "${LOGFILE}" diff -r 2a8298bafec2 -r f9501248b6bd tests/test-003-non-existing-master-password-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-003-non-existing-master-password-file.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,5 @@ +# non-existing master password file + +$PWM -P "${TESTS_PATH}/nonexistent-password.txt" \ + "${TESTS_OUTPUT_PATH}/test.psafe3" < /dev/null +grep 'failed to open master password file' "${LOGFILE}" diff -r 2a8298bafec2 -r f9501248b6bd tests/test-004-non-readable-pwmrc.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-004-non-readable-pwmrc.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,8 @@ +# non-readable pwmrc + +mkdir -p "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm" +touch "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm/pwmrc" +chmod 000 "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm/pwmrc" +HOME="${TESTS_OUTPUT_PATH}/${TEST_NAME}" $PWM \ + -P "${TESTS_PATH}/password.txt" "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm/pwmrc" <<'EOF' +invalid +EOF +HOME="${TESTS_OUTPUT_PATH}/${TEST_NAME}" $PWM \ + -P "${TESTS_PATH}/password.txt" "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm/pwmrc" <<'EOF' +set pipecommand=cat +define lst=ls +EOF +HOME="${TESTS_OUTPUT_PATH}/${TEST_NAME}" $PWM \ + -P "${TESTS_PATH}/password.txt" <<'EOF' | grep pipecommand +S +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-008-info-of-existing-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-008-info-of-existing-file.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# info of existing file + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + \ + grep -E '^Format: +0x' +i +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-009-list-entries-of-existing-files.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-009-list-entries-of-existing-files.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,6 @@ +# list entries of existing files + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep '1 Foo' +ls +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-010-list-specific-entries-of-existing-files.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-010-list-specific-entries-of-existing-files.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,6 @@ +# list specific entries of existing files + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep '1 Foo' +ls title~Foo +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-011-show-entry.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-011-show-entry.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,6 @@ +# show entry + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep -E '^Title: +Foo' +s 1 +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-012-create-entry.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-012-create-entry.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# create entry + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep '3 Quux' +c title="Quux" password="SeCrEt" +ls title~Quux +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-013-generate-password-for-an-entry.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-013-generate-password-for-an-entry.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# generate password for an entry + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep '^Password: ' +gp 1 +s 1 password +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-014-modify-entry.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-014-modify-entry.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# modify entry + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep -E '^Title: +Quux' +m 1 title="Quux" +s 1 +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-015-show-status-of-modified-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-015-show-status-of-modified-file.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# show status of modified file + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep 'unsaved changes' +m 1 title="Quux" +t +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-016-remove-entry.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-016-remove-entry.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# remove entry + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' +rm 1 +s 1 +EOF +grep 'record 1 does not exist' "${LOGFILE}" diff -r 2a8298bafec2 -r f9501248b6bd tests/test-017-pipe-password-to-external-command.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-017-pipe-password-to-external-command.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,6 @@ +# pipe password to external command + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep 'Foo' +p 1 title cat +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-018-generate-password-with-limitations.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-018-generate-password-with-limitations.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,6 @@ +# generate password with limitations + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep -E '^[[:alnum:]]{8}$' +gp len=8 charclass=8:alnum +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-019-create-group.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-019-create-group.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,7 @@ +# create group + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' | \ + grep '\[Quux\]' +cg Quux +ls +EOF diff -r 2a8298bafec2 -r f9501248b6bd tests/test-020-remove-group.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-020-remove-group.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,8 @@ +# remove group + +$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/test.psafe3" <<'EOF' +cg Quux +rg Quux +rg Quux +EOF +grep 'empty group "Quux" does not exist' "${LOGFILE}" diff -r 2a8298bafec2 -r f9501248b6bd tests/test-021-remove-entry-in-readonly-mode.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-021-remove-entry-in-readonly-mode.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,6 @@ +# remove entry in readonly mode + +$PWM -P "${TESTS_PATH}/password.txt" -R "${TESTS_PATH}/test.psafe3" <<'EOF' +rm 1 +EOF +grep 'cannot remove entries in read-only mode' "${LOGFILE}" diff -r 2a8298bafec2 -r f9501248b6bd tests/test-022-change-master-password.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-022-change-master-password.sh Wed Aug 07 11:28:07 2019 +0200 @@ -0,0 +1,13 @@ +# change master password and save password database + +password="GeHeIm" +mkdir -p "${TESTS_OUTPUT_PATH}/${TEST_NAME}/" +cp "${TESTS_PATH}/test.psafe3" "${TESTS_OUTPUT_PATH}/${TEST_NAME}/test.psafe3" +printf "%s" "${password}" >"${TESTS_OUTPUT_PATH}/${TEST_NAME}/password.txt" +$PWM -P "${TESTS_PATH}/password.txt" \ + "${TESTS_OUTPUT_PATH}/${TEST_NAME}/test.psafe3" <