chiark / gitweb /
Merge config aliasing bug fix.
[disorder] / tests / user.py
1 #! /usr/bin/env python
2 #
3 # This file is part of DisOrder.
4 # Copyright (C) 2007, 2008 Richard Kettlewell
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 import dtest,disorder
20
21 def test():
22     """Test user database"""
23     dtest.start_daemon()
24     dtest.create_user()
25     print " checking user creation"
26     c = disorder.client()
27     c.adduser("bob", "bobpass")
28     users = c.users()
29     assert dtest.lists_have_same_contents(users,
30                                           ["fred", "bob", "root"])
31     rights = c.userinfo("bob", "rights")
32     print " new user rights are: %s" % rights
33     print " checking new user can log in"
34     c = disorder.client(user="bob", password="bobpass")
35     c.version()
36     print " checking bob can set their email address"
37     c.edituser("bob", "email", "foo@bar")
38     email = c.userinfo("bob", "email")
39     assert email == "foo@bar", "checking bob's email address"
40     print " checking user deletion"
41     c = disorder.client()
42     c.deluser("bob")
43     print " checking new user can no longer log in"
44     c = disorder.client(user="bob", password="bobpass")
45     try:
46       c.version()
47       print "*** should not be able to log in after deletion ***"
48       assert False
49     except disorder.operationError:
50       pass                              # good
51     print " deleted user could no longer log in."
52     c = disorder.client()
53     users = c.users()
54     assert dtest.lists_have_same_contents(users,
55                                           ["fred", "root"])
56     print " creating the guest user"
57     dtest.command(["disorder",
58                    "--config", disorder._configfile, "--no-per-user-config",
59                    "--user", "root", "setup-guest"])
60     print " logging in as guest user"
61     gc = disorder.client(user="guest", password="")
62     gc.version()
63     print " testing user registration"
64     cs = gc.register("joe", "joepass", "joe@nowhere.invalid")
65     print " confirmation string is %s" % cs
66     print " checking unconfirmed user cannot log in"
67     jc = disorder.client(user="joe", password="joepass")
68     try:
69       jc.version()
70       print "*** should not be able to log in before confirmation ***"
71       assert False
72     except disorder.operationError:
73       pass                              # good
74     print " confirming user"
75     gc = disorder.client(user="guest", password="")
76     gc.confirm(cs)
77     print " checking confirmed user can log in"
78     jc = disorder.client(user="joe", password="joepass")
79     jc.version()
80     print " checking new user's email address"
81     assert c.userinfo("joe", "email") == "joe@nowhere.invalid"
82     print " checking can change user email address"
83     c.edituser("joe", "email", "joe@another.invalid")
84     assert c.userinfo("joe", "email") == "joe@another.invalid"
85     print " checking bad email address rejected"
86     try:
87       c.edituser("joe", "email", "invalid")
88       print "*** should not be able to set invalid email address ***"
89       assert False
90     except disorder.operationError:
91       pass                              # good
92     assert c.userinfo("joe", "email") == "joe@another.invalid"
93     print " checking removal of email address"
94     c.edituser("joe", "email", "")
95     assert c.userinfo("joe", "email") == None
96
97 if __name__ == '__main__':
98     dtest.run()