Skip to content

Commit

Permalink
Fix local file path potential bug
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmatthews committed Feb 2, 2017
1 parent 69b0d1c commit adeea93
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions COT/disks/tests/test_iso.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# test_iso.py - Unit test cases for ISO disk representation.
#
# October 2016, Glenn F. Matthews
# Copyright (c) 2014-2016 the COT project developers.
# Copyright (c) 2014-2017 the COT project developers.
# See the COPYRIGHT.txt file at the top-level directory of this distribution
# and at https://github.com/glennmatthews/cot/blob/master/COPYRIGHT.txt.
#
Expand Down Expand Up @@ -34,6 +34,11 @@
class TestISO(COT_UT):
"""Test cases for ISO class."""

def setUp(self):
"""Test case setup function called automatically before each test."""
super(TestISO, self).setUp()
self.foo_iso = os.path.join(self.temp_dir, "foo.iso")

def tearDown(self):
"""Test case cleanup function called automatically after each test."""
for name in ['mkisofs', 'genisoimage', 'xorriso', 'isoinfo']:
Expand Down Expand Up @@ -112,19 +117,19 @@ def test_create_without_files(self):
def test_create_with_mkisofs(self, mock_call):
"""Creation of an ISO with mkisofs (default)."""
helpers['mkisofs']._installed = True
ISO(path='foo.iso', files=[self.input_ovf])
ISO(path=self.foo_iso, files=[self.input_ovf])
mock_call.assert_called_with(
['-output', 'foo.iso', '-full-iso9660-filenames',
['-output', self.foo_iso, '-full-iso9660-filenames',
'-iso-level', '2', '-allow-lowercase', '-r', self.input_ovf])

@mock.patch("COT.helpers.mkisofs.GenISOImage.call")
def test_create_with_genisoimage(self, mock_call):
"""Creation of an ISO with genisoimage if mkisofs is unavailable."""
helpers['mkisofs']._installed = False
helpers['genisoimage']._installed = True
ISO(path='foo.iso', files=[self.input_ovf])
ISO(path=self.foo_iso, files=[self.input_ovf])
mock_call.assert_called_with(
['-output', 'foo.iso', '-full-iso9660-filenames',
['-output', self.foo_iso, '-full-iso9660-filenames',
'-iso-level', '2', '-allow-lowercase', '-r', self.input_ovf])

@mock.patch("COT.helpers.mkisofs.XorrISO.call")
Expand All @@ -133,10 +138,11 @@ def test_create_with_xorriso(self, mock_call):
helpers['mkisofs']._installed = False
helpers['genisoimage']._installed = False
helpers['xorriso']._installed = True
ISO(path='foo.iso', files=[self.input_ovf])
ISO(path=self.foo_iso, files=[self.input_ovf])
mock_call.assert_called_with(
['-as', 'mkisofs', '-output', 'foo.iso', '-full-iso9660-filenames',
'-iso-level', '2', '-allow-lowercase', '-r', self.input_ovf])
['-as', 'mkisofs', '-output', self.foo_iso,
'-full-iso9660-filenames', '-iso-level', '2', '-allow-lowercase',
'-r', self.input_ovf])

def test_create_no_helpers_available(self):
"""Creation of ISO should fail if no helpers are install[ed|able]."""
Expand All @@ -148,16 +154,16 @@ def test_create_no_helpers_available(self):
helpers['yum']._installed = False
self.assertRaises(HelperNotFoundError,
ISO,
path='foo.iso',
path=self.foo_iso,
files=[self.input_ovf])

@mock.patch("COT.helpers.mkisofs.MkISOFS.call")
def test_create_with_mkisofs_non_rockridge(self, mock_call):
"""Creation of a non-Rock-Ridge ISO with mkisofs (default)."""
helpers['mkisofs']._installed = True
ISO(path='foo.iso', files=[self.input_ovf], disk_subformat="")
ISO(path=self.foo_iso, files=[self.input_ovf], disk_subformat="")
mock_call.assert_called_with(
['-output', 'foo.iso', '-full-iso9660-filenames',
['-output', self.foo_iso, '-full-iso9660-filenames',
'-iso-level', '2', '-allow-lowercase', self.input_ovf])

def test_file_is_this_type_nonexistent(self):
Expand Down

0 comments on commit adeea93

Please sign in to comment.