Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bool_validation():
c = config.Config()
assert c.preload_app is False
c.set("preload_app", True)
assert c.preload_app is True
c.set("preload_app", "true")
assert c.preload_app is True
c.set("preload_app", "false")
assert c.preload_app is False
pytest.raises(ValueError, c.set, "preload_app", "zilch")
pytest.raises(TypeError, c.set, "preload_app", 4)
def test_get_username_handles_malformed_basic_auth_header():
"""Should catch a malformed auth header"""
request = SimpleNamespace(headers=())
response = SimpleNamespace(
status='200', response_length=1024, sent=1024,
headers=(('Content-Type', 'text/plain'),),
)
environ = {
'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
'SERVER_PROTOCOL': 'HTTP/1.1',
'HTTP_AUTHORIZATION': 'Basic ixsTtkKzIpVTncfQjbBcnoRNoDfbnaXG',
}
logger = Logger(Config())
atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
assert atoms['u'] == '-'
def test_prefix_multiple_dots():
c = Config()
c.set("statsd_prefix", "test...")
logger = Statsd(c)
logger.sock = MockSocket(False)
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
def test_always_use_configured_logger():
c = config.Config()
c.set('logger_class', __name__ + '.MyLogger')
assert c.logger_class == MyLogger
c.set('statsd_host', 'localhost:12345')
# still uses custom logger over statsd
assert c.logger_class == MyLogger
def test_defaults():
c = config.Config()
for s in config.KNOWN_SETTINGS:
assert c.settings[s.name].validator(s.default) == c.settings[s.name].get()
def test_always_use_configured_logger():
c = config.Config()
c.set('logger_class', __name__ + '.MyLogger')
assert c.logger_class == MyLogger
c.set('statsd_host', 'localhost:12345')
# still uses custom logger over statsd
assert c.logger_class == MyLogger
def test_defaults():
c = config.Config()
for s in config.KNOWN_SETTINGS:
assert c.settings[s.name].validator(s.default) == c.settings[s.name].get()
from gunicorn.config import Config
cfg = Config()
cfg.set('proxy_protocol', True)
request = {
"method": "GET",
"uri": uri("/stuff/here?foo=bar"),
"version": (1, 0),
"headers": [
("SERVER", "http://127.0.0.1:5984"),
("CONTENT-TYPE", "application/json"),
("CONTENT-LENGTH", "14")
],
"body": b'{"nom": "nom"}'
}
def run(self, handler):
from gunicorn.arbiter import Arbiter
from gunicorn.config import Config
handler.cfg = Config({'bind': "%s:%d" % (self.host, self.port), 'workers': 4})
arbiter = Arbiter(handler)
arbiter.run()