mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 21:17:54 +00:00
CLI: rework webopen, and moreover its tests w.r.t. path handling
in the recent reconciliation of webopen patches, I wound up adjusting webopen to 'pass through' the state of the trailing slash on the given argument to the resultant url passed to the browser. this change removes the requirement that arguments must be directories, and allows webopen to be used with files. it also broke the tests that assumed that webopen would always normalise the url to have a trailing slash. in fixing the tests, I realised that, IMHO, there's something deeply awry with the way tahoe handles paths; specifically in the combination of '/' being the name of the root path within an alias, but a leading slash on paths, e.g. 'alias:/path', is catagorically incorrect. i.e. 'tahoe:' == 'tahoe:/' == '/' but 'tahoe:/foo' is an invalid path, and must be 'tahoe:foo' I wound up making the internals of webopen simply spot a 'path' of '/' and smash it to '', which 'fixes' webopen to match the behaviour of tahoe's path handling elsewhere, but that special case sort of points to the weirdness. (fwiw, I personally found the fact that the leading / in a path was disallowed to be weird - I'm just used to seeing paths qualified by the leading / I guess - so in a debate about normalising path handling I'd vote to include the /)
This commit is contained in:
parent
2c9a854f10
commit
ed9873c2a9
@ -189,7 +189,7 @@ class LnOptions(VDriveOptions):
|
||||
return "%s ln FROM TO" % (os.path.basename(sys.argv[0]),)
|
||||
|
||||
class WebopenOptions(VDriveOptions):
|
||||
def parseArgs(self, where=None):
|
||||
def parseArgs(self, where=''):
|
||||
self.where = where
|
||||
|
||||
def getSynopsis(self):
|
||||
|
@ -7,9 +7,9 @@ def webopen(options, opener=None):
|
||||
if not nodeurl.endswith("/"):
|
||||
nodeurl += "/"
|
||||
where = options.where
|
||||
if where is None:
|
||||
where = 'tahoe:'
|
||||
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
|
||||
if path == '/':
|
||||
path = ''
|
||||
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
|
||||
if path:
|
||||
url += "/" + escape_path(path)
|
||||
|
@ -263,20 +263,25 @@ class CreateAlias(SystemTestMixin, CLITestMixin, unittest.TestCase):
|
||||
node_url_file = os.path.join(self.getdir("client0"), "node.url")
|
||||
nodeurl = open(node_url_file, "r").read().strip()
|
||||
uribase = nodeurl + "uri/"
|
||||
self.tahoe_url = uribase + urllib.quote(aliases["tahoe"]) + "/"
|
||||
self.tahoe_subdir_url = self.tahoe_url + "subdir/"
|
||||
self.two_url = uribase + urllib.quote(aliases["two"]) + "/"
|
||||
self.tahoe_url = uribase + urllib.quote(aliases["tahoe"])
|
||||
self.tahoe_subdir_url = self.tahoe_url + "/subdir"
|
||||
self.two_url = uribase + urllib.quote(aliases["two"])
|
||||
d.addCallback(_stash_urls)
|
||||
|
||||
d.addCallback(lambda res: self._test_webopen([], self.tahoe_url))
|
||||
d.addCallback(lambda res: self._test_webopen(["/"], self.tahoe_url))
|
||||
d.addCallback(lambda res: self._test_webopen(["tahoe:"], self.tahoe_url))
|
||||
d.addCallback(lambda res: self._test_webopen(["tahoe:/"], self.tahoe_url))
|
||||
d.addCallback(lambda res: self._test_webopen(["tahoe:subdir"],
|
||||
self.tahoe_subdir_url))
|
||||
d.addCallback(lambda res: self._test_webopen(["tahoe:subdir/"],
|
||||
self.tahoe_subdir_url))
|
||||
d.addCallback(lambda res: self._test_webopen(["two:"], self.two_url))
|
||||
def _test_urls(junk):
|
||||
self._test_webopen([], self.tahoe_url)
|
||||
self._test_webopen(["/"], self.tahoe_url)
|
||||
self._test_webopen(["tahoe:"], self.tahoe_url)
|
||||
self._test_webopen(["tahoe:/"], self.tahoe_url)
|
||||
self._test_webopen(["tahoe:subdir"], self.tahoe_subdir_url)
|
||||
self._test_webopen(["tahoe:subdir/"], self.tahoe_subdir_url + '/')
|
||||
self._test_webopen(["tahoe:subdir/file"], self.tahoe_subdir_url + '/file')
|
||||
# if "file" is indeed a file, then the url produced by webopen in this
|
||||
# case is disallowed by the webui. but by design, webopen passes through
|
||||
# the mistake from the user to the resultant webopened url
|
||||
self._test_webopen(["tahoe:subdir/file/"], self.tahoe_subdir_url + '/file/')
|
||||
self._test_webopen(["two:"], self.two_url)
|
||||
d.addCallback(_test_urls)
|
||||
|
||||
return d
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user