Skip to content

Commit

Permalink
Check deleted username exception handling using tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekj117 committed Jun 10, 2020
1 parent 0b9ecfd commit 567e5bc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion securedrop/tests/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from db import db
from models import (InvalidPasswordLength, InstanceConfig, Journalist, Reply, Source,
Submission)
InvalidUsernameException, Submission)
from .utils.instrument import InstrumentedApp

# Smugly seed the RNG for deterministic testing
Expand Down Expand Up @@ -1116,6 +1116,25 @@ def test_deleted_user_cannot_login(journalist_app):
assert "Login failed" in text


def test_deleted_user_cannot_login_exception(journalist_app):
username = 'deleted'
uuid = 'deleted'

# Create a user with username and uuid as deleted
with journalist_app.app_context():
user, password = utils.db_helper.init_journalist(is_admin=False)
otp_secret = user.otp_secret
user.username = username
user.uuid = uuid
db.session.add(user)
db.session.commit()

with pytest.raises(InvalidUsernameException):
Journalist.login(username,
password,
TOTP(otp_secret).now())


def test_admin_add_user_without_username(journalist_app, test_admin):
with journalist_app.test_client() as app:
_login_user(app, test_admin['username'], test_admin['password'],
Expand Down

0 comments on commit 567e5bc

Please sign in to comment.