Skip to content

Commit

Permalink
Merge 4170ce3 into 448efd2
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Sep 1, 2020
2 parents 448efd2 + 4170ce3 commit db71992
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Products/PluggableAuthService/Extensions/upgrade.py
Expand Up @@ -48,14 +48,14 @@ def _replaceUserFolder(self, RESPONSE=None):
"""
from Acquisition import aq_base

from .interfaces.plugins import IAuthenticationPlugin
from .interfaces.plugins import IRoleAssignerPlugin
from .interfaces.plugins import IRoleEnumerationPlugin
from .interfaces.plugins import IRolesPlugin
from .interfaces.plugins import IUserEnumerationPlugin
from .PluggableAuthService import PluggableAuthService
from .plugins.ZODBRoleManager import ZODBRoleManager
from .plugins.ZODBUserManager import ZODBUserManager
from ..interfaces.plugins import IAuthenticationPlugin
from ..interfaces.plugins import IRoleAssignerPlugin
from ..interfaces.plugins import IRoleEnumerationPlugin
from ..interfaces.plugins import IRolesPlugin
from ..interfaces.plugins import IUserEnumerationPlugin
from ..PluggableAuthService import PluggableAuthService
from ..plugins.ZODBRoleManager import ZODBRoleManager
from ..plugins.ZODBUserManager import ZODBUserManager

if getattr(aq_base(self), '__allow_groups__', None):
if self.__allow_groups__.__class__ is PluggableAuthService:
Expand Down Expand Up @@ -162,7 +162,7 @@ def descend(user_folder, obj):
(map[key], npid))
obj.__ac_local_roles__ = new_map
_write(RESPONSE, 'upgradeLocalRoleAssignmentsFromRoot',
('Local Roles map changed for (%s)\n' %
('Local Roles map changed for %s\n' %
'/'.join(path)))
if (len(seen) % 100) == 0:
transaction.savepoint(True)
Expand All @@ -187,6 +187,3 @@ def replace_acl_users(self, RESPONSE=None):
_replaceUserFolder(self, RESPONSE)
_upgradeLocalRoleAssignments(self, RESPONSE)
self._upgraded_acl_users = 1
_write(RESPONSE, 'replace_acl_users',
'Root acl_users has been replaced,'
' and local role assignments updated.\n')
101 changes: 101 additions & 0 deletions Products/PluggableAuthService/tests/test_Extensions.py
@@ -0,0 +1,101 @@
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this
# distribution.
# THIS SOFTWARE IS PROVIDED 'AS IS' AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

from six import StringIO

from ..PluggableAuthService import PluggableAuthService
from ..tests import pastc


class UpgradeTests(pastc.PASTestCase):
def test_upgrade_pas(self):
# Test that upgrading acl_users PAS works, or at least does not fail.
# We had uncaught ImportErrors once.
from ..Extensions.upgrade import replace_acl_users

# This is already a PAS, but upgrade still does some stuff.
uf = self.folder.acl_users
self.assertIsInstance(uf, PluggableAuthService)

# Upgrade the folder that contains the acl_users.
response = StringIO()
replace_acl_users(self.folder, response)
uf = self.folder.acl_users
self.assertIsInstance(uf, PluggableAuthService)

# Check the messages.
response.seek(0)
messages = response.read().splitlines()
self.assertTrue(messages)
self.assertEqual(messages[0], 'Already replaced this user folder')
self.assertEqual(len(messages), 1)

# Do it again.
response = StringIO()
replace_acl_users(self.folder, response)
uf = self.folder.acl_users
self.assertIsInstance(uf, PluggableAuthService)
response.seek(0)
messages = response.read().splitlines()
self.assertTrue(messages)
self.assertEqual(messages[0], 'Already replaced this user folder')
self.assertEqual(
messages[1], 'Local role assignments have already been updated.',
)
self.assertEqual(len(messages), 2)

def test_upgrade_userfolder(self):
# Test that upgrading acl_users user folder works,
# or at least does not fail.
# We had uncaught ImportErrors once.
from OFS.userfolder import UserFolder

from ..Extensions.upgrade import replace_acl_users

# Current status
uf = self.app.acl_users
self.assertIsInstance(uf, UserFolder)

# Upgrade the root folder that contains the acl_users.
response = StringIO()
replace_acl_users(self.app, response)
uf = self.app.acl_users
self.assertIsInstance(uf, PluggableAuthService)

# Check the messages.
response.seek(0)
messages = response.read().splitlines()
self.assertTrue(messages)
self.assertEqual(
messages[0], 'Replaced root acl_users with PluggableAuthService',
)
# We could test for this message, but does not seem important.
# self.assertEqual(
# messages[1], ' Ignoring map for unknown principal test_user_1_'
# )
self.assertIn('Local Roles map changed for /acl_users', messages)

# Do it again.
response = StringIO()
replace_acl_users(self.app, response)
uf = self.app.acl_users
self.assertIsInstance(uf, PluggableAuthService)
response.seek(0)
messages = response.read().splitlines()
self.assertTrue(messages)
self.assertEqual(messages[0], 'Already replaced this user folder')
self.assertEqual(
messages[1], 'Local role assignments have already been updated.',
)
self.assertEqual(len(messages), 2)

0 comments on commit db71992

Please sign in to comment.