mounter: use custom exception for absolute path error
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
parent
162f00b773
commit
bcfa6b1c9c
|
@ -51,11 +51,15 @@ class OverlayCleanupError(Exception):
|
||||||
"""Exception to raise when an overlay could not be cleaned up."""
|
"""Exception to raise when an overlay could not be cleaned up."""
|
||||||
|
|
||||||
|
|
||||||
|
class AbsolutePathError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class _MountBase:
|
class _MountBase:
|
||||||
def p(self, *args: str) -> str:
|
def p(self, *args: str) -> str:
|
||||||
for a in args:
|
for a in args:
|
||||||
if a.startswith("/"):
|
if a.startswith("/"):
|
||||||
raise Exception("no absolute paths here please")
|
raise AbsolutePathError("no absolute paths here please")
|
||||||
return os.path.join(self.mountpoint, *args)
|
return os.path.join(self.mountpoint, *args)
|
||||||
|
|
||||||
def write(self, path, content):
|
def write(self, path, content):
|
||||||
|
|
|
@ -18,15 +18,33 @@ import pathlib
|
||||||
from unittest.mock import AsyncMock, Mock, call, patch
|
from unittest.mock import AsyncMock, Mock, call, patch
|
||||||
|
|
||||||
from subiquity.server.mounter import (
|
from subiquity.server.mounter import (
|
||||||
|
AbsolutePathError,
|
||||||
Mounter,
|
Mounter,
|
||||||
Mountpoint,
|
Mountpoint,
|
||||||
OverlayMountpoint,
|
OverlayMountpoint,
|
||||||
|
_MountBase,
|
||||||
lowerdir_for,
|
lowerdir_for,
|
||||||
)
|
)
|
||||||
from subiquitycore.tests import SubiTestCase
|
from subiquitycore.tests import SubiTestCase
|
||||||
from subiquitycore.tests.mocks import make_app
|
from subiquitycore.tests.mocks import make_app
|
||||||
|
|
||||||
|
|
||||||
|
class Test_MountBase(SubiTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.mountbase = _MountBase()
|
||||||
|
self.mountbase.mountpoint = "/target"
|
||||||
|
|
||||||
|
def test_p(self):
|
||||||
|
mnt = self.mountbase
|
||||||
|
|
||||||
|
self.assertEqual("/target/d1", mnt.p("d1"))
|
||||||
|
self.assertEqual("/target/d1/d2/d3/d4", mnt.p("d1", "d2/d3", "d4"))
|
||||||
|
|
||||||
|
def test_p__absolute(self):
|
||||||
|
with self.assertRaises(AbsolutePathError):
|
||||||
|
self.mountbase.p("a", "/b")
|
||||||
|
|
||||||
|
|
||||||
class TestMounter(SubiTestCase):
|
class TestMounter(SubiTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.model = Mock()
|
self.model = Mock()
|
||||||
|
|
Loading…
Reference in New Issue