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_with_allowed_sources(self): config = Config() config.ALLOWED_SOURCES = ["s.glbimg.com"] 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, "http://s.glbimg.com/logo.jpg")).to_be_true()
def validate(context, url): if url.startswith('http://'): return False return http_loader.validate(context, url, normalize_url_func=_normalize_url)
def _validate(context, url, normalize_url_func): if _use_http_loader(context, url): return http_loader.validate( context, url, normalize_url_func=http_loader._normalize_url) bucket, key = _get_bucket_and_key(context, url) return _validate_bucket(context, bucket)
def topic(self): config = Config() config.ALLOWED_SOURCES = [] ctx = Context(None, config, None) is_valid = loader.validate(ctx, 'http://www.google.com/logo.jpg') return is_valid
def topic(self): config = Config() config.ALLOWED_SOURCES = ['s.glbimg.com'] ctx = Context(None, config, None) is_valid = loader.validate(ctx, 'http://s2.glbimg.com/logo.jpg') return is_valid
def topic(self): config = Config() config.ALLOWED_SOURCES = ['s2.glbimg.com'] ctx = Context(None, config, None) is_valid = loader.validate( ctx, '/glob=:sfoir%20%20%3Co-pmb%20%20%20%20_%20%20%20%200%20%20g.-%3E%3Ca%20hplass=' ) return is_valid
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()
async def load(context, path): # First attempt to load with file_loader result = await file_loader.load(context, path) if result.successful: return result # If file_loader failed try http_loader if not http_loader.validate(context, path): result = LoaderResult() result.successful = False result.error = LoaderResult.ERROR_BAD_REQUEST result.extras["reason"] = "Unallowed domain" result.extras["source"] = path return result return await http_loader.load(context, path)
def test_without_allowed_sources(self): config = Config() config.ALLOWED_SOURCES = [] ctx = Context(None, config, None) is_valid = loader.validate(ctx, 'http://www.google.com/logo.jpg') expect(is_valid).to_be_true()
def validate(context, url): return http_loader.validate(context, url, normalize_url_func=_normalize_url)
def topic(self): config = Config() config.ALLOWED_SOURCES = ['s.glbimg.com'] ctx = Context(None, config, None) is_valid = loader.validate(ctx, 'http://s.glbimg.com/logo.jpg') return is_valid
def topic(self): config = Config() config.ALLOWED_SOURCES = ['s2.glbimg.com'] ctx = Context(None, config, None) is_valid = loader.validate(ctx, '/glob=:sfoir%20%20%3Co-pmb%20%20%20%20_%20%20%20%200%20%20g.-%3E%3Ca%20hplass=') return is_valid
def _validate(context, url, normalize_url_func): if _use_http_loader(context, url): return http_loader.validate(context, url, normalize_url_func=http_loader._normalize_url) bucket, key = _get_bucket_and_key(context, url) return _validate_bucket(context, bucket)
def topic(self): old_sources = options.ALLOWED_SOURCES options.ALLOWED_SOURCES = [] is_valid = loader.validate('http://www.google.com/logo.jpg') options.ALLOWED_SOURCES = old_sources return is_valid
def topic(self): return loader.validate("http://www.google.com/logo.jpg")