Commit 82235674 authored by Vincent Pelletier's avatar Vincent Pelletier

test: migrate to ERP5 Login authentication.

parent e3f117a8
......@@ -12,7 +12,6 @@ if person is None:
title=functional_test_username)
person.edit(reference=functional_test_username,
password=howto_dict['functional_test_user_password'],
default_email_text=howto_dict['functional_test_user_email'])
person.validate()
......@@ -23,6 +22,13 @@ if person is None:
function='company/manager')
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference=functional_test_username,
password=howto_dict['functional_test_user_password'],
)
login.validate()
# XXX (lucas): These tests must be able to run on an instance without security.
for role in ('Assignee', 'Assignor', 'Associate', 'Auditor', 'Owner'):
portal.acl_users.zodb_roles.assignRoleToPrincipal(role, person.Person_getUserId())
......
......@@ -12,7 +12,6 @@ if person is None:
title=functional_test_username)
person.edit(reference=functional_test_username,
password=howto_dict['functional_test_user_password'],
default_email_text=howto_dict['functional_test_user_email'])
person.validate()
......@@ -23,6 +22,13 @@ if person is None:
function='company/manager')
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference=functional_test_username,
password=howto_dict['functional_test_user_password'],
)
login.validate()
# XXX (lucas): These tests must be able to run on an instance without security.
for role in ('Assignee', 'Assignor', 'Associate', 'Auditor', 'Owner'):
portal.acl_users.zodb_roles.assignRoleToPrincipal(role, person.Person_getUserId())
......
......@@ -11,10 +11,15 @@ else:
person = person_module.newContent(portal_type="Person",
reference=user_id,
id=user_id,
password=new_password,
default_email_text="userA@example.invalid")
assignment = person.newContent(portal_type='Assignment')
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference=user_id,
password=new_password,
)
login.validate()
# Make sure always a new password
person.setPassword(new_password)
......
......@@ -27,7 +27,7 @@ if not portal.person_module.has_key('test_webmaster'):
else:
person = portal.person_module.test_webmaster
person.edit(first_name='Test', last_name='Webmaster',
reference='test_webmaster', password='test_webmaster')
reference='test_webmaster')
person.setRole('internal')
if not len(person.objectValues(portal_type='Assignment')):
assignment = person.newContent(portal_type='Assignment')
......@@ -36,6 +36,13 @@ if not len(person.objectValues(portal_type='Assignment')):
stop_date=DateTime('2990/12/31'))
if assignment.getValidationState() != 'open':
assignment.open()
if not len(person.objectValues(portal_type='ERP5 Login')):
login = person.newContent(
portal_type='ERP5 Login',
reference='test_webmaster',
password='test_webmaster',
)
login.validate()
if person.getValidationState() != 'validated':
person.validate()
......
......@@ -51,6 +51,11 @@ class TestUNGSecurity(ERP5TypeTestCase):
assignment = person.newContent(portal_type='Assignment')
assignment.setFunction("function/ung_user")
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference='ung_user',
)
login.validate()
self.tic()
def testERP5Site_createNewWebDocumentAsAnonymous(self):
......@@ -82,6 +87,11 @@ class TestUNGSecurity(ERP5TypeTestCase):
assignment = person.newContent(portal_type='Assignment')
assignment.setFunction("function/ung_user")
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference='ung_user2',
)
login.validate()
self.tic()
self.loginByUserName("ung_user")
self.changeSkin("UNGDoc")
......@@ -175,6 +185,11 @@ class TestUNGSecurity(ERP5TypeTestCase):
assignment = person.newContent(portal_type='Assignment')
assignment.setFunction("function/ung_user")
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference='ung_user2',
)
login.validate()
self.tic()
self.loginByUserName("ung_user")
self.changeSkin("UNGDoc")
......
......@@ -133,10 +133,12 @@ class TestUNG(ERP5TypeTestCase):
reference="ung_new_user")
assignment = person.newContent(portal_type='Assignment')
assignment.open()
person.newContent(portal_type='ERP5 Login', reference=person.getReference()).validate()
person = portal.person_module.newContent(portal_type='Person',
reference="ung_new_user2")
assignment = person.newContent(portal_type='Assignment')
assignment.open()
person.newContent(portal_type='ERP5 Login', reference=person.getReference()).validate()
self.tic()
self.loginByUserName("ung_new_user")
self.changeSkin("UNGDoc")
......
......@@ -52,8 +52,13 @@ class ShaSecurityMixin(object):
if person is None:
person = self.portal.person_module.newContent(portal_type='Person')
person.edit(first_name=reference,
reference=reference)
login = person.newContent(
portal_type='ERP5 Login',
reference=reference,
password=password)
password=password,
)
login.validate()
self.tic()
create = True
......
......@@ -82,6 +82,7 @@ class TestAccounting_l10n_fr(AccountingTestCase):
default_email_text=self.recipient_email_address)
assignment = person.newContent(portal_type='Assignment')
assignment.open()
person.newContent(portal_type='ERP5 Login', reference=self.username).validate()
self.tic()
uf = self.portal.acl_users
......
......@@ -126,6 +126,7 @@ class TestBug(ERP5TypeTestCase):
start_date='1980-01-01',
stop_date='2099-12-31')
assignment.open()
person.newContent(portal_type='ERP5 Login', reference='dummy').validate()
self.tic()
portal_type_list = []
for portal_type in (self.project_portal_type,
......
......@@ -50,6 +50,7 @@ class TestCertificateAuthority(ERP5TypeTestCase):
person = self.portal.person_module.newContent(portal_type='Person',
reference=login, password=login)
person.newContent(portal_type='Assignment').open()
person.newContent(portal_type='ERP5 Login', reference=login).validate()
self.tic()
return login
......
......@@ -1167,14 +1167,14 @@ class TestERP5Base(ERP5TypeTestCase):
self.tic()
# a user is created
user = self.portal.acl_users.getUserById('user_login')
user = self.portal.acl_users.getUser('user_login')
self.assertNotEquals(None, user)
# and this user has a preference created
newSecurityManager(None, user.__of__(self.portal.acl_users))
self.assertNotEquals(None,
self.portal.portal_catalog.getResultValue(portal_type='Preference',
owner='user_login'))
owner=user.getId()))
# for his assignent group
self.assertEqual('group/nexedi',
self.portal.portal_preferences.getPreferredSectionCategory())
......
......@@ -227,6 +227,7 @@ class TestCommerce(ERP5TypeTestCase):
start_date='1972-01-01', stop_date='2999-12-31',
group=group, destination_project=destination_project)
assignment.open()
person.newContent(portal_type='ERP5 Login', reference=reference).validate()
self.tic()
#XXX: Security hack (lucas)
......
......@@ -303,8 +303,7 @@ class TestERP5Credential(ERP5TypeTestCase):
self.portal.ERP5Site_activeLogin(mail_message.getReference())
self.login()
self.tic()
person = portal_catalog.getResultValue(reference=reference,
portal_type="Person")
person = self.portal.acl_users.getUser(reference).getUserValue()
assignment_list = person.objectValues(portal_type="Assignment")
self.assertEqual(len(assignment_list), 1)
assignment = assignment_list[0]
......@@ -380,7 +379,7 @@ class TestERP5Credential(ERP5TypeTestCase):
last_name='Simpson', reference='homie')
self.assertEqual(len(result), 1)
sequence.edit(subscription_request=result[0],
person_reference=credential_reference)
login_reference=credential_reference)
def stepAcceptSubscriptionRequest(self, sequence=None, sequence_list=None,
**kw):
......@@ -407,9 +406,9 @@ class TestERP5Credential(ERP5TypeTestCase):
# check homie can log in the system
self._assertUserExists('homie', 'secret')
self.login('homie')
self.loginByUserName('homie')
from AccessControl import getSecurityManager
self.assertEqual(getSecurityManager().getUser().getIdOrUserName(), 'homie')
self.assertEqual(getSecurityManager().getUser().getUserName(), 'homie')
def stepCreateCredentialUpdate(self, sequence=None, sequence_list=None, **kw):
'''
......@@ -418,10 +417,9 @@ class TestERP5Credential(ERP5TypeTestCase):
'''
self.login()
# get the 'homie' person object
person_module = self.portal.getDefaultModule('Person')
result = person_module.searchFolder(reference='homie')
result = self.portal.portal_catalog(portal_type='ERP5 Login', reference='homie')
self.assertEqual(len(result), 1)
homie = result[0]
homie = result[0].getParentValue()
# create a credential update
credential_update_module = self.portal.getDefaultModule(\
......@@ -453,9 +451,9 @@ class TestERP5Credential(ERP5TypeTestCase):
# check that informations on the person object have been updated
person_module = self.portal.getDefaultModule('Person')
related_person_result = person_module.searchFolder(reference='homie')
self.assertEqual(len(related_person_result), 1)
related_person = related_person_result[0]
related_login_result = self.portal.portal_catalog(portal_type='ERP5 Login', reference='homie')
self.assertEqual(len(related_login_result), 1)
related_person = related_login_result[0].getParentValue()
self.assertEqual(related_person.getLastName(), 'Simpsons')
self.assertEqual(related_person.getDefaultEmailText(),
'homie.simpsons@fox.com')
......@@ -609,7 +607,7 @@ class TestERP5Credential(ERP5TypeTestCase):
sequence.edit(barney=person)
# check barney can log in the system
self._assertUserExists('barney-login', 'secret')
self.login('barney')
self.loginByUserName('barney-login')
from AccessControl import getSecurityManager
self.assertEqual(getSecurityManager().getUser().getIdOrUserName(), person.Person_getUserId())
......@@ -658,10 +656,10 @@ class TestERP5Credential(ERP5TypeTestCase):
self.portal.ERP5Site_newCredentialRecovery(
default_email_text=default_email_text)
def stepLoginAsCurrentPersonReference(self, sequence=None,
def stepLoginAsCurrentLoginReference(self, sequence=None,
sequence_list=None, **kw):
person_reference = sequence["person_reference"]
self.login(person_reference)
login_reference = sequence["login_reference"]
self.loginByUserName(login_reference)
def stepCreateCredentialUpdateWithERP5Site_newCredentialUpdate(self,
sequence=None, sequence_list=None, **kw):
......@@ -863,8 +861,7 @@ class TestERP5Credential(ERP5TypeTestCase):
def stepCheckPersonAfterSubscriptionRequest(self, sequence=None,
sequence_list=None, **kw):
self.login()
person = self.portal.portal_catalog.getResultValue(
reference=sequence["person_reference"], portal_type="Person")
person = self.portal.acl_users.getUser(sequence['login_reference']).getUserValue()
self.assertEqual("Homer", person.getFirstName())
self.assertEqual("Simpson", person.getLastName())
self.assertEqual("homer.simpson@fox.com", person.getDefaultEmailText())
......@@ -873,16 +870,14 @@ class TestERP5Credential(ERP5TypeTestCase):
def stepSetAuditorRoleToCurrentPerson(self, sequence=None,
sequence_list=None, **kw):
person_reference = sequence["person_reference"]
self.login()
person = self.portal.acl_users.getUser(person_reference).getUserValue()
person = self.portal.acl_users.getUser(sequence['login_reference']).getUserValue()
person.manage_setLocalRoles(person.Person_getUserId(), ["Auditor"])
self.logout()
def stepCheckPersonAfterUpdatePerson(self, sequence=None,
sequence_list=None, **kw):
person = self.portal.portal_catalog.getResultValue(
reference=sequence["person_reference"], portal_type="Person")
person = self.portal.acl_users.getUser(sequence['login_reference']).getUserValue()
self.assertEqual("tom", person.getFirstName())
self.assertEqual("Simpson", person.getLastName())
self.assertEqual("tom@host.com", person.getDefaultEmailText())
......@@ -1123,8 +1118,7 @@ class TestERP5Credential(ERP5TypeTestCase):
self.portal.ERP5Site_activeLogin(mail_message.getReference())
self.login()
self.tic()
person = portal_catalog.getResultValue(reference="barney",
portal_type="Person")
person = self.portal.acl_users.getUser('barney').getUserValue()
assignment_list = person.objectValues(portal_type="Assignment")
self.assertNotEquals(assignment_list, [])
self.assertEqual(len(assignment_list), 1)
......@@ -1233,7 +1227,7 @@ class TestERP5Credential(ERP5TypeTestCase):
"stepCheckPersonAfterSubscriptionRequest " \
"SetAuditorRoleToCurrentPerson " \
"SetAssigneeRoleToCurrentPersonInCredentialUpdateModule Tic " \
"LoginAsCurrentPersonReference " \
"LoginAsCurrentLoginReference " \
"CreateCredentialUpdateWithERP5Site_newCredentialUpdate Tic " \
"SelectCredentialUpdate " \
"AcceptCredentialUpdate Tic "\
......@@ -1296,7 +1290,7 @@ class TestERP5Credential(ERP5TypeTestCase):
'''
sequence_list = SequenceList()
sequence_string = "CreatePersonWithQuestionUsingCamelCase Tic " \
"LoginAsCurrentPersonReference " \
"LoginAsCurrentLoginReference " \
"CreateCredentialRecoveryWithSensitiveAnswer Tic " \
"AcceptCredentialRecovery Tic " \
"CheckEmailIsSent Tic "\
......
This diff is collapsed.
......@@ -117,6 +117,7 @@ class TestWorklist(ERP5TypeTestCase):
stop_date = '01/01/2900',
)
assignment.open()
person.newContent(portal_type='ERP5 Login', reference=user_login).validate()
# Reindexing is required for the security to work
self.tic()
......
......@@ -150,6 +150,10 @@ class TestERP5BankingMixin(ERP5TypeTestCase):
# by the assignment workflow when NuxUserGroup is used and
# by ERP5Security PAS plugins in the context of PAS use.
assignment.open()
person.newContent(
portal_type='ERP5 Login',
reference=user_login,
).validate()
if self.PAS_installed:
# reindexing is required for the security to work
......
......@@ -128,6 +128,7 @@ CREATE TABLE alternate_roles_and_users (
reference='user1')
user1_id = user1.Person_getUserId()
user1.newContent(portal_type='Assignment', group='g1').open()
user1.newContent(portal_type='ERP5 Login', reference='user1').validate()
user1.updateLocalRolesOnSecurityGroups()
self.assertEqual(user1.__ac_local_roles__.get(user1_id), ['Auditor'])
self.assertEqual(user1.__ac_local_roles__.get('GROUP1'), ['Unknown'])
......@@ -136,6 +137,7 @@ CREATE TABLE alternate_roles_and_users (
reference='user2')
user2_id = user2.Person_getUserId()
user2.newContent(portal_type='Assignment', group='g1').open()
user2.newContent(portal_type='ERP5 Login', reference='user2').validate()
user2.updateLocalRolesOnSecurityGroups()
self.assertEqual(user2.__ac_local_roles__.get(user2_id), ['Auditor'])
self.assertEqual(user2.__ac_local_roles__.get('GROUP1'), ['Unknown'])
......
......@@ -72,6 +72,7 @@ class TestGUISecurity(ERP5TypeTestCase):
self.assertTrue('Created Successfully' in message)
if not hasattr(portal.person_module, 'user'):
user = portal.person_module.newContent(portal_type='Person', id='user', reference='user')
user.newContent(portal_type='ERP5 Login', reference='user').validate()
asg = user.newContent(portal_type='Assignment')
asg.setStartDate(DateTime() - 100)
asg.setStopDate(DateTime() + 100)
......
......@@ -64,10 +64,15 @@ class TestDeferredStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
person = person_module.newContent(id='pers', portal_type='Person',
reference=self.username,
first_name=self.first_name,
password=self.password,
default_email_text=self.recipient_email_address)
assignment = person.newContent(portal_type='Assignment')
assignment.open()
login = person.newContent(
portal_type='ERP5 Login',
reference=self.username,
password=self.password,
)
login.validate()
self.tic()
def loginAsUser(self, username):
......
......@@ -471,8 +471,11 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
person = self.portal.person_module.newContent(portal_type='Person',
reference=reference,
password=password,
**person_kw)
login = person.newContent(portal_type='ERP5 Login',
reference=reference,
password=password)
login.validate()
return person
def createUserAssignment(self, user, assignment_kw):
......
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