projects/libpws

changeset 4:dfd3ddbdb201

Add tests
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Fri May 13 14:32:44 2016 +0200 (2016-05-13)
parents 2b9244d20ecf
children b3fc9f7e2b43
files Makefile tests/bad-key.psafe3 tests/corrupted-file-2.psafe3 tests/corrupted-file.psafe3 tests/empty-file.psafe3 tests/garbage-block.pws3 tests/invalid-iterations.psafe3 tests/invalid-record-field-length.pws3 tests/invalid-version.psafe3 tests/minimal.psafe3 tests/missing-version.psafe3 tests/password.txt tests/random-garbage.psafe3 tests/record-without-uuid.pws3 tests/run-tests.sh tests/test-001-non-existent-file.sh tests/test-002-empty-file.sh tests/test-003-random-garbage-file.sh tests/test-004-invalid-iterations.sh tests/test-005-wrong-password.sh tests/test-006-bad-key.sh tests/test-007-truncated-file.sh tests/test-008-corrupt-files.sh tests/test-009-valid-minimal-file.sh tests/test-010-invalid-version.sh tests/test-011-missing-version-field.sh tests/test-012-unknown-fields.sh tests/test-013-valid-file.sh tests/test-014-invalid-record-field-length.sh tests/test-015-record-without-uuid.sh tests/truncated-file.psafe3 tests/unknown-fields.psafe3 tests/valid.dump tests/valid.psafe3 tests/wrong-password.psafe3
line diff
     1.1 --- a/Makefile	Fri Apr 03 14:57:57 2015 +0200
     1.2 +++ b/Makefile	Fri May 13 14:32:44 2016 +0200
     1.3 @@ -66,6 +66,8 @@
     1.4  				--stringparam css.decoration 0 \
     1.5  				--stringparam default.table.width '100%'
     1.6  
     1.7 +TESTS_OUTPUT_PATH = ./tests/output
     1.8 +
     1.9  define generate-manpage-rule =
    1.10  $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
    1.11  	$$(XSLTPROC) \
    1.12 @@ -248,7 +250,7 @@
    1.13  
    1.14  .DEFAULT_TARGET = all
    1.15  
    1.16 -.PHONY: all clean clobber dist install
    1.17 +.PHONY: all clean clobber dist install check
    1.18  
    1.19  all: $(PWSDUMP_BIN) $(LIBPWS_LIB) $(MANPAGES)
    1.20  
    1.21 @@ -362,9 +364,15 @@
    1.22  	    fi \
    1.23  	done
    1.24  
    1.25 +check: $(PWSDUMP_BIN)
    1.26 +	rm -rf $(TESTS_OUTPUT_PATH); \
    1.27 +	SHELL=$(SHELL) PWSDUMP=$(PWSDUMP_BIN) \
    1.28 +	    TESTS_OUTPUT_PATH=$(TESTS_OUTPUT_PATH) $(SHELL) tests/run-tests.sh
    1.29 +
    1.30  clean:
    1.31  	rm -f $(LIBPWS_LIB) $(PWSDUMP_BIN) $(OBJS) $(MANPAGES) \
    1.32  	    $(XHTML_DOCUMENTATION)
    1.33 +	rm -rf $(TESTS_OUTPUT_PATH)
    1.34  
    1.35  clobber: clean
    1.36  	rm -f $(patsubst %.o,%.d,$(OBJS))
     2.1 Binary file tests/bad-key.psafe3 has changed
     3.1 Binary file tests/corrupted-file-2.psafe3 has changed
     4.1 Binary file tests/corrupted-file.psafe3 has changed
     5.1 Binary file tests/garbage-block.pws3 has changed
     6.1 Binary file tests/invalid-iterations.psafe3 has changed
     7.1 Binary file tests/invalid-record-field-length.pws3 has changed
     8.1 Binary file tests/invalid-version.psafe3 has changed
     9.1 Binary file tests/minimal.psafe3 has changed
    10.1 Binary file tests/missing-version.psafe3 has changed
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tests/password.txt	Fri May 13 14:32:44 2016 +0200
    11.3 @@ -0,0 +1,1 @@
    11.4 +PaSsWoRd
    12.1 Binary file tests/random-garbage.psafe3 has changed
    13.1 Binary file tests/record-without-uuid.pws3 has changed
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tests/run-tests.sh	Fri May 13 14:32:44 2016 +0200
    14.3 @@ -0,0 +1,63 @@
    14.4 +#!/bin/sh
    14.5 +#
    14.6 +# Copyright (C) 2016 Guido Berhoerster <guido+libpws@berhoerster.name>
    14.7 +#
    14.8 +# Permission is hereby granted, free of charge, to any person obtaining
    14.9 +# a copy of this software and associated documentation files (the
   14.10 +# "Software"), to deal in the Software without restriction, including
   14.11 +# without limitation the rights to use, copy, modify, merge, publish,
   14.12 +# distribute, sublicense, and/or sell copies of the Software, and to
   14.13 +# permit persons to whom the Software is furnished to do so, subject to
   14.14 +# the following conditions:
   14.15 +#
   14.16 +# The above copyright notice and this permission notice shall be included
   14.17 +# in all copies or substantial portions of the Software.
   14.18 +#
   14.19 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   14.20 +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   14.21 +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   14.22 +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   14.23 +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   14.24 +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   14.25 +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   14.26 +#
   14.27 +
   14.28 +export PWSDUMP="${PWSDUMP:-pwsdump}"
   14.29 +
   14.30 +export LC_ALL=C
   14.31 +export TESTS_PATH="$(dirname "$0")"
   14.32 +export TESTS_OUTPUT_PATH="${TESTS_OUTPUT_PATH:-${TESTS_PATH}/output}"
   14.33 +
   14.34 +tests_passed=0
   14.35 +tests_failed=0
   14.36 +
   14.37 +mkdir -p "${TESTS_OUTPUT_PATH}" || exit 1
   14.38 +
   14.39 +for t in "${TESTS_PATH}"/test-*.sh; do
   14.40 +    [ -r "${t}" ] || break
   14.41 +
   14.42 +    export LOGFILE="${TESTS_OUTPUT_PATH}/$(basename "${t}").log"
   14.43 +
   14.44 +    [ -t 1 ] && printf "Running %s" "${t}"
   14.45 +    if ${SHELL:-/bin/sh} "$t" >/dev/null 2>"${LOGFILE}"; then
   14.46 +        tests_passed=$(( tests_passed + 1 ))
   14.47 +        if [ -t 1 ]; then
   14.48 +            printf "\rOK      "
   14.49 +        else
   14.50 +            printf "OK      %s" "${t}"
   14.51 +        fi
   14.52 +    else
   14.53 +        tests_failed=$(( tests_failed + 1 ))
   14.54 +        if [ -t 1 ]; then
   14.55 +            printf "\rFAILED  "
   14.56 +        else
   14.57 +            printf "FAILED  %s" "${t}"
   14.58 +        fi
   14.59 +    fi
   14.60 +    printf "%s\n" "${t}"
   14.61 +done
   14.62 +
   14.63 +printf -- "-----------\npassed: %3d\nfailed: %3d\ntotal:  %3d\n" $tests_passed \
   14.64 +    $tests_failed $(( tests_failed + tests_passed ))
   14.65 +
   14.66 +[ $tests_failed -eq 0 ]
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tests/test-001-non-existent-file.sh	Fri May 13 14:32:44 2016 +0200
    15.3 @@ -0,0 +1,3 @@
    15.4 +# try to open a file that does not exist
    15.5 +$PWSDUMP "${TESTS_OUTPUT_PATH}/non-existent.psafe3"
    15.6 +grep 'could not open input file' "${LOGFILE}"
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tests/test-002-empty-file.sh	Fri May 13 14:32:44 2016 +0200
    16.3 @@ -0,0 +1,3 @@
    16.4 +# try to open an empty file
    16.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/empty-file.psafe3"
    16.6 +grep 'unexpected end of file' "${LOGFILE}"
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tests/test-003-random-garbage-file.sh	Fri May 13 14:32:44 2016 +0200
    17.3 @@ -0,0 +1,3 @@
    17.4 +# try to open a file that does not START with "PWS3"
    17.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/random-garbage.psafe3"
    17.6 +grep 'unknown filetype' "${LOGFILE}"
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tests/test-004-invalid-iterations.sh	Fri May 13 14:32:44 2016 +0200
    18.3 @@ -0,0 +1,4 @@
    18.4 +# try to opena file that specifies 0 iterations
    18.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" \
    18.6 +    "${TESTS_PATH}/invalid-iterations.psafe3"
    18.7 +grep 'invalid number of iterations: 0' "${LOGFILE}"
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tests/test-005-wrong-password.sh	Fri May 13 14:32:44 2016 +0200
    19.3 @@ -0,0 +1,3 @@
    19.4 +# try to open a file with the wrong password
    19.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/wrong-password.psafe3"
    19.6 +grep 'wrong password' "${LOGFILE}"
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tests/test-006-bad-key.sh	Fri May 13 14:32:44 2016 +0200
    20.3 @@ -0,0 +1,3 @@
    20.4 +# try to open a file which contains a corrupt key
    20.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/bad-key.psafe3"
    20.6 +grep 'checksum failed' "${LOGFILE}"
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/tests/test-007-truncated-file.sh	Fri May 13 14:32:44 2016 +0200
    21.3 @@ -0,0 +1,3 @@
    21.4 +# try to open a file which has been truncated
    21.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/truncated-file.psafe3"
    21.6 +grep 'unexpected end of file' "${LOGFILE}"
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tests/test-008-corrupt-files.sh	Fri May 13 14:32:44 2016 +0200
    22.3 @@ -0,0 +1,4 @@
    22.4 +# try to open corrupted files
    22.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/corrupted-file.psafe3"
    22.6 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/corrupted-file-2.psafe3"
    22.7 +grep 'invalid field length' "${LOGFILE}" && grep 'checksum failed' "${LOGFILE}"
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/tests/test-009-valid-minimal-file.sh	Fri May 13 14:32:44 2016 +0200
    23.3 @@ -0,0 +1,3 @@
    23.4 +# try to open a file which contains nothing but a version header field
    23.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/minimal.psafe3" | \
    23.6 +    grep '^00:030b'
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/tests/test-010-invalid-version.sh	Fri May 13 14:32:44 2016 +0200
    24.3 @@ -0,0 +1,3 @@
    24.4 +# try to open a file which specifies an unsupported version
    24.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/invalid-version.psafe3"
    24.6 +grep 'unsupported database version' "${LOGFILE}"
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/tests/test-011-missing-version-field.sh	Fri May 13 14:32:44 2016 +0200
    25.3 @@ -0,0 +1,3 @@
    25.4 +# try to open a file which does not start with a version header field
    25.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/missing-version.psafe3"
    25.6 +grep 'header does not start with a version field' "${LOGFILE}"
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tests/test-012-unknown-fields.sh	Fri May 13 14:32:44 2016 +0200
    26.3 @@ -0,0 +1,6 @@
    26.4 +# try to read and write header and record fields of an unknown type
    26.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" -n "${TESTS_PATH}/password.txt" \
    26.6 +    -t pws3 -o "${TESTS_OUTPUT_PATH}/unknown-fields.psafe3" \
    26.7 +    "${TESTS_PATH}/unknown-fields.psafe3" || exit 1
    26.8 +$PWSDUMP -p "${TESTS_PATH}/password.txt" \
    26.9 +    "${TESTS_OUTPUT_PATH}/unknown-fields.psafe3" | grep '^fe:'
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/tests/test-013-valid-file.sh	Fri May 13 14:32:44 2016 +0200
    27.3 @@ -0,0 +1,9 @@
    27.4 +# conversions between dump and pws3 format
    27.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" -o "${TESTS_OUTPUT_PATH}/valid.dump" \
    27.6 +    "${TESTS_PATH}/valid.psafe3"
    27.7 +cmp "${TESTS_PATH}/valid.dump" "${TESTS_OUTPUT_PATH}/valid.dump" || exit 1
    27.8 +$PWSDUMP -f dump -t pws3 -n "${TESTS_PATH}/password.txt" \
    27.9 +    -o "${TESTS_OUTPUT_PATH}/valid.psafe3" "${TESTS_PATH}/valid.dump"
   27.10 +$PWSDUMP -p "${TESTS_PATH}/password.txt" -o "${TESTS_OUTPUT_PATH}/valid-new.dump" \
   27.11 +    "${TESTS_OUTPUT_PATH}/valid.psafe3"
   27.12 +cmp "${TESTS_PATH}/valid.dump" "${TESTS_OUTPUT_PATH}/valid-new.dump" || exit 1
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/tests/test-014-invalid-record-field-length.sh	Fri May 13 14:32:44 2016 +0200
    28.3 @@ -0,0 +1,4 @@
    28.4 +# record fields with invalid lenghts
    28.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" \
    28.6 +    "${TESTS_PATH}/invalid-record-field-length.pws3"
    28.7 +grep 'invalid field length' "${LOGFILE}"
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/tests/test-015-record-without-uuid.sh	Fri May 13 14:32:44 2016 +0200
    29.3 @@ -0,0 +1,2 @@
    29.4 +# read a record without an UUID field which forces generation of a new UUID
    29.5 +$PWSDUMP -p "${TESTS_PATH}/password.txt" "${TESTS_PATH}/record-without-uuid.pws3"
    30.1 Binary file tests/truncated-file.psafe3 has changed
    31.1 Binary file tests/unknown-fields.psafe3 has changed
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/tests/valid.dump	Fri May 13 14:32:44 2016 +0200
    32.3 @@ -0,0 +1,29 @@
    32.4 +# Passwordsafe v3 database dump
    32.5 +Header
    32.6 +00:030b
    32.7 +01:ddba98acd8fb027626c0a1c3212e0a12
    32.8 +03:111
    32.9 +04:2016-05-10T10:35:29Z
   32.10 +06:pwsdump 1.0.0
   32.11 +07:user
   32.12 +08:host
   32.13 +11:foo
   32.14 +11:foo.bar
   32.15 +Record 1
   32.16 +01:091e87b0f8beca00d53d7bceac4580bf
   32.17 +02:foo.bar.baz
   32.18 +03:Bla
   32.19 +04:Joe
   32.20 +06:PaSsWoRd
   32.21 +07:2016-07-27T19:35:31Z
   32.22 +08:2016-07-27T19:35:31Z
   32.23 +0c:2016-07-27T19:35:53Z
   32.24 +Record 2
   32.25 +01:6f452a3189b724df91b241adcf793621
   32.26 +02:foo.bar.baz
   32.27 +03:Waldo
   32.28 +04:Joe
   32.29 +06:pAsSwOrD
   32.30 +07:2016-07-29T08:01:22Z
   32.31 +08:2016-07-29T08:01:22Z
   32.32 +0c:2016-07-29T08:01:45Z
    33.1 Binary file tests/valid.psafe3 has changed
    34.1 Binary file tests/wrong-password.psafe3 has changed