diff --git a/api/config/settings/common.py b/api/config/settings/common.py index 97a0883384afc6f5017d0c2cf13089b7bb3b23b9..c0ff1e8283bb2286c2ab0cd5080a8911c228e65f 100644 --- a/api/config/settings/common.py +++ b/api/config/settings/common.py @@ -592,3 +592,7 @@ VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = { ] } VERSATILEIMAGEFIELD_SETTINGS = {"create_images_on_demand": False} +RSA_KEY_SIZE = 2048 +# for performance gain in tests, since we don't need to actually create the +# thumbnails +CREATE_IMAGE_THUMBNAILS = env.bool("CREATE_IMAGE_THUMBNAILS", default=True) diff --git a/api/config/settings/local.py b/api/config/settings/local.py index f639fabd8f5e7601aa11b4e34324d3247f4ab5c6..91a202b6465b099588002c5ee4b99a07c9a9ad3a 100644 --- a/api/config/settings/local.py +++ b/api/config/settings/local.py @@ -31,7 +31,6 @@ EMAIL_PORT = 1025 # django-debug-toolbar # ------------------------------------------------------------------------------ -MIDDLEWARE += ("debug_toolbar.middleware.DebugToolbarMiddleware",) # INTERNAL_IPS = ('127.0.0.1', '10.0.2.2',) @@ -45,14 +44,18 @@ DEBUG_TOOLBAR_CONFIG = { # django-extensions # ------------------------------------------------------------------------------ # INSTALLED_APPS += ('django_extensions', ) -INSTALLED_APPS += ("debug_toolbar",) + +# Debug toolbar is slow, we disable it for tests +DEBUG_TOOLBAR_ENABLED = env.bool("DEBUG_TOOLBAR_ENABLED", default=DEBUG) +if DEBUG_TOOLBAR_ENABLED: + MIDDLEWARE += ("debug_toolbar.middleware.DebugToolbarMiddleware",) + INSTALLED_APPS += ("debug_toolbar",) # TESTING # ------------------------------------------------------------------------------ TEST_RUNNER = "django.test.runner.DiscoverRunner" # CELERY -# In development, all tasks will be executed locally by blocking until the task returns CELERY_TASK_ALWAYS_EAGER = False # END CELERY @@ -72,3 +75,8 @@ LOGGING = { }, } CSRF_TRUSTED_ORIGINS = [o for o in ALLOWED_HOSTS] + + +if env.bool("WEAK_PASSWORDS", default=False): + # Faster during tests + PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",) diff --git a/api/funkwhale_api/federation/keys.py b/api/funkwhale_api/federation/keys.py index e7c30c50aefc866e4ad74b6ef18a2ebaab89cb10..780e149e2305ef2d41b2b941f21bf2e998df7194 100644 --- a/api/funkwhale_api/federation/keys.py +++ b/api/funkwhale_api/federation/keys.py @@ -1,6 +1,8 @@ import re import urllib.parse +from django.conf import settings + from cryptography.hazmat.backends import default_backend as crypto_default_backend from cryptography.hazmat.primitives import serialization as crypto_serialization from cryptography.hazmat.primitives.asymmetric import rsa @@ -8,7 +10,8 @@ from cryptography.hazmat.primitives.asymmetric import rsa KEY_ID_REGEX = re.compile(r"keyId=\"(?P<id>.*)\"") -def get_key_pair(size=2048): +def get_key_pair(size=None): + size = size or settings.RSA_KEY_SIZE key = rsa.generate_private_key( backend=crypto_default_backend(), public_exponent=65537, key_size=size ) diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py index 03e4a9568cf792e9a360febe4672641a95979754..325cdacece4b2d471775bd769124a11cf7cb3e42 100644 --- a/api/funkwhale_api/music/models.py +++ b/api/funkwhale_api/music/models.py @@ -1107,7 +1107,7 @@ def update_request_status(sender, instance, created, **kwargs): @receiver(models.signals.post_save, sender=Album) def warm_album_covers(sender, instance, **kwargs): - if not instance.cover: + if not instance.cover or not settings.CREATE_IMAGE_THUMBNAILS: return album_covers_warmer = VersatileImageFieldWarmer( instance_or_queryset=instance, rendition_key_set="square", image_attr="cover" diff --git a/api/funkwhale_api/users/models.py b/api/funkwhale_api/users/models.py index 79650301e9e68acb01b32c754a249e46b3d30102..32e4869a37fbaa1ac313a2e88e7033ac7e9faeca 100644 --- a/api/funkwhale_api/users/models.py +++ b/api/funkwhale_api/users/models.py @@ -295,7 +295,7 @@ def init_ldap_user(sender, user, ldap_user, **kwargs): @receiver(models.signals.post_save, sender=User) def warm_user_avatar(sender, instance, **kwargs): - if not instance.avatar: + if not instance.avatar or not settings.CREATE_IMAGE_THUMBNAILS: return user_avatar_warmer = VersatileImageFieldWarmer( instance_or_queryset=instance, rendition_key_set="square", image_attr="avatar" diff --git a/api/setup.cfg b/api/setup.cfg index aa9a57abb82f0ce78ff2a927880daa9b49f212d1..4466d626f68de8b786b4acb85bc447dd3c653318 100644 --- a/api/setup.cfg +++ b/api/setup.cfg @@ -19,3 +19,7 @@ env = CELERY_BROKER_URL=memory:// CELERY_TASK_ALWAYS_EAGER=True FEDERATION_HOSTNAME=test.federation + DEBUG_TOOLBAR_ENABLED=False + DEBUG=False + WEAK_PASSWORDS=True + CREATE_IMAGE_THUMBNAILS=False diff --git a/api/tests/conftest.py b/api/tests/conftest.py index 22d8f7ebaf7b41a5249ccd1c307282a13efc03ed..03dbdfa4e53caf36cf40e37c639378ab4517516e 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -410,3 +410,9 @@ def no_api_auth(preferences): def migrator(transactional_db): yield MigrationExecutor(connection) call_command("migrate", interactive=False) + + +@pytest.fixture(autouse=True) +def rsa_small_key(settings): + # smaller size for faster generation, since it's CPU hungry + settings.RSA_KEY_SIZE = 512 diff --git a/changes/changelog.d/648.enhancement b/changes/changelog.d/648.enhancement new file mode 100644 index 0000000000000000000000000000000000000000..acf1fd28574cc81019fcef16e915481cfe3af6d6 --- /dev/null +++ b/changes/changelog.d/648.enhancement @@ -0,0 +1 @@ +Improved test suite speed by reducing / disabling expensive operations (#648)