chiark / gitweb /
The server now treats setting an empty email address as removing that
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 19 Apr 2008 18:37:45 +0000 (19:37 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 19 Apr 2008 18:37:45 +0000 (19:37 +0100)
property.  Includes a test.

doc/disorder_protocol.5.in
lib/trackdb.c
tests/user.py

index 24ad5e834796b233b0214ac290f2e08197b10350..678c1fd0da4e5438bd5771f881c3808efb973814 100644 (file)
@@ -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.
index 6a93fbaba33562676ea7fd0f828ca64855d2dd10..80bfa01e0647e402b4658eb1fd24e6a6b8618bea 100644 (file)
@@ -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;
index 2e5f86e85de8f3060faab9098e89e39d701abb22..1f3a39fe568775f767ed7b2ee74d512fd7cc6c4c 100755 (executable)
@@ -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()