'Generic Commit'
This commit is contained in:
@@ -120,10 +120,16 @@ void UpdateHandler::handle_update_object(const drogon::HttpRequestPtr& req, std:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare updated entry (keep hash and labeltags, update metadata)
|
// Prepare updated entry
|
||||||
dbEntry updated_entry = entry;
|
dbEntry updated_entry = entry;
|
||||||
updated_entry.metadata = new_metadata;
|
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["labeltags"] = updated_entry.labeltags;
|
||||||
updated_entry.metadata["hash"] = updated_entry.hash;
|
updated_entry.metadata["hash"] = updated_entry.hash;
|
||||||
|
|
||||||
|
746
testing/test.sh
746
testing/test.sh
@@ -42,49 +42,52 @@ cat << EOF
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Test 0: Verify the script is running
|
|
||||||
title "0: Verify the server is running"
|
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"
|
||||||
|
echo "sudo apt-get install jq"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# read sos_config.json
|
||||||
|
CONFIG_PATH="${SCRIPT_DIR}/sos_config.json"
|
||||||
|
if [ ! -f "${CONFIG_PATH}" ]; then
|
||||||
|
echo "config file not found at ${CONFIG_PATH}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
CONFIG=$(cat "${CONFIG_PATH}")
|
||||||
|
|
||||||
|
# extract the first write token from the config
|
||||||
|
WRITE_TOKEN=$(echo "$CONFIG" | jq -r '.write_tokens[0]')
|
||||||
|
|
||||||
|
BASE_TAG="autotest"
|
||||||
|
|
||||||
|
if ! command -v wget &> /dev/null; then
|
||||||
|
echo "wget could not be found"
|
||||||
|
exit 1
|
||||||
|
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}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# test jq is installed
|
function test1() {
|
||||||
if ! command -v jq &> /dev/null; then
|
# test every action in the README.md file, leaving the system in the same state it was found
|
||||||
echo "jq could not be found"
|
# and print the output of each action
|
||||||
echo "sudo apt-get install jq"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# read sos_config.json
|
# Construct metadata JSON
|
||||||
CONFIG_PATH="${SCRIPT_DIR}/sos_config.json"
|
METADATA_JSON=$(cat <<EOF
|
||||||
if [ ! -f "${CONFIG_PATH}" ]; then
|
|
||||||
echo "config file not found at ${CONFIG_PATH}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CONFIG=$(cat "${CONFIG_PATH}")
|
|
||||||
|
|
||||||
# extract the first write token from the config
|
|
||||||
WRITE_TOKEN=$(echo "$CONFIG" | jq -r '.write_tokens[0]')
|
|
||||||
|
|
||||||
BASE_TAG="autotest"
|
|
||||||
|
|
||||||
if ! command -v wget &> /dev/null; then
|
|
||||||
echo "wget could not be found"
|
|
||||||
exit 1
|
|
||||||
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}"
|
|
||||||
|
|
||||||
# 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
|
|
||||||
{
|
{
|
||||||
"labeltags": ["${BASE_TAG}:test1"],
|
"labeltags": ["${BASE_TAG}:test1"],
|
||||||
"description": "Example file",
|
"description": "Example file",
|
||||||
@@ -93,24 +96,26 @@ METADATA_JSON=$(cat <<EOF
|
|||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
#------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------
|
||||||
# Test 1: Verify extra metadata fields are preserved
|
# Test 1: Verify extra metadata fields are preserved
|
||||||
title "1: Upload script to ${BASE_TAG}:test1"
|
title "1: Upload script to ${BASE_TAG}:test1"
|
||||||
|
|
||||||
TEST_FILE="${SCRIPT_DIR}/${SCRIPT_NAME}"
|
TEST_FILE="${SCRIPT_DIR}/${SCRIPT_NAME}"
|
||||||
|
|
||||||
# upload this script as an object
|
# upload this script as an object
|
||||||
echo "uploading ${TEST_FILE} to ${BASE_TAG}:test1"
|
echo "uploading ${TEST_FILE} to ${BASE_TAG}:test1"
|
||||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
-F "file=@${TEST_FILE}" \
|
-F "file=@${TEST_FILE}" \
|
||||||
-F "metadata=${METADATA_JSON}" \
|
-F "metadata=${METADATA_JSON}" \
|
||||||
"${HOSTURL}/upload")
|
"${HOSTURL}/upload")
|
||||||
|
|
||||||
echo "upload response: ${UPLOAD_RESPONSE}"
|
echo "upload response: ${UPLOAD_RESPONSE}"
|
||||||
|
|
||||||
OBJECT_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
OBJECT_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
||||||
|
}
|
||||||
|
|
||||||
|
function test2() {
|
||||||
#------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------
|
||||||
title "2: Check sos hash matches"
|
title "2: Check sos hash matches"
|
||||||
|
|
||||||
@@ -119,44 +124,46 @@ CMD="${HOSTURL}/hash/${BASE_TAG}:test1"
|
|||||||
echo "checking hash via ${CMD}"
|
echo "checking hash via ${CMD}"
|
||||||
CHECK_HASH=$(curl --fail-with-body -s "${CMD}" | jq -r '.hash')
|
CHECK_HASH=$(curl --fail-with-body -s "${CMD}" | jq -r '.hash')
|
||||||
[ "${OBJECT_HASH}" != "${CHECK_HASH}" ] && die "hash does not match: ${OBJECT_HASH} != ${CHECK_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"
|
title "3: Check MD5Sum matches, for both label:tag and hash downloads"
|
||||||
|
|
||||||
# get md5sum of this file
|
# get md5sum of this file
|
||||||
MD5SUM=$(md5sum "${TEST_FILE}" | awk '{print $1}')
|
MD5SUM=$(md5sum "${TEST_FILE}" | awk '{print $1}')
|
||||||
echo "md5sum of ${TEST_FILE} is ${MD5SUM}"
|
echo "md5sum of ${TEST_FILE} is ${MD5SUM}"
|
||||||
|
|
||||||
# download the object
|
# download the object
|
||||||
DOWNLOAD_FILE="${TEST_FILE}.downloaded"
|
DOWNLOAD_FILE="${TEST_FILE}.downloaded"
|
||||||
echo "downloading ${OBJECT_HASH} to ${DOWNLOAD_FILE}1"
|
echo "downloading ${OBJECT_HASH} to ${DOWNLOAD_FILE}1"
|
||||||
if ! curl --fail-with-body -s "${HOSTURL}/${OBJECT_HASH}" -o "${DOWNLOAD_FILE}1"; then
|
if ! curl --fail-with-body -s "${HOSTURL}/${OBJECT_HASH}" -o "${DOWNLOAD_FILE}1"; then
|
||||||
die "Command failed: curl -s ${HOSTURL}/${OBJECT_HASH} -o ${DOWNLOAD_FILE}1"
|
die "Command failed: curl -s ${HOSTURL}/${OBJECT_HASH} -o ${DOWNLOAD_FILE}1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# download the object again via the label:tag
|
# download the object again via the label:tag
|
||||||
echo "downloading ${BASE_TAG}:test1 to ${DOWNLOAD_FILE}2"
|
echo "downloading ${BASE_TAG}:test1 to ${DOWNLOAD_FILE}2"
|
||||||
if ! curl --fail-with-body -s "${HOSTURL}/${BASE_TAG}:test1" -o "${DOWNLOAD_FILE}2"; then
|
if ! curl --fail-with-body -s "${HOSTURL}/${BASE_TAG}:test1" -o "${DOWNLOAD_FILE}2"; then
|
||||||
die "failed to download ${BASE_TAG}:test1"
|
die "failed to download ${BASE_TAG}:test1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get md5sum of the downloaded file
|
# get md5sum of the downloaded file
|
||||||
MD5SUM_DOWNLOADED1=$(md5sum "${DOWNLOAD_FILE}1" | awk '{print $1}')
|
MD5SUM_DOWNLOADED1=$(md5sum "${DOWNLOAD_FILE}1" | awk '{print $1}')
|
||||||
echo "md5sum of ${DOWNLOAD_FILE}1 is ${MD5SUM_DOWNLOADED1}"
|
echo "md5sum of ${DOWNLOAD_FILE}1 is ${MD5SUM_DOWNLOADED1}"
|
||||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED1}" ] && die "md5sums do not match"
|
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED1}" ] && die "md5sums do not match"
|
||||||
MD5SUM_DOWNLOADED2=$(md5sum "${DOWNLOAD_FILE}2" | awk '{print $1}')
|
MD5SUM_DOWNLOADED2=$(md5sum "${DOWNLOAD_FILE}2" | awk '{print $1}')
|
||||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED2}" ] && die "md5sums do not match"
|
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED2}" ] && die "md5sums do not match"
|
||||||
|
|
||||||
rm "${DOWNLOAD_FILE}1"
|
rm "${DOWNLOAD_FILE}1"
|
||||||
rm "${DOWNLOAD_FILE}2"
|
rm "${DOWNLOAD_FILE}2"
|
||||||
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------
|
||||||
LABELTAG="finangle-wrangler:fuzzy_test"
|
function test3b() {
|
||||||
title "3b: Upload script to ${LABELTAG}"
|
LABELTAG="finangle-wrangler:fuzzy_test"
|
||||||
|
title "3b: Upload script to ${LABELTAG}"
|
||||||
|
|
||||||
|
METADATA_JSON=$(cat <<EOF
|
||||||
METADATA_JSON=$(cat <<EOF
|
|
||||||
{
|
{
|
||||||
"labeltags": ["${LABELTAG}"],
|
"labeltags": ["${LABELTAG}"],
|
||||||
"description": "Test File for fuzzy test",
|
"description": "Test File for fuzzy test",
|
||||||
@@ -164,71 +171,74 @@ METADATA_JSON=$(cat <<EOF
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
# upload this script as an object
|
|
||||||
echo "uploading ${TEST_FILE} to ${LABELTAG}"
|
# upload this script as an object
|
||||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
echo "uploading ${TEST_FILE} to ${LABELTAG}"
|
||||||
|
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
-F "file=@${TEST_FILE}" \
|
-F "file=@${TEST_FILE}" \
|
||||||
-F "metadata=${METADATA_JSON}" \
|
-F "metadata=${METADATA_JSON}" \
|
||||||
"${HOSTURL}/upload")
|
"${HOSTURL}/upload")
|
||||||
|
|
||||||
echo "upload response: ${UPLOAD_RESPONSE}"
|
echo "upload response: ${UPLOAD_RESPONSE}"
|
||||||
|
|
||||||
OBJECT_HASH2=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
OBJECT_HASH2=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
||||||
|
|
||||||
if [ ! "${OBJECT_HASH}" == "${OBJECT_HASH2}" ]; then
|
if [ ! "${OBJECT_HASH}" == "${OBJECT_HASH2}" ]; then
|
||||||
die "object hash does not match: ${OBJECT_HASH} != ${OBJECT_HASH2}"
|
die "object hash does not match: ${OBJECT_HASH} != ${OBJECT_HASH2}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# test the description and custom field matches our new ones.
|
# test the description and custom field matches our new ones.
|
||||||
METADATA_RESPONSE=$(curl "${HOSTURL}/meta/${OBJECT_HASH2}")
|
METADATA_RESPONSE=$(curl "${HOSTURL}/meta/${OBJECT_HASH2}")
|
||||||
|
|
||||||
echo "metadata response: ${METADATA_RESPONSE}"
|
echo "metadata response: ${METADATA_RESPONSE}"
|
||||||
|
|
||||||
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.description' | grep -q "Test File for fuzzy test"; then
|
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.description' | grep -q "Test File for fuzzy test"; then
|
||||||
die "description does not match"
|
die "description does not match"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.custom_field' | grep -q "Upload2!!!111 Yay. This is a test file for the fuzzy test."; then
|
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.custom_field' | grep -q "Upload2!!!111 Yay. This is a test file for the fuzzy test."; then
|
||||||
die "custom field does not match"
|
die "custom field does not match"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# download via the label:tag
|
# download via the label:tag
|
||||||
echo "downloading ${LABELTAG} to ${DOWNLOAD_FILE}3"
|
echo "downloading ${LABELTAG} to ${DOWNLOAD_FILE}3"
|
||||||
if ! curl --fail-with-body -s "${HOSTURL}/${LABELTAG}" -o "${DOWNLOAD_FILE}3"; then
|
if ! curl --fail-with-body -s "${HOSTURL}/${LABELTAG}" -o "${DOWNLOAD_FILE}3"; then
|
||||||
die "failed to download ${LABELTAG}"
|
die "failed to download ${LABELTAG}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get md5sum of the downloaded file
|
# get md5sum of the downloaded file
|
||||||
MD5SUM_DOWNLOADED3=$(md5sum "${DOWNLOAD_FILE}3" | awk '{print $1}')
|
MD5SUM_DOWNLOADED3=$(md5sum "${DOWNLOAD_FILE}3" | awk '{print $1}')
|
||||||
echo "md5sum of ${DOWNLOAD_FILE}3 is ${MD5SUM_DOWNLOADED3}"
|
echo "md5sum of ${DOWNLOAD_FILE}3 is ${MD5SUM_DOWNLOADED3}"
|
||||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED3}" ] && die "md5sums do not match"
|
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED3}" ] && die "md5sums do not match"
|
||||||
|
|
||||||
rm "${DOWNLOAD_FILE}3"
|
rm "${DOWNLOAD_FILE}3"
|
||||||
|
}
|
||||||
|
|
||||||
|
function test4() {
|
||||||
|
#------------------------------------------------------------------------------------------------
|
||||||
|
title "4: Delete the object"
|
||||||
|
|
||||||
|
# delete the object
|
||||||
|
echo "deleting ${OBJECT_HASH}"
|
||||||
|
if ! curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
|
||||||
|
die "failed to delete ${OBJECT_HASH}"
|
||||||
|
fi
|
||||||
|
|
||||||
#------------------------------------------------------------------------------------------------
|
# verify the object is deleted
|
||||||
title "4: Delete the object"
|
echo "verifying ${OBJECT_HASH} is deleted"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
# delete the object
|
function test5() {
|
||||||
echo "deleting ${OBJECT_HASH}"
|
#------------------------------------------------------------------------------------------------
|
||||||
if ! curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
|
title "5: Test metadata field preservation"
|
||||||
die "failed to delete ${OBJECT_HASH}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# verify the object is deleted
|
# Upload with extra metadata fields
|
||||||
echo "verifying ${OBJECT_HASH} is deleted"
|
EXTRA_METADATA_JSON=$(cat <<EOF
|
||||||
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
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------------------------
|
|
||||||
title "5: Test metadata field preservation"
|
|
||||||
|
|
||||||
# Upload with extra metadata fields
|
|
||||||
EXTRA_METADATA_JSON=$(cat <<EOF
|
|
||||||
{
|
{
|
||||||
"labeltags": ["${BASE_TAG}:test2"],
|
"labeltags": ["${BASE_TAG}:test2"],
|
||||||
"description": "Test with extra fields",
|
"description": "Test with extra fields",
|
||||||
@@ -239,62 +249,64 @@ EXTRA_METADATA_JSON=$(cat <<EOF
|
|||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
echo "uploading with extra metadata fields"
|
echo "uploading with extra metadata fields"
|
||||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
|
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
|
||||||
-F "metadata=${EXTRA_METADATA_JSON}" \
|
-F "metadata=${EXTRA_METADATA_JSON}" \
|
||||||
"${HOSTURL}/upload")
|
"${HOSTURL}/upload")
|
||||||
UPLOAD_EXIT_CODE=$?
|
UPLOAD_EXIT_CODE=$?
|
||||||
echo "Upload response: ${UPLOAD_RESPONSE}"
|
echo "Upload response: ${UPLOAD_RESPONSE}"
|
||||||
echo "Upload exit code: ${UPLOAD_EXIT_CODE}"
|
echo "Upload exit code: ${UPLOAD_EXIT_CODE}"
|
||||||
|
|
||||||
if [ ${UPLOAD_EXIT_CODE} -ne 0 ]; then
|
if [ ${UPLOAD_EXIT_CODE} -ne 0 ]; then
|
||||||
die "Failed to upload object: curl returned ${UPLOAD_EXIT_CODE}"
|
die "Failed to upload object: curl returned ${UPLOAD_EXIT_CODE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! echo "${UPLOAD_RESPONSE}" | jq -e . >/dev/null 2>&1; then
|
if ! echo "${UPLOAD_RESPONSE}" | jq -e . >/dev/null 2>&1; then
|
||||||
die "Invalid JSON response from upload: ${UPLOAD_RESPONSE}"
|
die "Invalid JSON response from upload: ${UPLOAD_RESPONSE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OBJECT_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
OBJECT_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
||||||
echo "Received hash: ${OBJECT_HASH}"
|
echo "Received hash: ${OBJECT_HASH}"
|
||||||
|
|
||||||
# Verify the object exists
|
# Verify the object exists
|
||||||
echo "Verifying object exists..."
|
echo "Verifying object exists..."
|
||||||
EXISTS_RESPONSE=$(curl -s "${HOSTURL}/exists/${BASE_TAG}:test2")
|
EXISTS_RESPONSE=$(curl -s "${HOSTURL}/exists/${BASE_TAG}:test2")
|
||||||
echo "Exists response: ${EXISTS_RESPONSE}"
|
echo "Exists response: ${EXISTS_RESPONSE}"
|
||||||
|
|
||||||
# Get metadata and verify extra fields are preserved
|
# Get metadata and verify extra fields are preserved
|
||||||
echo "Retrieving metadata for ${BASE_TAG}:test2"
|
echo "Retrieving metadata for ${BASE_TAG}:test2"
|
||||||
METADATA_RESPONSE=$(curl -s "${HOSTURL}/meta/${BASE_TAG}:test2")
|
METADATA_RESPONSE=$(curl -s "${HOSTURL}/meta/${BASE_TAG}:test2")
|
||||||
CURL_EXIT_CODE=$?
|
CURL_EXIT_CODE=$?
|
||||||
echo "Curl exit code: ${CURL_EXIT_CODE}"
|
echo "Curl exit code: ${CURL_EXIT_CODE}"
|
||||||
echo "Full metadata response: ${METADATA_RESPONSE}"
|
echo "Full metadata response: ${METADATA_RESPONSE}"
|
||||||
|
|
||||||
if [ ${CURL_EXIT_CODE} -ne 0 ]; then
|
if [ ${CURL_EXIT_CODE} -ne 0 ]; then
|
||||||
die "Failed to retrieve metadata: curl returned ${CURL_EXIT_CODE}"
|
die "Failed to retrieve metadata: curl returned ${CURL_EXIT_CODE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! echo "${METADATA_RESPONSE}" | jq -e . >/dev/null 2>&1; then
|
if ! echo "${METADATA_RESPONSE}" | jq -e . >/dev/null 2>&1; then
|
||||||
die "Invalid JSON response: ${METADATA_RESPONSE}"
|
die "Invalid JSON response: ${METADATA_RESPONSE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field1' | grep -q 'value1'; then
|
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field1' | grep -q 'value1'; then
|
||||||
die "extra_field1 not preserved in metadata"
|
die "extra_field1 not preserved in metadata"
|
||||||
fi
|
fi
|
||||||
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field2' | grep -q 'value2'; then
|
if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field2' | grep -q 'value2'; then
|
||||||
die "extra_field2 not preserved in metadata"
|
die "extra_field2 not preserved in metadata"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------------------------------
|
function test6() {
|
||||||
title "6: Test tag versioning behavior"
|
#------------------------------------------------------------------------------------------------
|
||||||
|
title "6: Test tag versioning behavior"
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${OBJECT_HASH}" > /dev/null
|
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${HOSTURL}/deleteobject?hash=${OBJECT_HASH}" > /dev/null
|
||||||
|
|
||||||
# Upload first version with tag 'latest'
|
# Upload first version with tag 'latest'
|
||||||
FIRST_METADATA_JSON=$(cat <<EOF
|
FIRST_METADATA_JSON=$(cat <<EOF
|
||||||
{
|
{
|
||||||
"labeltags": ["${BASE_TAG}:latest", "${BASE_TAG}:v1"],
|
"labeltags": ["${BASE_TAG}:latest", "${BASE_TAG}:v1"],
|
||||||
"description": "First version"
|
"description": "First version"
|
||||||
@@ -302,36 +314,34 @@ FIRST_METADATA_JSON=$(cat <<EOF
|
|||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
echo "uploading first version with tag 'latest'"
|
echo "uploading first version with tag 'latest'"
|
||||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
|
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
|
||||||
-F "metadata=${FIRST_METADATA_JSON}" \
|
-F "metadata=${FIRST_METADATA_JSON}" \
|
||||||
"${HOSTURL}/upload")
|
"${HOSTURL}/upload")
|
||||||
|
|
||||||
FIRST_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
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
|
||||||
|
die "failed to download ${BASE_TAG}"
|
||||||
|
fi
|
||||||
|
# get md5sum of the downloaded file
|
||||||
|
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"
|
||||||
|
|
||||||
# check downloading without tag!
|
# Store first version's metadata before uploading second version
|
||||||
echo "downloading ${BASE_TAG} to ${DOWNLOAD_FILE}4"
|
FIRST_METADATA=$(curl -s "${HOSTURL}/meta/${FIRST_HASH}")
|
||||||
if ! curl -s --fail-with-body "${HOSTURL}/${BASE_TAG}" -o "${DOWNLOAD_FILE}4"; then
|
echo "First version metadata response: ${FIRST_METADATA}"
|
||||||
die "failed to download ${BASE_TAG}"
|
if ! echo "${FIRST_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:v1"; then
|
||||||
fi
|
die "First version does not have v1 tag"
|
||||||
# get md5sum of the downloaded file
|
fi
|
||||||
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"
|
|
||||||
|
|
||||||
|
# Upload second version with same tag 'latest'
|
||||||
# Store first version's metadata before uploading second version
|
SECOND_METADATA_JSON=$(cat <<EOF
|
||||||
FIRST_METADATA=$(curl -s "${HOSTURL}/meta/${FIRST_HASH}")
|
|
||||||
echo "First version metadata response: ${FIRST_METADATA}"
|
|
||||||
if ! echo "${FIRST_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:v1"; then
|
|
||||||
die "First version does not have v1 tag"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Upload second version with same tag 'latest'
|
|
||||||
SECOND_METADATA_JSON=$(cat <<EOF
|
|
||||||
{
|
{
|
||||||
"labeltags": ["${BASE_TAG}:latest", "${BASE_TAG}:v2"],
|
"labeltags": ["${BASE_TAG}:latest", "${BASE_TAG}:v2"],
|
||||||
"description": "Second version"
|
"description": "Second version"
|
||||||
@@ -339,170 +349,200 @@ SECOND_METADATA_JSON=$(cat <<EOF
|
|||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
echo "uploading second version with tag 'latest'"
|
echo "uploading second version with tag 'latest'"
|
||||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
-F "file=@${SCRIPT_DIR}/test_1GB_file_upload.sh" \
|
-F "file=@${SCRIPT_DIR}/test_1GB_file_upload.sh" \
|
||||||
-F "metadata=${SECOND_METADATA_JSON}" \
|
-F "metadata=${SECOND_METADATA_JSON}" \
|
||||||
"${HOSTURL}/upload")
|
"${HOSTURL}/upload")
|
||||||
|
|
||||||
SECOND_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
SECOND_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash')
|
||||||
|
|
||||||
# Verify first version's metadata still has v1 tag
|
# Verify first version's metadata still has v1 tag
|
||||||
FIRST_METADATA=$(curl -s "${HOSTURL}/meta/${FIRST_HASH}")
|
FIRST_METADATA=$(curl -s "${HOSTURL}/meta/${FIRST_HASH}")
|
||||||
echo "First version metadata response: ${FIRST_METADATA}"
|
echo "First version metadata response: ${FIRST_METADATA}"
|
||||||
if ! echo "${FIRST_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:v1"; then
|
if ! echo "${FIRST_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:v1"; then
|
||||||
die "First version does not have v1 tag"
|
die "First version does not have v1 tag"
|
||||||
fi
|
|
||||||
|
|
||||||
# Verify first version's metadata no longer has the latest tag
|
|
||||||
if echo "${FIRST_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:latest"; then
|
|
||||||
die "First version still has latest tag"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Verify second version has the correct tags: v2 and latest
|
|
||||||
SECOND_METADATA=$(curl -s "${HOSTURL}/meta/${SECOND_HASH}")
|
|
||||||
echo "Second version metadata response: ${SECOND_METADATA}"
|
|
||||||
if ! echo "${SECOND_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:latest"; then
|
|
||||||
die "Second version does not have latest tag"
|
|
||||||
fi
|
|
||||||
if ! echo "${SECOND_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:v2"; then
|
|
||||||
die "Second version does not have v2 tag"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------------------------
|
|
||||||
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
|
|
||||||
|
|
||||||
# Use a known invalid token
|
|
||||||
INVALID_TOKEN="invalid_token"
|
|
||||||
|
|
||||||
# Make 5 requests with an invalid token
|
|
||||||
for i in {1..5}; do
|
|
||||||
echo "Attempt $i with invalid token"
|
|
||||||
RESPONSE=$(curl -s -X PUT -H "Authorization: Bearer ${INVALID_TOKEN}" -F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" -F "metadata={\"labeltags\":[\"test:latest\"]}" "${HOSTURL}/upload")
|
|
||||||
echo "Response: ${RESPONSE}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Now try a request with a valid token - should be rate limited
|
|
||||||
echo "Attempting request with valid token (should 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")
|
|
||||||
if ! echo "${RESPONSE}" | jq -r '.error' | grep -q "Too many authentication attempts"; then
|
|
||||||
die "Expected rate limit error, got: ${RESPONSE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Sleeping for 3 seconds to allow rate limit to reset"
|
|
||||||
echo "(Normally 5 mins, but we set to 2s for this test!)"
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
fi
|
||||||
else
|
|
||||||
echo "test:form_updated not found, skipping deletion"
|
# Verify first version's metadata no longer has the latest tag
|
||||||
echo "HASH=${HASH}, TODELHASH=${TODELHASH}"
|
if echo "${FIRST_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:latest"; then
|
||||||
fi
|
die "First version still has latest tag"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify second version has the correct tags: v2 and latest
|
||||||
|
SECOND_METADATA=$(curl -s "${HOSTURL}/meta/${SECOND_HASH}")
|
||||||
|
echo "Second version metadata response: ${SECOND_METADATA}"
|
||||||
|
if ! echo "${SECOND_METADATA}" | jq -r '.metadata.labeltags[]' | grep -q "${BASE_TAG}:latest"; then
|
||||||
|
die "Second version does not have latest tag"
|
||||||
|
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
|
||||||
|
|
||||||
|
# Use a known invalid token
|
||||||
|
INVALID_TOKEN="invalid_token"
|
||||||
|
|
||||||
|
# Make 5 requests with an invalid token
|
||||||
|
for i in {1..5}; do
|
||||||
|
echo "Attempt $i with invalid token"
|
||||||
|
RESPONSE=$(curl -s -X PUT -H "Authorization: Bearer ${INVALID_TOKEN}" -F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" -F "metadata={\"labeltags\":[\"test:latest\"]}" "${HOSTURL}/upload")
|
||||||
|
echo "Response: ${RESPONSE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Now try a request with a valid token - should be rate limited
|
||||||
|
echo "Attempting request with valid token (should 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")
|
||||||
|
if ! echo "${RESPONSE}" | jq -r '.error' | grep -q "Too many authentication attempts"; then
|
||||||
|
die "Expected rate limit error, got: ${RESPONSE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Sleeping for 3 seconds to allow rate limit to reset"
|
||||||
|
echo "(Normally 5 mins, but we set to 2s for this test!)"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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: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
|
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"
|
title "ALL TESTS PASSED"
|
||||||
|
Reference in New Issue
Block a user