Ticket #640 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

Mercurial always clobbers if repo-url contains password

Reported by: miltondp Owned by: marcusl
Priority: critical Milestone: 0.7.12
Version: 0.7.11 Keywords:
Cc: miltondp@…

Description

Buildbot 0.7.11p3 always clobber with Mercurial. When the URL of repositories are compared in function _checkRepoURL, in the file slave/commands.py, they are always different, because Mercurial obscures the password.

There is a patch for Mercurial, which adds an option for the "paths" command: --show-passwords, which doesn't change URL. It can be found here:

 http://www.selenic.com/pipermail/mercurial-devel/2009-February/010529.html

And it's necessary a small patch for Buildbot:

 http://www.miltonpividori.com.ar/files/buildbot_commands.patch

Attachments

test_removeUserAndPasswordFromURL.py Download (1.6 KB) - added by miltondp 3 years ago.
Test case for _removeUserAndPasswordFromURL function
mercurial_step-remote_repo.html Download (25.2 KB) - added by miltondp 3 years ago.
Mercurial step - Remote repository
mercurial_step-local_repo.html Download (28.6 KB) - added by miltondp 3 years ago.
Mercurial step - Local repository

Change History

comment:1 Changed 4 years ago by marcusl

  • Summary changed from Always clobber with Mercurial to Mercurial always clobbers if repo-url contains password

better description

comment:2 Changed 4 years ago by dustin

  • Milestone changed from undecided to 0.7.+

Is there a solution that doesn't require users to patch mercurial?

comment:3 Changed 4 years ago by marcusl

One could always use a regex to select the part(s) of the URL that's relevant to compare. I don't have any Mercurial repo URLs with password nearby, so it's hard to say if it's feasible.

Milton: Could you give some examples?

comment:4 Changed 3 years ago by miltondp

marcusl, sorry but I didn't receive any mail about your comment.

I think your idea is perfectly feasible, but maybe it would be cleaner if Mercurial had an option to show the password (it should exist, in my opinion). What you say can be implemented in the _checkRepoURL function, in the commands.py file.

Here you have an URL with a password (if that's what you meant):  http://miltondo:mypassword@myurl.com/myrepo

comment:5 follow-up: ↓ 7 Changed 3 years ago by marcusl

Strange, I hope you get this though. :)

Ok, no different from ordinary HTTP URLs. (Sigh, I don't know what other type of passworded URLs I was thinking of, maybe those with green goblins in them ;)

So, pending a new feature in Mercurial (which you'd have to implement yourself, then try to get accepted, and then Buildbot still has to be backwards compatible with previous Hg versions) I'd say we move ahead with the current plan.

comment:6 Changed 3 years ago by marcusl

  • Priority changed from blocker to critical

Also, this is not really a blocker, just pretty important.

comment:7 in reply to: ↑ 5 Changed 3 years ago by miltondp

  • Cc miltondp@… added

Replying to marcusl:

Strange, I hope you get this though. :)

Ok, no different from ordinary HTTP URLs. (Sigh, I don't know what other type of passworded URLs I was thinking of, maybe those with green goblins in them ;)

So, pending a new feature in Mercurial (which you'd have to implement yourself, then try to get accepted, and then Buildbot still has to be backwards compatible with previous Hg versions) I'd say we move ahead with the current plan.

You are right :) I will try a solution with a regular expression to remove the user and password from the URL. I think it's not necessary for the propose of _checkRepoURL function.

comment:8 Changed 3 years ago by marcusl

How about this:

  • buildbot/slave/commands.py

    diff --git a/buildbot/slave/commands.py b/buildbot/slave/commands.py
    index 69fb37c..c9b8184 100755
    a b class Mercurial(SourceBase): 
    27992799                else: 
    28002800                    repourl = self.repourl 
    28012801 
     2802                def _remove_userpassword(url): 
     2803                    if '@' not in url: 
     2804                        return url 
     2805 
     2806                    from urlparse import urlparse 
     2807                    p = urlparse(url) 
     2808                    netloc = p[1].split('@') 
     2809 
     2810                    if len(netloc) > 1: 
     2811                        return p[0] + '://' + netloc[1] + p[2] 
     2812                    else: 
     2813                        return p[0] + '://' + p[1] 
     2814 
     2815                oldurl = _remove_userpassword(oldurl) 
     2816                repourl = _remove_userpassword(repourl) 
     2817 
    28022818                if oldurl != repourl: 
    28032819                    self.clobber = self._clobber 
    28042820                    msg = "RepoURL changed from '%s' in wc to '%s' in update. Clobbering" % (oldurl, repourl) 

comment:9 Changed 3 years ago by marcusl

doh.. + p[2] in the else too..

comment:10 Changed 3 years ago by marcusl

It's now residing here:  http://github.com/marcusl/buildbot/commits/bug640

Could you test it? It's kinda tricky writing a test-case, unless we could alter the current test to use a password-protected repo (via hg serve) by default.

comment:11 Changed 3 years ago by miltondp

Great! Yesterday I wrote a solution too but I couldn't test it and I can't right now (I'll do it tomorroy). Using urlparse seems to be much better. Anyway, here it is:

--- /usr/share/pyshared/buildbot/slave/commands.py	2009-08-13 12:53:17.000000000 -0300
+++ commands.py	2009-12-27 16:49:29.783838053 -0300
@@ -2665,6 +2665,16 @@
                 else:
                     repourl = self.repourl
 
+                def _removeUserAndPasswordFromURL(url):
+                    protocol_url = url.split('://')
+                    protocol = protocol_url[0]
+                    repo_url = protocol_url[1].split('@')[-1]
+
+                    return protocol + '://' + repo_url
+
+                oldurl = _removeUserAndPasswordFromURL(oldurl)
+                repourl = _removeUserAndPasswordFromURL(repourl)
+
                 if oldurl != repourl:
                     self.clobber = self._clobber
                     msg = "RepoURL changed from '%s' in wc to '%s' in update. Clobbering" % (oldurl, repourl)

I attach a test-case also (not for _checkRepoURL, but for _removeUserAndPasswordFromURL)

Changed 3 years ago by miltondp

Test case for _removeUserAndPasswordFromURL function

comment:12 Changed 3 years ago by marcusl

Be sure to test it with local paths as well. You can't assume that : is present.

[-1] is a nice trick. I'll use that in my change, and add your test. :)

comment:13 Changed 3 years ago by marcusl

  • Owner set to marcusl
  • Status changed from new to accepted

Here:  new bug640 branch in my repo

Your tests was a good thing, urlparse doesn't deal with ssh properly, so I had to use your code, and combine it with mine.

Are you able to test my bug640 branch properly?

comment:14 Changed 3 years ago by marcusl

I rebased onto master, so use  http://github.com/marcusl/buildbot/commits/bug640 which will always be correct.

(Sorry for spamming with so many comments, I suppose google wave would rule in this context..)

comment:15 Changed 3 years ago by miltondp

No problem for so many comments :)

Tomorrow I will run this code in my environment and post a comment here.

comment:16 Changed 3 years ago by miltondp

It works!! Thank you very much! I tried with remote (with user and password) and local repositories. I attach both log files of the Mercurial step.

Great job, I liked a lot to help with this bug!

Changed 3 years ago by miltondp

Mercurial step - Remote repository

Changed 3 years ago by miltondp

Mercurial step - Local repository

comment:17 Changed 3 years ago by dustin

  • Milestone changed from 0.8.+ to 0.7.12

Hey, cool! Marcus, I'll leave it to you to push the changes, but let me know if you'd like me to do it.

comment:18 Changed 3 years ago by marcusl

  • Status changed from accepted to closed
  • Resolution set to fixed
commit 7e4e948a49b2f511367caac0ea91f91501fee546
Author: Marcus Lindblom <macke@yar.nu>
Date:   Tue Dec 29 11:45:02 2009 +0100

    Remove user/passwd when comparing Mercurial URLs (fixes #640)
    Thanks to Milton Pividon for doing most of the work. :)

:)

comment:19 Changed 3 years ago by miltondp

Great!!!

Note: See TracTickets for help on using tickets.