Commits

Markus Zapke-Gründemann  committed 94cc11d

Fixed handling of auth section credentials.

  • Participants
  • Parent commits 968fb49

Comments (0)

Files changed (3)

File mercurial_keyring.py

                 return user, pwd
 
         if auth_user:
-            if user and (user != auth_user):
-                # TODO this maybe obsolete for Mercurial >= 1.9
+            if user and (user == auth_user):
                 raise util.Abort(_('mercurial_keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, user, auth_user)))
             user = auth_user
             if pwd:
-                # TODO this maybe obsolete for Mercurial >= 1.9
                 self.pwd_cache[cache_key] = user, pwd
                 _debug_reply(ui, _("Auth data set in .hg/hgrc"),
                              base_url, user, pwd)

File tests/test-find_auth.py

 t.test_uri('https://hg.example.com/repo/module?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between',
         msg='use cached password and strip off query params')
 
-t = TestAuth('bob')
+password = 'cookies'
+# add password to .hgrc
+hgrc = open(os.environ["HGRCPATH"], 'a')
+hgrc.write('myremote.password = %s\n' % password)
+hgrc.close()
+
+t = TestAuth('bob', password)
 t.test_uri('https://bob@hg.example.com/repo',
-    msg='keyring is used because usernames in URI and .hgrc match')
+    msg='aborts because username is set in url and .hgrc')
+t.test_uri('https://hg.example.com/repo',
+    msg='password is read from .hgrc')
+t.test_uri('https://hg.example.com/repo?cmd=capabilities',
+    msg='use cached auth data')
 t.test_uri('https://clara@hg.example.com/repo',
     msg='store password for clara on keyring')
 
-t = TestAuth('clara')
+# delete password from .hgrc
+hgrc = open(os.environ["HGRCPATH"], 'a')
+hgrc.write('myremote.password =\n')
+hgrc.close()
+
+t = TestAuth('bob')
+t.test_uri('https://hg.example.com/repo',
+    msg='username is taken from .hgrc and password is read from keyring')
+
+t = TestAuth('clara', password)
 t.test_uri('https://clara@hg.example.com/repo',
     msg='read password for clara on keyring')
 

File tests/test-find_auth.py.out

 [HgKeyring] Keyring URL: https://hg.example.com
 [HgKeyring] Cached auth data found. Url: https://hg.example.com/repo/module, user: bob, passwd: ******
 
-[test] keyring is used because usernames in URI and .hgrc match
+[test] aborts because username is set in url and .hgrc
 [test] testing user bob at https://bob@hg.example.com/repo
 [HgKeyring] Stripped username "bob" from URL
 [HgKeyring] Keyring URL: https://hg.example.com
-[HgKeyring] Username found in .hg/hgrc: bob
-[HgKeyring] Looking for password for user bob and url https://hg.example.com
-[test] reading password from keyring for https://hg.example.com
-[HgKeyring] Keyring password found. Url: https://bob@hg.example.com/repo, user: bob, passwd: ******
+[test] abort: mercurial_keyring: username for https://bob@hg.example.com/repo specified both in repository path (bob) and in .hg/hgrc/[auth] (bob). Please, leave only one of those
+
+[test] password is read from .hgrc
+[test] testing user bob at https://hg.example.com/repo
+[HgKeyring] Keyring URL: https://hg.example.com
+[HgKeyring] Auth data set in .hg/hgrc. Url: https://hg.example.com/repo, user: bob, passwd: *******
+
+[test] use cached auth data
+[test] testing user bob at https://hg.example.com/repo?cmd=capabilities
+[HgKeyring] Keyring URL: https://hg.example.com
+[HgKeyring] Cached auth data found. Url: https://hg.example.com/repo, user: bob, passwd: *******
 
 [test] store password for clara on keyring
 [test] testing user bob at https://clara@hg.example.com/repo
 realm: None
 user: clara (fixed in .hg/hgrc)
 [HgKeyring] Saving password for clara to keyring
-[test] stored username clara and password secret
-[HgKeyring] Manually entered password. Url: https://clara@hg.example.com/repo, user: clara, passwd: ******
+[test] stored username clara and password cookies
+[HgKeyring] Manually entered password. Url: https://clara@hg.example.com/repo, user: clara, passwd: *******
 [test] warning: user did not match
 
+[test] username is taken from .hgrc and password is read from keyring
+[test] testing user bob at https://hg.example.com/repo
+[HgKeyring] Keyring URL: https://hg.example.com
+[HgKeyring] Username found in .hg/hgrc: bob
+[HgKeyring] Looking for password for user bob and url https://hg.example.com
+[test] reading password from keyring for https://hg.example.com
+[HgKeyring] Keyring password found. Url: https://hg.example.com/repo, user: bob, passwd: ******
+
 [test] read password for clara on keyring
 [test] testing user clara at https://clara@hg.example.com/repo
 [HgKeyring] Stripped username "clara" from URL
 [HgKeyring] Keyring URL: https://clara@hg.example.com/repo
 [HgKeyring] Looking for password for user clara and url https://clara@hg.example.com/repo
 [test] reading password from keyring for https://clara@hg.example.com/repo
-[HgKeyring] Keyring password found. Url: https://clara@hg.example.com/repo, user: clara, passwd: ******
+[HgKeyring] Keyring password found. Url: https://clara@hg.example.com/repo, user: clara, passwd: *******
 
 [test] read password from keyring and use full URI because of catch all prefix
 [test] testing user bob at https://hg.example.com/repo