misc: update password management emails to django template syntax (#81828)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-09-30 10:08:59 +02:00
parent c59a96d2a2
commit bbfc1fd75f
2 changed files with 59 additions and 34 deletions

View File

@ -4,7 +4,6 @@ import re
import pytest
from wcs.qommon import force_str
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.ident.password_accounts import PasswordAccount
from .utilities import clean_temporary_pub, create_temporary_pub, get_app
@ -13,21 +12,20 @@ from .utilities import clean_temporary_pub, create_temporary_pub, get_app
@pytest.fixture
def pub(request):
pub = create_temporary_pub()
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
pub.set_app_dir(req)
pub.cfg['misc'] = {'charset': 'utf-8'}
pub.cfg['identification'] = {'methods': ['password']}
pub.cfg['identities'] = {'creation': 'self'}
pub.write_cfg()
return pub
def teardown_module(module):
yield pub
clean_temporary_pub()
def test_no_configuration(pub):
pub.cfg['identification'] = {}
pub.write_cfg()
resp = get_app(pub).get('/register/')
assert 'Authentication subsystem is not yet configured.' in resp.text
def test_no_user_registration(pub):
# makes sure the page is not published unless configured
app = get_app(pub)
@ -140,6 +138,7 @@ def test_admin_notification(pub, emails):
assert emails.get('New Registration')
assert emails.get('New Registration')['email_rcpt'] == ['admin@localhost']
assert 'A new account has been created on example.net.' in emails.get('New Registration').email.body
def test_user_notification(pub, emails):
@ -286,3 +285,29 @@ def test_forgotten(pub, emails):
resp.forms[0]['password'] = 'foo'
resp = resp.forms[0].submit()
assert resp.status_int == 302
def test_self_registration_email_confirmation(pub, emails):
pub.cfg['identities'] = {'creation': 'self', 'email-confirmation': True, 'email-as-username': True}
pub.cfg['passwords'] = {
'generate': False,
'min_length': 8,
'count_uppercase': 1,
'count_lowercase': 1,
'count_digit': 1,
'count_special': 1,
}
pub.write_cfg()
resp = get_app(pub).get('/register/')
resp.form['username'] = 'user@example.net'
resp.form['password$pwd1'] = '123abcDEF!!'
resp.form['password$pwd2'] = '123abcDEF!!'
resp = resp.form.submit('submit')
assert 'Email sent' in resp.text
assert PasswordAccount.get('user@example.net').awaiting_confirmation is True
assert PasswordAccount.get_with_credentials('user@example.net', '123abcDEF!!')
assert emails.latest_subject == 'Subscription Confirmation'
url = re.findall(r'\b(http:.*?)\s', emails.get('Subscription Confirmation').email.body, re.DOTALL)[0]
resp = get_app(pub).get(url)
assert 'Account Creation Confirmed' in resp.text
assert PasswordAccount.get('user@example.net').awaiting_confirmation is False

View File

@ -987,17 +987,17 @@ EmailsDirectory.register(
default_body=_(
'''\
We have received a request for subscription of your email address,
"[email]", to the [website] web site.
"{{email}}", to the {{website}} web site.
To confirm that you want to be subscribed to the web site, simply
visit this web page:
[token_url]
{{token_url}}
If you do not wish to be subscribed to the web site, pleasy simply
disregard this message. If you think you are being maliciously
subscribed to the web site, or have any other questions, send them
to [admin_email].
to {{admin_email}}.
'''
),
)
@ -1014,15 +1014,15 @@ EmailsDirectory.register(
You have (or someone impersonating you has) requested to change your
password. To complete the change, visit the following link:
[change_url]
{{change_url}}
If you are not the person who made this request, or you wish to cancel
this request, visit the following link:
[cancel_url]
{{cancel_url}}
If you do nothing, the request will lapse after 3 days (precisely on
[time]).
{{time}}).
"""
),
)
@ -1039,11 +1039,11 @@ EmailsDirectory.register(
'''\
Hello,
You have requested a new password for [hostname], here are your new
You have requested a new password for {{hostname}}, here are your new
account details:
- username: [username]
- password: [password]
- username: {{username}}
- password: {{password}}
'''
),
)
@ -1062,8 +1062,8 @@ Your account has been approved.
Account details:
- username: [username]
[if-any password]- password: [password][end]
- username: {{username}}
{% if password %}- password: {{password}}{% endif %}
'''
),
)
@ -1079,10 +1079,10 @@ EmailsDirectory.register(
'''\
Hello,
A new account has been created on [hostname].
A new account has been created on {{hostname}}.
- name: [name]
- username: [username]
- name: {{name}}
- username: {{username}}
'''
),
)
@ -1093,12 +1093,12 @@ EmailsDirectory.register(
_('Available variables: hostname, username, password, email_as_username'),
category=_('Identification'),
condition=is_password_enabled,
default_subject=_('Welcome to [hostname]'),
default_subject=_('Welcome to {{hostname}}'),
default_body=_(
'''\
Welcome to [hostname],
Welcome to {{hostname}},
Your password is: [password]
Your password is: {{password}}
'''
),
)
@ -1109,12 +1109,12 @@ EmailsDirectory.register(
_('Available variables: hostname, name, username, password'),
category=_('Identification'),
condition=is_password_enabled,
default_subject=_('Your new password for [hostname]'),
default_subject=_('Your new password for {{hostname}}'),
default_body=_(
'''\
Hello [name],
Hello {{name}},
Here is your new password for [hostname]: [password]
Here is your new password for {{hostname}}: {{password}}
'''
),
)
@ -1125,12 +1125,12 @@ EmailsDirectory.register(
_('Available variables: hostname, name, username, password'),
category=_('Identification'),
condition=is_password_enabled,
default_subject=_('Your password for [hostname]'),
default_subject=_('Your password for {{hostname}}'),
default_body=_(
'''\
Hello [name],
Hello {{{name}},
Here is your password for [hostname]: [password]
Here is your password for {{hostname}}: {{password}}
'''
),
)
@ -1220,7 +1220,7 @@ TextsDirectory.register(
condition=is_password_enabled,
default=_(
'''<p>
If you do not have an account, you should go to the <a href="[register_url]">
If you do not have an account, you should go to the <a href="{{register_url}}">
New Account page</a>.
</p>'''
),