From e12d30888f73b30c3d86ad394bea6d3b20c48899 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 4 Sep 2008 19:14:27 +0100 Subject: [PATCH] Reject URIs without a path component (e.g. http://host) --- tests/testlaunch.py | 12 ++++++------ tests/testmodel.py | 10 ++++++++-- zeroinstall/injector/model.py | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/testlaunch.py b/tests/testlaunch.py index 5a8960c..806804d 100755 --- a/tests/testlaunch.py +++ b/tests/testlaunch.py @@ -100,18 +100,18 @@ class TestLaunch(BaseTest): assert err def testOK(self): - out, err = self.run_0launch(['--dry-run', 'http://foo']) - self.assertEquals("Would download 'http://foo'\nFinished\n", out) + out, err = self.run_0launch(['--dry-run', 'http://foo/d']) + self.assertEquals("Would download 'http://foo/d'\nFinished\n", out) self.assertEquals("", err) def testOffline(self): - out, err = self.run_0launch(['--offline', 'http://foo']) - self.assertEquals("Can't find all required implementations:\n- -> None\n", err) + out, err = self.run_0launch(['--offline', 'http://foo/d']) + self.assertEquals("Can't find all required implementations:\n- -> None\n", err) self.assertEquals("", out) def testDisplay(self): os.environ['DISPLAY'] = ':foo' - out, err = self.run_0launch(['--dry-run', 'http://foo']) + out, err = self.run_0launch(['--dry-run', 'http://foo/d']) # Uses local copy of GUI assert out.startswith("Would execute: ") assert 'basetest.py' in out @@ -124,7 +124,7 @@ class TestLaunch(BaseTest): def testRefreshDisplay(self): os.environ['DISPLAY'] = ':foo' - out, err = self.run_0launch(['--dry-run', '--refresh', 'http://foo']) + out, err = self.run_0launch(['--dry-run', '--refresh', 'http://foo/d']) assert out.startswith("Would execute: ") assert 'basetest.py' in out self.assertEquals("", err) diff --git a/tests/testmodel.py b/tests/testmodel.py index 7ed11eb..45f0a70 100755 --- a/tests/testmodel.py +++ b/tests/testmodel.py @@ -225,8 +225,14 @@ class TestModel(BaseTest): assert 'Malformed arch' in str(ex) def testCanonical(self): - self.assertEquals('http://foo', - model.canonical_iface_uri('http://foo')) + try: + model.canonical_iface_uri('http://foo') + assert False + except model.SafeException, ex: + assert 'Missing /' in str(ex) + + self.assertEquals('http://foo/', + model.canonical_iface_uri('http://foo/')) try: model.canonical_iface_uri('bad-name') assert False diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index 53758e9..e758d20 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -833,7 +833,9 @@ def canonical_iface_uri(uri): @rtype: str @raise SafeException: if uri isn't valid """ - if uri.startswith('http:'): + if uri.startswith('http://'): + if uri.find("/", 7) == -1: + raise SafeException("Missing / after hostname in URI '%s'" % uri) return uri elif uri.startswith('file:///'): return uri[7:] -- 2.11.4.GIT