Skip to content

Commit 64fa30b

Browse files
authored
Merge pull request #247 from dtinit/aaronaej/chore/test-infra-and-cleanup
[PR #1] Fix test infrastructure and safe code cleanup
2 parents fabb09e + 72eb40e commit 64fa30b

7 files changed

Lines changed: 23 additions & 13 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ logs/
3838
# Development files that should not be checked in
3939
testbed/core/management/commands/cleandb.py
4040

41+
# AI tool files
42+
CLAUDE.md
43+
4144
# IDE and editor files
4245
.idea/
4346
.vscode/

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
2-
DJANGO_SETTINGS_MODULE = testbed.settings.development
2+
DJANGO_SETTINGS_MODULE = testbed.settings.test
33
pythonpath = .
44
python_files = test_*.py

testbed/core/forms/__init__.py

Whitespace-only changes.

testbed/core/utils/oauth_utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
2+
import string
23
import secrets # Python's secure random number generator module
34
import base64 # For encoding binary data as text
45
from oauth2_provider.models import get_application_model
5-
from testbed.core.utils.utils import random_client_id, random_client_secret
66

77
logger = logging.getLogger(__name__)
88
Application = get_application_model()
@@ -20,6 +20,17 @@
2020
TOKEN_EXPIRY_SESSION_KEY = 'lola_token_expiry'
2121
TOKEN_SCOPE_SESSION_KEY = 'lola_token_scope'
2222

23+
24+
def random_client_id(length=10):
25+
"""Generate a random alphanumeric OAuth client ID of the given length."""
26+
return ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(length))
27+
28+
29+
def random_client_secret(length=40):
30+
"""Generate a random alphanumeric OAuth client secret of the given length."""
31+
return ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(length))
32+
33+
2334
# Get or create the single OAuth Application for a user.
2435
# This enforces the one-application-per-user approach where each user
2536
# represents an ActivityPub service in the LOLA portability flow.

testbed/core/utils/utils.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

testbed/core/views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from django.urls import reverse
2323
import logging
2424
import requests
25-
from django.urls import reverse
2625
from django.conf import settings
2726
from functools import wraps
2827

@@ -769,7 +768,12 @@ def test_token_exchange_view(request):
769768
context['token_error'] = f"Error: {error_details.get('error', 'Unknown error')}"
770769
if 'error_description' in error_details:
771770
context['token_error'] += f" - {error_details['error_description']}"
772-
except:
771+
except (ValueError, KeyError):
772+
# ValueError catches JSONDecodeError (response body is not valid JSON).
773+
# KeyError is included defensively; in practice it cannot fire here
774+
# because error_details['error_description'] is guarded by the 'in' check above.
775+
# Note: AttributeError/TypeError (non-dict JSON) fall through to the outer
776+
# except Exception handler at the call site with a less precise error message.
773777
logger.warning(f"Response text: {token_response.text}")
774778
context['token_error'] = f"Error: HTTP {token_response.status_code} - {token_response.text}"
775779

testbed/settings/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
DEBUG = False
77
ALLOWED_SEED_COMMAND = True
88
SECRET_KEY = env.str("DJANGO_SECRET_KEY", default="your-dev-secret-key")
9-
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["locahost", "127.0.0.1"])
9+
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["localhost", "127.0.0.1"])
1010
BASE_URL = "http://testserver"
1111

1212
SEED_ADMIN_USERNAME = "admin"

0 commit comments

Comments
 (0)