#!/bin/bash
export AUTH_SOCKET="/tmp/weborf_auth_yes.socket"
. testsuite/functions.sh

run_auth allow_all.py

# Set up the directory
rm -f site1/prova.txt
rm -f site1/bleble.txt
rm -fr site1/bleble
rm -f /tmp/prova.copy
echo "test" > site1/prova.txt


PORT=12356
run_weborf -b site1 -p $PORT --auth "$AUTH_SOCKET"

curl -siLXPROPFIND http://127.0.0.1:$PORT | grep "207 OK"

curl -siLXCOPY http://127.0.0.1:$PORT/prova.txt -H "Destination: /prova.copy"
test -e site1/prova.copy

curl -siLXDELETE http://127.0.0.1:$PORT/prova.copy
! test -e site1/prova.copy

curl -siLXMOVE http://127.0.0.1:$PORT/prova.txt -H "Destination: /prova.copy"
test -e site1/prova.copy
curl -siLXMOVE http://127.0.0.1:$PORT/prova.copy -H "Destination: /prova.txt"
test -e site1/prova.txt

curl -siLXMKCOL http://127.0.0.1:$PORT/bleble
test -d site1/bleble
rmdir site1/bleble

curl -d "ciccio" -siLXPUT http://127.0.0.1:$PORT/bleble.txt
test -e site1/bleble.txt
grep "ciccio" < site1/bleble.txt
rm site1/bleble.txt

curl -siLXCOPY http://127.0.0.1:$PORT/prova.txt -H "Destination: /../../../../../../../../../../../../../tmp/prova.copy" | grep "403 Forbidden"
! test -e /tmp/prova.copy

curl -siLXMOVE http://127.0.0.1:$PORT/prova.txt -H "Destination: /../../../../../../../../../../../../../tmp/prova.copy" | grep "403 Forbidden"
! test -e /tmp/prova.copy
