Exemple #1
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        server_params = ServerParameters(None, None, None, None, None, None)
        server_params.gifsicle_path = which('gifsicle')

        cfg.DETECTORS = [
            'thumbor.detectors.face_detector',
            'thumbor.detectors.profile_detector',
            'thumbor.detectors.glasses_detector',
            'thumbor.detectors.feature_detector',
        ]
        cfg.STORAGE = 'thumbor.storages.no_storage'
        cfg.LOADER = 'thumbor.loaders.file_loader'
        cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__), 'imgs')
        cfg.ENGINE = getattr(self, 'engine', None)
        cfg.USE_GIFSICLE_ENGINE = True
        cfg.FFMPEG_PATH = which('ffmpeg')
        cfg.ENGINE_THREADPOOL_SIZE = 10
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.gifv',
        ]
        if not cfg.ENGINE:
            return None

        importer = Importer(cfg)
        importer.import_modules()
        ctx = Context(server_params, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
 def get_app(self):
     cfg = Config.load(fixture_for('encrypted_handler_conf.py'))
     server_params = ServerParameters(None, None, None, None, None, None)
     server_params.security_key = 'HandlerVows'
     importer = Importer(cfg)
     importer.import_modules()
     ctx = Context(server_params, cfg, importer)
     application = ThumborServiceApp(ctx)
     return application
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.ENABLE_ETAGS = False

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        return Context(server, cfg, importer)
Exemple #5
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
        def topic(self):
            cfg = Config(SECURITY_KEY='ACME-SEC', SENTRY_DSN_URL="http://sentry-dsn-url")
            server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
            server.security_key = 'ACME-SEC'
            ctx = Context(server, cfg, None)

            client_mock = FakeSentry("FAKE DSN")
            handler = ErrorHandler(cfg, client=client_mock)
            http_handler = FakeHandler()

            handler.handle_error(ctx, http_handler, RuntimeError("Test"))

            return client_mock
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.STORAGE = "thumbor.storages.no_storage"
        cfg.MAX_PIXELS = 1000

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which("gifsicle")
        return ctx
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.FFMPEG_PATH = which("ffmpeg")
        cfg.OPTIMIZERS = ["thumbor.optimizers.gifv"]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which("gifsicle")
        return ctx
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.AUTO_WEBP = True
        cfg.USE_GIFSICLE_ENGINE = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which('gifsicle')
        return ctx
Exemple #10
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.STORAGE = "thumbor.storages.no_storage"
        cfg.RESPECT_ORIENTATION = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        self.context = Context(server, cfg, importer)
        self.context.server.gifsicle_path = which('gifsicle')
        return self.context
Exemple #11
0
    def test_can_set_security_key(self):
        params = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path='/tmp/config_path.conf',
            keyfile='./tests/fixtures/thumbor.key',
            log_level='debug',
            app_class='app',
            fd='fd',
            gifsicle_path='gifsicle_path',
        )

        params.security_key = u'testé'
        expect(params._security_key).to_equal(u'testé'.encode('utf-8'))
Exemple #12
0
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.JPEGTRAN_PATH = which("jpegtran")
        cfg.PROGRESSIVE_JPEG = True
        cfg.OPTIMIZERS = ["thumbor.optimizers.jpegtran"]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        return ctx
Exemple #13
0
    def get_app(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.ALLOW_UNSAFE_URL = False

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8890, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Exemple #14
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.QUALITY = 'keep'
        cfg.SVG_DPI = 200

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
        def topic(self):
            #use temporary file to store logs
            tmp = tempfile.NamedTemporaryFile(prefix='thumborTest.')

            cfg = Config(SECURITY_KEY='ACME-SEC', ERROR_FILE_LOGGER=tmp.name)
            server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
            server.security_key = 'ACME-SEC'
            ctx = Context(server, cfg, None)

            handler = ErrorHandler(cfg)
            http_handler = FakeHandler()

            handler.handle_error(ctx, http_handler, RuntimeError("Test"))
            #return content of file
            return tmp.read()
Exemple #16
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='MYKEY')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.ALLOW_UNSAFE_URL = False
        cfg.ALLOW_OLD_URLS = True
        cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True

        cfg.STORAGE = 'thumbor.storages.file_storage'
        cfg.STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'MYKEY'
        return Context(server, cfg, importer)
Exemple #17
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.FFMPEG_PATH = which('ffmpeg')
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.gifv',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which('gifsicle')
        return ctx
Exemple #18
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path

        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path

        cfg.SEND_IF_MODIFIED_LAST_MODIFIED_HEADERS = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
Exemple #19
0
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path

        cfg.RESULT_STORAGE = "thumbor.result_storages.file_storage"
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)

        return ctx
Exemple #20
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.JPEGTRAN_PATH = which('jpegtran')
        cfg.PROGRESSIVE_JPEG = True,
        cfg.RESULT_STORAGE_STORES_UNSAFE = True,
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.jpegtran',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        return ctx
Exemple #21
0
    def get_app(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.OPTIMIZERS = ["thumbor.optimizers.gifv"]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which("gifsicle")
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
Exemple #22
0
    def get_app(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = FILE_STORAGE_ROOT_PATH
        if exists(FILE_STORAGE_ROOT_PATH):
            rmtree(FILE_STORAGE_ROOT_PATH)

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Exemple #23
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path
        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.request = self.get_request()
        ctx.server.gifsicle_path = which('gifsicle')
        return ctx
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.ALLOW_UNSAFE_URL = False
        cfg.ALLOW_OLD_URLS = True
        cfg.STORAGE="thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH=storage_path
        cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = 'thumbor.loaders.file_loader'
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.OPTIMIZERS = [
            'thumbor_plugins.optimizers.jp2',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
Exemple #26
0
    def get_app(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            LOADER='thumbor.loaders.file_loader',
            RESULT_STORAGE='thumbor.result_storages.file_storage',
            RESULT_STORAGE_STORES_UNSAFE=True,
            RESULT_STORAGE_EXPIRATION_SECONDS=2592000,
            FILE_LOADER_ROOT_PATH=storage_path
        )

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Exemple #27
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.gifv',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
Exemple #28
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = self.loader_path

        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.AUTO_WEBP = True
        cfg.MAX_WIDTH = 150
        cfg.MAX_HEIGHT = 150

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)

        return ctx
Exemple #29
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.AUTO_WEBP = True
        cfg.USE_GIFSICLE_ENGINE = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which('gifsicle')
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
Exemple #30
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC',
                     LOADER='thumbor.loaders.file_loader',
                     RESULT_STORAGE='thumbor.result_storages.file_storage',
                     RESULT_STORAGE_STORES_UNSAFE=False,
                     RESULT_STORAGE_EXPIRATION_SECONDS=2592000,
                     FILE_LOADER_ROOT_PATH=storage_path,
                     STORAGE='thumbor.storages.no_storage',
                     OPTIMIZERS=['thumbor.optimizers.jpegtran'])

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Exemple #31
0
        def topic(self):
            port = 8890
            #use temporary file to store logs
            tmp = tempfile.NamedTemporaryFile(prefix='thumborTest.%i.' % port)

            cfg = Config(SECURITY_KEY='ACME-SEC',
                         ERROR_FILE_LOGGER=tmp.name.replace(
                             'thumborTest.%i.' % port, 'thumborTest.%i.'),
                         ERROR_FILE_NAME_USE_CONTEXT='server.port')
            server = ServerParameters(port, 'localhost', 'thumbor.conf', None,
                                      'info', None)
            server.security_key = 'ACME-SEC'
            ctx = Context(server, cfg, None)

            handler = ErrorHandler(cfg)
            http_handler = FakeHandler()

            handler.handle_error(ctx, http_handler, RuntimeError("Test"))
            #return content of file
            return tmp.read()
Exemple #32
0
    def get_app(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            LOADER='thumbor.loaders.file_loader',
            RESULT_STORAGE_STORES_UNSAFE=False,
            RESULT_STORAGE_EXPIRATION_SECONDS=2592000,
            FILE_LOADER_ROOT_PATH=storage_path,
            OPTIMIZERS=[],
            USE_GIFSICLE_ENGINE=True,
        )

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        server.gifsicle_path = which('gifsicle')
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Exemple #33
0
    def get_app(self):
        server_params = ServerParameters(None, None, None, None, None, None)

        cfg = self.get_config()

        importer = Importer(cfg)
        importer.import_modules()
        self.ctx = Context(server_params, cfg, importer)
        application = App(self.ctx)

        return application
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "tests.stub_file_loader"
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.QUALITY = 'keep'
        cfg.SVG_DPI = 200

        self.image = 'http://test.domain/image.jpg'
        self.quoted_image = quote(self.image, safe='')
        self.transform = '400x400/smart'
        self.signature = UrlSigner(security_key="ACME-SEC").signature('%s/%s' % (self.transform, self.quoted_image))
        self.signed_prefix = "/%s/%s" % (self.signature, self.transform)
        self.full_image = "/%s/%s/%s" % (self.signature, self.transform, self.quoted_image)

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', 'thumbor_flexible_validation.app.ThumborServiceProxy')
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = "/path/that/does/not/exist"

        cfg.RESULT_STORAGE = "thumbor.result_storages.file_storage"
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path

        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(
            8889, "localhost", "thumbor.conf", None, "info", None
        )
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)

        return ctx
Exemple #36
0
 def test_loading_does_nothing_if_no_keyfile():
     params = ServerParameters(
         port=8888,
         ip="0.0.0.0",
         config_path="/my/config_path.conf",
         keyfile=None,
         log_level="debug",
         app_class="app",
         fd="fd",
         gifsicle_path="gifsicle_path",
     )
     expect(params._security_key).to_be_null()  # pylint: disable=protected-access
def get_app(table):
    cfg = Config(HBASE_STORAGE_TABLE=table,
                 HBASE_STORAGE_SERVER_PORT=9090,
                 STORAGE='thumbor_hbase.storage')
    importer = Importer(cfg)
    importer.import_modules()
    server = ServerParameters(8888, 'localhost', 'thumbor.conf', None, 'info',
                              None)
    ctx = Context(server, cfg, importer)
    application = ThumborServiceApp(ctx)

    return application
Exemple #38
0
    async def test_should_raise_for_invalid_compatibility_storage(self):
        config = Config(
            FILE_LOADER_ROOT_PATH=STORAGE_PATH,
            STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True,
        )
        importer = Importer(config)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None,
                                  "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, config=config, importer=importer)
        storage = Storage(ctx)

        with expect.error_to_happen(
                RuntimeError,
                message=(
                    "The 'COMPATIBILITY_LEGACY_STORAGE' configuration should "
                    "point to a valid storage when using compatibility storage."
                ),
        ):
            await storage.get("invalid-path")
Exemple #39
0
    def get_app(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            LOADER='thumbor.loaders.file_loader',
            RESULT_STORAGE_STORES_UNSAFE=False,
            RESULT_STORAGE_EXPIRATION_SECONDS=2592000,
            FILE_LOADER_ROOT_PATH=storage_path,
            OPTIMIZERS=[],
            USE_GIFSICLE_ENGINE=True,
        )

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        server.gifsicle_path = which('gifsicle')
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Exemple #40
0
    def test_loading_does_nothing_if_no_keyfile(self):
        params = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path='/tmp/config_path.conf',
            keyfile=None,
            log_level='debug',
            app_class='app',
            fd='fd',
            gifsicle_path='gifsicle_path',
        )

        expect(params._security_key).to_be_null()
Exemple #41
0
 def test_cant_load_invalid_security_key_file(self):
     expected_msg = 'Could not find security key file at /bogus. Please verify the keypath argument.'
     with expect.error_to_happen(ValueError, message=expected_msg):
         ServerParameters(
             port=8888,
             ip='0.0.0.0',
             config_path='/tmp/config_path.conf',
             keyfile='/bogus',
             log_level='debug',
             app_class='app',
             fd='fd',
             gifsicle_path='gifsicle_path',
         )
Exemple #42
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='MYKEY')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.ALLOW_UNSAFE_URL = False
        cfg.ALLOW_OLD_URLS = True
        cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'MYKEY'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        storage = FileStorage(Context(config=cfg, server=server))

        # Store fixtures (image.jpg and image.txt) into the file storage
        storage.put('image.jpg', open(join(storage_path, 'image.jpg')).read())
        storage.put_crypto('image.jpg')   # Write a file on the file storage containing the security key

        return application
Exemple #43
0
    def get_app(self):
        cfg = Config(SECURITY_KEY="ACME-SEC")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.RESULT_STORAGE = "thumbor.result_storages.file_storage"
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = tempfile.mkdtemp(prefix="thumbor_test")
        cfg.USE_GIFSICLE_ENGINE = True
        cfg.AUTO_WEBP = True
        cfg.OPTIMIZERS = ["thumbor.optimizers.gifv"]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None, "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which("gifsicle")
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
Exemple #44
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='MYKEY')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.ALLOW_UNSAFE_URL = False
        cfg.ALLOW_OLD_URLS = True
        cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'MYKEY'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        storage = FileStorage(Context(config=cfg, server=server))

        # Store fixtures (image.jpg and image.txt) into the file storage
        storage.put('image.jpg', open(join(storage_path, 'image.jpg')).read())
        storage.put_crypto('image.jpg')   # Write a file on the file storage containing the security key

        return application
Exemple #45
0
def get_server_parameters(arguments=None):
    parser = optparse.OptionParser(
        usage="thumbor or type thumbor -h (--help) for help", description=__doc__, version=__version__
    )
    parser.add_option(
        "-p", "--port", type="int", dest="port", default=8888,
        help="The port to run this thumbor instance at [default: %default]."
    )
    parser.add_option(
        "-i", "--ip", dest="ip", default="0.0.0.0",
        help="The host address to run this thumbor instance at [default: %default]."
    )
    parser.add_option(
        "-f", "--fd", dest="file_descriptor",
        help="The file descriptor number or path to listen for connections on (--port and --ip will be ignored if this is set)"
        "[default: %default]."
    )
    parser.add_option(
        "-c", "--conf", dest="conf", default="",
        help="The path of the configuration file to use for this thumbor instance [default: %default]."
    )
    parser.add_option(
        "-k", "--keyfile", dest="keyfile", default="",
        help="The path of the security key file to use for this thumbor instance [default: %default]."
    )
    parser.add_option(
        "-l", "--log-level", dest="log_level", default="warning",
        help="The log level to be used. Possible values are: debug, info, warning, error, critical or notset. "
        "[default: %default]."
    )
    parser.add_option(
        "-a", "--app", dest="app", default='thumbor.app.ThumborServiceApp',
        help="A custom app to use for this thumbor server in case you subclassed ThumborServiceApp [default: %default]."
    )

    (options, args) = parser.parse_args(arguments)

    port = options.port
    ip = options.ip
    fd = options.file_descriptor
    conf = options.conf or None
    keyfile = options.keyfile or None
    log_level = options.log_level

    return ServerParameters(port=port,
                            ip=ip,
                            config_path=conf,
                            keyfile=keyfile,
                            log_level=log_level,
                            app_class=options.app,
                            fd=fd)
Exemple #46
0
        def topic(self):
            config = Config()
            server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                      'info', None)

            context = Context(server, config, Importer(config))

            with open("%s/quantization.jpg" % FIXTURES_FOLDER, "rb") as f:
                buffer = f.read()

            engine = PIL.Engine(context=context)
            engine.load(buffer, '.jpg')

            return engine
Exemple #47
0
 def test_cant_load_invalid_security_key_file():
     expected_msg = ("Could not find security key file at /bogus."
                     " Please verify the keypath argument.")
     with expect.error_to_happen(ValueError, message=expected_msg):
         ServerParameters(
             port=8888,
             ip="0.0.0.0",
             config_path="/my/config_path.conf",
             keyfile="/bogus",
             log_level="debug",
             app_class="app",
             fd="fd",
             gifsicle_path="gifsicle_path",
         )
Exemple #48
0
def context(config):
    config.ENGINE = 'thumbor_video_engine.engines.video'

    importer = Importer(config)
    importer.import_modules()

    server = ServerParameters(None,
                              'localhost',
                              'thumbor.conf',
                              None,
                              'info',
                              config.APP_CLASS,
                              gifsicle_path=which('gifsicle'))
    server.security_key = config.SECURITY_KEY

    req = RequestParameters()

    configure_log(config, 'DEBUG')

    with Context(server=server, config=config, importer=importer) as context:
        context.request = req
        context.request.engine = context.modules.engine
        yield context
Exemple #49
0
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = '/tmp/path/that/does/not/exist'

        cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage'
        cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60
        cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.FFMPEG_PATH = which('ffmpeg')

        cfg.USE_GIFSICLE_ENGINE = True
        cfg.AUTO_WEBP = True
        cfg.OPTIMIZERS = [
            'thumbor.optimizers.gifv',
        ]

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        ctx.server.gifsicle_path = which('gifsicle')

        return ctx
Exemple #50
0
    def test_can_server_app_class_override_config():
        server = ServerParameters(
            port=8888,
            ip="0.0.0.0",
            config_path="/my/config_path.conf",
            keyfile="./tests/fixtures/thumbor.key",
            log_level="debug",
            app_class="server.app",
        )

        cfg = Config(APP_CLASS="config.app", )
        importer = Importer(cfg)
        ctx = Context(config=cfg, importer=importer, server=server)

        expect(ctx.app_class).to_equal("server.app")
Exemple #51
0
    def test_can_server_app_class_override_config(self):
        server = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path='/tmp/config_path.conf',
            keyfile='./tests/fixtures/thumbor.key',
            log_level='debug',
            app_class='server.app',
        )

        cfg = Config(APP_CLASS='config.app', )
        importer = Importer(cfg)
        ctx = Context(config=cfg, importer=importer, server=server)

        expect(ctx.app_class).to_equal('server.app')
    def get_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "tests.stub_file_loader"
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.QUALITY = 'keep'
        cfg.SVG_DPI = 200

        self.image = 'http://test.domain/image.jpg'
        self.quoted_image = quote(self.image, safe='')
        self.transform = '400x400/smart'
        self.signature = UrlSigner(security_key="ACME-SEC").signature(
            '%s/%s' % (self.transform, self.quoted_image))
        self.signed_prefix = "/%s/%s" % (self.signature, self.transform)
        self.full_image = "/%s/%s/%s" % (self.signature, self.transform,
                                         self.quoted_image)

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(
            8889, 'localhost', 'thumbor.conf', None, 'info',
            'thumbor_flexible_validation.app.ThumborServiceProxy')
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
        def topic(self):
            config = Config()
            server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                      'info', None)
            config.PILLOW_JPEG_SUBSAMPLING = 2
            config.PILLOW_JPEG_QTABLES = 'web_high'
            context = Context(server, config, Importer(config))

            with open("%s/quantization.jpg" % FIXTURES_FOLDER, "rb") as f:
                buffer = f.read()

            engine = PIL.Engine(context=context)
            engine.load(buffer, '.jpg')
            engine.read('.jpg', None)

            return engine.image
Exemple #54
0
def get_app(prevent_result_storage=False, detection_error=False):
    cfg = Config.load(fixture_for('max_age_conf.py'))
    server_params = ServerParameters(None, None, None, None, None, None)

    cfg.DETECTORS = []
    if prevent_result_storage:
        cfg.DETECTORS.append('fixtures.prevent_result_storage_detector')
    if detection_error:
        cfg.DETECTORS.append('fixtures.detection_error_detector')

    importer = Importer(cfg)
    importer.import_modules()
    ctx = Context(server_params, cfg, importer)
    application = ThumborServiceApp(ctx)

    return application
Exemple #55
0
        def topic(self):
            config = Config()
            server = ServerParameters(
                8889, 'localhost', 'thumbor.conf', None, 'info', None
            )

            context = Context(server, config, Importer(config))
            context.server.gifsicle_path = which('gifsicle')

            context.request = RequestParameters()

            with open("%s/animated_image.gif" % FIXTURES_FOLDER, "rb") as f:
                buffer = f.read()

            engine = GifEngine(context=context)
            engine.load(buffer, '.gif')

            return engine.read()
Exemple #56
0
    def get_app(self):
        file_storage_root_path = '/tmp/thumbor-vows/storage'
        if exists(file_storage_root_path):
            rmtree(file_storage_root_path)

        cfg = Config()
        cfg.USE_BLACKLIST = True
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = abspath(join(dirname(__file__), 'fixtures/'))
        cfg.STORAGE = 'thumbor.storages.file_storage'
        cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path

        importer = Importer(cfg)
        importer.import_modules()

        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'debug', None)
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)
        return application
def start_thumbor():
    """
    Runs thumbor server with the specified arguments.
    """
    try:
        server_parameters = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path=None,
            keyfile=False,
            log_level=log_level,
            app_class='thumbor.app.ThumborServiceApp',
            use_environment=True)
        global config
        # SO-SIH-167 - 08/08/2018 - Allowing environment variable
        # Passing environment variable flag to server parameters
        config = get_config(thumbor_config_path,
                            server_parameters.use_environment)
        configure_log(config, server_parameters.log_level)
        importer = get_importer(config)
        os.environ["PATH"] += os.pathsep + '/var/task'
        validate_config(config, server_parameters)
        with get_context(server_parameters, config,
                         importer) as thumbor_context:
            application = get_application(thumbor_context)
            run_server(application, thumbor_context)
            tornado.ioloop.IOLoop.instance().start()
            logging.info(
                'thumbor running at %s:%d' %
                (thumbor_context.server.ip, thumbor_context.server.port))
            return config
    except RuntimeError as error:
        if str(error) != "IOLoop is already running":
            logging.error('start_thumbor RuntimeError: %s' % (error))
            stop_thumbor()
    except Exception as error:
        stop_thumbor()
        logging.error('start_thumbor error: %s' % (error))
        logging.error('start_thumbor trace: %s' % traceback.format_exc())
Exemple #58
0
    def test_can_create_server_parameters(self):
        params = ServerParameters(
            port=8888,
            ip='0.0.0.0',
            config_path='/tmp/config_path.conf',
            keyfile='./tests/fixtures/thumbor.key',
            log_level='debug',
            app_class='app',
            fd='fd',
            gifsicle_path='gifsicle_path',
        )

        expect(params.port).to_equal(8888)
        expect(params.ip).to_equal('0.0.0.0')
        expect(params.config_path).to_equal('/tmp/config_path.conf')
        expect(params.keyfile).to_equal('./tests/fixtures/thumbor.key')
        expect(params.log_level).to_equal('debug')
        expect(params.app_class).to_equal('app')
        expect(params._security_key).to_equal('SECURITY_KEY_FILE')
        expect(params.fd).to_equal('fd')
        expect(params.gifsicle_path).to_equal('gifsicle_path')

        expect(params.security_key).to_equal('SECURITY_KEY_FILE')
Exemple #59
0
    def test_can_create_server_parameters():
        params = ServerParameters(
            port=8888,
            ip="0.0.0.0",
            config_path="/my/config_path.conf",
            keyfile="./tests/fixtures/thumbor.key",
            log_level="debug",
            app_class="app",
            fd="fd",
            gifsicle_path="gifsicle_path",
        )

        expect(params.port).to_equal(8888)
        expect(params.ip).to_equal("0.0.0.0")
        expect(params.config_path).to_equal("/my/config_path.conf")
        expect(params.keyfile).to_equal("./tests/fixtures/thumbor.key")
        expect(params.log_level).to_equal("debug")
        expect(params.app_class).to_equal("app")
        expect(params._security_key).to_equal(  # pylint: disable=protected-access
            "SECURITY_KEY_FILE")
        expect(params.fd).to_equal("fd")
        expect(params.gifsicle_path).to_equal("gifsicle_path")

        expect(params.security_key).to_equal("SECURITY_KEY_FILE")
Exemple #60
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        server_params = ServerParameters(None, None, None, None, None, None)

        cfg.DETECTORS = [
            'thumbor.detectors.face_detector',
            'thumbor.detectors.profile_detector',
            'thumbor.detectors.glasses_detector',
            'thumbor.detectors.feature_detector',
        ]
        cfg.STORAGE = 'thumbor.storages.no_storage'
        cfg.LOADER = 'thumbor.loaders.file_loader'
        cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__),
                                                 'imgs')
        cfg.ENGINE = getattr(self, 'engine', None)
        if not cfg.ENGINE:
            return None

        importer = Importer(cfg)
        importer.import_modules()
        ctx = Context(server_params, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application