Skip to content

Commit 1dfed4b

Browse files
committed
Ensure default password for TigaUser
1 parent 05e7a2f commit 1dfed4b

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.2.25 on 2025-10-28 14:49
2+
3+
from django.db import migrations, models
4+
import tigaserver_app.models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('tigaserver_app', '0086_auto_20251016_1353'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='tigauser',
16+
name='password',
17+
field=models.CharField(default=tigaserver_app.models.get_default_password_hash, max_length=128, verbose_name='password'),
18+
),
19+
]

tigaserver_app/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from django.conf import settings
2121
from django.contrib.auth import get_user_model
22+
from django.contrib.auth.hashers import make_password
2223
from django.contrib.auth.models import AbstractBaseUser, AnonymousUser
2324
from django.contrib.gis.db import models
2425
from django.contrib.gis.db.models.functions import Distance as DistanceFunction
@@ -170,14 +171,17 @@ class RankingData(models.Model):
170171
score_v2 = models.IntegerField()
171172
last_update = models.DateTimeField(help_text="Last time ranking data was updated", null=True, blank=True)
172173

174+
def get_default_password_hash():
175+
return make_password(settings.DEFAULT_TIGAUSER_PASSWORD)
176+
173177
class TigaUser(UserRolePermissionMixin, AbstractBaseUser, AnonymousUser):
174178
AVAILABLE_LANGUAGES = [
175179
(standarize_language_tag(code), Language.get(code).autonym().title()) for code, _ in settings.LANGUAGES
176180
]
177181

178182
USERNAME_FIELD = 'pk'
179183

180-
password = models.CharField(_('password'), max_length=128, null=True, blank=True)
184+
password = models.CharField(_('password'), max_length=128, default=get_default_password_hash)
181185

182186
user_UUID = models.CharField(max_length=36, primary_key=True, default=uuid.uuid4, editable=False, help_text='UUID randomly generated on '
183187
'phone to identify each unique user. Must be exactly 36 '

tigaserver_app/tests/tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,9 @@ def setUp(self):
24602460
self.global_topic = NotificationTopic.objects.create(topic_code='global')
24612461
self.language_topic = NotificationTopic.objects.create(topic_code='en')
24622462

2463+
@override_settings(
2464+
DEFAULT_TIGAUSER_PASSWORD='DEFAULT_PASSWORD_FOR_TESTS'
2465+
)
24632466
def test_POST_new_user(self):
24642467
self.client.force_authenticate(user=self.mobile_user)
24652468
new_user_uuid = uuid.uuid4()
@@ -2482,6 +2485,8 @@ def test_POST_new_user(self):
24822485

24832486
user = TigaUser.objects.get(pk=str(new_user_uuid))
24842487

2488+
self.assertTrue(user.check_password('DEFAULT_PASSWORD_FOR_TESTS'))
2489+
24852490
# Check if the user is subscribed to the global topic
24862491
self.assertTrue(UserSubscription.objects.filter(user=user, topic=self.global_topic).exists())
24872492

tigaserver_project/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
SECRET_KEY = 'h0v(25z3u9yquh+01+#%tj@7iyk*raq!-6)jwz+0ac^h2grd0@'
3434

35+
# Change this in prod
36+
DEFAULT_TIGAUSER_PASSWORD = 'TEST_PASSWORD'
37+
3538
# SECURITY WARNING: don't run with debug turned on in production!
3639
DEBUG = False
3740

0 commit comments

Comments
 (0)