Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case of deleted journalists #5284

Merged
merged 14 commits into from
Jul 8, 2020

Conversation

prateekj117
Copy link
Contributor

@prateekj117 prateekj117 commented May 30, 2020

Status

Ready for review

Description of Changes

Fixes #5232

Changes proposed in this pull request:

Because of #5178, deleted journalist username and uuid is set to deleted. We should not allow the deleted journalist to login. Also, we can differentiate it from other not deleted journalists whose username is deleted by comparing both the username and uuid rather than just username. Also, we should not allow adding new journalist with username deleted for less confusion.

Testing

How should the reviewer test this PR?

Make a test journalist with username deleted, it would fail (due to changes in form.py file). Undo those changes and make a new journalist with username deleted and try logging in using credentials of that journalist, it should succeed. Change uuid of that journalist to deleted, it should fail to login again for that journalist.

Checklist

If you made changes to the server application code:

  • Linting (make lint) and tests (make test) pass in the development container

If you made changes to securedrop-admin:

  • Linting and tests (make -C admin test) pass in the admin development container

If you made changes to the system configuration:

If you made non-trivial code changes:

  • I have written a test plan and validated it for this PR

Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a list of usernames which will not be allowed, that will enable us to add more such keywords/names safely to the blocking list in future.

We also need required unit and functional tests and also related explanation documentation for the same in the PR.

securedrop/journalist_app/forms.py Outdated Show resolved Hide resolved
@prateekj117
Copy link
Contributor Author

@kushaldas Done. Ready for another review. Let me know if I missed something.

@kushaldas
Copy link
Contributor

@prateekj117 this PR needs a rebase with develop.

@kushaldas
Copy link
Contributor

@prateekj117 Also, can you please add a functional test for the same? As right now the error should propagate to the admin nicely.

@prateekj117 prateekj117 force-pushed the handle-deleted-condition branch 2 times, most recently from f2db3a0 to 997fed7 Compare June 6, 2020 12:39
@prateekj117
Copy link
Contributor Author

@kushaldas Done. Ready for another review.

@prateekj117
Copy link
Contributor Author

@kushaldas One thing that can be missing from here is I think we can also check the exception that is being raised in unit tests. Let me know if that is required.

@prateekj117
Copy link
Contributor Author

Hey @kushaldas. The thing is, it's an endpoint, I am not sure how I will write a test for checking exception raising. app.post won't be able to check the exception as it happens on the server-side and app.post would just return a response. Can you share an example? It would be of great help. Thanks.

@prateekj117
Copy link
Contributor Author

Ok, I think I got what you meant. Added the tests. Let me know if anything else is required.

@kushaldas
Copy link
Contributor

Hey @kushaldas. The thing is, it's an endpoint, I am not sure how I will write a test for checking exception raising. app.post won't be able to check the exception as it happens on the server-side and app.post would just return a response. Can you share an example?

This whole code base is server side. I don't understand what do you mean by endpoint in this case. You have to test that the right error message is showing in the proper way in the web application, Please have a look at https://github.com/freedomofpress/securedrop/blob/develop/securedrop/tests/functional/test_source_notfound.py or any other file in that directory for examples.

@prateekj117
Copy link
Contributor Author

@kushaldas Now that I see the examples, I get it. I will correct it. Thanks !!!

@prateekj117
Copy link
Contributor Author

@kushaldas Done.

@prateekj117 prateekj117 force-pushed the handle-deleted-condition branch 2 times, most recently from d0f7373 to 85327b0 Compare June 24, 2020 12:29
Copy link
Contributor

@rmol rmol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @prateekj117. This looks pretty good. I requested a pedantic grammar change, would like to keep the list of invalid usernames on the Journalist model, and think we should omit invalid usernames from the exception or flash messages.

docs/admin.rst Outdated Show resolved Hide resolved
securedrop/journalist_app/forms.py Outdated Show resolved Hide resolved
securedrop/journalist_app/forms.py Outdated Show resolved Hide resolved
securedrop/models.py Outdated Show resolved Hide resolved
securedrop/models.py Outdated Show resolved Hide resolved
securedrop/models.py Outdated Show resolved Hide resolved
securedrop/tests/functional/journalist_navigation_steps.py Outdated Show resolved Hide resolved
securedrop/tests/test_journalist.py Outdated Show resolved Hide resolved
@prateekj117
Copy link
Contributor Author

@rmol Did the changes. Ready for another review.

rmol
rmol previously approved these changes Jun 25, 2020
Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get some feedback from @ninavizz about adding/showing the invalid usernames in the web form to create a new user.

securedrop/journalist_app/forms.py Outdated Show resolved Hide resolved
securedrop/models.py Show resolved Hide resolved
Copy link
Contributor

@rmol rmol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I've run through the test scenario and confirmed behavior and messaging with the latest changes. Thanks again for your patience and perseverance, @prateekj117.

@rmol rmol dismissed kushaldas’s stale review July 8, 2020 14:54

The behavior is as we specified.

@rmol rmol merged commit 1f91c97 into freedomofpress:develop Jul 8, 2020
@rmol rmol added this to the 1.5.0 milestone Jul 15, 2020
kushaldas added a commit that referenced this pull request Jul 16, 2020
In #5284 we made sure that the username `deleted` is not not allowed
to be added in the system via the admin section of the journalist web
application. But, one could still edit any existing user and change
the name to `deleted`. Or, an admin can add a new user via `manage.py`
in command line.

In PR adds checks to make sure that addiving a new user via `manage.py`
will fail if you try to set the username as `deleted`, it also blocks
editing any existing username to `deleted`.

The PR also includes unit and functional tests.
kushaldas added a commit that referenced this pull request Jul 16, 2020
In #5284 we made sure that the username `deleted` is not not allowed
to be added in the system via the admin section of the journalist web
application. But, one could still edit any existing user and change
the name to `deleted`. Or, an admin can add a new user via `manage.py`
in command line.

In PR adds checks to make sure that addiving a new user via `manage.py`
will fail if you try to set the username as `deleted`, it also blocks
editing any existing username to `deleted`.

The PR also includes unit and functional tests.
rmol pushed a commit that referenced this pull request Jul 16, 2020
In #5284 we made sure that the username `deleted` is not not allowed
to be added in the system via the admin section of the journalist web
application. But, one could still edit any existing user and change
the name to `deleted`. Or, an admin can add a new user via `manage.py`
in command line.

In PR adds checks to make sure that addiving a new user via `manage.py`
will fail if you try to set the username as `deleted`, it also blocks
editing any existing username to `deleted`.

The PR also includes unit and functional tests.

(cherry picked from commit 90e19ea)
@zenmonkeykstop zenmonkeykstop mentioned this pull request Jul 20, 2020
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

We should not allow journalist username deleted
4 participants