def testBlockedMount(self): """ Test that when a mount point is non-empty the mount fails, is reported, and is not left in the list of mounts. """ from girder.plugins.fuse import server_fuse blockFile = os.path.join(self.extraMountPath, 'block') open(blockFile, 'wb').close() mountpath = self.extraMountPath self.extraMount = 'test' with mock.patch( 'girder.utility.plugin_utilities.logprint.error') as logprint: server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user) # If can take a short amount of time to trigger an error, so wait # for it. Also wait for the mount information to be cleaned up. for iter in six.moves.range(50): if logprint.call_count and not server_fuse.isServerFuseMounted( self.extraMount, level=AccessType.READ, user=self.user): break time.sleep(0.1) logprint.assert_called_once() self.assertFalse( server_fuse.isServerFuseMounted(self.extraMount, level=AccessType.READ, user=self.user)) os.unlink(blockFile)
def testRemount(self): """ Test remounting with different credentials. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'remount' # mount with user2 self.assertTrue( server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user2)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) publicFile = os.path.join(mountpath, self.publicFileName) privateFile = os.path.join(mountpath, self.privateFileName) self.assertTrue(os.path.exists(publicFile)) self.assertFalse(os.path.exists(privateFile)) # remount with user self.assertFalse( server_fuse.isServerFuseMounted(self.extraMount, level=AccessType.READ, user=self.user)) self.assertTrue( server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) self.assertTrue(os.path.exists(publicFile)) self.assertTrue(os.path.exists(privateFile))
def testRemount(self): """ Test remounting with different credentials. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'remount' # mount with user2 self.assertTrue(server_fuse.mountServerFuse( self.extraMount, mountpath, level=AccessType.READ, user=self.user2)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) publicFile = os.path.join(mountpath, self.publicFileName) privateFile = os.path.join(mountpath, self.privateFileName) self.assertTrue(os.path.exists(publicFile)) self.assertFalse(os.path.exists(privateFile)) # remount with user self.assertFalse(server_fuse.isServerFuseMounted( self.extraMount, level=AccessType.READ, user=self.user)) self.assertTrue(server_fuse.mountServerFuse( self.extraMount, mountpath, level=AccessType.READ, user=self.user)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) self.assertTrue(os.path.exists(publicFile)) self.assertTrue(os.path.exists(privateFile))
def testUnmountWithOpenFiles(self): """ Unmounting with open files will return a non-zero value. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'test' self.assertTrue( server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) path = os.path.join(mountpath, self.publicFileName) fh = open(path) fh.read(1) with six.assertRaisesRegex(self, GirderException, 'Can\'t unmount'): server_fuse.unmountServerFuse(self.extraMount) # unmount all should fail silently, but still not unmount server_fuse.unmountAll() # We should still be able to read from the file. fh.read(1) fh.close() # Now we can unmount successefully server_fuse.unmountServerFuse(self.extraMount) self.extraMount = None
def testRemountWithoutChanges(self): """ Test remounting with different credentials. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'remountWithoutChanges' # remount with user server_fuse.mountServerFuse( self.extraMount, mountpath, level=AccessType.READ, user=self.user) # remount without any changes should work self.assertTrue(server_fuse.isServerFuseMounted( self.extraMount, level=AccessType.READ, user=self.user)) self.assertEqual(server_fuse.mountServerFuse( self.extraMount, mountpath, level=AccessType.READ, user=self.user), 'present')
def testRemountWithoutChanges(self): """ Test remounting with different credentials. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'remountWithoutChanges' # remount with user server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user) # remount without any changes should work self.assertTrue( server_fuse.isServerFuseMounted(self.extraMount, level=AccessType.READ, user=self.user)) self.assertEqual( server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user), 'present')
def testUserMount(self): """ The first non-admin user should be able to see all of their own items, folders, collections, and files, but not the admin items or private folders. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'test' self.assertTrue( server_fuse.mountServerFuse(self.extraMount, mountpath, level=AccessType.READ, user=self.user)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) # The admin's private are not visible nonVisiblePattern = '/admin/Private' # Check that the mount lists users and collections self.assertEqual(sorted(os.listdir(mountpath)), sorted(['user', 'collection'])) # Check that all known paths exist and that arbitrary other paths don't for testpath, contents in six.iteritems(self.knownPaths): localpath = os.path.join(mountpath, testpath) # We can see all path that aren't the admin's private paths canSee = nonVisiblePattern not in testpath self.assertEqual(os.path.exists(localpath), canSee) # If the path is a file and we can see it, check that it equals the # expected value, and raises an error if we can't see it. if contents: if canSee: with open(localpath) as file1: self.assertEqual(file1.read().strip(), contents) else: with self.assertRaises(IOError): with open(localpath) as file1: pass # All parents should be folders if they can seen and report at not # if they can't. subpath = testpath while '/' in subpath: subpath = subpath.rsplit('/')[0] localpath = os.path.join(mountpath, subpath) canSee = nonVisiblePattern not in subpath self.assertEqual(os.path.isdir(localpath), canSee)
def testUserMount(self): """ The first non-admin user should be able to see all of their own items, folders, collections, and files, but not the admin items or private folders. """ from girder.plugins.fuse import server_fuse mountpath = self.extraMountPath self.extraMount = 'test' self.assertTrue(server_fuse.mountServerFuse( self.extraMount, mountpath, level=AccessType.READ, user=self.user)) # The OS can cache stat, so wait 1 second before using the mount. time.sleep(1) # The admin's private are not visible nonVisiblePattern = '/admin/Private' # Check that the mount lists users and collections self.assertEqual(sorted(os.listdir(mountpath)), sorted(['user', 'collection'])) # Check that all known paths exist and that arbitrary other paths don't for testpath, contents in six.iteritems(self.knownPaths): localpath = os.path.join(mountpath, testpath) # We can see all path that aren't the admin's private paths canSee = nonVisiblePattern not in testpath self.assertEqual(os.path.exists(localpath), canSee) # If the path is a file and we can see it, check that it equals the # expected value, and raises an error if we can't see it. if contents: if canSee: with open(localpath) as file1: self.assertEqual(file1.read().strip(), contents) else: with self.assertRaises(IOError): with open(localpath) as file1: pass # All parents should be folders if they can seen and report at not # if they can't. subpath = testpath while '/' in subpath: subpath = subpath.rsplit('/')[0] localpath = os.path.join(mountpath, subpath) canSee = nonVisiblePattern not in subpath self.assertEqual(os.path.isdir(localpath), canSee)