test/bin-test/test-dav-sync-symlink1.sh

Sun, 17 Dec 2023 15:33:50 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 17 Dec 2023 15:33:50 +0100
changeset 800
30d484806c2b
parent 686
ab159748055c
permissions
-rwxr-xr-x

fix faulty string to int conversion utilities

Probably it was expected that errno is set to EINVAL when illegal characters are encountered. But this is not standard and does not happen on every system, allowing illegal strings to be parsed as valid integers.

#!/bin/sh
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright 2019 Olaf Wintermann. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   1. Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#
#   2. Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

if [ -z "$DAV_BIN" ];
then
	echo "DAV_BIN variable not set"
	exit 1
fi
if [ -z "$DAV_SYNC_BIN" ];
then
	echo "DAV_BIN variable not set"
	exit 1
fi

XATTR=../../build/xattrtool

# checks if tmp-sync/out.txt contains a specific text
# arg1: pattern
# arg2: errormsg
check_tmpout()
{
	TEST=`cat tmp-sync/out.txt | grep "$1"`
	if [ $? -ne 0 ];
	then
		echo "$2"
		exit 2	
	fi
}

# checks if tmp-sync/out.txt does not contain a specific text
# arg1: pattern
# arg2: errormsg
ncheck_tmpout()
{
	TEST=`cat tmp-sync/out.txt | grep "$1"`
	if [ $? -eq 0 ];
	then
		echo "$2"
		exit 2	
	fi
}

# do dav-sync push and check return value
# arg1: dir
# arg2: errormsg
dav_sync_push()
{
	$DAV_SYNC_BIN push $1 > tmp-sync/out.txt
	if [ $? -ne 0 ];
	then
		echo "$2"
		exit 2
	fi
}
# do dav-sync pull and check return value
# arg1: dir
# arg2: errormsg
dav_sync_pull()
{
	$DAV_SYNC_BIN pull $1 > tmp-sync/out.txt
	if [ $? -ne 0 ];
	then
		echo "$2"
		exit 2
	fi
}

rm -f .dav/dav-sync-tests-test7a-db.xml
rm -f .dav/dav-sync-tests-test7b-db.xml

$DAV_BIN rm dav-test-repo/sync/test7 2> /dev/null

$DAV_BIN mkcol dav-test-repo/sync/test7 2> /dev/null

# tmp sync dir
rm -Rf tmp-sync
mkdir tmp-sync
mkdir tmp-sync/test7a
mkdir tmp-sync/test7b

# ----------------------------------------------------------------------------
# test 1: try to sync symlinks with symlinks disabled (test7a1)
# expected result: only normal files synced

mkdir tmp-sync/files
mkdir tmp-sync/test7a/dir1
mkdir tmp-sync/test7a/dir1/sub1

echo "extern-file1" > tmp-sync/extern1
echo "extern-file2" > tmp-sync/files/extern2
echo "extern-file3" > tmp-sync/files/extern3

which ln > /dev/null 2>&1
if [ $? -ne 0 ]; then
	exit 0 # symlinks unsupported on this platform
fi

ln -s -r tmp-sync/extern1 tmp-sync/test7a/extern1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
	exit 0 # symlinks unsupported on this platform
fi

ln -s -r tmp-sync/files/extern2 tmp-sync/test7a/extern2
ln -s -r tmp-sync/files/extern3 tmp-sync/test7a/dir1/sub1/extern3

cp synctest/file1 tmp-sync/test7a
cp synctest/file2 tmp-sync/test7a/dir1
cp synctest/file3 tmp-sync/test7a/dir1/sub1

ln -s -r tmp-sync/test7a/file1 tmp-sync/test7a/intern1
ln -s -r tmp-sync/test7a/dir1/file2 tmp-sync/test7a/intern2
ln -s -r tmp-sync/test7a/file1 tmp-sync/test7a/dir1/sub1/intern3

dav_sync_push test7a1 "test 1: push failed"
check_tmpout "3 files pushed" "test 1: wrong push counter"
check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)"
check_tmpout "0 errors" "test 1: wrong error counter (push)"
ncheck_tmpout "extern" "test 1: external symlinks pushed"
ncheck_tmpout "intern" "test 1: internal symlinks pushed"

dav_sync_pull test7b "test 1: pull failed"
check_tmpout "3 files pulled" "test 1: wrong pull counter"
check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 1: wrong error counter (pull)"


# ----------------------------------------------------------------------------
# test 2: try to sync internal symlinks (test7a2)
# expected result: internal symlinks synced, external symlinks ignored

dav_sync_push test7a2 "test 2: push failed"
check_tmpout "3 files pushed" "test 2: wrong push counter"
check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)"
check_tmpout "0 errors" "test 2: wrong error counter (push)"
check_tmpout "link: /intern1" "test 2: no links created (push)"
ncheck_tmpout "extern" "test 2: external symlinks pushed"

dav_sync_pull test7b "test 2: pull failed"
check_tmpout "3 files pulled" "test 2: wrong pull counter"
check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 2: wrong error counter (pull)"
check_tmpout "link: /intern1" "test 2: no links created (pull)"

# compare links
HASH_A=`cat tmp-sync/test7a/intern1 | sha256sum`
HASH_B=`cat tmp-sync/test7b/intern1 | sha256sum`
if [ "$HASH_A" != "$HASH_B" ]; then
	echo "test 2: intern1 has wrong content"
	exit 2
fi
HASH_A=`cat tmp-sync/test7a/intern2 | sha256sum`
HASH_B=`cat tmp-sync/test7b/intern2 | sha256sum`
if [ "$HASH_A" != "$HASH_B" ]; then
	echo "test 2: intern2 has wrong content"
	exit 2
fi
HASH_A=`cat tmp-sync/test7a/dir1/sub1/intern3 | sha256sum`
HASH_B=`cat tmp-sync/test7b/dir1/sub1/intern3 | sha256sum`
if [ "$HASH_A" != "$HASH_B" ]; then
	echo "test 2: intern3 has wrong content"
	exit 2
fi


# ----------------------------------------------------------------------------
# test 3: push with symlink-extern follow (test7a)
# expected result: external links pushed as regular files

dav_sync_push test7a "test 3: push failed"
check_tmpout "3 files pushed" "test 3: wrong push counter"
check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)"
check_tmpout "0 errors" "test 3: wrong error counter (push)"
check_tmpout "extern" "test 3: no links created (push)"

dav_sync_pull test7b "test 3: pull failed"
check_tmpout "3 files pulled" "test 3: wrong pull counter"
check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 3: wrong error counter (pull)"


# ----------------------------------------------------------------------------
# test 4: push, add new file, push (test if double sync happens)
# expected result: push1: 0 files pushed, push2: 1 file pushed

dav_sync_push test7a "test 4: push failed"
check_tmpout "0 files pushed" "test 4: wrong push counter"
check_tmpout "0 conflicts" "test 4: wrong conflict counter (push)"
check_tmpout "0 errors" "test 4: wrong error counter (push)"

echo "test3-new1" > tmp-sync/test7a/new1

dav_sync_push test7a "test 4: push 2 failed"
check_tmpout "1 file pushed" "test 4: wrong push counter (2)"
check_tmpout "0 conflicts" "test 4: wrong conflict counter (2)"
check_tmpout "0 errors" "test 4: wrong error counter (2)"

dav_sync_pull test7b "test 4: pull failed"
check_tmpout "1 file pulled" "test 4: wrong pull counter"
check_tmpout "0 conflicts" "test 4: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 4: wrong error counter (pull)"


# ----------------------------------------------------------------------------
# test 5: modify file1, sync
# expected result: file1 synced, intern1 not synced

sleep 2

echo "test5-mod1" >> tmp-sync/test7a/file1

dav_sync_push test7a "test 5: push failed"
check_tmpout "1 file pushed" "test 5: wrong push counter"
check_tmpout "0 conflicts" "test 5: wrong conflict counter (push)"
check_tmpout "0 errors" "test 5: wrong error counter (push)"
ncheck_tmpout "intern1" "test 5: intern1 updated (push)"

dav_sync_pull test7b "test 5: pull failed"
check_tmpout "1 file pulled" "test 5: wrong pull counter"
check_tmpout "0 conflicts" "test 5: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 5: wrong error counter (pull)"


# ----------------------------------------------------------------------------
# test 6: change intern1 target
# expected result: intern1 updated

rm -f tmp-sync/test7a/intern1
ln -s -r tmp-sync/test7a/new1 tmp-sync/test7a/intern1

dav_sync_push test7a "test 6: push failed"
check_tmpout "1 file pushed" "test 6: wrong push counter"
check_tmpout "0 conflicts" "test 6: wrong conflict counter (push)"
check_tmpout "0 errors" "test 6: wrong error counter (push)"
check_tmpout "intern1" "test 6: intern1 not updated (push)"

dav_sync_pull test7b "test 6: pull failed"
check_tmpout "1 file pulled" "test 6: wrong pull counter"
check_tmpout "0 conflicts" "test 6: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 6: wrong error counter (pull)"
check_tmpout "intern1" "test 6: intern1 not updated (pull)"


# ----------------------------------------------------------------------------
# test 7: change intern1 target on both sides
# expected result: conflict

# preparation: add regular files on both sides and sync

echo "test7-new2a" > tmp-sync/test7a/new2a
echo "test7-new2b" > tmp-sync/test7b/new2b

dav_sync_push test7a "test 7: push a failed"
check_tmpout "1 file pushed" "test 7: wrong push counter (push a)"
check_tmpout "0 conflicts" "test 7: wrong conflict counter (push a)"
check_tmpout "0 errors" "test 7: wrong error counter (push a)"

dav_sync_push test7b "test 7: push b failed"
check_tmpout "1 file pushed" "test 7: wrong push counter (push b)"
check_tmpout "0 conflicts" "test 7: wrong conflict counter (push b)"
check_tmpout "0 errors" "test 7: wrong error counter (push b)"

dav_sync_pull test7a "test 7: pull a failed"
check_tmpout "1 file pulled" "test 7: wrong pull counter (pull a)"
check_tmpout "0 conflicts" "test 7: wrong conflict counter (pull a)"
check_tmpout "0 errors" "test 7: wrong error counter (pull a)"

dav_sync_pull test7b "test 7: pull b failed"
check_tmpout "1 file pulled" "test 7: wrong pull counter (pull b)"
check_tmpout "0 conflicts" "test 7: wrong conflict counter (pull b)"
check_tmpout "0 errors" "test 7: wrong error counter (pull b)"

# test: change symlinks

rm -f tmp-sync/test7a/intern1
ln -s -r tmp-sync/test7a/new2a tmp-sync/test7a/intern1

rm -f tmp-sync/test7b/intern1
ln -s -r tmp-sync/test7b/new2b tmp-sync/test7b/intern1

dav_sync_push test7a "test 7: push a failed (a)"
check_tmpout "1 file pushed" "test 7: wrong push counter (push a 2)"
check_tmpout "0 conflicts" "test 7: wrong conflict counter (push a 2)"
check_tmpout "0 errors" "test 7: wrong error counter (push a 2)"
check_tmpout "intern1" "test 7: intern1 not updated (push a 2)"

dav_sync_push test7b "test 7: push b failed (b)"
check_tmpout "1 conflict" "test 7: wrong conflict counter (push b 2)"
check_tmpout "0 errors" "test 7: wrong error counter (push b 2)"


# ----------------------------------------------------------------------------
# test 8: pull test7b
# expected result: conflict

dav_sync_pull test7b "test 8: pull failed"
check_tmpout "1 file pulled" "test8: wrong pull counter (pull)"
check_tmpout "1 conflict" "test 8: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 8: wrong error counter (pull)"

$DAV_SYNC_BIN delete-conflicts test7b > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "test 8: delete-conflicts failed"
	exit 2
fi

dav_sync_pull test7b "test 8: pull 2 failed"
check_tmpout "0 files pulled" "test8: wrong pull counter (pull 2)"
check_tmpout "0 conflicts" "test 8: wrong conflict counter (pull 2)"
check_tmpout "0 errors" "test 8: wrong error counter (pull 2)"

dav_sync_push test7b "test 8: push b failed (b)"
check_tmpout "0 files pushed" "test 8: wrong push counter"
check_tmpout "0 conflicts" "test 8: wrong conflict counter (push)"
check_tmpout "0 errors" "test 8: wrong error counter (push)"


# ----------------------------------------------------------------------------
# test 9: add new link on both sides
# expected result: conflict

ln -s -r tmp-sync/test7a/new2a tmp-sync/test7a/newlink1
ln -s -r tmp-sync/test7b/new2b tmp-sync/test7b/newlink1

dav_sync_push test7a "test 9: push a failed (a)"
check_tmpout "1 file pushed" "test 9: wrong push counter (push a)"
check_tmpout "0 conflicts" "test 9: wrong conflict counter (push a)"
check_tmpout "0 errors" "test 9: wrong error counter (push a)"
check_tmpout "newlink1" "test 9: intern1 not updated (push a)"

dav_sync_push test7b "test 9: push b failed (b)"
check_tmpout "1 conflict" "test 9: wrong conflict counter (push b)"
check_tmpout "0 errors" "test 9: wrong error counter (push b)"

# pull

dav_sync_pull test7b "test 9: pull failed"
check_tmpout "1 file pulled" "test9: wrong pull counter (pull)"
check_tmpout "1 conflict" "test 9: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 9: wrong error counter (pull)"

$DAV_SYNC_BIN delete-conflicts test7b > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "test 9: delete-conflicts failed"
	exit 2
fi

mercurial