From 57ad60747b70e56187cb21211856d0f2eab1d5aa Mon Sep 17 00:00:00 2001 From: Andrey Dushinov Date: Tue, 26 Nov 2019 11:54:43 +0700 Subject: [PATCH 1/3] Fix header authentication for host:port type --- CHANGELOG-MASTER.rst | 2 ++ bravado/requests_client.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-MASTER.rst b/CHANGELOG-MASTER.rst index fefbcc35..6d4d61e7 100644 --- a/CHANGELOG-MASTER.rst +++ b/CHANGELOG-MASTER.rst @@ -1,2 +1,4 @@ Changelog-Master ================ + +- Fix header authentication for host:port type \ No newline at end of file diff --git a/bravado/requests_client.py b/bravado/requests_client.py index 4e5f6aeb..3c52db61 100644 --- a/bravado/requests_client.py +++ b/bravado/requests_client.py @@ -46,7 +46,7 @@ def matches(self, url): :return: True if matches host, port and scheme, False otherwise. """ split = urlparse.urlsplit(url) - return self.host == split.hostname + return self.host == split.netloc def apply(self, request): # type: (requests.Request) -> requests.Request From 4797fd7482396e4616efe9d2a1525c529a37b3d1 Mon Sep 17 00:00:00 2001 From: Andrey Dushinov Date: Mon, 16 Dec 2019 14:39:29 +0700 Subject: [PATCH 2/3] Add authenticator tests --- bravado/requests_client.py | 2 +- tests/http_client_test.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bravado/requests_client.py b/bravado/requests_client.py index 3c52db61..391367a5 100644 --- a/bravado/requests_client.py +++ b/bravado/requests_client.py @@ -43,7 +43,7 @@ def matches(self, url): """Returns true if this authenticator applies to the given url. :param url: URL to check. - :return: True if matches host, port and scheme, False otherwise. + :return: True if matches host and port, False otherwise. """ split = urlparse.urlsplit(url) return self.host == split.netloc diff --git a/tests/http_client_test.py b/tests/http_client_test.py index 3029ba56..f83b4350 100644 --- a/tests/http_client_test.py +++ b/tests/http_client_test.py @@ -9,6 +9,7 @@ import typing from bravado_core.response import IncomingResponse +from bravado.requests_client import Authenticator from bravado.requests_client import RequestsClient @@ -179,6 +180,15 @@ def test_auth_leak(self): httpretty.last_request().headers.get('Authorization') is None) +class AuthenticatorTestCase(unittest.TestCase): + + def test_matches(self): + authenticator = Authenticator("test.com:8080") + self.assertTrue(authenticator.matches("https://test.com:8080/")) + self.assertFalse(authenticator.matches("https://test.com:80/")) + self.assertFalse(authenticator.matches("https://test.net:8080/")) + + @pytest.fixture def mock_session(): return mock.create_autospec(requests.Session) From 5a06e93b25aecee747e75e5b10c183c46476e16c Mon Sep 17 00:00:00 2001 From: Andrey Dushinov Date: Mon, 16 Dec 2019 16:57:18 +0700 Subject: [PATCH 3/3] Fix End of Files --- CHANGELOG-MASTER.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG-MASTER.rst b/CHANGELOG-MASTER.rst index 6d4d61e7..3104a6b9 100644 --- a/CHANGELOG-MASTER.rst +++ b/CHANGELOG-MASTER.rst @@ -1,4 +1,4 @@ Changelog-Master ================ -- Fix header authentication for host:port type \ No newline at end of file +- Fix header authentication for host:port type