Skip to content

Commit

Permalink
Merge pull request #9667 from rouault/fix_test_vsicurl_bearer
Browse files Browse the repository at this point in the history
autotest: make test_vsicurl_bearer() independent of currently flaky server
  • Loading branch information
rouault authored Apr 15, 2024
2 parents 466915e + 653ab95 commit 732d82c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
21 changes: 21 additions & 0 deletions autotest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@ def pytest_collection_modifyitems(config, items):
if not gdaltest.built_against_curl():
item.add_marker(pytest.mark.skip("curl support not available"))

required_version = [
mark.args[0] if len(mark.args) > 0 else 0,
mark.args[1] if len(mark.args) > 1 else 0,
mark.args[2] if len(mark.args) > 2 else 0,
]

actual_version = [0, 0, 0]
for build_info_item in gdal.VersionInfo("BUILD_INFO").strip().split("\n"):
if build_info_item.startswith("CURL_VERSION="):
actual_version = [
int(x)
for x in build_info_item[len("CURL_VERSION=") :].split(".")
]

if actual_version < required_version:
item.add_marker(
pytest.mark.skip(
f"Requires curl >= {'.'.join(str(x) for x in required_version)}"
)
)


def pytest_addoption(parser):
parser.addini("gdal_version", "GDAL version for which pytest.ini was generated")
Expand Down
52 changes: 40 additions & 12 deletions autotest/gcore/vsicurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,19 +1109,47 @@ def test_vsicurl_NETRC_FILE():
# Check auth with bearer token


def test_vsicurl_bearer():
if gdaltest.is_travis_branch("ubuntu_1804") or gdaltest.is_travis_branch(
"ubuntu_1804_32bit"
):
pytest.skip("Too old libcurl version, requires at least 7.61.0")
@gdaltest.enable_exceptions()
@pytest.mark.require_curl(7, 61, 0)
def test_vsicurl_bearer(server):

gdal.VSICurlClearCache()

handler = webserver.SequentialHandler()
handler.add("GET", "/", 404)
handler.add(
"HEAD",
"/test_vsicurl_bearer.bin",
200,
{"Content-Length": "3"},
expected_headers={
"Authorization": "Bearer myuniqtok",
},
)
handler.add(
"GET",
"/test_vsicurl_bearer.bin",
200,
{"Content-Length": "3"},
b"foo",
expected_headers={
"Authorization": "Bearer myuniqtok",
},
)

token = "myuniqtok"
with gdal.config_options({"GDAL_HTTP_AUTH": "BEARER", "GDAL_HTTP_BEARER": token}):
f = gdal.VSIFOpenL("/vsicurl/http://httpbin.org/bearer", "rb")
gdal.VSIFSeekL(f, 0, 2)
vsilen = gdal.VSIFTellL(f)
gdal.VSIFSeekL(f, 0, 0)
data = gdal.VSIFReadL(1, vsilen, f).decode("ascii")
assert token in data
with webserver.install_http_handler(handler):
with gdal.config_options(
{"GDAL_HTTP_AUTH": "BEARER", "GDAL_HTTP_BEARER": token}
):
f = gdal.VSIFOpenL(
"/vsicurl/http://localhost:%d/test_vsicurl_bearer.bin" % server.port,
"rb",
)
assert f
data = gdal.VSIFReadL(1, 3, f)
gdal.VSIFCloseL(f)
assert data == b"foo"


###############################################################################
Expand Down

0 comments on commit 732d82c

Please sign in to comment.