-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send email notification when API key is (re-)generated
- Loading branch information
1 parent
8828cff
commit c20c3d8
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,13 @@ | ||
{% extends "email/layout.html" %} | ||
|
||
{% block content -%} | ||
{% if event == "regenerated" -%} | ||
{% trans -%} | ||
Your API key has been regenerated. If that wasn’t you, please contact an administrator. | ||
{%- endtrans %} | ||
{% else -%} | ||
{% trans -%} | ||
An API key has been generated for your account. If that wasn’t you, please contact an administrator. | ||
{%- endtrans %} | ||
{%- endif %} | ||
{%- endblock %} |
This file contains 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,13 @@ | ||
{% extends "email/layout.txt" %} | ||
|
||
{% block content -%} | ||
{% if event == "regenerated" -%} | ||
{% trans -%} | ||
Your API key has been regenerated. If that wasn’t you, please contact an administrator. | ||
{%- endtrans %} | ||
{% else -%} | ||
{% trans -%} | ||
An API key has been generated for your account. If that wasn’t you, please contact an administrator. | ||
{%- endtrans %} | ||
{%- endif %} | ||
{%- endblock %} |
This file contains 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 |
---|---|---|
|
@@ -249,6 +249,32 @@ def test_generate_api_key(self): | |
res = self.client.get(url, headers={"Authorization": new_key}) | ||
self.assertEqual(res.status_code, 200) | ||
|
||
def test_generate_api_key_notification(self): | ||
role, headers = self.login(email="[email protected]") | ||
url = f"/api/2/roles/{role.id}/generate_api_key" | ||
|
||
with mail.record_messages() as outbox: | ||
assert len(outbox) == 0 | ||
self.client.post(url, headers=headers) | ||
assert len(outbox) == 1 | ||
|
||
msg = outbox[0] | ||
assert msg.recipients == ["[email protected]"] | ||
assert msg.subject == "[Aleph] API key generated" | ||
assert "An API key has been generated for your account" in msg.body | ||
assert "An API key has been generated for your account" in msg.html | ||
|
||
with mail.record_messages() as outbox: | ||
assert len(outbox) == 0 | ||
self.client.post(url, headers=headers) | ||
assert len(outbox) == 1 | ||
|
||
msg = outbox[0] | ||
assert msg.recipients == ["[email protected]"] | ||
assert msg.subject == "[Aleph] API key regenerated" | ||
assert "Your API key has been regenerated" in msg.body | ||
assert "Your API key has been regenerated" in msg.html | ||
|
||
def test_new_roles_no_api_key(self): | ||
SETTINGS.PASSWORD_LOGIN = True | ||
email = "[email protected]" | ||
|
This file contains 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