annotate MoinMoin/_tests/test_user.py @ 5740:51240cc99af5

Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
author pavel_vinogradov
date Tue, 30 Nov 2010 21:57:25 +0300
parents 1b4b3f510f9b
children 62875f1ab006
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - MoinMoin.user Tests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
5 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
4656
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
6 2009 by ReimarBauer
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
10 import os
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
11 import py
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
12
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13 from MoinMoin import user, caching
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
15
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
16 class TestEncodePassword(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 """user: encode passwords tests"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 def testAscii(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 """user: encode ascii password"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 # u'MoinMoin' and 'MoinMoin' should be encoded to same result
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
22 expected = "{SSHA}xkDIIx1I7A4gC98Vt/+UelIkTDYxMjM0NQ=="
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
23
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
24 result = user.encodePassword("MoinMoin", salt='12345')
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
25 assert result == expected
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
26 result = user.encodePassword(u"MoinMoin", salt='12345')
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
27 assert result == expected
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
28
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
29 def testUnicode(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30 """ user: encode unicode password """
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
31 result = user.encodePassword(u'סיסמה סודית בהחלט', salt='12345') # Hebrew
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
32 expected = "{SSHA}YiwfeVWdVW9luqyVn8t2JivlzmUxMjM0NQ=="
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
33 assert result == expected
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
36 class TestLoginWithPassword(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 """user: login tests"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
39 def setup_method(self, method):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 # Save original user and cookie
4212
1ca179133f01 Fix tests: small fixes after merge
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3820
diff changeset
41 self.saved_cookie = self.request.cookies
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 self.saved_user = self.request.user
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
43
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44 # Create anon user for the tests
4212
1ca179133f01 Fix tests: small fixes after merge
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3820
diff changeset
45 self.request.cookies = {}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 self.request.user = user.User(self.request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
48 self.user = None
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
49
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
50 def teardown_method(self, method):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 """ Run after each test
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
52
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 Remove user and reset user listing cache.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 # Remove user file and user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 if self.user is not None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 path = self.user._User__filename()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 os.remove(path)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 except OSError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 del self.user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 # Restore original user
4212
1ca179133f01 Fix tests: small fixes after merge
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3820
diff changeset
65 self.request.cookies = self.saved_cookie
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 self.request.user = self.saved_user
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
67
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 # Remove user name to id cache, or next test will fail
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
69 caching.CacheEntry(self.request, 'user', 'name2id', scope='wiki').remove()
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
70 try:
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
71 del self.request.cfg.cache.name2id
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
72 except:
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
73 pass
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
74
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 def testAsciiPassword(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 """ user: login with ascii password """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 # Create test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 name = u'__Non Existent User Name__'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 password = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 self.createUser(name, password)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
81
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
82 # Try to "login"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 theUser = user.User(self.request, name=name, password=password)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
84 assert theUser.valid
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 def testUnicodePassword(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87 """ user: login with non-ascii password """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88 # Create test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 name = u'__שם משתמש לא קיים__' # Hebrew
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90 password = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 self.createUser(name, password)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
92
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 # Try to "login"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 theUser = user.User(self.request, name=name, password=password)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
95 assert theUser.valid
5740
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
96
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
97 def test_auth_with_apr1_stored_password(self):
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
98 """
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
99 Create user with {APR1} password and check that user can login.
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
100 """
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
101 # Create test user
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
102 name = u'Test User'
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
103 password = '{APR1}$apr1$salt$kKtoJ6r.fd87EWbzq2TiF0' # 12345
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
104 self.createUser(name, password, True)
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
105
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
106 # Try to "login"
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
107 theuser = user.User(self.request, name=name, password='12345')
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
108 assert theuser.valid
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
109
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
110 def test_auth_with_md5_stored_password(self):
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
111 """
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
112 Create user with {MD5} password and check that user can login.
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
113 """
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
114 # Create test user
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
115 name = u'Test User'
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
116 password = '{MD5}$1$salt$etVYf53ma13QCiRbQOuRk/' # 12345
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
117 self.createUser(name, password, True)
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
118
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
119 # Try to "login"
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
120 theuser = user.User(self.request, name=name, password='12345')
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
121 assert theuser.valid
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
122
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
123 #This test is disabled because require crypt, which not
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
124 #presented on some platforms
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
125 def test_auth_with_des_stored_password(self):
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
126 """
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
127 Create user with {DES} password and check that user can login.
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
128 """
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
129 # Create test user
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
130 name = u'Test User'
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
131 password = '{DES}sajEeYaHYyeSU' # 12345
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
132 self.createUser(name, password, True)
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
133
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
134 try:
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
135 import crypt
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
136 # Try to "login"
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
137 theuser = user.User(self.request, name=name, password='12345')
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
138 assert theuser.valid
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
139 except ImportError:
51240cc99af5 Add new tests for user auth with migrated passwords (ARP1, MD5, DES)
pavel_vinogradov
parents: 5739
diff changeset
140 crypt = None
5738
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
141
2038
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
142 def testSubscriptionSubscribedPage(self):
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
143 """ user: tests isSubscribedTo """
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
144 pagename = u'HelpMiscellaneous'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
145 name = u'__Jürgen Herman__'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
146 password = name
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
147 self.createUser(name, password)
2038
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
148 # Login - this should replace the old password in the user file
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
149 theUser = user.User(self.request, name=name, password=password)
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
150 theUser.subscribe(pagename)
2827
c61cd68592c2 test_user: fixed indenting
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2818
diff changeset
151 assert theUser.isSubscribedTo([pagename]) # list(!) of pages to check
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
152
2038
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
153 def testSubscriptionSubPage(self):
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
154 """ user: tests isSubscribedTo on a subpage """
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
155 pagename = u'HelpMiscellaneous'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
156 testPagename = u'HelpMiscellaneous/FrequentlyAskedQuestions'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
157 name = u'__Jürgen Herman__'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
158 password = name
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
159 self.createUser(name, password)
2038
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
160 # Login - this should replace the old password in the user file
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
161 theUser = user.User(self.request, name=name, password=password)
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
162 theUser.subscribe(pagename)
2827
c61cd68592c2 test_user: fixed indenting
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2818
diff changeset
163 assert not theUser.isSubscribedTo([testPagename]) # list(!) of pages to check
3120
a7c1680aeaa0 PEP8 fixes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3103
diff changeset
164
3103
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
165 def testRenameUser(self):
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
166 """ create user and then rename user and check
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
167 if the old username is removed from the cache name2id
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
168 """
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
169 # Create test user
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
170 name = u'__Some Name__'
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
171 password = name
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
172 self.createUser(name, password)
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
173 # Login - this should replace the old password in the user file
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
174 theUser = user.User(self.request, name=name)
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
175 # Rename user
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
176 theUser.name = u'__SomeName__'
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
177 theUser.save()
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
178 theUser = user.User(self.request, name=name, password=password)
3120
a7c1680aeaa0 PEP8 fixes, mostly whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3103
diff changeset
179
3103
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
180 assert not theUser.exists()
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
181
5738
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
182 def test_upgrade_password_from_sha_to_ssha(self):
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
183 """
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
184 Create user with {SHA} password and check that logging in
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
185 upgrades to {SSHA}.
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
186 """
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
187 name = u'/no such user/'
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
188 password = '{SHA}jLIjfQZ5yojbZGTqxg2pY0VROWQ=' # 12345
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
189 self.createUser(name, password, True)
5738
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
190
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
191 #User don't require to be valid
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
192 theuser = user.User(self.request, name=name, password='12345')
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
193 assert theuser.enc_password[:6] == '{SSHA}'
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
194
5739
1b4b3f510f9b Rename hash name from ARP1 to APR1
pavel_vinogradov
parents: 5738
diff changeset
195 def test_upgrade_password_from_apr1_to_ssha(self):
5738
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
196 """
5739
1b4b3f510f9b Rename hash name from ARP1 to APR1
pavel_vinogradov
parents: 5738
diff changeset
197 Create user with {APR1} password and check that logging in
5738
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
198 upgrades to {SSHA}.
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
199 """
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
200 # Create test user
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
201 name = u'Test User'
5739
1b4b3f510f9b Rename hash name from ARP1 to APR1
pavel_vinogradov
parents: 5738
diff changeset
202 password = '{APR1}$apr1$salt$kKtoJ6r.fd87EWbzq2TiF0' # 12345
5738
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
203 self.createUser(name, password, True)
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
204
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
205 #User don't require to be valid
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
206 theuser = user.User(self.request, name=name, password='12345')
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
207 assert theuser.enc_password[:6] == '{SSHA}'
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
208
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
209 def test_upgrade_password_from_md5_to_ssha(self):
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
210 """
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
211 Create user with {MD5} password and check that logging in
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
212 upgrades to {SSHA}.
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
213 """
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
214 # Create test user
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
215 name = u'Test User'
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
216 password = '{MD5}$1$salt$etVYf53ma13QCiRbQOuRk/' # 12345
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
217 self.createUser(name, password, True)
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
218
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
219 #User don't require to be valid
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
220 theuser = user.User(self.request, name=name, password='12345')
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
221 assert theuser.enc_password[:6] == '{SSHA}'
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
222
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
223 def test_upgrade_password_from_des_to_ssha(self):
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
224 """
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
225 Create user with {DES} password and check that logging in
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
226 upgrades to {SSHA}.
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
227 """
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
228 # Create test user
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
229 name = u'Test User'
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
230 password = '{DES}sajEeYaHYyeSU' # 12345
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
231 self.createUser(name, password, True)
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
232
02798509e918 Add new tests for password upgrading on login (ARP1, MD5, DES)
pavel_vinogradov
parents: 5613
diff changeset
233 #User don't require to be valid
3820
2f2c95506713 user tests: remove form hack that is no longer necessary, fix upgrade test
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3818
diff changeset
234 theuser = user.User(self.request, name=name, password='12345')
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
235 assert theuser.enc_password[:6] == '{SSHA}'
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
236
4656
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
237 def test_for_email_attribute_by_name(self):
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
238 """
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
239 checks for no access to the email attribute by getting the user object from name
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
240 """
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
241 name = u"__TestUser__"
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
242 password = u"ekfdweurwerh"
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
243 email = "__TestUser__@moinhost"
4657
1da5c7d21660 test_user: fixed the wrong encoding of the password
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4656
diff changeset
244 self.createUser(name, password, email=email)
4656
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
245 theuser = user.User(self.request, name=name)
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
246 assert theuser.email == ""
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
247
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
248 def test_for_email_attribut_by_uid(self):
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
249 """
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
250 checks access to the email attribute by getting the user object from the uid
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
251 """
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
252 name = u"__TestUser2__"
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
253 password = u"ekERErwerwerh"
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
254 email = "__TestUser2__@moinhost"
4657
1da5c7d21660 test_user: fixed the wrong encoding of the password
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4656
diff changeset
255 self.createUser(name, password, email=email)
4656
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
256 uid = user.getUserId(self.request, name)
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
257 theuser = user.User(self.request, uid)
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
258 assert theuser.email == email
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
259
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
260 # Helpers ---------------------------------------------------------
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
261
4656
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
262 def createUser(self, name, password, pwencoded=False, email=None):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
263 """ helper to create test user
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
264 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
265 # Create user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
266 self.user = user.User(self.request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
267 self.user.name = name
4656
052b6926c82d test_user: added two tests for the difference of retrieving an user object by uid or name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4027
diff changeset
268 self.user.email = email
3818
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
269 if not pwencoded:
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
270 password = user.encodePassword(password)
fe9305d5c7cf user: adjust tests, add one for password upgrade and fix a bug found
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3120
diff changeset
271 self.user.enc_password = password
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
272
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
273 # Validate that we are not modifying existing user data file!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
274 if self.user.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
275 self.user = None
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
276 py.test.skip("Test user exists, will not override existing user data file!")
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
277
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
278 # Save test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
279 self.user.save()
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
280
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
281 # Validate user creation
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
282 if not self.user.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
283 self.user = None
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
284 py.test.skip("Can't create test user")
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
285
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
286
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
287 class TestGroupName(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
288
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
289 def testGroupNames(self):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
290 """ user: isValidName: reject group names """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
291 test = u'AdminGroup'
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
292 assert not user.isValidName(self.request, test)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
293
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
294
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
295 class TestIsValidName(object):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
296
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
297 def testNonAlnumCharacters(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
298 """ user: isValidName: reject unicode non alpha numeric characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
299
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
300 : and , used in acl rules, we might add more characters to the syntax.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
301 """
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
302 invalid = u'! # $ % ^ & * ( ) = + , : ; " | ~ / \\ \u0000 \u202a'.split()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
303 base = u'User%sName'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
304 for c in invalid:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305 name = base % c
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
306 assert not user.isValidName(self.request, name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
307
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
308 def testWhitespace(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 """ user: isValidName: reject leading, trailing or multiple whitespace """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
310 cases = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 u' User Name',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312 u'User Name ',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
313 u'User Name',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
314 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
315 for test in cases:
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
316 assert not user.isValidName(self.request, test)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
318 def testValid(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 """ user: isValidName: accept names in any language, with spaces """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
320 cases = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 u'Jürgen Hermann', # German
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322 u'ניר סופר', # Hebrew
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323 u'CamelCase', # Good old camel case
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 u'가각간갇갈 갉갊감 갬갯걀갼' # Hangul (gibberish)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
326 for test in cases:
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
327 assert user.isValidName(self.request, test)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
328
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
329
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
330 coverage_modules = ['MoinMoin.user']
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
331