Skip to content

Commit f091808

Browse files
committed
test byte range requests in integration tests
1 parent fe11c12 commit f091808

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

test/integration/test_api.sh

+32-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ if ! [ -x "${checksum_cmd}" ]; then
7777
exit ${no_dep_exit_code}
7878
fi
7979

80+
81+
file_convert_command="$(command -v dd || true)"
82+
83+
if ! [ -x "${file_convert_command}" ]; then
84+
e "required dependency not found: dd not found in the path or not executable"
85+
exit ${no_dep_exit_code}
86+
fi
87+
8088
# If we are using the `md5` executable
8189
# then use the -r flag which makes it behave the same as `md5sum`
8290
# this is done after the `-x` check for ability to execute
@@ -140,6 +148,27 @@ assertHttpRequestEquals() {
140148
exit ${test_fail_exit_code}
141149
fi
142150
fi
151+
# Not a real method but better than making a whole new helper or massively refactoring this one
152+
elif [ "${method}" = "GET_RANGE" ]; then
153+
# Call format to check for a range of byte 30 to 1000:
154+
# assertHttpRequestEquals "GET_RANGE" "a.txt" "data/bucket-1/a.txt" 30 1000 "206"
155+
body_data_path="${test_dir}/$3"
156+
range_start="$4"
157+
range_end="$5"
158+
byte_count=$((range_end - range_start + 1)) # add one since we read through the last byte
159+
expected_response_code="$6"
160+
161+
file_checksum=$(${file_convert_command} if="$body_data_path" bs=1 skip="$range_start" count="$byte_count" 2>/dev/null | md5 -r)
162+
expected_checksum="${file_checksum:0:${checksum_length}}"
163+
164+
curl_checksum_output="$(${curl_cmd} -X "GET" -r "${range_start}"-"${range_end}" "${uri}" ${extra_arg} | ${checksum_cmd})"
165+
s3_file_checksum="${curl_checksum_output:0:${checksum_length}}"
166+
167+
if [ "${expected_checksum}" != "${s3_file_checksum}" ]; then
168+
e "Checksum doesn't match expectation. Request [GET ${uri} Range: "${range_start}"-"${range_end}"] Expected [${expected_checksum}] Actual [${s3_file_checksum}]"
169+
e "curl command: ${curl_cmd} -X "GET" -r "${range_start}"-"${range_end}" "${uri}" ${extra_arg} | ${checksum_cmd}"
170+
exit ${test_fail_exit_code}
171+
fi
143172
else
144173
e "Method unsupported: [${method}]"
145174
fi
@@ -175,7 +204,6 @@ if [ -n "${prefix_leading_directory_path}" ]; then
175204
fi
176205

177206
# Ordinary filenames
178-
179207
assertHttpRequestEquals "HEAD" "a.txt" "200"
180208
assertHttpRequestEquals "HEAD" "a.txt?some=param&that=should&be=stripped#aaah" "200"
181209
assertHttpRequestEquals "HEAD" "b/c/d.txt" "200"
@@ -184,6 +212,9 @@ assertHttpRequestEquals "HEAD" "b/e.txt" "200"
184212
assertHttpRequestEquals "HEAD" "b//e.txt" "200"
185213
assertHttpRequestEquals "HEAD" "a/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.txt" "200"
186214

215+
# Byte range requests
216+
assertHttpRequestEquals "GET_RANGE" 'a/plus%2Bplus.txt' "data/bucket-1/a/plus+plus.txt" 30 1000 "206"
217+
187218
# We try to request URLs that are properly encoded as well as URLs that
188219
# are not properly encoded to understand what works and what does not.
189220

0 commit comments

Comments
 (0)