2020-06-08 05:56:03 +02:00
|
|
|
import os
|
|
|
|
from typing import Dict, List, Tuple
|
|
|
|
|
|
|
|
import ldap
|
|
|
|
from django_auth_ldap.config import LDAPSearch
|
|
|
|
|
|
|
|
from zerver.lib.db import TimeTrackingConnection
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-06-08 05:56:03 +02:00
|
|
|
from .config import DEPLOY_ROOT, get_from_file_if_exists
|
|
|
|
from .settings import (
|
|
|
|
AUTHENTICATION_BACKENDS,
|
|
|
|
CACHES,
|
|
|
|
DATABASES,
|
|
|
|
EXTERNAL_HOST,
|
|
|
|
LOCAL_DATABASE_PASSWORD,
|
|
|
|
LOGGING,
|
|
|
|
WEBPACK_LOADER,
|
|
|
|
)
|
|
|
|
|
|
|
|
FAKE_EMAIL_DOMAIN = "zulip.testserver"
|
|
|
|
|
|
|
|
# Clear out the REALM_HOSTS set in dev_settings.py
|
|
|
|
REALM_HOSTS: Dict[str, str] = {}
|
|
|
|
|
|
|
|
# Used to clone DBs in backend tests.
|
|
|
|
BACKEND_DATABASE_TEMPLATE = 'zulip_test_template'
|
|
|
|
|
|
|
|
DATABASES["default"] = {
|
|
|
|
"NAME": os.getenv("ZULIP_DB_NAME", "zulip_test"),
|
|
|
|
"USER": "zulip_test",
|
|
|
|
"PASSWORD": LOCAL_DATABASE_PASSWORD,
|
|
|
|
"HOST": "localhost",
|
|
|
|
"SCHEMA": "zulip",
|
|
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
|
|
"TEST_NAME": "django_zulip_tests",
|
|
|
|
"OPTIONS": {"connection_factory": TimeTrackingConnection},
|
|
|
|
}
|
|
|
|
|
|
|
|
TORNADO_SERVER = os.environ.get("TORNADO_SERVER")
|
|
|
|
if TORNADO_SERVER is not None:
|
|
|
|
# This covers the Casper test suite case
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# This covers the backend test suite case
|
|
|
|
CAMO_URI = 'https://external-content.zulipcdn.net/external_content/'
|
|
|
|
CAMO_KEY = 'dummy'
|
|
|
|
|
|
|
|
CASPER_TESTS = "CASPER_TESTS" in os.environ
|
|
|
|
if CASPER_TESTS:
|
|
|
|
# Disable search pills prototype for production use
|
|
|
|
SEARCH_PILLS_ENABLED = False
|
|
|
|
|
|
|
|
if "RUNNING_OPENAPI_CURL_TEST" in os.environ:
|
|
|
|
RUNNING_OPENAPI_CURL_TEST = True
|
|
|
|
|
|
|
|
if "GENERATE_STRIPE_FIXTURES" in os.environ:
|
|
|
|
GENERATE_STRIPE_FIXTURES = True
|
|
|
|
|
|
|
|
# Decrease the get_updates timeout to 1 second.
|
|
|
|
# This allows CasperJS to proceed quickly to the next test step.
|
|
|
|
POLL_TIMEOUT = 1000
|
|
|
|
|
|
|
|
# Stores the messages in `django.core.mail.outbox` rather than sending them.
|
|
|
|
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
|
|
|
|
|
|
|
# The test suite uses EmailAuthBackend
|
|
|
|
AUTHENTICATION_BACKENDS += ('zproject.backends.EmailAuthBackend',)
|
|
|
|
|
|
|
|
# Configure Google OAuth2
|
|
|
|
GOOGLE_OAUTH2_CLIENT_ID = "test_client_id"
|
|
|
|
|
|
|
|
# Makes testing LDAP backend require less mocking
|
|
|
|
AUTH_LDAP_ALWAYS_UPDATE_USER = False
|
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=zulip,dc=com",
|
|
|
|
ldap.SCOPE_ONELEVEL, "(uid=%(user)s)")
|
|
|
|
AUTH_LDAP_USERNAME_ATTR = "uid"
|
|
|
|
AUTH_LDAP_REVERSE_EMAIL_SEARCH = LDAPSearch("ou=users,dc=zulip,dc=com",
|
|
|
|
ldap.SCOPE_ONELEVEL,
|
|
|
|
"(mail=%(email)s)")
|
|
|
|
|
|
|
|
TEST_SUITE = True
|
|
|
|
RATE_LIMITING = False
|
|
|
|
RATE_LIMITING_AUTHENTICATE = False
|
|
|
|
# Don't use rabbitmq from the test suite -- the user_profile_ids for
|
|
|
|
# any generated queue elements won't match those being used by the
|
|
|
|
# real app.
|
|
|
|
USING_RABBITMQ = False
|
|
|
|
|
|
|
|
# Disable the tutorial because it confuses the client tests.
|
|
|
|
TUTORIAL_ENABLED = False
|
|
|
|
|
|
|
|
# Disable use of memcached for caching
|
|
|
|
CACHES['database'] = {
|
|
|
|
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
|
|
|
'LOCATION': 'zulip-database-test-cache',
|
|
|
|
'TIMEOUT': 3600,
|
|
|
|
'CONN_MAX_AGE': 600,
|
|
|
|
'OPTIONS': {
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
'MAX_ENTRIES': 100000,
|
|
|
|
},
|
2020-06-08 05:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Disable caching on sessions to make query counts consistent
|
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.db"
|
|
|
|
|
|
|
|
# Use production config from Webpack in tests
|
|
|
|
if CASPER_TESTS:
|
|
|
|
WEBPACK_FILE = 'webpack-stats-production.json'
|
|
|
|
else:
|
|
|
|
WEBPACK_FILE = os.path.join('var', 'webpack-stats-test.json')
|
|
|
|
WEBPACK_LOADER['DEFAULT']['BUNDLE_DIR_NAME'] = 'webpack-bundles/'
|
|
|
|
WEBPACK_LOADER['DEFAULT']['STATS_FILE'] = os.path.join(DEPLOY_ROOT, WEBPACK_FILE)
|
|
|
|
|
|
|
|
# Don't auto-restart Tornado server during automated tests
|
|
|
|
AUTORELOAD = False
|
|
|
|
|
|
|
|
if not CASPER_TESTS:
|
|
|
|
# Use local memory cache for backend tests.
|
|
|
|
CACHES['default'] = {
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
2020-06-08 05:56:03 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 01:29:34 +02:00
|
|
|
# This logger is used only for automated tests validating the
|
|
|
|
# error-handling behavior of the zulip_admins handler.
|
|
|
|
LOGGING['loggers']['zulip.test_zulip_admins_handler'] = {
|
|
|
|
'handlers': ['zulip_admins'],
|
|
|
|
'propagate': False,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Here we set various loggers to be less noisy for unit tests.
|
2020-06-08 05:56:03 +02:00
|
|
|
def set_loglevel(logger_name: str, level: str) -> None:
|
|
|
|
LOGGING['loggers'].setdefault(logger_name, {})['level'] = level
|
|
|
|
set_loglevel('zulip.requests', 'CRITICAL')
|
|
|
|
set_loglevel('zulip.management', 'CRITICAL')
|
|
|
|
set_loglevel('django.request', 'ERROR')
|
|
|
|
set_loglevel('django_auth_ldap', 'WARNING')
|
|
|
|
set_loglevel('fakeldap', 'ERROR')
|
|
|
|
set_loglevel('zulip.send_email', 'ERROR')
|
|
|
|
set_loglevel('zerver.lib.push_notifications', 'WARNING')
|
|
|
|
set_loglevel('zerver.lib.digest', 'ERROR')
|
|
|
|
set_loglevel('zerver.lib.email_mirror', 'ERROR')
|
|
|
|
set_loglevel('zerver.worker.queue_processors', 'WARNING')
|
|
|
|
set_loglevel('stripe', 'WARNING')
|
|
|
|
|
|
|
|
# Enable file:/// hyperlink support by default in tests
|
|
|
|
ENABLE_FILE_LINKS = True
|
|
|
|
|
|
|
|
# These settings are set dynamically in `zerver/lib/test_runner.py`:
|
|
|
|
TEST_WORKER_DIR = ''
|
|
|
|
# Allow setting LOCAL_UPLOADS_DIR in the environment so that the
|
|
|
|
# Casper/API tests in test_server.py can control this.
|
|
|
|
if "LOCAL_UPLOADS_DIR" in os.environ:
|
|
|
|
LOCAL_UPLOADS_DIR = os.getenv("LOCAL_UPLOADS_DIR")
|
|
|
|
# Otherwise, we use the default value from dev_settings.py
|
|
|
|
|
|
|
|
S3_KEY = 'test-key'
|
|
|
|
S3_SECRET_KEY = 'test-secret-key'
|
|
|
|
S3_AUTH_UPLOADS_BUCKET = 'test-authed-bucket'
|
|
|
|
S3_AVATAR_BUCKET = 'test-avatar-bucket'
|
|
|
|
|
|
|
|
INLINE_URL_EMBED_PREVIEW = False
|
|
|
|
|
|
|
|
HOME_NOT_LOGGED_IN = '/login/'
|
|
|
|
LOGIN_URL = '/accounts/login/'
|
|
|
|
|
|
|
|
# By default will not send emails when login occurs.
|
|
|
|
# Explicitly set this to True within tests that must have this on.
|
|
|
|
SEND_LOGIN_EMAILS = False
|
|
|
|
|
|
|
|
GOOGLE_OAUTH2_CLIENT_ID = "id"
|
|
|
|
GOOGLE_OAUTH2_CLIENT_SECRET = "secret"
|
|
|
|
|
|
|
|
SOCIAL_AUTH_GITHUB_KEY = "key"
|
|
|
|
SOCIAL_AUTH_GITHUB_SECRET = "secret"
|
|
|
|
SOCIAL_AUTH_GITLAB_KEY = "key"
|
|
|
|
SOCIAL_AUTH_GITLAB_SECRET = "secret"
|
|
|
|
SOCIAL_AUTH_GOOGLE_KEY = "key"
|
|
|
|
SOCIAL_AUTH_GOOGLE_SECRET = "secret"
|
|
|
|
SOCIAL_AUTH_SUBDOMAIN = 'auth'
|
|
|
|
SOCIAL_AUTH_APPLE_SERVICES_ID = 'com.zulip.chat'
|
2020-06-26 12:22:48 +02:00
|
|
|
SOCIAL_AUTH_APPLE_APP_ID = 'com.zulip.bundle.id'
|
2020-06-08 05:56:03 +02:00
|
|
|
SOCIAL_AUTH_APPLE_CLIENT = 'com.zulip.chat'
|
2020-06-26 12:22:48 +02:00
|
|
|
SOCIAL_AUTH_APPLE_AUDIENCE = [SOCIAL_AUTH_APPLE_APP_ID, SOCIAL_AUTH_APPLE_SERVICES_ID]
|
2020-06-08 05:56:03 +02:00
|
|
|
SOCIAL_AUTH_APPLE_KEY = 'KEYISKEY'
|
|
|
|
SOCIAL_AUTH_APPLE_TEAM = 'TEAMSTRING'
|
|
|
|
SOCIAL_AUTH_APPLE_SECRET = get_from_file_if_exists("zerver/tests/fixtures/apple/private_key.pem")
|
|
|
|
|
|
|
|
APPLE_JWK = get_from_file_if_exists("zerver/tests/fixtures/apple/jwk")
|
|
|
|
APPLE_ID_TOKEN_GENERATION_KEY = get_from_file_if_exists("zerver/tests/fixtures/apple/token_gen_private_key")
|
|
|
|
|
|
|
|
VIDEO_ZOOM_CLIENT_ID = "client_id"
|
|
|
|
VIDEO_ZOOM_CLIENT_SECRET = "client_secret"
|
|
|
|
|
2020-04-27 22:41:31 +02:00
|
|
|
BIG_BLUE_BUTTON_SECRET = "123"
|
|
|
|
BIG_BLUE_BUTTON_URL = "https://bbb.example.com/bigbluebutton/"
|
|
|
|
|
2020-06-08 05:56:03 +02:00
|
|
|
# By default two factor authentication is disabled in tests.
|
|
|
|
# Explicitly set this to True within tests that must have this on.
|
|
|
|
TWO_FACTOR_AUTHENTICATION_ENABLED = False
|
|
|
|
PUSH_NOTIFICATION_BOUNCER_URL = None
|
|
|
|
|
|
|
|
THUMBOR_URL = 'http://127.0.0.1:9995'
|
|
|
|
THUMBNAIL_IMAGES = True
|
|
|
|
THUMBOR_SERVES_CAMO = True
|
|
|
|
|
|
|
|
# Logging the emails while running the tests adds them
|
|
|
|
# to /emails page.
|
|
|
|
DEVELOPMENT_LOG_EMAILS = False
|
|
|
|
|
|
|
|
SOCIAL_AUTH_SAML_SP_ENTITY_ID = 'http://' + EXTERNAL_HOST
|
|
|
|
SOCIAL_AUTH_SAML_SP_PUBLIC_CERT = get_from_file_if_exists("zerver/tests/fixtures/saml/zulip.crt")
|
|
|
|
SOCIAL_AUTH_SAML_SP_PRIVATE_KEY = get_from_file_if_exists("zerver/tests/fixtures/saml/zulip.key")
|
|
|
|
|
|
|
|
SOCIAL_AUTH_SAML_ORG_INFO = {
|
|
|
|
"en-US": {
|
|
|
|
"name": "example",
|
|
|
|
"displayname": "Example Inc.",
|
2020-06-13 08:59:37 +02:00
|
|
|
"url": "{}{}".format('http://', EXTERNAL_HOST),
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
},
|
2020-06-08 05:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SOCIAL_AUTH_SAML_TECHNICAL_CONTACT = {
|
|
|
|
"givenName": "Tech Gal",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"emailAddress": "technical@example.com",
|
2020-06-08 05:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
|
|
|
|
"givenName": "Support Guy",
|
|
|
|
"emailAddress": "support@example.com",
|
|
|
|
}
|
|
|
|
|
|
|
|
SOCIAL_AUTH_SAML_ENABLED_IDPS = {
|
|
|
|
"test_idp": {
|
|
|
|
"entity_id": "https://idp.testshib.org/idp/shibboleth",
|
|
|
|
"url": "https://idp.testshib.org/idp/profile/SAML2/Redirect/SSO",
|
|
|
|
"x509cert": get_from_file_if_exists("zerver/tests/fixtures/saml/idp.crt"),
|
|
|
|
"attr_user_permanent_id": "email",
|
|
|
|
"attr_first_name": "first_name",
|
|
|
|
"attr_last_name": "last_name",
|
|
|
|
"attr_username": "email",
|
|
|
|
"attr_email": "email",
|
|
|
|
"display_name": "Test IdP",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
},
|
2020-06-08 05:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RATE_LIMITING_RULES: Dict[str, List[Tuple[int, int]]] = {
|
|
|
|
'api_by_user': [],
|
|
|
|
'authenticate_by_username': [],
|
|
|
|
'password_reset_form_by_email': [],
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE_TRIAL_DAYS = None
|