Fix lookup
This commit is contained in:
74
test.sh
74
test.sh
@@ -3,6 +3,13 @@
|
||||
SCRIPT_DIR=$(dirname $0)
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
|
||||
|
||||
function die() {
|
||||
echo "error: $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# test jq is installed
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "jq could not be found"
|
||||
@@ -34,6 +41,71 @@ BASE_TAG="autotest"
|
||||
|
||||
# upload this script as an object
|
||||
echo "uploading ${SCRIPT_DIR}/${SCRIPT_NAME} to ${BASE_TAG}:test1"
|
||||
OBJECT_HASH=$(curl "${BASE_URL}/upload?token=${WRITE_TOKEN}&labeltag=${BASE_TAG}:test1&filename=${SCRIPT_NAME}" -T ${SCRIPT_DIR}/${SCRIPT_NAME} | jq -r '.hash')
|
||||
OBJECT_HASH=$(curl -s "${BASE_URL}/upload?token=${WRITE_TOKEN}&labeltag=${BASE_TAG}:test1&filename=${SCRIPT_NAME}" -T ${SCRIPT_DIR}/${SCRIPT_NAME} | jq -r '.hash')
|
||||
echo "received hash ${OBJECT_HASH}"
|
||||
|
||||
# check the hash matches.
|
||||
CHECK_HASH=$(curl -s "${BASE_URL}/hash/${BASE_TAG}:test1" | jq -r '.hash')
|
||||
[ "${OBJECT_HASH}" != "${CHECK_HASH}" ] && die "hash does not match"
|
||||
|
||||
# get md5sum of this file
|
||||
MD5SUM=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME} | awk '{print $1}')
|
||||
echo "md5sum of ${SCRIPT_DIR}/${SCRIPT_NAME} is ${MD5SUM}"
|
||||
|
||||
# download the object
|
||||
echo "downloading ${OBJECT_HASH} to ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1"
|
||||
curl -s "${BASE_URL}/object/${OBJECT_HASH}" -o ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1
|
||||
|
||||
# download the object again via the label:tag
|
||||
echo "downloading ${BASE_TAG}:test1 to ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2"
|
||||
curl -s "${BASE_URL}/object/${BASE_TAG}:test1" -o ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2
|
||||
|
||||
# get md5sum of the downloaded file
|
||||
MD5SUM_DOWNLOADED1=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1 | awk '{print $1}')
|
||||
echo "md5sum of ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1 is ${MD5SUM_DOWNLOADED1}"
|
||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED1}" ] && die "md5sums do not match"
|
||||
MD5SUM_DOWNLOADED2=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2 | awk '{print $1}')
|
||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED2}" ] && die "md5sums do not match"
|
||||
|
||||
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1
|
||||
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2
|
||||
|
||||
# delete the object tags
|
||||
echo "deleting tag ${BASE_TAG}:test1"
|
||||
if ! curl -s "${BASE_URL}/deletetag?token=${WRITE_TOKEN}&labeltag=${BASE_TAG}:test1" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to delete tag ${BASE_TAG}:test1"
|
||||
fi
|
||||
|
||||
# testing we CANT download via the label:tag
|
||||
echo "testing we CANT download via the label:tag"
|
||||
if curl -s "${BASE_URL}/object/${BASE_TAG}:test1" | jq -r '.result' | grep -q 'success'; then
|
||||
die "downloaded via the label:tag"
|
||||
fi
|
||||
|
||||
# testing we can still download via the hash
|
||||
echo "testing we can still download via the hash"
|
||||
if ! curl -s "${BASE_URL}/object/${OBJECT_HASH}" -o ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded3 | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to download via the hash"
|
||||
fi
|
||||
|
||||
MD5SUM_DOWNLOADED3=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded3 | awk '{print $1}')
|
||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED3}" ] && die "md5sums do not match"
|
||||
|
||||
# delete the downloaded file
|
||||
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded3
|
||||
|
||||
# delete the object
|
||||
echo "deleting ${OBJECT_HASH}"
|
||||
if ! curl -s "${BASE_URL}/deleteobject?token=${WRITE_TOKEN}&hash=${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to delete ${OBJECT_HASH}"
|
||||
fi
|
||||
|
||||
# verify the object is deleted
|
||||
echo "verifying ${OBJECT_HASH} is deleted"
|
||||
DELETE_RESPONSE=$(curl -s "${BASE_URL}/object/${OBJECT_HASH}")
|
||||
echo "delete response: ${DELETE_RESPONSE}"
|
||||
if ! echo "${DELETE_RESPONSE}" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to verify ${OBJECT_HASH} is deleted"
|
||||
fi
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user