Edgewall Software

Ticket #679 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[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

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

Change History

Changed 2 years ago by anatoly techtonik <techtonik@…>

  • keywords easy added
  • milestone changed from 0.6.2 to 0.6.1

Changed 2 years ago by hodgestar

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

Changed 2 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.

Changed 2 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.

Changed 2 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.

Changed 2 years ago by hodgestar

  • status changed from new to closed
  • resolution set to fixed

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

Changed 2 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] 

Changed 2 years ago by anatoly techtonik <techtonik@…>

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

Add/Change #679 ([patch] slave: Make URL parsing more robust)

Author


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


Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.