Skip to content

Commit

Permalink
Feature/http ssl verify configuration (#4547)
Browse files Browse the repository at this point in the history
* add test for http ssl_verify configuration

* add ssl_verify flag to HTTPTree
  • Loading branch information
MetalBlueberry authored Sep 9, 2020
1 parent 1ca2dc1 commit 54a48e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RelPath(str):
"user": str,
"password": str,
"ask_password": Bool,
"ssl_verify": Bool,
}
WEBDAV_COMMON = {
"user": str,
Expand Down
3 changes: 3 additions & 0 deletions dvc/tree/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, repo, config):
self.password = config.get("password", None)
self.ask_password = config.get("ask_password", False)
self.headers = {}
self.ssl_verify = config.get("ssl_verify", True)

def _auth_method(self, path_info=None):
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
Expand Down Expand Up @@ -81,6 +82,8 @@ def _session(self):

session = requests.Session()

session.verify = self.ssl_verify

retries = Retry(
total=self.SESSION_RETRIES,
backoff_factor=self.SESSION_BACKOFF_FACTOR,
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/remote/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,26 @@ def test_custom_auth_method(dvc):
assert tree._auth_method() is None
assert header in tree.headers
assert tree.headers[header] == password


def test_ssl_verify_is_enabled_by_default(dvc):
config = {
"url": "http://example.com/",
"path_info": "file.html",
}

tree = HTTPTree(dvc, config)

assert tree._session.verify is True


def test_ssl_verify_disable(dvc):
config = {
"url": "http://example.com/",
"path_info": "file.html",
"ssl_verify": False,
}

tree = HTTPTree(dvc, config)

assert tree._session.verify is False

0 comments on commit 54a48e3

Please sign in to comment.