# HG changeset patch # User liscju # Date 2016-06-09 10:41:57 # Node ID fc777c855d663b101c61cb707fc1d0d8fb15e2b3 # Parent fea71f66ebff0f7fe487cf731da0549efea9374b largefiles: make cloning not ask two times about password (issue4883) Before this commit url.opener overwritten stored password for connection with given url/user even when new password for given connection was not filled. This commit makes opener overwrites saved authentication only when it contains password. diff --git a/mercurial/url.py b/mercurial/url.py --- a/mercurial/url.py +++ b/mercurial/url.py @@ -493,8 +493,10 @@ def opener(ui, authinfo=None): passmgr = passwordmgr(ui, ui.httppasswordmgrdb) if authinfo is not None: - passmgr.add_password(*authinfo) - user, passwd = authinfo[2:4] + realm, uris, user, passwd = authinfo + saveduser, savedpass = passmgr.find_stored_password(uris[0]) + if user != saveduser or passwd: + passmgr.add_password(realm, uris, user, passwd) ui.debug('http auth: user %s, password %s\n' % (user, passwd and '*' * len(passwd) or 'not set')) diff --git a/tests/test-largefiles-wireproto.t b/tests/test-largefiles-wireproto.t --- a/tests/test-largefiles-wireproto.t +++ b/tests/test-largefiles-wireproto.t @@ -380,4 +380,60 @@ available locally. $ killdaemons.py +largefiles should not ask for password again after succesfull authorization + + $ hg init credentialmain + $ cd credentialmain + $ echo "aaa" >> a + $ hg add --large a + $ hg commit -m "a" + Invoking status precommit hook + A a + +Before running server clear the user cache to force clone to download +a large file from the server rather than to get it from the cache + + $ rm "${USERCACHE}"/* + + $ cd .. + $ cat << EOT > userpass.py + > import base64 + > from mercurial.hgweb import common + > def perform_authentication(hgweb, req, op): + > auth = req.env.get('HTTP_AUTHORIZATION') + > if not auth: + > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who', + > [('WWW-Authenticate', 'Basic Realm="mercurial"')]) + > if base64.b64decode(auth.split()[1]).split(':', 1) != ['user', 'pass']: + > raise common.ErrorResponse(common.HTTP_FORBIDDEN, 'no') + > def extsetup(): + > common.permhooks.insert(0, perform_authentication) + > EOT + $ hg serve --config extensions.x=userpass.py -R credentialmain \ + > -d -p $HGPORT --pid-file hg.pid -A access.log + $ cat hg.pid >> $DAEMON_PIDS + $ cat << EOF > get_pass.py + > import getpass + > def newgetpass(arg): + > return "pass" + > getpass.getpass = newgetpass + > EOF + $ hg clone --config ui.interactive=true --config extensions.getpass=get_pass.py \ + > http://user@localhost:$HGPORT credentialclone + requesting all changes + http authorization required for http://localhost:$HGPORT/ + realm: mercurial + user: user + password: adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + updating to branch default + getting changed largefiles + 1 largefiles updated, 0 removed + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + + $ rm hg.pid access.log + $ killdaemons.py + #endif