-
Notifications
You must be signed in to change notification settings - Fork 1k
Send email when a 2fa method is added or removed #6930
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
Merged
ewdurbin
merged 7 commits into
pypi:master
from
rascalking:5808-email-on-2fa-enable-disable
Feb 8, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c35d6bc
initial working 2fa emails
rascalking a8e2ab9
only look for the request when we know we have work
rascalking 7c5f062
Merge branch 'master' into 5808-email-on-2fa-enable-disable
rascalking df0b4f8
just send the 2fa emails directly from the view
rascalking 43ab54f
Merge branch 'master' into 5808-email-on-2fa-enable-disable
ewdurbin 09c5098
s/2fa/two_factor/
rascalking 49630aa
Merge branch '5808-email-on-2fa-enable-disable' of github.com:rascalk…
rascalking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1090,3 +1090,72 @@ def test_added_as_collaborator_email_unverified( | |
|
||
assert pyramid_request.task.calls == [] | ||
assert send_email.delay.calls == [] | ||
|
||
|
||
class Test2faEmail: | ||
@pytest.mark.parametrize( | ||
("action", "method", "pretty_method"), | ||
[ | ||
("added", "totp", "TOTP"), | ||
("removed", "totp", "TOTP"), | ||
("added", "webauthn", "WebAuthn"), | ||
("removed", "webauthn", "WebAuthn"), | ||
], | ||
) | ||
def test_2fa_email( | ||
self, | ||
pyramid_request, | ||
pyramid_config, | ||
monkeypatch, | ||
action, | ||
method, | ||
pretty_method, | ||
): | ||
stub_user = pretend.stub( | ||
username="username", | ||
name="", | ||
email="[email protected]", | ||
primary_email=pretend.stub(email="[email protected]", verified=True), | ||
) | ||
subject_renderer = pyramid_config.testing_add_renderer( | ||
f"email/2fa-{action}/subject.txt" | ||
) | ||
subject_renderer.string_response = "Email Subject" | ||
body_renderer = pyramid_config.testing_add_renderer( | ||
f"email/2fa-{action}/body.txt" | ||
) | ||
body_renderer.string_response = "Email Body" | ||
html_renderer = pyramid_config.testing_add_renderer( | ||
f"email/2fa-{action}/body.html" | ||
) | ||
html_renderer.string_response = "Email HTML Body" | ||
|
||
send_email = pretend.stub( | ||
delay=pretend.call_recorder(lambda *args, **kwargs: None) | ||
) | ||
pyramid_request.task = pretend.call_recorder(lambda *args, **kwargs: send_email) | ||
monkeypatch.setattr(email, "send_email", send_email) | ||
|
||
send_method = getattr(email, f"send_2fa_{action}_email") | ||
result = send_method(pyramid_request, stub_user, method=method) | ||
|
||
assert result == {"method": pretty_method, "username": stub_user.username} | ||
subject_renderer.assert_() | ||
body_renderer.assert_(method=pretty_method, username=stub_user.username) | ||
html_renderer.assert_(method=pretty_method, username=stub_user.username) | ||
assert pyramid_request.task.calls == [pretend.call(send_email)] | ||
assert send_email.delay.calls == [ | ||
pretend.call( | ||
f"{stub_user.username} <{stub_user.email}>", | ||
attr.asdict( | ||
EmailMessage( | ||
subject="Email Subject", | ||
body_text="Email Body", | ||
body_html=( | ||
"<html>\n<head></head>\n" | ||
"<body><p>Email HTML Body</p></body>\n</html>\n" | ||
), | ||
) | ||
), | ||
) | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-#} | ||
{% extends "email/_base/body.html" %} | ||
|
||
|
||
{% block content %} | ||
<p>{% trans method=method, username=username %}Someone, perhaps you, has added a {{ method }} two-factor authentication method to your PyPI account <strong>{{ username }}</strong>.{% endtrans %}</p> | ||
|
||
<p>{% trans href='mailto:[email protected]', email_address='[email protected]' %}If you did not make this change, you can email <a href="{{ href }}">{{ email_address }}</a> to communicate with the PyPI administrators.{% endtrans %}</p> | ||
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-#} | ||
{% extends "email/_base/body.txt" %} | ||
|
||
{% block content %} | ||
{% trans method=method, username=username %}Someone, perhaps you, has added a {{ method }} two-factor authentication method to your PyPI account | ||
'{{ username }}'.{% endtrans %} | ||
|
||
{% trans email_address='[email protected]' %}If you did not make this change, you can email {{ email_address }} to | ||
communicate with the PyPI administrators.{% endtrans %} | ||
{% endblock %} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-#} | ||
|
||
{% extends "email/_base/subject.txt" %} | ||
|
||
{% block subject %}{% trans %}Two-factor method added{% endtrans %}{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-#} | ||
{% extends "email/_base/body.html" %} | ||
|
||
|
||
{% block content %} | ||
<p>{% trans method=method, username=username %}Someone, perhaps you, has removed a {{ method }} two-factor authentication method from your PyPI account <strong>{{ username }}</strong>.{% endtrans %}</p> | ||
|
||
<p>{% trans href='mailto:[email protected]', email_address='[email protected]' %}If you did not make this change, you can email <a href="{{ href }}">{{ email_address }}</a> to communicate with the PyPI administrators.{% endtrans %}</p> | ||
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-#} | ||
{% extends "email/_base/body.txt" %} | ||
|
||
{% block content %} | ||
{% trans method=method, username=username %}Someone, perhaps you, has removed a {{ method }} two-factor authentication method from your PyPI account | ||
'{{ username }}'.{% endtrans %} | ||
|
||
{% trans email_address='[email protected]' %}If you did not make this change, you can email {{ email_address }} to | ||
communicate with the PyPI administrators.{% endtrans %} | ||
{% endblock %} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-#} | ||
|
||
{% extends "email/_base/subject.txt" %} | ||
|
||
{% block subject %}{% trans %}Two-factor method removed{% endtrans %}{% endblock %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like
2fa
should be spelled out astwo_factor
here and other places in this changeset. This is more consistent with what we in other places in the code base.