diff options
author | Daiki Ueno <dueno@src.gnome.org> | 2019-08-19 17:56:17 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2019-10-13 06:21:38 +0000 |
commit | f2b7f6d505488a6bc2a04e48e89bf5511d2949a9 (patch) | |
tree | c596847fecd947bdf0aa7f11ec93cbe9222a138b /tool | |
parent | 8e4317235e43f4dc03049f1ea91ab90becebf820 (diff) | |
download | libsecret-f2b7f6d505488a6bc2a04e48e89bf5511d2949a9.tar.gz |
secret-tool: Add tests using file backend
Diffstat (limited to 'tool')
-rw-r--r-- | tool/Makefile.am | 4 | ||||
-rw-r--r-- | tool/meson.build | 6 | ||||
-rwxr-xr-x | tool/test-secret-tool.sh | 104 |
3 files changed, 114 insertions, 0 deletions
diff --git a/tool/Makefile.am b/tool/Makefile.am index 2361311..9d25ea1 100644 --- a/tool/Makefile.am +++ b/tool/Makefile.am @@ -5,3 +5,7 @@ tool_secret_tool_SOURCES = \ tool_secret_tool_LDADD = \ libsecret-@SECRET_MAJOR@.la + +if WITH_GCRYPT +TESTS += tool/test-secret-tool.sh +endif diff --git a/tool/meson.build b/tool/meson.build index 686cf24..1bf9a84 100644 --- a/tool/meson.build +++ b/tool/meson.build @@ -9,3 +9,9 @@ secret_tool = executable('secret-tool', c_args: libsecret_cflags, install: true, ) + +if with_gcrypt and host_machine.system() != 'windows' + test('test-secret-tool.sh', + find_program('test-secret-tool.sh'), + env: test_env) +endif diff --git a/tool/test-secret-tool.sh b/tool/test-secret-tool.sh new file mode 100755 index 0000000..9bd4fbd --- /dev/null +++ b/tool/test-secret-tool.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +set -e + +testdir=$PWD/test-secret-tool-$$ +test -d "$testdir" || mkdir "$testdir" + +cleanup () { + rm -rf "$testdir" +} +trap cleanup 0 + +cd "$testdir" + +SECRET_BACKEND=file +export SECRET_BACKEND + +SECRET_FILE_TEST_PATH=$testdir/keyring +export SECRET_FILE_TEST_PATH + +SECRET_FILE_TEST_PASSWORD=test +export SECRET_FILE_TEST_PASSWORD + +: ${SECRET_TOOL="$abs_top_builddir"/tool/secret-tool} + +: ${DIFF=diff} + +echo 1..4 + +echo test1 | ${SECRET_TOOL} store --label label1 foo bar +if test $? -eq 0; then + echo "ok 1 /secret-tool/store" +else + echo "not ok 1 /secret-tool/store" +fi + +echo test2 | ${SECRET_TOOL} store --label label2 foo bar apple orange +if test $? -eq 0; then + echo "ok 1 /secret-tool/store" +else + echo "not ok 1 /secret-tool/store" +fi + +echo test1 > lookup.exp +${SECRET_TOOL} lookup foo bar > lookup.out +if ${DIFF} lookup.exp lookup.out > lookup.diff; then + echo "ok 2 /secret-tool/lookup" +else + echo "not ok 2 /secret-tool/lookup" + sed 's/^/# /' lookup.diff + exit 1 +fi + +cat > search.exp <<EOF +[no path] +label = label1 +secret = test1 + +[no path] +label = label2 +secret = test2 + +EOF + +${SECRET_TOOL} search foo bar | sed '/^created\|^modified/d' > search.out +if test $? -ne 0; then + echo "not ok 3 /secret-tool/search" + exit 1 +fi +if ${DIFF} search.exp search.out > search.diff; then + echo "ok 3 /secret-tool/search" +else + echo "not ok 3 /secret-tool/search" + sed 's/^/# /' search.diff + exit 1 +fi + +${SECRET_TOOL} clear apple orange +if test $? -eq 0; then + echo "ok 4 /secret-tool/clear" +else + echo "not ok 4 /secret-tool/clear" + exit 1 +fi + +cat > search-after-clear.exp <<EOF +[no path] +label = label1 +secret = test1 + +EOF + +${SECRET_TOOL} search foo bar | sed '/^created\|^modified/d' > search-after-clear.out +if test $? -ne 0; then + echo "not ok 5 /secret-tool/search-after-clear" + exit 1 +fi +if ${DIFF} search-after-clear.exp search-after-clear.out > search-after-clear.diff; then + echo "ok 5 /secret-tool/search-after-clear" +else + echo "not ok 5 /secret-tool/search-after-clear" + sed 's/^/# /' search-after-clear.diff + exit 1 +fi |