Ejemplo n.º 1
0
    def __call__(self, req):
        parsed = urllib_parse.urlparse(req.url)

        # Split the credentials from the netloc.
        netloc, url_user_password = split_auth_from_netloc(parsed.netloc)

        # Set the url of the request to the url without any credentials
        req.url = urllib_parse.urlunparse(parsed[:1] + (netloc,) + parsed[2:])

        # Use any stored credentials that we have for this netloc
        username, password = self.passwords.get(netloc, (None, None))

        # Use the credentials embedded in the url if we have none stored
        if username is None:
            username, password = url_user_password

        # Get creds from netrc if we still don't have them
        if username is None and password is None:
            netrc_auth = get_netrc_auth(req.url)
            username, password = netrc_auth if netrc_auth else (None, None)

        if username or password:
            # Store the username and password
            self.passwords[netloc] = (username, password)

            # Send the basic auth with this request
            req = HTTPBasicAuth(username or "", password or "")(req)

        # Attach a hook to handle 401 responses
        req.register_hook("response", self.handle_401)

        return req
Ejemplo n.º 2
0
    def get_netloc_and_auth(cls, netloc, scheme):
        """
        This override allows the auth information to be passed to svn via the
        --username and --password options instead of via the URL.
        """
        if scheme == 'ssh':
            # The --username and --password options can't be used for
            # svn+ssh URLs, so keep the auth information in the URL.
            return super(Subversion, cls).get_netloc_and_auth(netloc, scheme)

        return split_auth_from_netloc(netloc)
Ejemplo n.º 3
0
    def filename(self):
        # type: () -> str
        path = self.path.rstrip('/')
        name = posixpath.basename(path)
        if not name:
            # Make sure we don't leak auth information if the netloc
            # includes a username and password.
            netloc, user_pass = split_auth_from_netloc(self.netloc)
            return netloc

        name = urllib_parse.unquote(name)
        assert name, ('URL %r produced no filename' % self._url)
        return name
Ejemplo n.º 4
0
    def get_netloc_and_auth(
            cls, netloc: str,
            scheme: str) -> Tuple[str, Tuple[Optional[str], Optional[str]]]:
        """
        This override allows the auth information to be passed to svn via the
        --username and --password options instead of via the URL.
        """
        if scheme == "ssh":
            # The --username and --password options can't be used for
            # svn+ssh URLs, so keep the auth information in the URL.
            return super().get_netloc_and_auth(netloc, scheme)

        return split_auth_from_netloc(netloc)
Ejemplo n.º 5
0
def test_split_auth_from_netloc(netloc, expected):
    actual = split_auth_from_netloc(netloc)
    assert actual == expected
Ejemplo n.º 6
0
def test_split_auth_from_netloc(netloc, expected):
    actual = split_auth_from_netloc(netloc)
    assert actual == expected
Ejemplo n.º 7
0
 def get_netloc_and_auth(self, netloc):
     """
     This override allows the auth information to be passed to svn via the
     --username and --password options instead of via the URL.
     """
     return split_auth_from_netloc(netloc)
Ejemplo n.º 8
0
def test_split_auth_from_netloc(
        netloc: str, expected: Tuple[str, Tuple[Optional[str],
                                                Optional[str]]]) -> None:
    actual = split_auth_from_netloc(netloc)
    assert actual == expected