Commit 885dca4a authored by Jérome Perrin's avatar Jérome Perrin

preference tool password

parent b90e9db7
......@@ -2,6 +2,7 @@
Check that password matchs with confirmation and that it complies to the authentication policy.
"""
from AccessControl import getSecurityManager
from Products.Formulator.Errors import ValidationError
password_confirm = request.get('field_password_confirm',
......@@ -11,9 +12,9 @@ password_confirm = request.get('field_password_confirm',
if password_confirm != editor:
return 0
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue()
if user is not None:
validation_message_list = user.analyzePassword(editor)
login = getSecurityManager().getUser().getLoginValue()
if login is not None:
validation_message_list = login.analyzePassword(editor)
if validation_message_list:
message = u' '.join([str(x) for x in validation_message_list])
raise ValidationError('external_validator_failed', context, error_text=message)
......
......@@ -52,6 +52,14 @@
<key> <string>_params</string> </key>
<value> <string>editor, request</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PreferenceTool_validatePassword</string> </value>
......
......@@ -32,6 +32,7 @@ import unittest
import urllib
from StringIO import StringIO
import time
import httplib
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.Formulator.Errors import ValidationError
from Products.ERP5Type.Document import newTempBase
......@@ -750,8 +751,8 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
person.newContent(portal_type = 'Assignment').open()
login = person.objectValues(portal_type='ERP5 Login')[0]
preference = self.portal.portal_catalog.getResultValue(
portal_type = 'System Preference',
title = 'Authentication',)
portal_type='System Preference',
title='Authentication',)
preference.setPreferredMinPasswordLength(10)
self._clearCache()
self.tic()
......@@ -770,14 +771,14 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
})),
request_method="POST",
handle_errors=False)
self.assertEquals(200, ret.getStatus())
self.assertEqual(httplib.OK, ret.getStatus())
self.assertIn(
'<span class="error">Too short. </span>',
'<span class="error">Too short.</span>',
ret.getBody())
# if for some reason, PreferenceTool_setNewPassword is called directly,
# the password policy is also checked, so this cause an unhandled exception.
self.login(person.getId())
self.login(person.getUserId())
self.assertRaises(
ValueError,
self.portal.PreferenceTool_setNewPassword,
......@@ -798,7 +799,9 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
})),
request_method="POST",
handle_errors=False)
self.assertEquals(200, ret.getStatus())
# When password reset is succesful, user is logged out
self.assertEqual(httplib.FOUND, ret.getStatus())
self.assertTrue(ret.getHeader("Location").endswith("/logout"))
# password is changed on the login
self.assertTrue(login.checkPassword('long_enough_password'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment