Self hosted FLOSS fitness/workout, nutrition and weight tracker
Change used SESSION_ENGINE
Roland Geider6658b2874667
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d8dbc2400..e68359103 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -88,6 +88,8 @@ Also, we now support two-factor authentication like security codes or passkeys.(`POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`) from `prod.env` insteadof having them hardcoded in the yaml file.+* Due to changes in the auth system, you will need to re-login on the website+## Breaking changes*(only relevant if you have your own scripts or interact with the REST API)*diff --git a/settings/main.py b/settings/main.pyindex 900f528c9..88889e27a 100644--- a/settings/main.py+++ b/settings/main.py@@ -151,7 +151,7 @@ ALLOWED_HOSTS = ['*',]-SESSION_ENGINE = 'django.contrib.sessions.backends.cache'+SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'# Configure a real backend in productionif DEBUG:diff --git a/wger/core/tasks.py b/wger/core/tasks.pyindex 4c852955e..875627b0d 100644--- a/wger/core/tasks.py+++ b/wger/core/tasks.py@@ -47,7 +47,7 @@ def flush_expired_jwt_tokens_task():@app.taskdef flush_expired_long_lived_sessions_task():"""- Delete expired DB-backed sessions, i.e. the headless long-lived refresh tokens+ Delete all expired DB-backed sessions"""SessionStore.clear_expired()diff --git a/wger/core/tests/test_apikey.py b/wger/core/tests/test_apikey.pyindex 3d9520579..7e650920c 100644--- a/wger/core/tests/test_apikey.py+++ b/wger/core/tests/test_apikey.py@@ -20,6 +20,7 @@ from datetime import timedelta# Djangofrom django.contrib.auth.models import Userfrom django.contrib.sessions.models import Session+from django.test import override_settingsfrom django.urls import reversefrom django.utils import timezone@@ -273,6 +274,47 @@ class LongLivedRefreshTokenTestCase(WgerTestCase):body = response.json()self.assertIn('access_token', body['data'])+ @override_settings(SESSION_ENGINE='django.contrib.sessions.backends.cached_db')+ def test_refresh_works_under_cache_backed_engine(self):+ """+ With the production-style cache-backed engine, the DB-persisted session+ is still resolved on refresh (via the engine's DB fallback) and returns a+ new access token.+ """+ self.user_login('test')+ user = User.objects.get(username='test')++ token = mint_long_lived_refresh_token(user, lifetime_seconds=120 * 86400)++ api = APIClient()+ response = api.post(+ reverse('headless:app:tokens:refresh'),+ data=json.dumps({'refresh_token': token}),+ content_type='application/json',+ )+ self.assertEqual(response.status_code, 200, response.content)+ self.assertIn('access_token', response.json()['data'])++ @override_settings(SESSION_ENGINE='django.contrib.sessions.backends.cache')+ def test_refresh_fails_under_pure_cache_engine(self):+ """+ A pure-cache session engine cannot read the DB-persisted long-lived+ session, so refresh is rejected. This pins down why the feature requires+ a DB-backed engine in production.+ """+ self.user_login('test')+ user = User.objects.get(username='test')++ token = mint_long_lived_refresh_token(user, lifetime_seconds=120 * 86400)++ api = APIClient()+ response = api.post(+ reverse('headless:app:tokens:refresh'),+ data=json.dumps({'refresh_token': token}),+ content_type='application/json',+ )+ self.assertGreaterEqual(response.status_code, 400)+def test_revoke_invalidates_token(self):"""Revoking a long-lived session breaks the matching refresh token.