Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekj117 committed Jun 25, 2020
1 parent 642cd64 commit bf1d966
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ whether they will be using FreeOTP or a YubiKey for two-factor authentication.

.. note::
We don't allow the username **deleted** as we use it to mark the
journalist which are deleted from the system.
journalists which are deleted from the system.

FreeOTP
^^^^^^^
Expand Down
5 changes: 2 additions & 3 deletions securedrop/journalist_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ def name_length_validation(form, field):


def check_invalid_usernames(form, field):
invalid_usernames = ['deleted']
if field.data in invalid_usernames:
if field.data in Journalist.INVALID_USERNAMES:
raise ValidationError(gettext(
"Invalid username '{}'".format(field.data)))
"Invalid username"))


class NewUserForm(FlaskForm):
Expand Down
8 changes: 4 additions & 4 deletions securedrop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ class Journalist(db.Model):
MIN_USERNAME_LEN = 3
MIN_NAME_LEN = 0
MAX_NAME_LEN = 100
INVALID_USERNAMES = ['deleted']

def __init__(self,
username: str,
Expand Down Expand Up @@ -642,17 +643,16 @@ def login(cls,
password: str,
token: str) -> 'Journalist':

invalid_usernames = ['deleted']

try:
user = Journalist.query.filter_by(username=username).one()
except NoResultFound:
raise InvalidUsernameException(
"invalid username '{}'".format(username))

if user.username in invalid_usernames and user.uuid in invalid_usernames:
if user.username in Journalist.INVALID_USERNAMES and \
user.uuid in Journalist.INVALID_USERNAMES:
raise InvalidUsernameException(
"Invalid username '{}'".format(username))
"Invalid username")

if LOGIN_HARDENING:
cls.throttle_login(user)
Expand Down
2 changes: 1 addition & 1 deletion securedrop/tests/functional/journalist_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def _admin_adds_a_user_with_invalid_username(self):
self.wait_for(lambda: self.driver.find_element_by_css_selector(".form-validation-error"))

error_msg = self.driver.find_element_by_css_selector(".form-validation-error")
assert "Invalid username '{}'".format(invalid_username) in error_msg.text
assert "Invalid username" in error_msg.text

def _admin_adds_a_user(self, is_admin=False, new_username=""):
self.safe_click_by_id("add-user")
Expand Down
2 changes: 1 addition & 1 deletion securedrop/tests/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def test_admin_add_user_with_invalid_username(journalist_app, test_admin):
password=VALID_PASSWORD,
is_admin=None))

assert "Invalid username '{}'".format(username) in resp.data.decode('utf-8')
assert "Invalid username" in resp.data.decode('utf-8')


def test_deleted_user_cannot_login(journalist_app):
Expand Down

0 comments on commit bf1d966

Please sign in to comment.