예제 #1
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_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()
예제 #3
0
def validate(context, url):
    if url.startswith('http://'):
        return False

    return http_loader.validate(context,
                                url,
                                normalize_url_func=_normalize_url)
예제 #4
0
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)
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
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=",  # 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()
예제 #9
0
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)
예제 #10
0
 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()
예제 #11
0
def validate(context, url):
    return http_loader.validate(context, url, normalize_url_func=_normalize_url)
예제 #12
0
 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()
예제 #13
0
 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
예제 #14
0
 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
예제 #15
0
 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
예제 #16
0
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)
예제 #17
0
 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
예제 #18
0
def validate(context, url):
    if url.startswith('http://'):
        return False

    return http_loader.validate(context, url, normalize_url_func=_normalize_url)
예제 #19
0
def validate(context, url):
    return http_loader.validate(context,
                                url,
                                normalize_url_func=_normalize_url)
예제 #20
0
 def topic(self):
     return loader.validate("http://www.google.com/logo.jpg")