From ee237c40da97962e350c74119f36f1b23593cb4e Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 9 Jun 2012 08:54:03 -0400 Subject: [PATCH] Add more tests. Add LIST, MOVE and more STORE tests. --- KnownBugs | 5 + po/pwmd.pot | 184 ++++++++++++++++---------------- tests/Makefile.am | 36 ++++++- tests/README | 12 ++- tests/common.sh | 48 ++++++--- tests/datafile.xml | 3 +- tests/import-common.sh | 12 +++ tests/import-xml | 38 +++---- tests/list | 45 ++++++++ tests/list.key | 1 + tests/list.result1 | 11 ++ tests/list.result2 | 11 ++ tests/list.result3 | 11 ++ tests/list.result4 | 37 +++++++ tests/list.result5 | 8 ++ tests/list.xml | 14 +++ tests/move | 66 ++++++++++++ tests/move.result4 | 41 +++++++ tests/move.result5 | 37 +++++++ tests/move.result6 | 26 +++++ tests/store | 139 ++++++++++++++++++++---- tests/{store.result6 => store.result10} | 0 tests/{store.result6 => store.result11} | 0 tests/store.result13 | 1 + tests/store.result15 | 1 + tests/store.result6 | 1 - tests/store.result7 | 1 + 27 files changed, 627 insertions(+), 162 deletions(-) rewrite tests/README (74%) create mode 100644 tests/import-common.sh rewrite tests/import-xml (65%) create mode 100755 tests/list create mode 100644 tests/list.key create mode 100644 tests/list.result1 create mode 100644 tests/list.result2 create mode 100644 tests/list.result3 create mode 100644 tests/list.result4 create mode 100644 tests/list.result5 create mode 100644 tests/list.xml create mode 100755 tests/move create mode 100644 tests/move.result4 create mode 100644 tests/move.result5 create mode 100644 tests/move.result6 copy tests/{store.result6 => store.result10} (100%) copy tests/{store.result6 => store.result11} (100%) create mode 100644 tests/store.result13 create mode 100644 tests/store.result15 diff --git a/KnownBugs b/KnownBugs index 5be7e188..032af1c0 100644 --- a/KnownBugs +++ b/KnownBugs @@ -3,3 +3,8 @@ sure to use the INQUIRE_MAXLEN status message and to not exceed its value when sending its data. Otherwise, the exceeded data will be buffered and sent as commands to gpg-agent after gpg-agent has returned it's error stating that the maximum length has been encountered. + +The LIST command will stop processing the current element when a child element +of the current elements' target contains an error (i.e., GPG_ERR_ELOOP), even +if there are other children without errors. The current element is flagged as +having an error even though it may not; a child does. diff --git a/po/pwmd.pot b/po/pwmd.pot index 3ab36452..28a83aa4 100644 --- a/po/pwmd.pot +++ b/po/pwmd.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bjk@luxsci.net\n" -"POT-Creation-Date: 2012-05-26 20:21-0400\n" +"POT-Creation-Date: 2012-06-09 16:47-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -47,57 +47,57 @@ msgstr "" msgid "passphrase" msgstr "" -#: src/agent.c:824 +#: src/agent.c:975 #, c-format msgid "Sign keygrip is %s" msgstr "" -#: src/agent.c:1247 +#: src/agent.c:1374 #, c-format msgid "Keygrip is %s" msgstr "" -#: src/agent.c:1280 +#: src/agent.c:1407 #, c-format msgid "WARNING: keylen=%i, truncated to %i." msgstr "" -#: src/agent.c:1385 +#: src/agent.c:1512 #, c-format msgid "The passphrase is too large: have=%u, max=%u." msgstr "" -#: src/agent.c:1448 +#: src/agent.c:1575 msgid "Generating a new keypair ..." msgstr "" -#: src/agent.c:1450 +#: src/agent.c:1577 #, c-format msgid "Using passphrase obtained from file '%s'" msgstr "" -#: src/agent.c:1480 +#: src/agent.c:1607 #, c-format msgid "Success! Keygrip is %s." msgstr "" -#: src/agent.c:1487 +#: src/agent.c:1614 #, c-format msgid "Signed with keygrip %s." msgstr "" -#: src/pwmd.c:148 +#: src/pwmd.c:147 #, c-format msgid "reloading configuration file '%s'" msgstr "" -#: src/pwmd.c:329 +#: src/pwmd.c:327 msgid "unknown" msgstr "" -#: src/pwmd.c:382 +#: src/pwmd.c:378 #, c-format -msgid "gcry_check_version(): Incompatible libgcrypt. Wanted %s, got %s." +msgid "gcry_check_version(): Incompatible libgcrypt. Wanted %s, got %s.\n" msgstr "" #: src/pwmd.c:484 @@ -122,106 +122,106 @@ msgstr "" msgid "Could not find root \"pwmd\" element." msgstr "" -#: src/pwmd.c:898 +#: src/pwmd.c:899 #, c-format msgid "Trying to add datafile '%s' to the file cache ..." msgstr "" -#: src/pwmd.c:902 +#: src/pwmd.c:903 #, c-format msgid "%s: Invalid characters in filename" msgstr "" -#: src/pwmd.c:913 +#: src/pwmd.c:914 msgid "Trying the passphrase specified in config ..." msgstr "" -#: src/pwmd.c:920 +#: src/pwmd.c:921 #, c-format msgid "Trying the passphrase using file '%s' ..." msgstr "" -#: src/pwmd.c:993 +#: src/pwmd.c:994 #, c-format msgid "Successfully added '%s' to the cache." msgstr "" -#: src/pwmd.c:1035 +#: src/pwmd.c:1036 #, c-format msgid "new connection: tid=%p, fd=%i, addr=%s" msgstr "" -#: src/pwmd.c:1038 +#: src/pwmd.c:1039 #, c-format msgid "new connection: tid=%p, fd=%i" msgstr "" -#: src/pwmd.c:1188 +#: src/pwmd.c:1189 msgid "could not bind" msgstr "" -#: src/pwmd.c:1340 +#: src/pwmd.c:1341 #, c-format msgid "caught signal %i (%s)" msgstr "" -#: src/pwmd.c:1351 +#: src/pwmd.c:1352 msgid "clearing file cache" msgstr "" -#: src/pwmd.c:1383 +#: src/pwmd.c:1384 msgid "waiting for all clients to disconnect" msgstr "" -#: src/pwmd.c:1394 +#: src/pwmd.c:1395 #, c-format msgid "%i clients remain" msgstr "" -#: src/pwmd.c:1451 +#: src/pwmd.c:1452 #, c-format msgid "%s started for user %s" msgstr "" -#: src/pwmd.c:1453 +#: src/pwmd.c:1454 msgid "Peer credential checking is NOT supported on this OS." msgstr "" -#: src/pwmd.c:1457 +#: src/pwmd.c:1458 #, c-format msgid "Listening on %s and TCP port %i" msgstr "" -#: src/pwmd.c:1460 src/pwmd.c:1462 +#: src/pwmd.c:1461 src/pwmd.c:1463 #, c-format msgid "Listening on %s" msgstr "" -#: src/pwmd.c:1516 +#: src/pwmd.c:1517 msgid "Received second termination request. Exiting." msgstr "" -#: src/pwmd.c:1553 +#: src/pwmd.c:1554 msgid "" "Failed to add a file to the cache. Use --ignore to force startup. Exiting." msgstr "" -#: src/pwmd.c:1635 +#: src/pwmd.c:1639 #, c-format msgid "Converting version 2 data file \"%s\" ..." msgstr "" -#: src/pwmd.c:1642 +#: src/pwmd.c:1646 #, c-format msgid "Using passphrase file \"%s\" for decryption ..." msgstr "" -#: src/pwmd.c:1699 +#: src/pwmd.c:1704 #, c-format msgid "Output written to \"%s\"." msgstr "" -#: src/pwmd.c:1842 +#: src/pwmd.c:1848 #, c-format msgid "" "%s\n" @@ -234,36 +234,26 @@ msgid "" "%s" msgstr "" -#: src/pwmd.c:1922 +#: src/pwmd.c:1940 msgid "incompatible version: 2.1.0 or later required" msgstr "" -#: src/pwmd.c:1966 -#, c-format -msgid "%s: socket_path not defined" -msgstr "" - -#: src/pwmd.c:1972 -#, c-format -msgid "%s: data_directory not defined" -msgstr "" - -#: src/pwmd.c:2046 +#: src/pwmd.c:2059 msgid "Done. Daemonizing..." msgstr "" -#: src/pwmd.c:2046 +#: src/pwmd.c:2059 msgid "Done. Waiting for connections..." msgstr "" -#: src/pwmd.c:2075 +#: src/pwmd.c:2088 #, c-format msgid "" "Either there is another pwmd running or '%s' is a \n" "stale socket. Please remove it manually." msgstr "" -#: src/pwmd.c:2157 +#: src/pwmd.c:2173 msgid "pwmd exiting normally" msgstr "" @@ -271,17 +261,17 @@ msgstr "" msgid "Waiting for lock" msgstr "" -#: src/commands.c:473 +#: src/commands.c:476 #, c-format msgid "client validation failed for file '%s'" msgstr "" -#: src/commands.c:3236 +#: src/commands.c:3274 #, c-format msgid "command completed: rc=%u" msgstr "" -#: src/commands.c:3248 +#: src/commands.c:3286 msgid "" "Usage: HELP []\n" "For commands that take an element path as an argument, each element is " @@ -289,37 +279,39 @@ msgid "" "COMMANDS:" msgstr "" -#: src/commands.c:3278 +#: src/commands.c:3316 #, c-format msgid "Usage: %s" msgstr "" -#: src/commands.c:3529 +#: src/commands.c:3599 msgid "" "HELP []\n" " Show available commands or command specific help text." msgstr "" -#: src/commands.c:3534 +#: src/commands.c:3604 msgid "" "AGENT \n" "Send a @command{gpg-agent} protocol @var{command} directly to the @command" "{gpg-agent}." msgstr "" -#: src/commands.c:3540 +#: src/commands.c:3610 msgid "" -"GETINFO CACHE | CLIENTS | PID | LAST_ERROR | VERSION\n" +"GETINFO [--data] CACHE | CLIENTS | PID | LAST_ERROR | VERSION\n" "Get server and other information: @var{cache} returns the number of cached " "documents via a status message. @var{clients} returns the number of " "connected clients via a status message. @var{pid} returns the process ID " "number of the server via a data response. @var{VERSION} returns the server " "version number and compile-time features with a data response with each " "being space delimited. @var{LAST_ERROR} returns a detailed description of " -"the last failed command when available. @xref{Status Messages}." +"the last failed command when available. @xref{Status Messages}. \n" +"When the @option{--data} option is specified then the result will be send " +"via a data response rather than a status message." msgstr "" -#: src/commands.c:3551 +#: src/commands.c:3624 msgid "" "PASSWD [--reset] [--s2k-count=N]\n" "Changes the passphrase of the secret key required to open the current file. " @@ -332,7 +324,7 @@ msgid "" "@xref{SAVE}." msgstr "" -#: src/commands.c:3564 +#: src/commands.c:3637 msgid "" "KEYGRIP [--sign] \n" "Returns the hex encoded keygrip of the specified @var{filename} with a data " @@ -341,7 +333,7 @@ msgid "" "of the specified @var{filename} will be returned." msgstr "" -#: src/commands.c:3573 +#: src/commands.c:3646 msgid "" "OPEN [--lock] [--no-pinentry] []\n" "Opens @var{filename} using @var{passphrase}. When the filename is not found " @@ -361,10 +353,11 @@ msgid "" "options." msgstr "" -#: src/commands.c:3594 +#: src/commands.c:3667 msgid "" -"SAVE [--no-passphrase] [--reset] [--s2k-count=N] [--cipher=] [--" -"inquire-keyparam] [--keygrip=hexstring [--sign-keygrip=hexstring]]\n" +"SAVE [--no-passphrase] [--reset] [--s2k-count=N] [--cipher=] [--cipher-" +"iterations=N] [--inquire-keyparam] [--keygrip=hexstring [--sign-" +"keygrip=hexstring]]\n" "Writes the @abbr{XML} document to disk. The file written to is the file that " "was opened using the @code{OPEN} command (@pxref{OPEN}). If the file is a " "new one or the option @option{--inquire-keyparam} was passed, then a new " @@ -376,6 +369,8 @@ msgid "" "The @option{--cipher} option can be used to encrypt the @abbr{XML} data to " "an alternate cipher. The default is @code{aes256}. See the Configuration " "(@pxref{Configuration}) for available ciphers.\n" +"The @option{--cipher-iterations} option specifies the number of times to " +"encrypt the XML data. The default is 0 although 1 iteration is still done.\n" "The @option{--inquire-keyparam} option will send a server @emph{INQUIRE} to " "the client to obtain the key paramaters to use when generating a new " "keypair. The inquired data is expected to be an S-expression. If not " @@ -395,7 +390,7 @@ msgid "" "the setting, use the @code{PASSWD} command (@pxref{PASSWD})." msgstr "" -#: src/commands.c:3631 +#: src/commands.c:3707 msgid "" "ISCACHED [--lock] \n" "An @emph{OK} response is returned if the specified @var{filename} is found " @@ -406,13 +401,13 @@ msgid "" "file exists; it does not need to be opened nor cached." msgstr "" -#: src/commands.c:3642 +#: src/commands.c:3718 msgid "" "CLEARCACHE []\n" "Clears a file cache entry for all or the specified @var{filename}." msgstr "" -#: src/commands.c:3647 +#: src/commands.c:3723 msgid "" "CACHETIMEOUT \n" "The time in @var{seconds} until @var{filename} will be removed from the " @@ -421,7 +416,7 @@ msgid "" "{Configuration}, and the @code{cache_timeout} parameter." msgstr "" -#: src/commands.c:3655 +#: src/commands.c:3731 msgid "" "LIST [--inquire] [--no-recurse] [--verbose] [--with-target] [--all] [[!]" "element[[!]child[..]]]\n" @@ -455,7 +450,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3692 +#: src/commands.c:3768 msgid "" "REALPATH [--inquire] [!]element[[!]child[..]]\n" "Resolves all @code{target} attributes of the specified element path and " @@ -465,7 +460,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3701 +#: src/commands.c:3777 msgid "" "STORE [!]element[[!]child[..]][content]\n" "This command uses a server @emph{INQUIRE} to retrieve data from the client.\n" @@ -483,7 +478,7 @@ msgid "" "to prevent @abbr{XML} and @command{pwmd} parsing errors." msgstr "" -#: src/commands.c:3720 +#: src/commands.c:3796 msgid "" "RENAME [--inquire] [!]element[[!]child[..]] \n" "Renames the specified @var{element} to the new @var{value}. If an element of " @@ -492,7 +487,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3729 +#: src/commands.c:3805 msgid "" "COPY [--inquire] [!]source[[!]child[..]] [!]dest[[!]child[..]]\n" "Copies the entire element tree starting from the child node of the source " @@ -506,7 +501,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3745 +#: src/commands.c:3821 msgid "" "MOVE [--inquire] [!]source[[!]child[..]] [[!]dest[[!]child[..]]]\n" "Moves the source element path to the destination element path. If the " @@ -517,7 +512,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3756 +#: src/commands.c:3832 msgid "" "DELETE [--inquire] [!]element[[!]child[..]]\n" "Removes the specified element path and all of its children. This may break " @@ -527,7 +522,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3766 +#: src/commands.c:3842 msgid "" "GET [--inquire] [!]element[[!]child[..]]\n" "Retrieves the content of the specified element. The content is returned with " @@ -536,7 +531,7 @@ msgid "" "arguments are retrieved via a server @emph{INQUIRE}." msgstr "" -#: src/commands.c:3775 +#: src/commands.c:3851 msgid "" "ATTR [--inquire] SET|GET|DELETE|LIST [] [!]element[[!]child" "[..]] ..\n" @@ -570,7 +565,7 @@ msgid "" "@xref{Target Attribute}, for details about this special attribute." msgstr "" -#: src/commands.c:3812 +#: src/commands.c:3888 msgid "" "XPATH [--inquire] [[value]]\n" "Evaluates an XPath @var{expression}. If no @var{value} argument is " @@ -590,7 +585,7 @@ msgid "" "expression syntax." msgstr "" -#: src/commands.c:3835 +#: src/commands.c:3911 msgid "" "XPATHATTR [--inquire] SET|DELETE [[]]\n" "Like the @code{XPATH} command (@pxref{XPATH}) but operates on element " @@ -608,7 +603,7 @@ msgid "" "expression syntax." msgstr "" -#: src/commands.c:3856 +#: src/commands.c:3932 msgid "" "IMPORT [[!]element[[!]child[..]]]\n" "This command uses a server @emph{INQUIRE} to retrieve data from the client.\n" @@ -621,14 +616,14 @@ msgid "" "for details." msgstr "" -#: src/commands.c:3870 +#: src/commands.c:3946 msgid "" "DUMP\n" "Shows the in memory @abbr{XML} document with indenting. @xref{XPATH}, for " "dumping a specific node." msgstr "" -#: src/commands.c:3876 +#: src/commands.c:3952 msgid "" "LOCK\n" "Locks the mutex associated with the opened file. This prevents other clients " @@ -637,14 +632,14 @@ msgid "" "{UNLOCK}." msgstr "" -#: src/commands.c:3884 +#: src/commands.c:3960 msgid "" "UNLOCK\n" "Unlocks the file mutex which was locked with the @code{LOCK} command or a " "commands' @option{lock} option. @xref{LOCK}." msgstr "" -#: src/commands.c:3890 +#: src/commands.c:3966 msgid "" "GETCONFIG [filename] \n" "Returns the value of a @command{pwmd} configuration @var{parameter} with a " @@ -654,7 +649,7 @@ msgid "" "with the @code{OPTION} command (@pxref{OPTION}) will be returned." msgstr "" -#: src/commands.c:3899 +#: src/commands.c:3975 msgid "" "OPTION =\n" "Sets a client option @var{name} to @var{value}. The value for an option is " @@ -681,26 +676,27 @@ msgid "" "@item NAME\n" " Associates the thread ID of the connection with the specified textual " "representation. Useful for debugging log messages.\n" -"@item RC_ON_LOCKED\n" -" When @code{1}, a command will return an error code rather than a status " -"message when a file mutex is locked by another thread.\n" -"@end table\n" +"@item LOCK-TIMEOUT\n" +" When not @code{0}, the duration in tenths of a second to wait for the file " +"mutex which has been locked by another thread to be released before " +"returning an error. When @code{-1}, then an error will be returned " +"immediately.@end table\n" msgstr "" -#: src/commands.c:3933 +#: src/commands.c:4010 msgid "" "LS\n" -"Lists the contents of @code{data_directory}. @xref{Configuration}, for " -"details. The result is a newline separated list of filenames." +"Lists the available data files stored in the data directory (@file{~/.pwmd/" +"data}). The result is a newline separated list of filenames." msgstr "" -#: src/commands.c:3939 +#: src/commands.c:4016 msgid "" "RESET\n" "Closes the currently opened file but keeps any previously set client options." msgstr "" -#: src/commands.c:3944 +#: src/commands.c:4021 msgid "" "NOP\n" "Does nothing. Always returns successfully." diff --git a/tests/Makefile.am b/tests/Makefile.am index b46f589f..3adc107b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,38 @@ EXTRA_DIST= common.sh convert.result convert-v2x datafile.key datafile.v2x \ datafile-v2x.key datafile.xml gpg-agent.conf import-xml README \ store store.result1 store.result2 store.result3 store.result4 \ - store.result5 store.result6 store.result7 + store.result5 store.result6 store.result7 store.result10 \ + store.result11 store.result13 store.result15 list list.xml \ + list.key list.result1 list.result2 list.result3 list.result4 \ + list.result5 move move.result4 move.result5 move.result6 \ + import-common.sh + +convert-v2x.stamp: + touch ./convert-v2x.stamp +convert-v2x: convert-v2x.stamp + test -z $(VPATH) && ./convert-v2x || exit 0 + +import-xml.stamp: + touch ./import-xml.stamp +import-xml: import-xml.stamp + test -z $(VPATH) && ./import-xml || exit 0 + +store.stamp: + touch ./store.stamp +store: store.stamp + test -z $(VPATH) && ./store || exit 0 + +list.stamp: + touch ./list.stamp +list: list.stamp + test -z $(VPATH) && ./list || exit 0 + +move.stamp: + touch ./move.stamp +move: move.stamp + test -z $(VPATH) && ./move || exit 0 + +tests: convert-v2x import-xml store list move + +distclean: + test ! -z $(VPATH) && rm -f *.stamp Makefile diff --git a/tests/README b/tests/README dissimilarity index 74% index c6943925..0a864e0d 100644 --- a/tests/README +++ b/tests/README @@ -1,5 +1,7 @@ -Most of these tests require the pwmc client included with libpwmd. The results -of commands are compared against static results. The --homedir is used to have -this directory contain the pwmd socket, data file directory and temporary -configuration files. A gpg-agent process is started with this same home -directory. +Most of these tests require the pwmc client included with libpwmd. The results +of commands are compared against static results. The --homedir command line +option is used to have this directory contain the pwmd socket, data file +directory and temporary configuration files. A gpg-agent process is started +with this same home directory and puts the private keys in private-keys-v1.d/. + +Doing 'make tests' will run all tests. Or you can run them individually. diff --git a/tests/common.sh b/tests/common.sh index c5c39289..5f9be233 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -1,27 +1,47 @@ -set -e - -PWMD="../src/pwmd" -WDIR="`/bin/pwd`" -PID= -trap on_exit EXIT - on_exit() { if [ $PID ]; then kill $PID fi + if [ -f "gpg-agent.env" ]; then + local pid="`awk -F: '{print $2}' < gpg-agent.env`" + kill $pid 2>/dev/null + unset pid + rm -f gpg-agent.env + fi + rm -f config } -eval `gpg-agent --homedir $WDIR --sh --daemon` +wait_for_socket() { + local pid="$1" + local socket="$2" + + until [ -e $socket ]; do + echo "waiting for socket '$socket' ..." + if [ $pid != 0 ]; then + kill -0 $PID || break; + fi + sleep 1 + done + + unset pid + unset socket +} launch_pwmd () { $PWMD --homedir $WDIR -n $@ > /dev/null & PID=$! - while :; do - echo "waiting for socket ..." - kill -0 $PID || break; - test -e socket && break - sleep 1 - done + wait_for_socket $PID socket } + +set -e + +PWMD="../src/pwmd" +WDIR="`/bin/pwd`" +PID= +trap on_exit EXIT + +eval `gpg-agent --homedir $WDIR --sh --daemon --write-env-file \ + $WDIR/gpg-agent.env` +wait_for_socket 0 "S.gpg-agent" diff --git a/tests/datafile.xml b/tests/datafile.xml index 2b87fca3..50a00855 100644 --- a/tests/datafile.xml +++ b/tests/datafile.xml @@ -1,6 +1,5 @@ - a value - a b value + a valuea b value diff --git a/tests/import-common.sh b/tests/import-common.sh new file mode 100644 index 00000000..549ff9c5 --- /dev/null +++ b/tests/import-common.sh @@ -0,0 +1,12 @@ +do_import() { + FILE="$1" + + #echo Importing with pinentry ... + #$PWMD --homedir $WDIR --import datafile.xml -o data/datafile $@ + #echo Result is $? + + echo "Importing from keyfile ..." + $PWMD --homedir $WDIR --import $FILE.xml -o data/$FILE \ + --s2k-count 150000 --cipher-iterations 1000 --cipher aes128 \ + --passphrase-file $FILE.key $@ +} diff --git a/tests/import-xml b/tests/import-xml dissimilarity index 65% index 5e63b37a..d3cf6bef 100755 --- a/tests/import-xml +++ b/tests/import-xml @@ -1,22 +1,16 @@ -#!/bin/bash -source common.sh - -#echo Importing with pinentry ... -#$PWMD --homedir $WDIR --import datafile.xml -o data/datafile $@ -#echo Result is $? - -cat > config << EOF -[datafile] -passphrase_file=$WDIR/datafile.key -EOF - -echo "Importing from keyfile ..." -$PWMD --homedir $WDIR --import datafile.xml -o data/datafile \ - --s2k-count 150000 --cipher-iterations 1000 --cipher aes128 \ - --passphrase-file datafile.key $@ - -launch_pwmd datafile -echo 'DUMP' | pwmc --url $WDIR/socket --key-file datafile.key datafile > result - -cmp result datafile.xml -rm -f result +#!/bin/bash +source common.sh +source import-common.sh + +do_import datafile + +cat > config << EOF +[$FILE] +passphrase_file=$WDIR/$FILE.key +EOF + +launch_pwmd datafile +echo 'DUMP' | pwmc --url $WDIR/socket --key-file datafile.key datafile > result + +cmp result datafile.xml +rm -f result diff --git a/tests/list b/tests/list new file mode 100755 index 00000000..d8a74d7f --- /dev/null +++ b/tests/list @@ -0,0 +1,45 @@ +#!/bin/bash +source common.sh +source import-common.sh + +do_import list + +cat > config << EOF +[global] +log_level=9 +#enable_logging=true +[list] +passphrase_file=`pwd`/list.key +EOF + +launch_pwmd list + +echo "Test 1. List root elements." +echo -ne 'LIST' | pwmc --url $WDIR/socket list > result +cmp list.result1 result +rm -f result + +echo +echo "Test 2. List root elements, verbose." +echo -ne 'LIST --verbose' | pwmc --url $WDIR/socket list > result +cmp list.result2 result +rm -f result + +echo +echo "Test 3. List root elements, verbose with targets." +echo -ne 'LIST --verbose --with-target' | pwmc --url $WDIR/socket list > result +cmp list.result3 result +rm -f result + +echo +echo "Test 4. List all elements, verbose with targets." +echo -ne 'LIST --all --with-target' | pwmc --url $WDIR/socket list > result +cmp list.result4 result +rm -f result + +echo +echo "Test 5. List single path, verbose with targets." +echo -ne 'LIST --all --with-target !a\t!b' | pwmc --url $WDIR/socket list \ + > result +cmp list.result5 result +rm -f result diff --git a/tests/list.key b/tests/list.key new file mode 100644 index 00000000..c85bf914 --- /dev/null +++ b/tests/list.key @@ -0,0 +1 @@ +9XA4af96PQU23tKb \ No newline at end of file diff --git a/tests/list.result1 b/tests/list.result1 new file mode 100644 index 00000000..7181dedc --- /dev/null +++ b/tests/list.result1 @@ -0,0 +1,11 @@ +!a +!b +b +!bad_target +bad_target +!target-loop-a +target-loop-a +!target-loop-b +target-loop-b +!c +!d \ No newline at end of file diff --git a/tests/list.result2 b/tests/list.result2 new file mode 100644 index 00000000..2d01544d --- /dev/null +++ b/tests/list.result2 @@ -0,0 +1,11 @@ +!a + +!b +b + +!bad_target +bad_target E +!target-loop-a +target-loop-a O +!target-loop-b +target-loop-b O +!c + +!d + \ No newline at end of file diff --git a/tests/list.result3 b/tests/list.result3 new file mode 100644 index 00000000..a6c0e888 --- /dev/null +++ b/tests/list.result3 @@ -0,0 +1,11 @@ +!a + +!b +b +T !a +!bad_target +bad_target E +!target-loop-a +target-loop-a O +!target-loop-b +target-loop-b O +!c + +!d + \ No newline at end of file diff --git a/tests/list.result4 b/tests/list.result4 new file mode 100644 index 00000000..55e90c00 --- /dev/null +++ b/tests/list.result4 @@ -0,0 +1,37 @@ +!a + +!a !b + +!a !b !c +!a !b c +T !c +!a !b c !d + +!a !b c d +T !d +!a !b c d !e +!a !b c !d !e +!a !b c !e +!a !c + +!a !c !d +!b +b +T !a +b !b + +b !b !c +b !b c +T !c +b !b c !d + +b !b c d +T !d +b !b c d !e +b !b c !d !e +b !b c !e +b !c + +b !c !d +!bad_target +bad_target E +!target-loop-a +target-loop-a O +!target-loop-b +target-loop-b O +!c + +!c !d + +!c d +T !d +!c d !e +!c !d !e +!c !e +!d + +!d !e \ No newline at end of file diff --git a/tests/list.result5 b/tests/list.result5 new file mode 100644 index 00000000..b3f7d35a --- /dev/null +++ b/tests/list.result5 @@ -0,0 +1,8 @@ +!a !b + +!a !b !c +!a !b c +T !c +!a !b c !d + +!a !b c d +T !d +!a !b c d !e +!a !b c !d !e +!a !b c !e \ No newline at end of file diff --git a/tests/list.xml b/tests/list.xml new file mode 100644 index 00000000..1024b7e3 --- /dev/null +++ b/tests/list.xml @@ -0,0 +1,14 @@ + + + +]> + + a valuea b valuea b c valuea c valuea c d value + b value + + + + c d e valuec d valuec e valuec value + d e valued value + diff --git a/tests/move b/tests/move new file mode 100755 index 00000000..68be148b --- /dev/null +++ b/tests/move @@ -0,0 +1,66 @@ +#!/bin/bash +# +# Most checks should be done by the client. For example, recursion loop +# checking is not done after the element has been moved. +# +source common.sh +source import-common.sh + +do_import list + +cat > config << EOF +[global] +log_level=9 +#enable_logging=true +[move] +passphrase_file=`pwd`/list.key +EOF + +mv -f data/list data/move +launch_pwmd move + +echo "Test 1. Move src to src." +set +o errexit +echo -ne 'MOVE !a !a' | pwmc --url $WDIR/socket move +if [ ${PIPESTATUS[1]} == 0 ]; then + echo "The previous command should have failed. Stopping." + exit 1 +fi + +set -e + +echo +echo "Test 2. Move non-existant." +set +o errexit +echo -ne 'MOVE non-existant !a' | pwmc --url $WDIR/socket move +if [ ${PIPESTATUS[1]} == 0 ]; then + echo "The previous command should have failed. Stopping." + exit 1 +fi + +set -e + +echo +echo "Test 3. Move child with target to root." +echo -ne 'MOVE !a\t!b\tc ' | pwmc --url $WDIR/socket move + +echo +echo "Test 4. Move child to sibling child with target." +echo -ne 'MOVE !a\tc !a\tb\tc\td\te' | pwmc --url $WDIR/socket -S move +echo -ne 'LIST --all --with-target' | pwmc --url $WDIR/socket move > result +cmp move.result4 result +rm -f result + +echo +echo "Test 5. Move child with target to parent sibling." +echo -ne 'MOVE !a\tb\tc\td\te\tc !a' | pwmc --url $WDIR/socket -S move +echo -ne 'LIST --all --with-target' | pwmc --url $WDIR/socket move > result +cmp move.result5 result +rm -f result + +echo +echo "Test 6. Overwrite existing tree." +echo -ne 'MOVE !a\tb\tc\t!d ' | pwmc --url $WDIR/socket -S move +echo -ne 'LIST --all --with-target' | pwmc --url $WDIR/socket move > result +cmp move.result6 result +rm -f result diff --git a/tests/move.result4 b/tests/move.result4 new file mode 100644 index 00000000..33abf062 --- /dev/null +++ b/tests/move.result4 @@ -0,0 +1,41 @@ +!a + +!a !b + +!a !b !c +!a !b c +T !c +!a !b c !d + +!a !b c d +T !d +!a !b c d !e + +!a !b c d !e !c + +!a !b c d !e !c !d +!a !b c !d !e +!a !b c !e +!b +b +T !a +b !b + +b !b !c +b !b c +T !c +b !b c !d + +b !b c d +T !d +b !b c d !e + +b !b c d !e !c + +b !b c d !e !c !d +b !b c !d !e +b !b c !e +!bad_target +bad_target E +!target-loop-a +target-loop-a O +!target-loop-b +target-loop-b O +!c + +!c !d + +!c d +T !d +!c d !e + +!c d !e !c + +!c d !e !c !d +!c !d !e +!c !e +!d + +!d !e + +!d !e !c + +!d !e !c !d \ No newline at end of file diff --git a/tests/move.result5 b/tests/move.result5 new file mode 100644 index 00000000..55e90c00 --- /dev/null +++ b/tests/move.result5 @@ -0,0 +1,37 @@ +!a + +!a !b + +!a !b !c +!a !b c +T !c +!a !b c !d + +!a !b c d +T !d +!a !b c d !e +!a !b c !d !e +!a !b c !e +!a !c + +!a !c !d +!b +b +T !a +b !b + +b !b !c +b !b c +T !c +b !b c !d + +b !b c d +T !d +b !b c d !e +b !b c !d !e +b !b c !e +b !c + +b !c !d +!bad_target +bad_target E +!target-loop-a +target-loop-a O +!target-loop-b +target-loop-b O +!c + +!c !d + +!c d +T !d +!c d !e +!c !d !e +!c !e +!d + +!d !e \ No newline at end of file diff --git a/tests/move.result6 b/tests/move.result6 new file mode 100644 index 00000000..c196eccb --- /dev/null +++ b/tests/move.result6 @@ -0,0 +1,26 @@ +!a + +!a !b + +!a !b !c +!a !b c +T !c +!a !b c !e +!a !c + +!a !c !d +!b +b +T !a +b !b + +b !b !c +b !b c +T !c +b !b c !e +b !c + +b !c !d +!bad_target +bad_target E +!target-loop-a +target-loop-a O +!target-loop-b +target-loop-b O +!c + +!c !e +!d + +!d !e +d O \ No newline at end of file diff --git a/tests/store b/tests/store index 27549efb..0a500b70 100755 --- a/tests/store +++ b/tests/store @@ -1,7 +1,8 @@ #!/bin/bash source common.sh +source import-common.sh -$WDIR/import-xml +do_import datafile cat > config << EOF [global] @@ -9,24 +10,28 @@ log_level=9 #enable_logging=true [datafile] passphrase_file=`pwd`/datafile.key +[datafile.tmp] +passphrase_file=`pwd`/datafile.key EOF launch_pwmd datafile -# Test 1. An element with the same value as the element name. -echo "Doing Test #1 ..." -echo -ne 'a\ta' | pwmc --url $WDIR/socket --inquire STORE -S datafile -echo -ne 'GET a' | pwmc --url $WDIR/socket datafile > result +echo "Test 1. An element with the same value as the element name." +cp -f data/datafile data/datafile.tmp +echo -ne 'a\ta' | pwmc --url $WDIR/socket --inquire STORE -S \ + --key-file $WDIR/datafile.key datafile.tmp +echo -ne 'GET a' | pwmc --url $WDIR/socket datafile.tmp > result cmp store.result1 result rm -f result -# Test 2. Empty content. echo -echo "Doing Test #2 ..." -echo -ne 'a\t' | pwmc --url $WDIR/socket --inquire STORE -S datafile +echo "Test 2. Empty content." +cp -f data/datafile data/datafile.tmp +echo -ne 'a\t' | pwmc --url $WDIR/socket --inquire STORE -S \ + --key-file $WDIR/datafile.key datafile.tmp set +o errexit -echo -ne 'GET a' | pwmc --url $WDIR/socket datafile > result +echo -ne 'GET a' | pwmc --url $WDIR/socket datafile.tmp > result if [ ${PIPESTATUS[1]} == 0 ]; then echo "The previous command should have failed. Stopping." exit 1 @@ -37,49 +42,137 @@ set -e cmp store.result2 result rm -f result -# Test 3. Child element content. echo -echo "Doing Test #3 ..." +echo "Test 3. Child element content." echo -ne 'a\tb\ta b value' | pwmc --url $WDIR/socket --inquire STORE -S datafile echo -ne 'GET a\tb' | pwmc --url $WDIR/socket datafile > result cmp store.result3 result rm -f result -# Test 4. Root targets. echo -echo "Doing Test #4 ..." +echo "Test 4. Root targets." echo -ne 'ATTR SET target b a' | pwmc --url $WDIR/socket -S datafile echo -ne 'GET b\tb' | pwmc --url $WDIR/socket datafile > result cmp store.result4 result rm -f result -# Test 5. Literal content. echo -echo "Doing Test #5 ..." +echo "Test 5. Literal content." echo -ne '!b\tb value' | pwmc --url $WDIR/socket --inquire STORE -S datafile echo -ne 'GET !b' | pwmc --url $WDIR/socket datafile > result cmp store.result5 result rm -f result -# Test 6. Target content. echo -echo "Doing Test #6 ..." -echo -ne 'b\tb\ta b value' | pwmc --url $WDIR/socket --inquire STORE -S datafile +echo "Test 6. Target, empty content." +echo -ne 'b\tb\t' | pwmc --url $WDIR/socket --inquire STORE -S datafile +set +o errexit echo -ne 'GET b\tb' | pwmc --url $WDIR/socket datafile > result +if [ ${PIPESTATUS[1]} == 0 ]; then + echo "The previous command should have failed. Stopping." + exit 1 +fi + +set -e cmp store.result6 result rm -f result -# Test 7. Target, empty content. echo -echo "Doing Test #7 ..." -echo -ne 'b\tb\t' | pwmc --url $WDIR/socket --inquire STORE -S datafile -set +o errexit +echo "Test 7. Target content." +echo -ne 'b\tb\ta b value' | pwmc --url $WDIR/socket --inquire STORE -S datafile echo -ne 'GET b\tb' | pwmc --url $WDIR/socket datafile > result +cmp store.result7 result +rm -f result + +echo "Test 8. Invalid syntax, too many '!'." +set +o errexit +echo -ne '!!b\tb value' | pwmc --url $WDIR/socket --inquire STORE -S datafile if [ ${PIPESTATUS[1]} == 0 ]; then echo "The previous command should have failed. Stopping." exit 1 fi set -e -cmp store.result7 result + +echo +echo "Test 9. Recursion loop." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a b' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +set +o errexit +echo -ne 'GET b\tb' | pwmc --url $WDIR/socket datafile.tmp > result +if [ ${PIPESTATUS[1]} == 0 ]; then + echo "The previous command should have failed. Stopping." + exit 1 +fi + +set -e + +echo +echo "Test 10. Recursion loop, retrieve literal value." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a b' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +echo -ne 'GET !a\tb' | pwmc --url $WDIR/socket datafile.tmp > result +cmp store.result10 result +rm -f result + +echo +echo "Test 11. Recursion loop, store literal value." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a b' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +echo -ne '!a\tb\ta b value' | pwmc --url $WDIR/socket --inquire STORE -S \ + datafile +echo -ne 'GET !a\tb' | pwmc --url $WDIR/socket datafile.tmp > result +cmp store.result11 result +rm -f result + +echo +echo "Test 12. Recursion to parent." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a b' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +set +o errexit +echo -ne 'ATTR SET target !a\tb a' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +if [ ${PIPESTATUS[1]} == 0 ]; then + echo "The previous command should have failed. Stopping." + exit 1 +fi + +set -e + +echo +echo "Test 13. Recursion to parent, literal result." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a b' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +echo -ne 'ATTR SET target !a\tb !a' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +echo -ne 'GET !a\tb' | pwmc --url $WDIR/socket datafile.tmp > result +cmp store.result13 result +rm -f result + +echo +echo "Test 14. Target to child." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a a\tb' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +set +o errexit +echo -ne 'GET a' | pwmc --url $WDIR/socket datafile.tmp > result +if [ ${PIPESTATUS[1]} == 0 ]; then + echo "The previous command should have failed. Stopping." + exit 1 +fi + +set -e + +echo +echo "Test 15. Target to literal self." +cp -f data/datafile data/datafile.tmp +echo -ne 'ATTR SET target a !a' | pwmc --url $WDIR/socket -S \ + --key-file $WDIR/datafile.key datafile.tmp +echo -ne 'GET a' | pwmc --url $WDIR/socket datafile.tmp > result +cmp store.result15 result rm -f result diff --git a/tests/store.result6 b/tests/store.result10 similarity index 100% copy from tests/store.result6 copy to tests/store.result10 diff --git a/tests/store.result6 b/tests/store.result11 similarity index 100% copy from tests/store.result6 copy to tests/store.result11 diff --git a/tests/store.result13 b/tests/store.result13 new file mode 100644 index 00000000..ec47713d --- /dev/null +++ b/tests/store.result13 @@ -0,0 +1 @@ +a value \ No newline at end of file diff --git a/tests/store.result15 b/tests/store.result15 new file mode 100644 index 00000000..ec47713d --- /dev/null +++ b/tests/store.result15 @@ -0,0 +1 @@ +a value \ No newline at end of file diff --git a/tests/store.result6 b/tests/store.result6 index c3d33f7a..e69de29b 100644 --- a/tests/store.result6 +++ b/tests/store.result6 @@ -1 +0,0 @@ -a b value \ No newline at end of file diff --git a/tests/store.result7 b/tests/store.result7 index e69de29b..c3d33f7a 100644 --- a/tests/store.result7 +++ b/tests/store.result7 @@ -0,0 +1 @@ +a b value \ No newline at end of file -- 2.11.4.GIT