changeset 3103:4ede355c6089

bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 23 Feb 2008 19:43:26 +0100
parents a78bf6977df8
children ce6f12d51736
files MoinMoin/_tests/test_user.py MoinMoin/user.py
diffstat 2 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_user.py	Sat Feb 23 16:14:04 2008 +0100
+++ b/MoinMoin/_tests/test_user.py	Sat Feb 23 19:43:26 2008 +0100
@@ -158,6 +158,25 @@
         theUser = user.User(self.request, name=name, password=password)
         theUser.subscribe(pagename)
         assert not theUser.isSubscribedTo([testPagename]) # list(!) of pages to check
+        
+    def testRenameUser(self):
+        """ create user and then rename user and check
+        if the old username is removed from the cache name2id
+        """
+        # Create test user
+        # Use iso charset to create user with old enc_password, as if
+        # the user file was migrated from pre 1.3 wiki.
+        name = u'__Some Name__'
+        password = name
+        self.createUser(name, password)
+        # Login - this should replace the old password in the user file
+        theUser = user.User(self.request, name=name)
+        # Rename user
+        theUser.name = u'__SomeName__'
+        theUser.save()
+        theUser = user.User(self.request, name=name, password=password)
+        
+        assert not theUser.exists()
 
     # Helpers ---------------------------------------------------------
 
--- a/MoinMoin/user.py	Sat Feb 23 16:14:04 2008 +0100
+++ b/MoinMoin/user.py	Sat Feb 23 19:43:26 2008 +0100
@@ -616,6 +616,14 @@
             data.write(line)
         data.close()
 
+        arena = 'user'
+        key = 'name2id'
+        cache = caching.CacheEntry(self._request, arena, key, scope='wiki').remove()
+        try:
+            del self._request.cfg.cache.name2id
+        except:
+            pass
+        
         if not self.disabled:
             self.valid = 1