From 18fa1a0272826143f27db6a3b923eea149a519c5 Mon Sep 17 00:00:00 2001 From: frederik-sandfort <70193035+frederik-sandfort@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:51:11 +0100 Subject: [PATCH] Custom header for dvc webdav (#8933)Fix https://github.com/iterative/dvc/issues/8931 * include custom auth header for webdav * Revert "include custom auth header for webdav" This reverts commit d2f2b2889b6bcf0429e4a28076f709a04642ae3a. * include custom auth header for dvc webdav, ran unit tests * update dvc-webdav version --- dvc/config_schema.py | 1 + pyproject.toml | 2 +- tests/unit/remote/test_webdav.py | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/dvc/config_schema.py b/dvc/config_schema.py index b5ee185a8..a5c077d3c 100644 --- a/dvc/config_schema.py +++ b/dvc/config_schema.py @@ -106,6 +106,7 @@ WEBDAV_COMMON = { "password": str, "ask_password": Bool, "token": str, + "custom_auth_header": str, "cert_path": str, "key_path": str, "timeout": Coerce(int), diff --git a/pyproject.toml b/pyproject.toml index 04141ff9f..555606219 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,7 @@ oss = ["dvc-oss==2.19.0"] s3 = ["dvc-s3==2.21.0"] ssh = ["dvc-ssh==2.21.0"] ssh_gssapi = ["dvc-ssh[gssapi]==2.21.0"] -webdav = ["dvc-webdav==2.19.0"] +webdav = ["dvc-webdav==2.19.1"] webhdfs = ["dvc-webhdfs==2.19.0"] webhdfs_kerberos = ["dvc-webhdfs[kerberos]==2.19.0"] terraform = ["tpi[ssh]>=2.1.0"] diff --git a/tests/unit/remote/test_webdav.py b/tests/unit/remote/test_webdav.py index cd8c188e3..416556793 100644 --- a/tests/unit/remote/test_webdav.py +++ b/tests/unit/remote/test_webdav.py @@ -9,6 +9,7 @@ url = "webdav://example.com/public.php/webdav" user = "username" password = "password" token = "4MgjsNM5aSJjxIKM" +custom_auth_header = "Custom-Header" def test_common(): @@ -23,6 +24,7 @@ def test_common(): password=None, ask_password=False, token=None, + custom_auth_header=None, ) assert issubset( { @@ -87,6 +89,46 @@ def test_ask_password(mocker): ask_password_mocked.assert_called_once_with(host, user) +def test_custom_auth_header(): + config = { + "url": url, + "custom_auth_header": custom_auth_header, + "password": password, + } + fs = WebDAVFileSystem(**config) + assert issubset( + {"headers": {custom_auth_header: password}, "auth": None}, + fs.fs_args, + ) + + +def test_ask_password_custom_auth_header(mocker): + ask_password_mocked = mocker.patch( + "dvc_webdav.ask_password", return_value="pass" + ) + host = "host" + + # it should not ask for password as password is set + config = { + "url": url, + "custom_auth_header": custom_auth_header, + "password": password, + "ask_password": True, + "host": host, + } + fs = WebDAVFileSystem(**config) + assert issubset( + {"headers": {custom_auth_header: password}, "auth": None}, fs.fs_args + ) + + config.pop("password") + fs = WebDAVFileSystem(**config) + assert issubset( + {"headers": {custom_auth_header: "pass"}, "auth": None}, fs.fs_args + ) + ask_password_mocked.assert_called_once_with(host, custom_auth_header) + + def test_ssl_verify_custom_cert(): config = { "url": url,