'Generic Commit'
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Failing after 30s
Build-Test-Publish / build (linux/arm64) (push) Failing after 40s
Build-Test-Publish / create-manifest (push) Has been skipped

This commit is contained in:
Your Name
2025-06-15 22:13:14 +12:00
parent 48d12367e7
commit 826fb95e56
2 changed files with 111 additions and 3 deletions

View File

@@ -402,6 +402,81 @@ sleep 3
# Now try a request with a valid token - should be rate limited
echo "Attempting request with valid token (should NOT be rate limited)"
RESPONSE=$(curl -s -X PUT -H "Authorization: Bearer ${WRITE_TOKEN}" -F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" -F "metadata={\"labeltags\":[\"test:latest\"]}" "${HOSTURL}/upload")
#------------------------------------------------------------------------------------------------
title "8: Test update endpoint"
# First upload a test file
UPLOAD_RESPONSE=$(curl -s -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
-F "metadata={\"labeltags\":[\"test:update\"]}" \
"${HOSTURL}/upload")
HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
if [ -z "${HASH}" ] || [ "${HASH}" = "null" ]; then
die "Failed to upload test file for update test"
fi
# Test 8.1: Update metadata using JSON
UPDATED_METADATA='{"labeltags":["test:updated", "version:1.0"], "new_field":"test_value"}'
UPDATE_RESPONSE=$(curl -s -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"hash\":\"${HASH}\", \"metadata\":${UPDATED_METADATA}}" \
"${HOSTURL}/update")
echo "Update response: ${UPDATE_RESPONSE}"
if [ "$(echo "${UPDATE_RESPONSE}" | jq -r '.result')" != "success" ]; then
die "Failed to update metadata via JSON"
fi
# Verify the update
UPDATED_METADATA_RESPONSE=$(curl -s "${HOSTURL}/meta/${HASH}")
if ! echo "${UPDATED_METADATA_RESPONSE}" | jq -e '.metadata.new_field == "test_value"' | grep -q true; then
die "Metadata was not updated correctly via JSON"
fi
# Test 8.2: Update metadata using form data
# Update with form data using raw JSON string
UPDATE_FORM_RESPONSE=$(curl -s -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "hash=${HASH}" \
-F 'metadata={"labeltags":["test:form_updated"], "form_field":"form_value"}' \
"${HOSTURL}/update")
echo "Form update response: ${UPDATE_FORM_RESPONSE}"
if [ "$(echo "${UPDATE_FORM_RESPONSE}" | jq -r '.result')" != "success" ]; then
die "Failed to update metadata via form data"
fi
# Verify the form update
UPDATED_FORM_METADATA_RESPONSE=$(curl -s "${HOSTURL}/meta/${HASH}")
if ! echo "${UPDATED_FORM_METADATA_RESPONSE}" | jq -e '.metadata.form_field == "form_value"' | grep -q true; then
die "Metadata was not updated correctly via form data"
fi
# Test 8.3: Test error cases
# Missing hash
MISSING_HASH_RESPONSE=$(curl -s -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-d '{"metadata":{}}' \
"${HOSTURL}/update")
if [ "$(echo "${MISSING_HASH_RESPONSE}" | jq -r '.error')" != "Missing 'hash' or 'metadata' field in request body" ]; then
die "Expected error for missing hash, got: ${MISSING_HASH_RESPONSE}"
fi
# Missing metadata
MISSING_METADATA_RESPONSE=$(curl -s -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-d "{\"hash\":\"${HASH}\"}" \
"${HOSTURL}/update")
if [ "$(echo "${MISSING_METADATA_RESPONSE}" | jq -r '.error')" != "Missing 'hash' or 'metadata' field in request body" ]; then
die "Expected error for missing metadata, got: ${MISSING_METADATA_RESPONSE}"
fi
# Clean up
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${HASH}" > /dev/null
if echo "${RESPONSE}" | jq -r '.error' | grep -q "Too many authentication attempts"; then
die "Expected no rate limit error, got: ${RESPONSE}"
fi