コード例 #1
0
def skip_on_broken_permissions(test_method):
    """
    Skips the wrapped test when the temporary directory is on a
    filesystem with broken permissions.

    Virtualbox's shared folder (as used for :file:`/vagrant`) doesn't entirely
    respect changing permissions. For example, this test detects running on a
    shared folder by the fact that all permissions can't be removed from a
    file.

    :param callable test_method: Test method to wrap.
    :return: The wrapped method.
    :raise SkipTest: when the temporary directory is on a filesystem with
        broken permissions.
    """
    @wraps(test_method)
    def wrapper(case, *args, **kwargs):
        test_file = FilePath(case.mktemp())
        test_file.touch()
        test_file.chmod(0o000)
        permissions = test_file.getPermissions()
        test_file.chmod(0o777)
        if permissions != Permissions(0o000):
            raise SkipTest(
                "Can't run test on filesystem with broken permissions.")
        return test_method(case, *args, **kwargs)
コード例 #2
0
ファイル: test_service.py プロジェクト: verchol/flocker
    def test_create_mode(self):
        """The created filesystem is readable/writable/executable by anyone.

        A better alternative will be implemented in
        https://clusterhq.atlassian.net/browse/FLOC-34
        """
        pool = FilesystemStoragePool(FilePath(self.mktemp()))
        service = VolumeService(FilePath(self.mktemp()), pool, reactor=Clock())
        service.startService()
        volume = self.successResultOf(service.create(service.get(MY_VOLUME)))
        self.assertEqual(
            pool.get(volume).get_path().getPermissions(), Permissions(0o777))
コード例 #3
0
ファイル: test_common.py プロジェクト: sajith/magic-folder
 def test_parent_writeable(self):
     """
     ``SyncTestCase.mktemp`` returns a path the parent of which is writeable
     only by the owner.
     """
     tmp = get_synctestcase().mktemp()
     stat = os.stat(os.path.split(tmp)[0])
     self.assertEqual(
         stat.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH),
         S_IWUSR,
         "Expected parent permissions to allow only owner writes, "
         "got {} instead.".format(Permissions(stat.st_mode), ),
     )
コード例 #4
0
    def test_clone_to_mode(self):
        """
        The cloned-to filesystem is readable/writable/executable by anyone.

        A better alternative will be implemented in
        https://github.com/ClusterHQ/flocker/issues/34
        """
        pool = FilesystemStoragePool(FilePath(self.mktemp()))
        service = VolumeService(FilePath(self.mktemp()), pool, reactor=Clock())
        service.startService()
        parent = self.successResultOf(service.create(service.get(MY_VOLUME)))

        volume = self.successResultOf(service.clone_to(parent, MY_VOLUME2))
        self.assertEqual(
            pool.get(volume).get_path().getPermissions(), Permissions(0o777))
コード例 #5
0
def stat_format(keys, props):
    st = swift_stat(**props)
    l = []
    for key in keys:
        if key == 'size':
            val = st.st_size
        elif key == 'directory':
            val = st.st_mode & stat.S_IFDIR == stat.S_IFDIR
        elif key == 'permissions':
            val = Permissions(st.st_mode)
        elif key == 'hardlinks':
            val = st.st_nlink
        elif key == 'modified':
            val = int(st.st_mtime)
        elif key in 'owner':
            val = 'nobody'
        elif key in 'group':
            val = 'nobody'
        else:  # Unknown Value
            val = ''
        l.append(val)
    return l