#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
306 306 try: 307 307 try: 308 308 if self.username and not self.auth_map.get(url): 309 login_url = '%s/login?referer=%s' % ( url[:-7],310 309 login_url = '%s/login?referer=%s' % ( 310 url.rsplit('/', 1)[0], urllib.quote_plus(url)) 311 311 # First request to url, authentication needed 312 312 if self.form_auth: 313 313 log.debug('Performing http form authentication')
Attachments (1)
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
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
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
227 227 if self.local: 228 228 self.urls = urls 229 229 else: 230 # add /builds suffix if missing 230 231 self.urls = [ 231 232 not url.endswith('/builds') and url.rstrip('/') + '/builds' 232 233 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). =)
Patch to automatically add '/builds' if it is missing from URLs.