summaryrefslogtreecommitdiffstats
path: root/tests/functional/test_wap_client/test_007_policy_uid.py
blob: 534ebdacf1641f110c011c444d217833136c2d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from ConfigParser import RawConfigParser
import time
import unittest

import pykolab
from pykolab import wap_client
from pykolab.auth import Auth
from pykolab.imap import IMAP

conf = pykolab.getConf()

class TestPolicyUid(unittest.TestCase):

    def remove_option(self, section, option):
        self.config.remove_option(section, option)

        fp = open(conf.config_file, "w")
        self.config.write(fp)
        fp.close()

    def set(self, section, option, value):
        self.config.set(section, option, value)

        fp = open(conf.config_file, "w")
        self.config.write(fp)
        fp.close()

    @classmethod
    def setup_class(self, *args, **kw):
        self.config = RawConfigParser()
        self.config.read(conf.config_file)

        from tests.functional.purge_users import purge_users
        purge_users()

        self.user = {
                'local': 'john.doe',
                'domain': 'example.org'
            }

        self.login = conf.get('ldap', 'bind_dn')
        self.password = conf.get('ldap', 'bind_pw')
        self.domain = conf.get('kolab', 'primary_domain')

        result = wap_client.authenticate(self.login, self.password, self.domain)

    @classmethod
    def teardown_class(self, *args, **kw):
        self.config.remove_option('example.org', 'policy_uid')

        fp = open(conf.config_file, "w")
        self.config.write(fp)
        fp.close()

        from tests.functional.purge_users import purge_users
        purge_users()

    def test_001_default(self):
        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('john.doe@example.org')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "doe")

        from tests.functional.purge_users import purge_users
        purge_users()

    def test_002_givenname_dot_surname(self):
        self.set('example.org', 'policy_uid', '%(givenname)s.%(surname)s')

        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('john.doe@example.org')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "John.Doe")

        from tests.functional.purge_users import purge_users
        purge_users()

    def test_003_givenname_fc_dot_surname(self):
        self.set('example.org', 'policy_uid', "'%(givenname)s'[0:1].%(surname)s")

        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('john.doe@example.org')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "J.Doe")

        from tests.functional.purge_users import purge_users
        purge_users()

    def test_004_givenname(self):
        self.set('example.org', 'policy_uid', '%(givenname)s')

        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('john.doe@example.org')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "John")

        from tests.functional.purge_users import purge_users
        purge_users()

    def test_005_lowercase_givenname(self):
        self.set('example.org', 'policy_uid', '%(givenname)s.lower()')

        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('john.doe@example.org')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "john")

        from tests.functional.purge_users import purge_users
        purge_users()

    def test_006_lowercase_givenname_surname(self):
        self.set('example.org', 'policy_uid', "%(givenname)s.lower().%(surname)s.lower()")

        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('john.doe@example.org')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "john.doe")

        from tests.functional.purge_users import purge_users
        purge_users()