Vaguely working

This commit is contained in:
Your Name
2025-05-25 11:23:36 +12:00
parent 3db0208fe9
commit 90b4946ce8
5 changed files with 17 additions and 36 deletions

View File

@@ -8,6 +8,8 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CACHE_DIR="${SCRIPT_DIR}/cache"
EXE_DIR="${SCRIPT_DIR}/exe"
rm -f ${EXE_DIR}/*
# FUNCTIONS
function title() {
echo "----------------------------------------"

View File

@@ -479,7 +479,7 @@ void Server::add_file_metadata(const std::string &file_path, nlohmann::json &met
void Server::handle_delete_object(const httplib::Request& req, httplib::Response& res) {
std::map<std::string, std::string> params;
if (!validate_write_request(req, res, {"token", "hash"}, params)) {
if (!validate_write_request(req, res, {"hash"}, params)) {
return;
}

47
test.sh
View File

@@ -51,12 +51,23 @@ BASE_TAG="autotest"
# test every action in the README.md file, leaving the system in the same state it was found
# and print the output of each action
# Construct metadata JSON
METADATA_JSON=$(cat <<EOF
{
"labeltag": "${BASE_TAG}:test1",
"description": "Example file",
"tags": ["test", "example"],
"custom_field": "custom value"
}
EOF
)
# upload this script as an object
echo "uploading ${SCRIPT_DIR}/${SCRIPT_NAME} to ${BASE_TAG}:test1"
UPLOAD_RESPONSE=$(curl -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
-F 'metadata={"labeltag":"${BASE_TAG}:test1","description":"Example file","tags":["test","example"],"custom_field":"custom value"}' \
-F "metadata=${METADATA_JSON}" \
"http://localhost:8123/upload")
echo "upload response: ${UPLOAD_RESPONSE}"
@@ -69,7 +80,7 @@ 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"
[ "${OBJECT_HASH}" != "${CHECK_HASH}" ] && die "hash does not match: ${OBJECT_HASH} != ${CHECK_HASH}"
# get md5sum of this file
MD5SUM=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME} | awk '{print $1}')
@@ -97,40 +108,10 @@ MD5SUM_DOWNLOADED2=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2 | awk '{pri
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}/exists/${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
die "failed to check exists via the hash"
fi
# download the object
echo "downloading ${OBJECT_HASH} to ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4"
if ! curl -s "${BASE_URL}/object/${OBJECT_HASH}" -o ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4; then
die "failed to download ${OBJECT_HASH}"
fi
MD5SUM_DOWNLOADED4=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4 | awk '{print $1}')
MD5SUM=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME} | awk '{print $1}')
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED4}" ] && die "md5sums do not match"
# delete the downloaded file
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4
# 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
if ! curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject?hash=${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
die "failed to delete ${OBJECT_HASH}"
fi

View File

@@ -1 +0,0 @@
{"error":"Invalid hash: null","result":"error"}

View File

@@ -1 +0,0 @@
{"error":"Invalid hash: autotest:test1","result":"error"}