Skip to content

Commit

Permalink
add presigned range GET test (#1447)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Oct 19, 2024
1 parent adb2409 commit 2d3982f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
46 changes: 22 additions & 24 deletions run_functional_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,35 @@
#

function run_minio_server() {
if [ ! -f tests/functional/minio ]; then
wget --quiet --output-document tests/functional/minio https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x tests/functional/minio
fi
if [ ! -f tests/functional/minio ]; then
wget --quiet --output-document tests/functional/minio https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x tests/functional/minio
fi

export MINIO_ACCESS_KEY=minio
export MINIO_SECRET_KEY=minio123
export MINIO_KMS_KES_ENDPOINT=https://play.min.io:7373
export MINIO_KMS_KES_KEY_FILE=tests/functional/play.min.io.kes.root.key
export MINIO_KMS_KES_CERT_FILE=tests/functional/play.min.io.kes.root.cert
export MINIO_KMS_KES_KEY_NAME=my-minio-key
export MINIO_NOTIFY_WEBHOOK_ENABLE_miniopytest=on
export MINIO_NOTIFY_WEBHOOK_ENDPOINT_miniopytest=http://example.org/
export SQS_ARN="arn:minio:sqs::miniopytest:webhook"
export MINIO_CI_CD=1
tests/functional/minio server --config-dir tests/functional/.cfg tests/functional/.d{1...4} >tests/functional/minio.log 2>&1 &
export MINIO_KMS_KES_ENDPOINT=https://play.min.io:7373
export MINIO_KMS_KES_KEY_FILE=tests/functional/play.min.io.kes.root.key
export MINIO_KMS_KES_CERT_FILE=tests/functional/play.min.io.kes.root.cert
export MINIO_KMS_KES_KEY_NAME=my-minio-key
export MINIO_NOTIFY_WEBHOOK_ENABLE_miniopytest=on
export MINIO_NOTIFY_WEBHOOK_ENDPOINT_miniopytest=http://example.org/
export SQS_ARN="arn:minio:sqs::miniopytest:webhook"
export MINIO_CI_CD=1
tests/functional/minio server --config-dir tests/functional/.cfg tests/functional/.d{1...4} >tests/functional/minio.log 2>&1 &
}

if [ -z ${SERVER_ENDPOINT+x} ]; then
run_minio_server
MINIO_PID=$!
trap 'kill -9 ${MINIO_PID} 2>/dev/null' INT
run_minio_server
MINIO_PID=$!
trap 'kill -9 ${MINIO_PID} 2>/dev/null' INT

export MINT_MODE=full
export SERVER_ENDPOINT=localhost:9000
export ACCESS_KEY=minio
export SECRET_KEY=minio123
export ENABLE_HTTPS=0
export MINT_MODE=full
export SERVER_ENDPOINT=localhost:9000
export ACCESS_KEY=minioadmin
export SECRET_KEY=minioadmin
export ENABLE_HTTPS=0
fi

PYTHONPATH=$PWD python tests/functional/tests.py
if [ -n "$MINIO_PID" ]; then
kill -9 "$MINIO_PID" 2>/dev/null
kill -9 "$MINIO_PID" 2>/dev/null
fi
48 changes: 45 additions & 3 deletions tests/functional/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,9 +1379,6 @@ def test_presigned_get_object_response_headers( # pylint: disable=invalid-name
size = 1 * KB
_CLIENT.put_object(bucket_name, object_name, LimitedRandomReader(size),
size)
presigned_get_object_url = _CLIENT.presigned_get_object(
bucket_name, object_name, timedelta(seconds=120))

response_headers = {
'response-content-type': content_type,
'response-content-language': content_language
Expand Down Expand Up @@ -1418,6 +1415,51 @@ def test_presigned_get_object_response_headers( # pylint: disable=invalid-name
_CLIENT.remove_bucket(bucket_name)


def test_presigned_get_object_range( # pylint: disable=invalid-name
log_entry):
"""Test presigned_get_object() with headers."""

# Get a unique bucket_name and object_name
bucket_name = _gen_bucket_name()
object_name = f"{uuid4()}"

log_entry["args"] = {
"bucket_name": bucket_name,
"object_name": object_name,
}

_CLIENT.make_bucket(bucket_name)
try:
size = 556433 # on purpose its unaligned
_CLIENT.put_object(bucket_name, object_name, LimitedRandomReader(size),
size)

presigned_get_object_url = _CLIENT.presigned_get_object(
bucket_name, object_name, timedelta(seconds=120))

log_entry["args"]["presigned_get_object_url"] = (
presigned_get_object_url)

response = HTTP.urlopen('GET', presigned_get_object_url,
headers={'Range': 'bytes=490897-556432'})

log_entry["args"]['response.status'] = response.status
log_entry["args"]['response.reason'] = response.reason
log_entry["args"]['response.headers'] = json.dumps(
response.headers.__dict__)
# pylint: disable=protected-access
log_entry["args"]['response._body'] = response._body.decode('utf-8')

if response.status != 200:
raise Exception(
"Presigned GET object URL {presigned_get_object_url} failed; "
"code: {response.code}, error: {response.data}"
)
finally:
_CLIENT.remove_object(bucket_name, object_name)
_CLIENT.remove_bucket(bucket_name)


def test_presigned_get_object_version( # pylint: disable=invalid-name
log_entry):
"""Test presigned_get_object() of versioned object."""
Expand Down

0 comments on commit 2d3982f

Please sign in to comment.