From: Richard Kettlewell Date: Sat, 19 Apr 2008 18:37:45 +0000 (+0100) Subject: The server now treats setting an empty email address as removing that X-Git-Tag: 4.0~115^2~11 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/0517868c5cbbfabf18625f6d833821047459f36d The server now treats setting an empty email address as removing that property. Includes a test. --- diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index 24ad5e8..678c1fd 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -91,6 +91,10 @@ Set a user property. With the \fBadmin\fR right any username and property may be specified. Otherwise the \fBuserinfo\fR right is required and only the \fBemail\fR and \fBpassword\fR properties may be set. +.IP +User properties are syntax-checked before setting. For instance \fBemail\fR +must contain an "@" sign or you will get an error. (Setting an empty value for +\fBemail\fR is allowed and removes the property.) .TP .B enable Re-enable further playing, and is the opposite of \fBdisable\fR. diff --git a/lib/trackdb.c b/lib/trackdb.c index 6a93fba..80bfa01 100644 --- a/lib/trackdb.c +++ b/lib/trackdb.c @@ -2630,10 +2630,13 @@ int trackdb_edituserinfo(const char *user, return -1; } } else if(!strcmp(key, "email")) { - if(!strchr(value, '@')) { - error(0, "invalid email address '%s' for user '%s'", user, value); - return -1; - } + if(*value) { + if(!strchr(value, '@')) { + error(0, "invalid email address '%s' for user '%s'", user, value); + return -1; + } + } else + value = 0; /* no email -> remove key */ } else if(!strcmp(key, "created")) { error(0, "cannot change creation date for user '%s'", user); return -1; diff --git a/tests/user.py b/tests/user.py index 2e5f86e..1f3a39f 100755 --- a/tests/user.py +++ b/tests/user.py @@ -79,6 +79,22 @@ def test(): print " checking confirmed user can log in" jc = disorder.client(user="joe", password="joepass") jc.version() + print " checking new user's email address" + assert c.userinfo("joe", "email") == "joe@nowhere.invalid" + print " checking can change user email address" + c.edituser("joe", "email", "joe@another.invalid") + assert c.userinfo("joe", "email") == "joe@another.invalid" + print " checking bad email address rejected" + try: + c.edituser("joe", "email", "invalid") + print "*** should not be able to set invalid email address ***" + assert False + except disorder.operationError: + pass # good + assert c.userinfo("joe", "email") == "joe@another.invalid" + print " checking removal of email address" + c.edituser("joe", "email", "") + assert c.userinfo("joe", "email") == None if __name__ == '__main__': dtest.run()