mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-06 07:18:28 +01:00
* remote.http: support _upload() via HTTP POST - uploaded files are sent as chunked encoding POST data Fixes #3247 * remote.http: add support for HTTP basic and digest auth - username, password, ask_password options work the same way as for ssh remotes - basic_auth (bool) and digest_auth (bool) options added for http(s) remotes - digest_auth takes precedence over basic_auth if both are enabled * remote.http: auth_method() unit tests * tests: Add functional tests for HTTP remotes - HTTP remotes now tested locally using a SimpleHTTPServer instance that allows reading/writing to a temp directory * tests: fix http tests on py3.5, 3.6 * remote.http: add custom auth method * s/custom_header/custom_auth_header/ * Apply suggestions from code review Co-Authored-By: Saugat Pachhai <[email protected]> Co-Authored-By: Ruslan Kuprieiev <[email protected]> Co-authored-by: Saugat Pachhai <[email protected]> Co-authored-by: Ruslan Kuprieiev <[email protected]>
101 lines
2.4 KiB
Python
101 lines
2.4 KiB
Python
import pytest
|
|
|
|
from dvc.config import ConfigError
|
|
from dvc.exceptions import HTTPError
|
|
from dvc.path_info import URLInfo
|
|
from dvc.remote.http import RemoteHTTP
|
|
from tests.utils.httpd import StaticFileServer
|
|
|
|
|
|
def test_no_traverse_compatibility(dvc):
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"no_traverse": False,
|
|
}
|
|
|
|
with pytest.raises(ConfigError):
|
|
RemoteHTTP(dvc, config)
|
|
|
|
|
|
def test_download_fails_on_error_code(dvc):
|
|
with StaticFileServer() as httpd:
|
|
url = "http://localhost:{}/".format(httpd.server_port)
|
|
config = {"url": url}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
with pytest.raises(HTTPError):
|
|
remote._download(URLInfo(url) / "missing.txt", "missing.txt")
|
|
|
|
|
|
def test_public_auth_method(dvc):
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"user": "",
|
|
"password": "",
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() is None
|
|
|
|
|
|
def test_basic_auth_method(dvc):
|
|
from requests.auth import HTTPBasicAuth
|
|
|
|
user = "username"
|
|
password = "password"
|
|
auth = HTTPBasicAuth(user, password)
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"auth": "basic",
|
|
"user": user,
|
|
"password": password,
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() == auth
|
|
assert isinstance(remote.auth_method(), HTTPBasicAuth)
|
|
|
|
|
|
def test_digest_auth_method(dvc):
|
|
from requests.auth import HTTPDigestAuth
|
|
|
|
user = "username"
|
|
password = "password"
|
|
auth = HTTPDigestAuth(user, password)
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"auth": "digest",
|
|
"user": user,
|
|
"password": password,
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() == auth
|
|
assert isinstance(remote.auth_method(), HTTPDigestAuth)
|
|
|
|
|
|
def test_custom_auth_method(dvc):
|
|
header = "Custom-Header"
|
|
password = "password"
|
|
config = {
|
|
"url": "http://example.com/",
|
|
"path_info": "file.html",
|
|
"auth": "custom",
|
|
"custom_auth_header": header,
|
|
"password": password,
|
|
}
|
|
|
|
remote = RemoteHTTP(dvc, config)
|
|
|
|
assert remote.auth_method() is None
|
|
assert header in remote.headers
|
|
assert remote.headers[header] == password
|