def test_deserialize_validator(): concrete = [ validators.block_internal_ips(), validators.ensure_port(80, 443, 21, 6453), validators.ensure_protocol('https', 'http', 'ftp'), validators.block_cidr_network('192.168.0.0/16'), ] svalidators = [validators.serialize_validator(v) for v in concrete] re = [validators.deserialize_validator(v) for v in svalidators] with pytest.raises(SecurityError): re[0]('127.0.0.1') re[0]('123.123.123.123') with pytest.raises(SecurityError): re[1]('http://example.com:1234') re[1]('http://example.com') re[1]('http://example.com:80') re[1]('http://example.com:6453') with pytest.raises(SecurityError): re[2]('gopher://mozilla') re[2]('http://example.com:80/path/?q=1') re[2]('https://example.com') re[2]('ftp://example.com') with pytest.raises(SecurityError): re[3]('192.168.3.1') re[3]('123.123.123.123')
INSTALLED_APPS += ('django_extensions', ) # TESTING # ------------------------------------------------------------------------------ TEST_RUNNER = 'django.test.runner.DiscoverRunner' ########## CELERY # In development, all tasks will be executed locally by blocking until the task returns CELERY_ALWAYS_EAGER = True #INSTALLED_APPS += ('kombu.transport.django',) ########## END CELERY # Your local stuff: Below this line define 3rd party library settings THORN_RECIPIENT_VALIDATORS = [ thorn_validators.ensure_protocol('http', 'https'), thorn_validators.ensure_port(80, 443, 8080, 8000), ] # print logging to the console LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'simple': { 'format': '%(asctime)s %(levelname)s %(module)s: %(message)s' }, }, 'filters': { 'require_debug_true': { '()': 'django.utils.log.RequireDebugTrue', },