forked from mtusi2026/mtusi2026lab4
all for lab4
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
: "${S3_BUCKET:?}"
|
||||
: "${S3_ACCESS_KEY:?}"
|
||||
: "${S3_SECRET_KEY:?}"
|
||||
|
||||
mc alias set app http://minio:9000 \
|
||||
"$S3_ACCESS_KEY" "$S3_SECRET_KEY" >/dev/null
|
||||
|
||||
TEST_ID="$(cat /proc/sys/kernel/random/uuid)"
|
||||
OBJECT_KEY="originals/access-check-$TEST_ID.txt"
|
||||
OUTSIDE_KEY="outside-access-check-$TEST_ID.txt"
|
||||
|
||||
cleanup() {
|
||||
mc rm --force \
|
||||
"app/$S3_BUCKET/$OBJECT_KEY" >/dev/null 2>&1 || true
|
||||
|
||||
mc rm --force \
|
||||
"app/$S3_BUCKET/$OUTSIDE_KEY" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
printf 'private attachment test' > /tmp/expected.txt
|
||||
|
||||
mc cp /tmp/expected.txt \
|
||||
"app/$S3_BUCKET/$OBJECT_KEY" >/dev/null
|
||||
|
||||
mc cat "app/$S3_BUCKET/$OBJECT_KEY" > /tmp/actual.txt
|
||||
|
||||
cmp /tmp/expected.txt /tmp/actual.txt
|
||||
|
||||
echo "PASS: API credentials can upload and download originals"
|
||||
|
||||
HTTP_CODE="$(
|
||||
curl --silent --show-error \
|
||||
--connect-timeout 3 \
|
||||
--max-time 10 \
|
||||
--output /tmp/anonymous-response.xml \
|
||||
--write-out '%{http_code}' \
|
||||
"http://minio:9000/$S3_BUCKET/$OBJECT_KEY"
|
||||
)"
|
||||
|
||||
if [ "$HTTP_CODE" != "403" ]; then
|
||||
echo "FAIL: anonymous GET returned HTTP $HTTP_CODE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -q '<Code>AccessDenied</Code>' \
|
||||
/tmp/anonymous-response.xml
|
||||
then
|
||||
echo "FAIL: expected S3 AccessDenied response" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PASS: anonymous download of an existing object is denied"
|
||||
|
||||
if mc cp /tmp/expected.txt \
|
||||
"app/$S3_BUCKET/$OUTSIDE_KEY" \
|
||||
> /tmp/outside-result.txt 2>&1
|
||||
then
|
||||
echo "FAIL: API credentials can write outside originals/" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -Eiq \
|
||||
'AccessDenied|Access Denied|Insufficient permissions|not authorized|not allowed' \
|
||||
/tmp/outside-result.txt
|
||||
then
|
||||
echo "FAIL: write failed for a reason other than access denial" >&2
|
||||
cat /tmp/outside-result.txt >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PASS: writing outside originals/ is denied"
|
||||
|
||||
if mc admin info app > /tmp/admin-result.txt 2>&1
|
||||
then
|
||||
echo "FAIL: API credentials have administrative access" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -Eiq \
|
||||
'AccessDenied|Access Denied|Insufficient permissions|not authorized|not allowed' \
|
||||
/tmp/admin-result.txt
|
||||
then
|
||||
echo "FAIL: admin command failed for an unexpected reason" >&2
|
||||
cat /tmp/admin-result.txt >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PASS: administrative access is denied"
|
||||
|
||||
mc rm "app/$S3_BUCKET/$OBJECT_KEY" >/dev/null
|
||||
|
||||
echo "PASS: API credentials can delete originals for cleanup"
|
||||
echo "PASS: S3 access checks completed"
|
||||
Reference in New Issue
Block a user