Edgewall Software
Modify

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#679 closed defect (fixed)

[patch] slave: Make URL parsing more robust

Reported by: anatoly techtonik <techtonik@…> Owned by:
Priority: major Milestone: 0.6.1
Component: Build slave Version: 0.6
Keywords: patch easy Cc:
Operating System: BSD

Description

Currently, if you've mistaken build and supply invalid http://bitten.edgewall.org/build URL, bitten-slave will timeout instead of failing.

>>> url = 'http://bitten.edgewall.org/build'
>>> url[:-7]
'http://bitten.edgewall.or'
>>> url.rsplit('/', 1)[0]
'http://bitten.edgewall.org'
>>>

The patch fixes this behaviour:

  • bitten/slave.py

     
    306306            try:
    307307                try:
    308308                    if self.username and not self.auth_map.get(url):
    309                         login_url = '%s/login?referer=%s' % (url[:-7],
    310                                                        urllib.quote_plus(url))
     309                        login_url = '%s/login?referer=%s' % (
     310                                 url.rsplit('/', 1)[0], urllib.quote_plus(url))
    311311                        # First request to url, authentication needed
    312312                        if self.form_auth:
    313313                            log.debug('Performing http form authentication')

Attachments (1)

add-builds-to-urls-patch.diff (1.4 KB) - added by hodgestar 13 years ago.
Patch to automatically add '/builds' if it is missing from URLs.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 13 years ago by anatoly techtonik <techtonik@…>

  • Keywords easy added
  • Milestone changed from 0.6.2 to 0.6.1

Changed 13 years ago by hodgestar

Patch to automatically add '/builds' if it is missing from URLs.

comment:2 Changed 13 years ago by hodgestar

I've added a patch that checks non-local URLs for whether they end in '/builds' and adds '/builds' if it isn't found. This allows one to use either 'http://project' or 'http://project/builds' when calling bitten-slave. If people are happy with the patch I'll update the documentation before committing. At the moment passing 'http://project/' results in 'http://projects//builds' which works for me but is perhaps less clean that without the second double slash. I'm +-0 on adding the extra code to ensure we end up with just one slash.

It was pointed out by osimons that #587 is a duplicate of this.

comment:3 Changed 13 years ago by hodgestar

P.S. My patch does ensure that Bitten never contacts the wrong domain regardless of how bad the URL is. The final URL used is available via 'bitten-slave -v' as always.

comment:4 Changed 13 years ago by osimons

Just use url.rstrip('/') + '/builds' to remove double slashes. Also, seems a bit overkill to del urls - we don't really go deleting all the other locals after we've done with them either?

Anyway, the idea is good i think, and would allow just pointing slave to a project. Of course, the typo that triggered the ticket will still be wrong (now /build/builds) but wrong urls from user input can happen anytime and anywhere and is beyond our control.

comment:5 Changed 13 years ago by hodgestar

  • Resolution set to fixed
  • Status changed from new to closed

Modified patch include osimons' suggestions committed as r995 and backported to 0.6.x in r996.

comment:6 Changed 13 years ago by anatoly techtonik <techtonik@…>

While this code wins +1 for doing the right thing and +1 for brevity, it still loses -3 on clarity. If I was the reviewer, I'd add obligatory comment. =)

  • slave.py

     
    227227        if self.local:
    228228            self.urls = urls
    229229        else:
     230            # add /builds suffix if missing
    230231            self.urls = [
    231232                not url.endswith('/builds') and url.rstrip('/') + '/builds'
    232233                or url for url in urls]

comment:7 Changed 13 years ago by anatoly techtonik <techtonik@…>

Anyway, thank for fruitful collaboration (even though the change minor). =)

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.