'Generic Commit'
This commit is contained in:
@@ -120,10 +120,16 @@ void UpdateHandler::handle_update_object(const drogon::HttpRequestPtr& req, std:
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare updated entry (keep hash and labeltags, update metadata)
|
||||
// Prepare updated entry
|
||||
dbEntry updated_entry = entry;
|
||||
updated_entry.metadata = new_metadata;
|
||||
// Ensure labeltags and hash are preserved in metadata
|
||||
|
||||
// Update labeltags if provided in the new metadata
|
||||
if (new_metadata.contains("labeltags") && new_metadata["labeltags"].is_array()) {
|
||||
updated_entry.labeltags = new_metadata["labeltags"].get<std::vector<std::string>>();
|
||||
}
|
||||
|
||||
// Ensure labeltags and hash are reflected in metadata
|
||||
updated_entry.metadata["labeltags"] = updated_entry.labeltags;
|
||||
updated_entry.metadata["hash"] = updated_entry.hash;
|
||||
|
||||
|
100
testing/test.sh
100
testing/test.sh
@@ -42,10 +42,11 @@ cat << EOF
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
function test0() {
|
||||
# Test 0: Verify the script is running
|
||||
title "0: Verify the server is running"
|
||||
|
||||
|
||||
# test jq is installed
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "jq could not be found"
|
||||
@@ -74,12 +75,14 @@ fi
|
||||
# test if server is running
|
||||
if ! wget -qO- "${HOSTURL}/status" | jq -r '.result' | grep -q 'success'; then
|
||||
wget -O - "${HOSTURL}/status"
|
||||
|
||||
die "server is not running on ${HOSTURL}"
|
||||
fi
|
||||
|
||||
echo "Simple Object Storage server is running at ${HOSTURL}"
|
||||
}
|
||||
|
||||
|
||||
function test1() {
|
||||
# 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
|
||||
|
||||
@@ -110,7 +113,9 @@ UPLOAD_RESPONSE=$(curl -X PUT \
|
||||
echo "upload response: ${UPLOAD_RESPONSE}"
|
||||
|
||||
OBJECT_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
||||
}
|
||||
|
||||
function test2() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "2: Check sos hash matches"
|
||||
|
||||
@@ -119,8 +124,9 @@ CMD="${HOSTURL}/hash/${BASE_TAG}:test1"
|
||||
echo "checking hash via ${CMD}"
|
||||
CHECK_HASH=$(curl --fail-with-body -s "${CMD}" | jq -r '.hash')
|
||||
[ "${OBJECT_HASH}" != "${CHECK_HASH}" ] && die "hash does not match: ${OBJECT_HASH} != ${CHECK_HASH}"
|
||||
}
|
||||
|
||||
|
||||
function test3() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "3: Check MD5Sum matches, for both label:tag and hash downloads"
|
||||
|
||||
@@ -150,12 +156,13 @@ MD5SUM_DOWNLOADED2=$(md5sum "${DOWNLOAD_FILE}2" | awk '{print $1}')
|
||||
|
||||
rm "${DOWNLOAD_FILE}1"
|
||||
rm "${DOWNLOAD_FILE}2"
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------------------------
|
||||
function test3b() {
|
||||
LABELTAG="finangle-wrangler:fuzzy_test"
|
||||
title "3b: Upload script to ${LABELTAG}"
|
||||
|
||||
|
||||
METADATA_JSON=$(cat <<EOF
|
||||
{
|
||||
"labeltags": ["${LABELTAG}"],
|
||||
@@ -164,6 +171,7 @@ METADATA_JSON=$(cat <<EOF
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# upload this script as an object
|
||||
echo "uploading ${TEST_FILE} to ${LABELTAG}"
|
||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||
@@ -205,9 +213,9 @@ echo "md5sum of ${DOWNLOAD_FILE}3 is ${MD5SUM_DOWNLOADED3}"
|
||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED3}" ] && die "md5sums do not match"
|
||||
|
||||
rm "${DOWNLOAD_FILE}3"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function test4() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "4: Delete the object"
|
||||
|
||||
@@ -223,7 +231,9 @@ DELETE_RESPONSE=$(curl -s "${HOSTURL}/${OBJECT_HASH}")
|
||||
if ! echo "${DELETE_RESPONSE}" | jq -r '.result' | grep -q 'error'; then
|
||||
die "failed to verify ${OBJECT_HASH} is deleted"
|
||||
fi
|
||||
}
|
||||
|
||||
function test5() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "5: Test metadata field preservation"
|
||||
|
||||
@@ -286,7 +296,9 @@ fi
|
||||
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field2' | grep -q 'value2'; then
|
||||
die "extra_field2 not preserved in metadata"
|
||||
fi
|
||||
}
|
||||
|
||||
function test6() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "6: Test tag versioning behavior"
|
||||
|
||||
@@ -311,7 +323,6 @@ UPLOAD_RESPONSE=$(curl -X PUT \
|
||||
|
||||
FIRST_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
||||
|
||||
|
||||
# check downloading without tag!
|
||||
echo "downloading ${BASE_TAG} to ${DOWNLOAD_FILE}4"
|
||||
if ! curl -s --fail-with-body "${HOSTURL}/${BASE_TAG}" -o "${DOWNLOAD_FILE}4"; then
|
||||
@@ -322,7 +333,6 @@ MD5SUM_DOWNLOADED4=$(md5sum "${DOWNLOAD_FILE}4" | awk '{print $1}')
|
||||
MD5SUM_ORIGINAL=$(md5sum "${SCRIPT_DIR}/${SCRIPT_NAME}" | awk '{print $1}')
|
||||
[ "${MD5SUM_ORIGINAL}" != "${MD5SUM_DOWNLOADED4}" ] && die "md5sums do not match"
|
||||
|
||||
|
||||
# Store first version's metadata before uploading second version
|
||||
FIRST_METADATA=$(curl -s "${HOSTURL}/meta/${FIRST_HASH}")
|
||||
echo "First version metadata response: ${FIRST_METADATA}"
|
||||
@@ -369,11 +379,12 @@ fi
|
||||
if ! echo "${SECOND_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:v2"; then
|
||||
die "Second version does not have v2 tag"
|
||||
fi
|
||||
}
|
||||
|
||||
function test7() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "7: Test rate limiting behavior"
|
||||
|
||||
|
||||
# Clean up
|
||||
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${FIRST_HASH}" > /dev/null
|
||||
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${SECOND_HASH}" > /dev/null
|
||||
@@ -402,7 +413,9 @@ 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")
|
||||
}
|
||||
|
||||
function test8() {
|
||||
#------------------------------------------------------------------------------------------------
|
||||
title "8: Test update endpoint"
|
||||
|
||||
@@ -475,34 +488,61 @@ if [ "$(echo "${MISSING_METADATA_RESPONSE}" | jq -r '.error')" != "Missing 'hash
|
||||
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
|
||||
|
||||
curl -s "${HOSTURL}/meta/${HASH}" | jq
|
||||
|
||||
# delete the object (only if it exists)
|
||||
TODELHASH=$(curl -s "${HOSTURL}/hash/test:form_updated" | jq -r '.hash')
|
||||
if [ "${TODELHASH}" != "null" ] && [ -n "${TODELHASH}" ]; then
|
||||
echo "deleting test:form_updated ${TODELHASH}"
|
||||
if ! curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${TODELHASH}" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to delete ${TODELHASH}"
|
||||
fi
|
||||
# Verify that labeltags were actually updated
|
||||
echo "Checking if test:updated tag exists..."
|
||||
UPDATED_HASH=$(curl -s "${HOSTURL}/hash/test:updated" | jq -r '.hash')
|
||||
if [ "${UPDATED_HASH}" = "${HASH}" ]; then
|
||||
echo "✓ test:updated tag correctly points to hash ${HASH}"
|
||||
else
|
||||
echo "test:form_updated not found, skipping deletion"
|
||||
echo "HASH=${HASH}, TODELHASH=${TODELHASH}"
|
||||
echo "✗ test:updated tag not found or points to wrong hash: ${UPDATED_HASH}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking if test:form_updated tag exists..."
|
||||
FORM_UPDATED_HASH=$(curl -s "${HOSTURL}/hash/test:form_updated" | jq -r '.hash')
|
||||
if [ "${FORM_UPDATED_HASH}" = "${HASH}" ]; then
|
||||
echo "✓ test:form_updated tag correctly points to hash ${HASH}"
|
||||
else
|
||||
echo "✗ test:form_updated tag not found or points to wrong hash: ${FORM_UPDATED_HASH}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up using the correct current labeltag
|
||||
echo "Cleaning up test object with hash: ${HASH}"
|
||||
RESPONSE=$(curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${HASH}")
|
||||
echo "Delete response: ${RESPONSE}"
|
||||
|
||||
if echo "${RESPONSE}" | jq -r '.result' | grep -q 'success'; then
|
||||
echo "Successfully deleted test object"
|
||||
else
|
||||
echo "Failed to delete test object: ${RESPONSE}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------------------------
|
||||
|
||||
function test_1GB_file_upload() {
|
||||
function test9() {
|
||||
title "9: Testing 1GB File upload"
|
||||
source test_1GB_file_upload.sh
|
||||
}
|
||||
|
||||
title "Testing 1GB File upload"
|
||||
test_1GB_file_upload
|
||||
|
||||
#------------------------------------------------------------------------------------------------
|
||||
|
||||
test0
|
||||
|
||||
test8
|
||||
exit 0
|
||||
|
||||
test1
|
||||
test2
|
||||
test3
|
||||
test3b
|
||||
test4
|
||||
test5
|
||||
test6
|
||||
test7
|
||||
test8
|
||||
test9
|
||||
|
||||
title "ALL TESTS PASSED"
|
||||
|
Reference in New Issue
Block a user