From 962a3f7d13b702a7eb7968977c04738284e7adc4 Mon Sep 17 00:00:00 2001 From: Evgeny Ezhov Date: Sun, 5 Apr 2020 17:43:10 -0700 Subject: [PATCH 1/3] Fixed #49: Remove tailing slashes in web_hostname --- tests/test_tailing_slash_client_it.py | 26 ++++++++++++++++++++++++++ webdav3/connection.py | 1 + webdav3/urn.py | 2 -- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/test_tailing_slash_client_it.py diff --git a/tests/test_tailing_slash_client_it.py b/tests/test_tailing_slash_client_it.py new file mode 100644 index 0000000..6a8744c --- /dev/null +++ b/tests/test_tailing_slash_client_it.py @@ -0,0 +1,26 @@ +import unittest + +from tests.test_client_it import ClientTestCase + + +class TailingSlashClientTestCase(ClientTestCase): + options = { + 'webdav_hostname': 'http://localhost:8585/', + 'webdav_login': 'alice', + 'webdav_password': 'secret1234', + 'webdav_override_methods': { + 'check': 'GET' + } + } + + def test_list_inner(self): + self._prepare_for_downloading(True) + file_list = self.client.list(self.remote_inner_path_dir) + self.assertIsNotNone(file_list, 'List of files should not be None') + + def test_hostname_no_tailing_slash(self): + self.assertEqual('5', self.client.webdav.hostname[-1]) + + +if __name__ == '__main__': + unittest.main() diff --git a/webdav3/connection.py b/webdav3/connection.py index 302212b..499ba23 100644 --- a/webdav3/connection.py +++ b/webdav3/connection.py @@ -50,6 +50,7 @@ class WebDAVSettings(ConnectionSettings): self.root = Urn(self.root).quote() if self.root else '' self.root = self.root.rstrip(Urn.separate) + self.hostname = self.hostname.rstrip(Urn.separate) def is_valid(self): if not self.hostname: diff --git a/webdav3/urn.py b/webdav3/urn.py index 6279de2..e78fa24 100644 --- a/webdav3/urn.py +++ b/webdav3/urn.py @@ -34,13 +34,11 @@ class Urn(object): return self._path def filename(self): - path_split = self._path.split(Urn.separate) name = path_split[-2] + Urn.separate if path_split[-1] == '' else path_split[-1] return unquote(name) def parent(self): - path_split = self._path.split(Urn.separate) nesting_level = self.nesting_level() parent_path_split = path_split[:nesting_level] From 39afefffc5e7b5613786dcaa2d719c50d847e703 Mon Sep 17 00:00:00 2001 From: Evgeny Ezhov Date: Sun, 5 Apr 2020 17:43:10 -0700 Subject: [PATCH 2/3] Fixed #49: Remove tailing slashes in web_hostname --- tests/test_tailing_slash_client_it.py | 26 ++++++++++++++++++++++++++ webdav3/connection.py | 1 + webdav3/urn.py | 2 -- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/test_tailing_slash_client_it.py diff --git a/tests/test_tailing_slash_client_it.py b/tests/test_tailing_slash_client_it.py new file mode 100644 index 0000000..6a8744c --- /dev/null +++ b/tests/test_tailing_slash_client_it.py @@ -0,0 +1,26 @@ +import unittest + +from tests.test_client_it import ClientTestCase + + +class TailingSlashClientTestCase(ClientTestCase): + options = { + 'webdav_hostname': 'http://localhost:8585/', + 'webdav_login': 'alice', + 'webdav_password': 'secret1234', + 'webdav_override_methods': { + 'check': 'GET' + } + } + + def test_list_inner(self): + self._prepare_for_downloading(True) + file_list = self.client.list(self.remote_inner_path_dir) + self.assertIsNotNone(file_list, 'List of files should not be None') + + def test_hostname_no_tailing_slash(self): + self.assertEqual('5', self.client.webdav.hostname[-1]) + + +if __name__ == '__main__': + unittest.main() diff --git a/webdav3/connection.py b/webdav3/connection.py index 302212b..499ba23 100644 --- a/webdav3/connection.py +++ b/webdav3/connection.py @@ -50,6 +50,7 @@ class WebDAVSettings(ConnectionSettings): self.root = Urn(self.root).quote() if self.root else '' self.root = self.root.rstrip(Urn.separate) + self.hostname = self.hostname.rstrip(Urn.separate) def is_valid(self): if not self.hostname: diff --git a/webdav3/urn.py b/webdav3/urn.py index 6279de2..e78fa24 100644 --- a/webdav3/urn.py +++ b/webdav3/urn.py @@ -34,13 +34,11 @@ class Urn(object): return self._path def filename(self): - path_split = self._path.split(Urn.separate) name = path_split[-2] + Urn.separate if path_split[-1] == '' else path_split[-1] return unquote(name) def parent(self): - path_split = self._path.split(Urn.separate) nesting_level = self.nesting_level() parent_path_split = path_split[:nesting_level] From a3c75b7155662cbc0c63e202e20dfea2e8d76480 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Mon, 6 Apr 2020 08:39:51 -0400 Subject: [PATCH 3/3] Fixes ezhov-evgeny#43 - local certificate options ignored If the webdav_cert_path and webdav_key_path options are set, they should be passed to the call to requests in Client.execute_request as the cert parameter. --- webdav3/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/webdav3/client.py b/webdav3/client.py index c88a172..9e495d1 100644 --- a/webdav3/client.py +++ b/webdav3/client.py @@ -217,6 +217,7 @@ class Client(object): auth=(self.webdav.login, self.webdav.password) if (not self.webdav.token and not self.session.auth) else None, headers=self.get_headers(action, headers_ext), timeout=self.timeout, + cert=(self.webdav.cert_path, self.webdav.key_path) if (self.webdav.cert_path and self.webdav.key_path) else None, data=data, stream=True, verify=self.verify