Exemple #1
0
        def topic(self):
            config = Config(FILE_STORAGE_ROOT_PATH="/tmp/thumbor/file_storage/")
            root_path = join(config.FILE_STORAGE_ROOT_PATH, dirname(SAME_IMAGE_URL % 999))
            if exists(root_path):
                shutil.rmtree(root_path)

            old_exists = Storage.storages.exists
            Storage.storages.exists = lambda path: False
            try:
                storage = Storage.Storage(Context(config=config, server=get_server('ACME-SEC')))

                storage.put(SAME_IMAGE_URL % 998, IMAGE_BYTES)
                storage.put(SAME_IMAGE_URL % 999, IMAGE_BYTES)
            finally:
                Storage.storages.exists = old_exists

            return storage.get(SAME_IMAGE_URL % 999)
Exemple #2
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

        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 #3
0
    def topic(self):
        conf = Config()
        conf.ENGINE = 'thumbor.engines.pil'
        imp = Importer(conf)
        imp.import_modules()
        imp.filters = [Filter]
        ctx = Context(None, conf, imp)

        for item in DATA:
            ctx.modules.engine.image = ctx.modules.engine.gen_image(item[1],'#fff')
            req = RequestParameters(fit_in=True,width=item[0][0],height=item[0][1])
            ctx.request = req

            filter_instances = ctx.filters_factory.create_instances(ctx, "fill(blue)")

            filter_instances[0].run()
            yield (filter_instances[0].engine.image.size,item[2])
    def to_context(self, detectors=[], ignore_detector_error=False):
        self.engine = MockEngine((self.source_width, self.source_height))

        flip_horizontally = self.target_width < 0
        flip_vertically = self.target_height < 0
        self.target_width = self.target_width == "orig" and "orig" or abs(
            self.target_width)
        self.target_height = self.target_height == "orig" and "orig" or abs(
            self.target_height)

        importer = Importer(None)
        importer.detectors = detectors
        importer.storage = NoStorage
        config = Config()
        config.IGNORE_SMART_ERRORS = ignore_detector_error
        ctx = Context(server=None, config=config, importer=importer)
        ctx.modules.engine = self.engine

        ctx.request = RequestParameters(buffer=None,
                                        debug=False,
                                        meta=self.meta,
                                        crop={
                                            'left': self.crop_left,
                                            'top': self.crop_top,
                                            'right': self.crop_right,
                                            'bottom': self.crop_bottom
                                        },
                                        adaptive=self.adaptive,
                                        full=self.full,
                                        fit_in=self.fit_in,
                                        horizontal_flip=flip_horizontally,
                                        vertical_flip=flip_vertically,
                                        width=self.target_width,
                                        height=self.target_height,
                                        halign=self.halign,
                                        valign=self.valign,
                                        focal_points=self.focal_points,
                                        smart=True,
                                        extension="JPEG",
                                        filters=[],
                                        quality=80,
                                        image="some.jpeg")
        ctx.request.engine = self.engine
        ctx.request.engine.extension = ".jpeg"

        return ctx
Exemple #5
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 #6
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 #7
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 #8
0
    def get_app(self):
        self.default_filename = 'image'

        cfg = Config()
        cfg.UPLOAD_ENABLED = True
        cfg.UPLOAD_PHOTO_STORAGE = 'thumbor.storages.file_storage'
        cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path
        cfg.UPLOAD_DELETE_ALLOWED = True
        cfg.UPLOAD_PUT_ALLOWED = False
        cfg.UPLOAD_DEFAULT_FILENAME = self.default_filename

        importer = Importer(cfg)
        importer.import_modules()

        ctx = Context(None, 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
        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 #10
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.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 #11
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,
                     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
    def test_can_load_image(self):
        client = botocore.session.get_session().create_client('s3')
        client.create_bucket(Bucket=s3_bucket)

        client.put_object(
            Bucket=s3_bucket,
            Key=''.join(['root_path', IMAGE_PATH]),
            Body=IMAGE_BYTES,
            ContentType='image/jpeg',
        )

        conf = Config(
            TC_AWS_LOADER_BUCKET=s3_bucket,
            TC_AWS_LOADER_ROOT_PATH='root_path',
        )

        image = yield presigning_loader.load(Context(config=conf), IMAGE_PATH)
        self.assertEqual(image.buffer, IMAGE_BYTES)
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC', OPTIPNG_PATH=which('optipng'), OPTIPNG_LEVEL=1)
        cfg.LOADER = 'thumbor.loaders.file_loader'
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.OPTIMIZERS = [
            'thumbor_plugins.optimizers.optipng',
        ]

        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 #14
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 #15
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 #16
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
    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
Exemple #18
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 test_can_build_presigned_url(self):
        context = Context(config=(Config()))
        url = yield presigning_loader._generate_presigned_url(
            context, "bucket-name", "some-s3-key")

        url = urlparse(url)
        self.assertEqual(url.scheme[0:4], 'http')
        self.assertEqual(url.path, '/bucket-name/some-s3-key')

        url_params = parse_qs(url.query)
        # We can't test Expires & Signature values as they vary depending on the TZ
        self.assertIn('Expires', url_params)
        self.assertIn('Signature', url_params)

        self.assertDictContainsSubset(
            {
                'AWSAccessKeyId': ['test-key'],
                'x-amz-security-token': ['test-session-token']
            }, url_params)
Exemple #20
0
    async def test_watermark_validate_allowed_source(self):
        config = Config(
            ALLOWED_SOURCES=[
                "s.glbimg.com",
            ],
            LOADER="thumbor.loaders.http_loader",
        )
        importer = Importer(config)
        importer.import_modules()

        context = Context(config=config, importer=importer)
        filter_instance = watermark.Filter("", context)

        expect(
            filter_instance.validate("https://s2.glbimg.com/logo.jpg")
        ).to_be_false()
        expect(
            filter_instance.validate("https://s.glbimg.com/logo.jpg")
        ).to_be_true()
Exemple #21
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 #22
0
        def topic(self, callback):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket,
                            TC_AWS_STORE_METADATA=True)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.headers = {
                'Content-Type': 'image/webp',
                'Some-Other-Header': 'doge-header'
            }
            ctx.request = Request
            ctx.request.url = 'my-image-meta.jpg'

            storage = Storage(ctx)
            storage.put(IMAGE_BYTES)

            file_abspath = storage._normalize_path(ctx.request.url)
            storage.storage.get(file_abspath, callback=callback)
Exemple #23
0
 def test_with_allowed_sources(self):
     config = Config()
     config.ALLOWED_SOURCES = [
         's.glbimg.com',
         re.compile(r'https:\/\/www\.google\.com/img/.*')
     ]
     ctx = Context(None, config, None)
     expect(loader.validate(
         ctx, 'http://www.google.com/logo.jpg')).to_be_false()
     expect(loader.validate(ctx,
                            'http://s2.glbimg.com/logo.jpg')).to_be_false()
     expect(
         loader.validate(
             ctx,
             '/glob=:sfoir%20%20%3Co-pmb%20%20%20%20_%20%20%20%200%20%20g.-%3E%3Ca%20hplass='
         )).to_be_false()
     expect(loader.validate(
         ctx, 'https://www.google.com/img/logo.jpg')).to_be_true()
     expect(loader.validate(ctx,
                            'http://s.glbimg.com/logo.jpg')).to_be_true()
    def test_can_store_image_randomly(self):
        config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket,
                        TC_AWS_RANDOMIZE_KEYS=True)
        ctx = Context(config=config, server=get_server('ACME-SEC'))
        ctx.request = Request
        ctx.request.url = 'foo/my-image.jpg'

        storage = Storage(ctx)

        yield storage.put(IMAGE_BYTES)

        expected_path = '/'.join([
            sha1("foo/my-image.jpg".encode('utf-8')).hexdigest(),
            'foo/my-image.jpg'
        ])

        client = botocore.session.get_session().create_client('s3')
        response = client.get_object(Bucket=s3_bucket, Key=expected_path)

        self.assertEqual(response['Body'].read(), IMAGE_BYTES)
Exemple #25
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 #26
0
    def get_filter(self, filter_name, params_string="", config_context=None):
        config = Config(FILTERS=[filter_name], )
        importer = Importer(config)
        importer.import_modules()

        req = RequestParameters()

        context = Context(config=config, importer=importer)
        context.request = req
        context.request.engine = context.modules.engine

        if config_context is not None:
            config_context(context)

        fltr = importer.filters[0]
        fltr.pre_compile()

        context.transformer = Transformer(context)

        return fltr(params_string, context=context)
 def test_with_allowed_sources(self):
     config = Config()
     config.ALLOWED_SOURCES = [
         "s.glbimg.com",
         re.compile(r"https://www\.google\.com/img/.*"),
     ]
     ctx = Context(None, config, None)
     expect(loader.validate(
         ctx, "http://www.google.com/logo.jpg")).to_be_false()
     expect(loader.validate(ctx,
                            "http://s2.glbimg.com/logo.jpg")).to_be_false()
     expect(
         loader.validate(
             ctx,
             "/glob=:sfoir%20%20%3Co-pmb%20%20%20%20_%20%20%20%200%20%20g.-%3E%3Ca%20hplass=",  # NOQA, pylint: disable=line-too-long
         )).to_be_false()
     expect(loader.validate(
         ctx, "https://www.google.com/img/logo.jpg")).to_be_true()
     expect(loader.validate(ctx,
                            "http://s.glbimg.com/logo.jpg")).to_be_true()
Exemple #28
0
        def topic(self):
            self.conn = S3Connection()
            self.conn.create_bucket(s3_bucket)

            config = Config(RESULT_STORAGE_BUCKET=s3_bucket,
                            RESULT_STORAGE_S3_STORE_METADATA=True)
            ctx = Context(config=config, server=get_server('ACME-SEC'))
            ctx.headers = {
                'Content-Type': 'image/webp',
                'Some-Other-Header': 'doge-header'
            }
            ctx.request = Request
            ctx.request.url = 'my-image-meta.jpg'

            storage = Storage(ctx)
            storage.put(IMAGE_BYTES)

            file_abspath = storage.normalize_path(ctx.request.url)
            file_key = storage.storage.get_key(file_abspath)
            return file_key.content_type, file_key.metadata, file_key.read()
Exemple #29
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 #30
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