NOTE: this patch only contains a better description than the previous.
This patch includes more examples of valid and invalid image URLs and ensures that the image processing handles them correctly.
Signed-off-by: Darryl L. Pierce dpierce@redhat.com --- cobbler/item_image.py | 21 ++++++++++++++------- cobbler/test_basic.py | 11 +++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/cobbler/item_image.py b/cobbler/item_image.py index b11dc9c..5a4123b 100644 --- a/cobbler/item_image.py +++ b/cobbler/item_image.py @@ -119,26 +119,33 @@ class Image(item.Item): * hostname:/path/to/the/filename.ext * /path/to/the/filename.ext """ - print "STARTING WITH FILENAME: %s" % filename uri = "" - auth = hostname = path = "" + scheme = auth = hostname = path = "" # we'll discard the protocol if it's supplied, for legacy support if filename.find("://") != -1: - ignored, uri = filename.split("://") + scheme, uri = filename.split("://") filename = uri else: uri = filename
if filename.find("@") != -1: auth, filename = filename.split("@") + # extract the hostname + # 1. if we have a colon, then everything before it is a hostname + # 2. if we don't have a colon, then check if we had a scheme; if + # we did, then grab all before the first forward slash as the + # hostname; otherwise, we've got a bad file if filename.find(":") != -1: hostname, filename = filename.split(":") elif filename[0] != '/': - index = filename.find("/") - hostname = filename[:index] - filename = filename[index:] + if len(scheme) > 0: + index = filename.find("/") + hostname = filename[:index] + filename = filename[index:] + else: + raise CX(_("invalid file: %s" % filename)) # raise an exception if we don't have a valid path - if filename[0] != '/': + if len(filename) > 0 and filename[0] != '/': raise CX(_("file contains an invalid path: %s" % filename)) if filename.find("/") != -1: path, filename = filename.rsplit("/", 1) diff --git a/cobbler/test_basic.py b/cobbler/test_basic.py index 7f6a062..27ecabe 100644 --- a/cobbler/test_basic.py +++ b/cobbler/test_basic.py @@ -873,8 +873,15 @@ class TestImage(BootTest): # ensure that only valid names are accepted and invalid ones are rejected image = self.api.new_image() self.assertTrue(image.set_file("nfs://hostname/path/to/filename.iso")) - self.assertTrue(image.set_file("/mcpierce@hostname:/path/to/filename.iso")) - self.assertTrue(image.set_file("path/to/filename.iso")) + self.assertTrue(image.set_file("nfs://mcpierce@hostname:/path/to/filename.iso")) + self.assertTrue(image.set_file("nfs://hostname:/path/to/filename.iso")) + self.assertTrue(image.set_file("nfs://hostname/filename.iso")) + self.assertTrue(image.set_file("hostname:/path/to/the/filename.iso")) + self.failUnlessRaises(CX, image.set_file, "hostname:filename.iso") + self.failUnlessRaises(CX, image.set_file, "path/to/filename.iso") + self.failUnlessRaises(CX, image.set_file, "hostname:") + # port is not allowed + self.failUnlessRaises(CX, image.set_file, "nfs://hostname:1234/path/to/the/filename.iso")
#class TestCLIBasic(BootTest): #