From 16cf8ea151d0b3e7f3377321bdba0e17ed03bbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan-David=20Schr=C3=B6der?= Date: Thu, 19 Jul 2018 15:12:19 +0200 Subject: [PATCH] Making requests_client.py's Authenticator URL matches() port-tolerant Authenticator::matches()'s documentation advertises full host, scheme and port match, when it just checks for hosts. However when checking hosts, it cannot compare well a configured self.host:withPort (eg. localhost:8080) with the outgoing request full URL's host. Such a corner case can happen with this piece of code: http_client.set_basic_auth( 'localhost:8080', BASIC_AUTH_LOGIN, BASIC_AUTH_PASSWORD ) --- bravado/requests_client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bravado/requests_client.py b/bravado/requests_client.py index 9234b391..ce30fac5 100644 --- a/bravado/requests_client.py +++ b/bravado/requests_client.py @@ -20,7 +20,7 @@ class Authenticator(object): """Authenticates requests. - :param host: Host to authenticate for. + :param host: Host to authenticate for. In some case """ def __init__(self, host): @@ -33,10 +33,11 @@ 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, False otherwise. """ + host_without_port = self.host.split(':')[0] split = urlparse.urlsplit(url) - return self.host == split.hostname + return host_without_port == split.hostname def apply(self, request): """Apply authentication to a request.