Example #1
0
 def testUserInfoSignupValidation2(self):
     """
     Ensure that invalid characters aren't allowed in usernames, that
     usernames are parsable as the local part of an email address and that
     usernames shorter than two characters are invalid.
     """
     signup = self.createFreeSignup(free_signup.userInfo.itemClass)
     self.assertEquals(signup.usernameAvailable(u'foo bar', u'localhost'),
                       [False, u"Username contains invalid character: ' '"])
     self.assertEquals(signup.usernameAvailable(u'[email protected]', u'localhost'),
                       [False, u"Username contains invalid character: '@'"])
     # '~' is not expressly forbidden by the validator in usernameAvailable,
     # yet it is rejected by parseAddress (in xmantissa.smtp).
     self.assertEquals(signup.usernameAvailable(u'fo~o', u'127.0.0.1'),
                       [False, u"Username fails to parse"])
     self.assertEquals(signup.usernameAvailable(u'f', u'localhost'),
                       [False, u"Username too short"])
Example #2
0
    def test_usernameAvailability(self):
        """
        Test that the usernames which ought to be available are and that those
        which aren't are not:

        Only syntactically valid localparts are allowed.  Localparts which are
        already assigned are not allowed.

        Only domains which are actually served by this mantissa instance are
        allowed.
        """

        signup = self.createFreeSignup(free_signup.userInfo.itemClass)
        # Allowed: unused localpart, same domain as the administrator created
        # by setUp.
        self.failUnless(signup.usernameAvailable(u'alice', u'localhost')[0])

        # Not allowed: unused localpart, unknown domain.
        self.failIf(signup.usernameAvailable(u'alice', u'example.com')[0])

        # Not allowed: used localpart, same domain as the administrator created
        # by setUp.
        self.failIf(signup.usernameAvailable(u'admin', u'localhost')[0])
        self.assertEquals(signup.usernameAvailable(u'fjones', u'localhost'),
                          [True, u'Username already taken'])

        signup.createUser(
            realName=u"Frank Jones",
            username=u'fjones',
            domain=u'localhost',
            password=u'asdf',
            emailAddress=u'[email protected]')

        self.assertEquals(signup.usernameAvailable(u'fjones', u'localhost'),
                          [False, u'Username already taken'])
        ss = self.ls.accountByAddress(u"fjones", u"localhost").avatars.open()
        self.assertEquals(ss.query(Installation).count(), 1)