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

preference tool password

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