changeset 36:f9501248b6bd

Add tests
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Wed, 07 Aug 2019 11:28:07 +0200
parents 2a8298bafec2
children e027dd4409c7
files Makefile tests/corrupt.psafe3 tests/password.txt tests/run-tests.sh tests/test-001-non-existing-home.sh tests/test-002-missing-master-password-file.sh tests/test-003-non-existing-master-password-file.sh tests/test-004-non-readable-pwmrc.sh tests/test-005-corrupt-pwmrc.sh tests/test-006-corrupt-password-database.sh tests/test-007-pwmrc-with-options-macros.sh tests/test-008-info-of-existing-file.sh tests/test-009-list-entries-of-existing-files.sh tests/test-010-list-specific-entries-of-existing-files.sh tests/test-011-show-entry.sh tests/test-012-create-entry.sh tests/test-013-generate-password-for-an-entry.sh tests/test-014-modify-entry.sh tests/test-015-show-status-of-modified-file.sh tests/test-016-remove-entry.sh tests/test-017-pipe-password-to-external-command.sh tests/test-018-generate-password-with-limitations.sh tests/test-019-create-group.sh tests/test-020-remove-group.sh tests/test-021-remove-entry-in-readonly-mode.sh tests/test-022-change-master-password.sh tests/test-023-show-help.sh tests/test.psafe3
diffstat 28 files changed, 239 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- /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
--- /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
--- /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 <guido+pwm@berhoerster.name>
+#
+# 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 ]
--- /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}"
--- /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}"
--- /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}"
--- /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" </dev/null
+grep 'failed to open configuration file' "${LOGFILE}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-005-corrupt-pwmrc.sh	Wed Aug 07 11:28:07 2019 +0200
@@ -0,0 +1,9 @@
+# corrupt pwmrc
+
+mkdir -p "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm"
+cat > "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm/pwmrc" <<'EOF'
+invalid
+EOF
+HOME="${TESTS_OUTPUT_PATH}/${TEST_NAME}" $PWM \
+    -P "${TESTS_PATH}/password.txt" </dev/null
+grep 'unknown configuration command' "${LOGFILE}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-006-corrupt-password-database.sh	Wed Aug 07 11:28:07 2019 +0200
@@ -0,0 +1,4 @@
+# corrupt password database
+
+$PWM -P "${TESTS_PATH}/password.txt" "${TESTS_PATH}/corrupt.psafe3" < /dev/null
+grep 'failed to read password database' "${LOGFILE}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-007-pwmrc-with-options-macros.sh	Wed Aug 07 11:28:07 2019 +0200
@@ -0,0 +1,11 @@
+# pwmrc with options, macros
+
+mkdir -p "${TESTS_OUTPUT_PATH}/${TEST_NAME}/.pwm"
+cat >"${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
--- /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
--- /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
--- /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
--- /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
--- /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
--- /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
--- /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
--- /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
--- /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}"
--- /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
--- /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
--- /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
--- /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}"
--- /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}"
--- /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" <<EOF
+ch $password
+w
+EOF
+$PWM -P "${TESTS_OUTPUT_PATH}/${TEST_NAME}/password.txt" \
+    "${TESTS_OUTPUT_PATH}/${TEST_NAME}/test.psafe3" </dev/null
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-023-show-help.sh	Wed Aug 07 11:28:07 2019 +0200
@@ -0,0 +1,6 @@
+# show help
+
+$PWM -P "${TESTS_PATH}/password.txt" -R "${TESTS_PATH}/test.psafe3" <<'EOF' | \
+    grep 'Commands:'
+h
+EOF
Binary file tests/test.psafe3 has changed