[PATCH] http: allow 'auth.prefix' to have a username consistent with the URI
Yuya Nishihara
yuya at tcha.org
Fri Nov 16 23:56:45 EST 2018
On Fri, 16 Nov 2018 21:37:07 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1542408996 18000
> # Fri Nov 16 17:56:36 2018 -0500
> # Node ID 9cada40ed879ce76c5dd3c44716cff61eecc8f16
> # Parent 610eb5c155df5ca300827e10cd2c3426f0ba0842
> http: allow 'auth.prefix' to have a username consistent with the URI
>
> It may be a little weird to put a username in the prefix, but the documentation
> doesn't disallow it, and silently disallowing it has caused confusion[1]. The
> username must match what is passed in (which seems to be from the URI via a
> circuitous route), as well as 'auth.username' if it was specified. I thought
> about printing a warning for a mismatch, but we already don't print a warning if
> the 'auth.username' and URI username don't match.
>
> This change allows the first and second last new test cases to work as expected.
> It looks like this would have been a problem since at least 0593e8f81c71.
>
> [1] https://www.mercurial-scm.org/pipermail/mercurial/2018-November/051069.html
>
> diff --git a/mercurial/httpconnection.py b/mercurial/httpconnection.py
> --- a/mercurial/httpconnection.py
> +++ b/mercurial/httpconnection.py
> @@ -92,6 +92,18 @@ def readauthforuri(ui, uri, user):
> prefix = auth.get('prefix')
> if not prefix:
> continue
> +
> + prefixurl = util.url(prefix)
> + if prefixurl.user and prefixurl.user != user:
> + # If a username was set in the prefix, it must match the username in
> + # the URI.
> + continue
> +
> + # The URI passed in has been stripped of credentials, so erase the user
> + # here to allow simpler matching.
> + prefixurl.user = None
> + prefix = bytes(prefixurl)
Looks good given how we handle the <scheme>:// part embedded in the prefix.
Queued, thanks.
> p = prefix.split('://', 1)
> if len(p) > 1:
> schemes, prefix = [p[0]], p[1]
Perhaps, this can be refactored to use the parsed prefixurl.
More information about the Mercurial-devel
mailing list