def serverMode(mode):
    old, config.getConfig()['server']['mode'] = config.getConfig(
    )['server']['mode'], mode
    try:
        yield mode
    finally:
        config.getConfig()['server']['mode'] = old
Пример #2
0
 def setUp(self):
     super(ServerFuseTestCase, self).setUp()
     self.admin = User().findOne({'login': '******'})
     self.user = User().findOne({'login': '******'})
     self.user2 = User().findOne({'login': '******'})
     curConfig = config.getConfig()
     self.mainMountPath = curConfig['server_fuse']['path']
     self.extraMountPath = tempfile.mkdtemp()
     self.extraMount = None
     self.knownPaths = {
         'user/admin/Private/Item 1/File 1A':
         'File 1A',
         'user/admin/Private/Item 1/File 1B':
         'File 1B',
         'user/admin/Private/Item 2/File 2':
         'File 2',
         'user/admin/Private/Item Without File/':
         None,
         'user/user/Public/Item 3/File 3':
         'File 3',
         'user/user/Private/Item 4/File 4':
         'File 4',
         'user/user/Private/Folder/Item 5/File 5':
         'File 5',
         'collection/Test Collection/Private/Collection Item/Collection File':
         'File 1A',
     }
     self.adminFileName = 'user/admin/Private/Item 1/File 1A'
     self.publicFileName = 'user/user/Public/Item 3/File 3'
     self.privateFileName = 'user/user/Private/Item 4/File 4'
def setUpModule():
    curConfig = config.getConfig()
    curConfig.setdefault('large_image', {})
    curConfig['large_image']['cache_backend'] = os.environ.get(
        'LARGE_IMAGE_CACHE_BACKEND')
    base.enabledPlugins.append('large_image')
    base.startServer(False)
    def test_binder_heuristics(self):
        from girder.plugins.wholetale.tasks.import_binder import sanitize_binder

        tale = Tale().createTale(self.image, [], creator=self.user, title="Binder")
        token = Token().createToken(user=self.user, days=0.25)
        tmpdir = tempfile.mkdtemp()

        with open(tmpdir + "/i_am_a_binder", "w") as fobj:
            fobj.write("but well hidden!")

        with tarfile.open(tmpdir + "/tale.tar.gz", "w:gz") as tar:
            tar.add(tmpdir + "/i_am_a_binder", arcname="dir_in_tar/i_am_a_binder")
        os.remove(tmpdir + "/i_am_a_binder")

        with zipfile.ZipFile(tmpdir + "/tale.zip", "w") as myzip:
            myzip.write(tmpdir + "/tale.tar.gz", arcname="dir_in_zip/tale.tar.gz")
        os.remove(tmpdir + "/tale.tar.gz")
        os.makedirs(tmpdir + "/hidden_binder")
        os.rename(tmpdir + "/tale.zip", tmpdir + "/hidden_binder" + "/tale.zip")

        girder_root = "http://localhost:{}".format(
            config.getConfig()["server.socket_port"]
        )
        with WebDAVFS(
            girder_root,
            login=self.user["login"],
            password="******".format(**token),
            root="/tales/{_id}".format(**tale),
        ) as destination_fs, OSFS(tmpdir) as source_fs:
            copy_fs(source_fs, destination_fs)
            sanitize_binder(destination_fs)
            self.assertEqual(destination_fs.listdir("/"), ["i_am_a_binder"])

        shutil.rmtree(tmpdir)
        Tale().remove(tale)
Пример #5
0
def setUpModule():
    curConfig = config.getConfig()
    curConfig.setdefault('large_image', {})
    curConfig['large_image']['cache_backend'] = os.environ.get(
        'LARGE_IMAGE_CACHE_BACKEND')
    base.enabledPlugins.append('large_image')
    base.startServer(False)
Пример #6
0
def tearDownModule():
    curConfig = config.getConfig()
    tempdir = curConfig['server_fuse']['path']
    base.stopServer()
    retries = 0
    while retries < 50:
        try:
            os.rmdir(tempdir)
            break
        except OSError:
            retries += 1
            time.sleep(0.1)
Пример #7
0
def tearDownModule():
    curConfig = config.getConfig()
    tempdir = curConfig['server_fuse']['path']
    base.stopServer()
    retries = 0
    while retries < 50:
        try:
            os.rmdir(tempdir)
            break
        except OSError:
            retries += 1
            time.sleep(0.1)
Пример #8
0
def setUpModule():
    global testServer
    mockS3 = False
    if "s3" in os.environ["ASSETSTORE_TYPE"]:
        mockS3 = True

    pluginDirs = os.environ.get("PLUGIN_DIRS", "")

    if pluginDirs:
        curConfig = config.getConfig()
        curConfig["plugins"] = {"plugin_directory": pluginDirs}

    plugins = os.environ.get("ENABLED_PLUGINS", "")
    if plugins:
        base.enabledPlugins.extend(plugins.split())
    testServer = base.startServer(False, mockS3=mockS3)
Пример #9
0
def setUpModule():
    global testServer
    mockS3 = False
    if 's3' in os.environ['ASSETSTORE_TYPE']:
        mockS3 = True

    pluginDirs = os.environ.get('PLUGIN_DIRS', '')

    if pluginDirs:
        curConfig = config.getConfig()
        curConfig['plugins'] = {'plugin_directory': pluginDirs}

    plugins = os.environ.get('ENABLED_PLUGINS', '')
    if plugins:
        base.enabledPlugins.extend(plugins.split())
    testServer = base.startServer(False, mockS3=mockS3)
Пример #10
0
def setUpModule():
    global testServer
    mockS3 = False
    if 's3' in os.environ['ASSETSTORE_TYPE']:
        mockS3 = True

    pluginDirs = os.environ.get('PLUGIN_DIRS', '')

    if pluginDirs:
        curConfig = config.getConfig()
        curConfig['plugins'] = {'plugin_directory': pluginDirs}

    plugins = os.environ.get('ENABLED_PLUGINS', '')
    if plugins:
        base.enabledPlugins.extend(plugins.split())
    testServer = base.startServer(False, mockS3=mockS3)
Пример #11
0
    def testStartFromConfig(self):
        from girder.plugins import fuse as girder_fuse

        girder.logger.error = mock.Mock(wraps=girder.logger.error)
        curConfig = config.getConfig()
        origdir = curConfig['server_fuse']['path']
        curConfig['server_fuse']['path'] = '/dev/null/nosuchpath'
        self.assertFalse(girder_fuse.startFromConfig())
        self.assertEqual(girder.logger.error.call_count, 1)
        self.assertIn('Can\'t mount resource fuse:', tuple(girder.logger.error.call_args)[0][0])
        fh, temppath = tempfile.mkstemp()
        os.write(fh, b'contents')
        curConfig['server_fuse']['path'] = temppath
        self.assertFalse(girder_fuse.startFromConfig())
        self.assertEqual(girder.logger.error.call_count, 2)
        self.assertIn('Can\'t mount resource fuse:', tuple(girder.logger.error.call_args)[0][0])
        os.close(fh)
        os.unlink(temppath)
        curConfig['server_fuse']['path'] = origdir
Пример #12
0
    def testStartFromConfig(self):
        from girder.plugins import fuse as girder_fuse

        girder.logger.error = mock.Mock(wraps=girder.logger.error)
        curConfig = config.getConfig()
        origdir = curConfig['server_fuse']['path']
        curConfig['server_fuse']['path'] = '/dev/null/nosuchpath'
        self.assertFalse(girder_fuse.startFromConfig())
        self.assertEqual(girder.logger.error.call_count, 1)
        self.assertIn('Can\'t mount resource fuse:',
                      tuple(girder.logger.error.call_args)[0][0])
        fh, temppath = tempfile.mkstemp()
        os.write(fh, b'contents')
        curConfig['server_fuse']['path'] = temppath
        self.assertFalse(girder_fuse.startFromConfig())
        self.assertEqual(girder.logger.error.call_count, 2)
        self.assertIn('Can\'t mount resource fuse:',
                      tuple(girder.logger.error.call_args)[0][0])
        os.close(fh)
        os.unlink(temppath)
        curConfig['server_fuse']['path'] = origdir
Пример #13
0
 def setUp(self):
     super(ServerFuseTestCase, self).setUp()
     self.admin = User().findOne({'login': '******'})
     self.user = User().findOne({'login': '******'})
     self.user2 = User().findOne({'login': '******'})
     curConfig = config.getConfig()
     self.mainMountPath = curConfig['server_fuse']['path']
     self.extraMountPath = tempfile.mkdtemp()
     self.extraMount = None
     self.knownPaths = {
         'user/admin/Private/Item 1/File 1A': 'File 1A',
         'user/admin/Private/Item 1/File 1B': 'File 1B',
         'user/admin/Private/Item 2/File 2': 'File 2',
         'user/admin/Private/Item Without File/': None,
         'user/user/Public/Item 3/File 3': 'File 3',
         'user/user/Private/Item 4/File 4': 'File 4',
         'user/user/Private/Folder/Item 5/File 5': 'File 5',
         'collection/Test Collection/Private/Collection Item/Collection File': 'File 1A',
     }
     self.adminFileName = 'user/admin/Private/Item 1/File 1A'
     self.publicFileName = 'user/user/Public/Item 3/File 3'
     self.privateFileName = 'user/user/Private/Item 4/File 4'
Пример #14
0
def setUpModule():
    curConfig = config.getConfig()
    curConfig.setdefault('server_fuse', {})
    curConfig['server_fuse']['path'] = tempfile.mkdtemp()
    base.enabledPlugins.append('fuse')
    base.startServer()
Пример #15
0
def serverMode(mode):
    old, config.getConfig()['server']['mode'] = config.getConfig()['server']['mode'], mode
    try:
        yield mode
    finally:
        config.getConfig()['server']['mode'] = old
Пример #16
0
def setUpModule():
    config.getConfig()['histomicstk'] = {'restrict_downloads': True}
    base.enabledPlugins.append('HistomicsTK')
    base.startServer()
Пример #17
0
def setUpModule():
    curConfig = config.getConfig()
    curConfig.setdefault('server_fuse', {})
    curConfig['server_fuse']['path'] = tempfile.mkdtemp()
    base.enabledPlugins.append('fuse')
    base.startServer()