# HG changeset patch # User Guido Berhoerster # Date 1463142764 -7200 # Node ID dfd3ddbdb20174ddfa3f452ee46e30ed71a9ef2c # Parent 2b9244d20ecf1644ace2784eafbf18f8100f07e3 Add tests diff -r 2b9244d20ecf -r dfd3ddbdb201 Makefile --- a/Makefile Fri Apr 03 14:57:57 2015 +0200 +++ b/Makefile Fri May 13 14:32:44 2016 +0200 @@ -66,6 +66,8 @@ --stringparam css.decoration 0 \ --stringparam default.table.width '100%' +TESTS_OUTPUT_PATH = ./tests/output + define generate-manpage-rule = $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl $$(XSLTPROC) \ @@ -248,7 +250,7 @@ .DEFAULT_TARGET = all -.PHONY: all clean clobber dist install +.PHONY: all clean clobber dist install check all: $(PWSDUMP_BIN) $(LIBPWS_LIB) $(MANPAGES) @@ -362,9 +364,15 @@ fi \ done +check: $(PWSDUMP_BIN) + rm -rf $(TESTS_OUTPUT_PATH); \ + SHELL=$(SHELL) PWSDUMP=$(PWSDUMP_BIN) \ + TESTS_OUTPUT_PATH=$(TESTS_OUTPUT_PATH) $(SHELL) tests/run-tests.sh + clean: rm -f $(LIBPWS_LIB) $(PWSDUMP_BIN) $(OBJS) $(MANPAGES) \ $(XHTML_DOCUMENTATION) + rm -rf $(TESTS_OUTPUT_PATH) clobber: clean rm -f $(patsubst %.o,%.d,$(OBJS)) diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/bad-key.psafe3 Binary file tests/bad-key.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/corrupted-file-2.psafe3 Binary file tests/corrupted-file-2.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/corrupted-file.psafe3 Binary file tests/corrupted-file.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/empty-file.psafe3 diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/garbage-block.pws3 Binary file tests/garbage-block.pws3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/invalid-iterations.psafe3 Binary file tests/invalid-iterations.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/invalid-record-field-length.pws3 Binary file tests/invalid-record-field-length.pws3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/invalid-version.psafe3 Binary file tests/invalid-version.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/minimal.psafe3 Binary file tests/minimal.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/missing-version.psafe3 Binary file tests/missing-version.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/password.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/password.txt Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,1 @@ +PaSsWoRd diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/random-garbage.psafe3 Binary file tests/random-garbage.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/record-without-uuid.pws3 Binary file tests/record-without-uuid.pws3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/run-tests.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/run-tests.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,63 @@ +#!/bin/sh +# +# Copyright (C) 2016 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 PWSDUMP="${PWSDUMP:-pwsdump}" + +export LC_ALL=C +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}").log" + + [ -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 2b9244d20ecf -r dfd3ddbdb201 tests/test-001-non-existent-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-001-non-existent-file.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file that does not exist +$PWSDUMP "${TESTS_OUTPUT_PATH}/non-existent.psafe3" +grep 'could not open input file' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-002-empty-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-002-empty-file.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open an empty file +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/empty-file.psafe3" +grep 'unexpected end of file' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-003-random-garbage-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-003-random-garbage-file.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file that does not START with "PWS3" +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/random-garbage.psafe3" +grep 'unknown filetype' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-004-invalid-iterations.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-004-invalid-iterations.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,4 @@ +# try to opena file that specifies 0 iterations +$PWSDUMP -p "${TESTS_PATH}/password.txt" \ + "${TESTS_PATH}/invalid-iterations.psafe3" +grep 'invalid number of iterations: 0' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-005-wrong-password.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-005-wrong-password.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file with the wrong password +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/wrong-password.psafe3" +grep 'wrong password' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-006-bad-key.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-006-bad-key.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file which contains a corrupt key +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/bad-key.psafe3" +grep 'checksum failed' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-007-truncated-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-007-truncated-file.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file which has been truncated +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/truncated-file.psafe3" +grep 'unexpected end of file' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-008-corrupt-files.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-008-corrupt-files.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,4 @@ +# try to open corrupted files +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/corrupted-file.psafe3" +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/corrupted-file-2.psafe3" +grep 'invalid field length' "${LOGFILE}" && grep 'checksum failed' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-009-valid-minimal-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-009-valid-minimal-file.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file which contains nothing but a version header field +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/minimal.psafe3" | \ + grep '^00:030b' diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-010-invalid-version.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-010-invalid-version.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file which specifies an unsupported version +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/invalid-version.psafe3" +grep 'unsupported database version' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-011-missing-version-field.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-011-missing-version-field.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,3 @@ +# try to open a file which does not start with a version header field +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/missing-version.psafe3" +grep 'header does not start with a version field' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-012-unknown-fields.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-012-unknown-fields.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,6 @@ +# try to read and write header and record fields of an unknown type +$PWSDUMP -p "${TESTS_PATH}/password.txt" -n "${TESTS_PATH}/password.txt" \ + -t pws3 -o "${TESTS_OUTPUT_PATH}/unknown-fields.psafe3" \ + "${TESTS_PATH}/unknown-fields.psafe3" || exit 1 +$PWSDUMP -p "${TESTS_PATH}/password.txt" \ + "${TESTS_OUTPUT_PATH}/unknown-fields.psafe3" | grep '^fe:' diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-013-valid-file.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-013-valid-file.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,9 @@ +# conversions between dump and pws3 format +$PWSDUMP -p "${TESTS_PATH}/password.txt" -o "${TESTS_OUTPUT_PATH}/valid.dump" \ + "${TESTS_PATH}/valid.psafe3" +cmp "${TESTS_PATH}/valid.dump" "${TESTS_OUTPUT_PATH}/valid.dump" || exit 1 +$PWSDUMP -f dump -t pws3 -n "${TESTS_PATH}/password.txt" \ + -o "${TESTS_OUTPUT_PATH}/valid.psafe3" "${TESTS_PATH}/valid.dump" +$PWSDUMP -p "${TESTS_PATH}/password.txt" -o "${TESTS_OUTPUT_PATH}/valid-new.dump" \ + "${TESTS_OUTPUT_PATH}/valid.psafe3" +cmp "${TESTS_PATH}/valid.dump" "${TESTS_OUTPUT_PATH}/valid-new.dump" || exit 1 diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-014-invalid-record-field-length.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-014-invalid-record-field-length.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,4 @@ +# record fields with invalid lenghts +$PWSDUMP -p "${TESTS_PATH}/password.txt" \ + "${TESTS_PATH}/invalid-record-field-length.pws3" +grep 'invalid field length' "${LOGFILE}" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/test-015-record-without-uuid.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-015-record-without-uuid.sh Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,2 @@ +# read a record without an UUID field which forces generation of a new UUID +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/record-without-uuid.pws3" diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/truncated-file.psafe3 Binary file tests/truncated-file.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/unknown-fields.psafe3 Binary file tests/unknown-fields.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/valid.dump --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/valid.dump Fri May 13 14:32:44 2016 +0200 @@ -0,0 +1,29 @@ +# Passwordsafe v3 database dump +Header +00:030b +01:ddba98acd8fb027626c0a1c3212e0a12 +03:111 +04:2016-05-10T10:35:29Z +06:pwsdump 1.0.0 +07:user +08:host +11:foo +11:foo.bar +Record 1 +01:091e87b0f8beca00d53d7bceac4580bf +02:foo.bar.baz +03:Bla +04:Joe +06:PaSsWoRd +07:2016-07-27T19:35:31Z +08:2016-07-27T19:35:31Z +0c:2016-07-27T19:35:53Z +Record 2 +01:6f452a3189b724df91b241adcf793621 +02:foo.bar.baz +03:Waldo +04:Joe +06:pAsSwOrD +07:2016-07-29T08:01:22Z +08:2016-07-29T08:01:22Z +0c:2016-07-29T08:01:45Z diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/valid.psafe3 Binary file tests/valid.psafe3 has changed diff -r 2b9244d20ecf -r dfd3ddbdb201 tests/wrong-password.psafe3 Binary file tests/wrong-password.psafe3 has changed