Skip to content

Commit f13b778

Browse files
BB2-3273: Removed password expirations (#1221)
* Removed password expirations * Further out synthetic date. * Minor wording in comment * Switched to config method * Update apps/accounts/validators.py Simplify password reuse condition Co-authored-by: jimmyfagan <[email protected]> * Update apps/accounts/validators.py Simplify password reuse interval comparison Co-authored-by: jimmyfagan <[email protected]> * Update apps/accounts/validators.py Simplify password expire condition Co-authored-by: jimmyfagan <[email protected]> --------- Co-authored-by: jimmyfagan <[email protected]>
1 parent 0b1b219 commit f13b778

File tree

5 files changed

+13
-38
lines changed

5 files changed

+13
-38
lines changed

apps/accounts/tests/test_password_reset_while_authenticated.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,15 @@ def test_password_change_reuse_validation(self):
193193
self.user = User.objects.get(username="fred") # get user again so that you can see password changed
194194
self.assertEquals(self.user.check_password("IchangedTHEpassword#123"), True)
195195

196-
# add 12 minutes to time to expire current password
197-
StubDate.now = classmethod(
198-
lambda cls, timezone: datetime.now().replace(tzinfo=pytz.UTC) + relativedelta(minutes=+12)
199-
)
200-
self.client.logout()
201-
form_data = {'username': 'fred',
202-
'password': 'IchangedTHEpassword#123'}
203-
response = self.client.post(reverse('login'), form_data, follow=True)
204-
self.assertContains(response,
205-
("Your password has expired, change password strongly recommended."))
206-
207196
@override_switch('login', active=True)
208197
@mock.patch("apps.accounts.validators.datetime", StubDate)
209-
def test_password_expire_not_affect_staff(self):
198+
def test_no_password_expire(self):
210199
self.client.logout()
211-
# add 20 minutes to time to show staff is not effected
200+
# add 90 days to time to show expiration is removed
212201
StubDate.now = classmethod(
213-
lambda cls, timezone: datetime.now().replace(tzinfo=pytz.UTC) + relativedelta(minutes=+20)
202+
lambda cls, timezone: datetime.now().replace(tzinfo=pytz.UTC) + relativedelta(days=+90)
214203
)
215-
form_data = {'username': 'staff',
204+
form_data = {'username': 'fred',
216205
'password': 'foobarfoobarfoobar'}
217206
response = self.client.post(reverse('login'), form_data, follow=True)
218207
# assert account dashboard page
@@ -222,8 +211,5 @@ def test_password_expire_not_affect_staff(self):
222211
("The Developer Sandbox lets you register applications to get credentials"))
223212

224213
def test_password_reuse_min_age_validator_args_check(self):
225-
with self.assertRaisesRegex(ValueError,
226-
(".*password_min_age < password_reuse_interval expected.*"
227-
"password_expire < password_reuse_interval expected.*"
228-
"password_min_age < password_expire expected.*")):
229-
PasswordReuseAndMinAgeValidator(60 * 60 * 24 * 30, 60 * 60 * 24 * 10, 60 * 60 * 24 * 20)
214+
with self.assertRaisesRegex(ValueError, ".*password_min_age < password_reuse_interval expected.*"):
215+
PasswordReuseAndMinAgeValidator(60 * 60 * 24 * 30, 60 * 60 * 24 * 10)

apps/accounts/validators.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PasswordReuseAndMinAgeValidator(object):
8686
def __init__(self,
8787
password_min_age=60 * 60 * 24,
8888
password_reuse_interval=60 * 60 * 24 * 120,
89-
password_expire=60 * 60 * 24 * 30):
89+
password_expire=0):
9090

9191
msg1 = "Invalid OPTIONS, password_min_age < password_reuse_interval expected, " \
9292
"but having password_min_age({}) >= password_reuse_interval({})"
@@ -96,14 +96,11 @@ def __init__(self,
9696
"but having password_expire({}) >= password_reuse_interval({})"
9797

9898
check_opt_err = []
99-
if password_min_age > 0 and password_reuse_interval > 0 \
100-
and password_min_age > password_reuse_interval:
99+
if 0 < password_reuse_interval < password_min_age:
101100
check_opt_err.append(msg1.format(password_min_age, password_reuse_interval))
102-
if password_expire > 0 and password_reuse_interval > 0 \
103-
and password_expire > password_reuse_interval:
101+
if 0 < password_reuse_interval < password_expire:
104102
check_opt_err.append(msg2.format(password_expire, password_reuse_interval))
105-
if password_min_age > 0 and password_expire > 0 \
106-
and password_min_age > password_expire:
103+
if 0 < password_expire < password_min_age:
107104
check_opt_err.append(msg3.format(password_min_age, password_expire))
108105
if len(check_opt_err) > 0:
109106
raise ValueError(check_opt_err)
@@ -234,8 +231,7 @@ def password_expired(self, user=None):
234231
except PastPassword.DoesNotExist:
235232
pass
236233
if passwds is not None and passwds.first() is not None:
237-
if (datetime.now(timezone.utc)
238-
- passwds.first().date_created).total_seconds() >= self.password_expire:
234+
if (datetime.now(timezone.utc) - passwds.first().date_created).total_seconds() >= self.password_expire:
239235
# the elapsed time since last password change / create is more than password_expire
240236
passwd_expired = True
241237
return passwd_expired

apps/accounts/views/login.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ def dispatch(self, request, *args, **kwargs):
2121
return super().dispatch(request, *args, **kwargs)
2222

2323
def form_valid(self, form):
24-
"""
25-
Extend django login view to do password expire check
26-
and redirect to password-change instead of user account home
27-
"""
28-
# auth_login(self.request, form.get_user())
2924
response = super().form_valid(form)
3025
if response.status_code == 302:
3126
passwd_validators = get_default_password_validators()

hhs_oauth_server/settings/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
"password_min_age": 60 * 5,
7878
# password reuse interval in seconds (365 days)
7979
"password_reuse_interval": 60 * 60 * 24 * 365,
80-
# password expire in seconds (60 days)
81-
"password_expire": 60 * 60 * 24 * 60,
80+
"password_expire": 0,
8281
},
8382
},
8483
{

hhs_oauth_server/settings/test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
'password_min_age': 60,
6464
# password reuse interval in seconds (50 minutes)
6565
'password_reuse_interval': 3000,
66-
# password expire in seconds (10 minutes)
67-
'password_expire': 600,
66+
'password_expire': 0,
6867
}
6968
},
7069
{

0 commit comments

Comments
 (0)