コード例 #1
0
 def test_addUser(self):
     newUser = user.addUser("dust", "goodPassword")
     self.assertEqual(newUser, user.getUser("dust"))  #Add user
     self.assertRaises(
         ValueError,
         lambda: user.addUser("", "goodPassword"))  #Min length username
     self.assertRaises(ValueError, lambda: user.addUser(
         "f" * 31, "goodPassword"))  #Max length username
     self.assertRaises(
         TypeError,
         lambda: user.addUser(None, "goodPassword"))  #Username type
     self.assertRaises(
         ValueError,
         lambda: user.addUser("another", "123"))  #Min length password
     self.assertRaises(TypeError,
                       lambda: user.addUser("one", None))  #Password type
     self.assertRaises(ValueError, lambda: user.addUser(
         "bytes", "goodPassword", name="F" * 61))  #Max length name
     self.assertRaises(ValueError, lambda: user.addUser(
         "the", "goodPassword", email="F" * 61))  #Min length email
     self.assertRaises(
         ValueError,
         lambda: user.addUser("dust", "goodPassword"))  #Duplicate username
     otherUser = user.addUser("jimbo", "goodPassword")
     self.assertNotEqual(newUser.salt,
                         otherUser.salt)  #Check for proper salting
     self.assertNotEqual(newUser.password_hash,
                         otherUser.password_hash)  #Check for proper hashing
コード例 #2
0
 def test_authenticateUser(self):
     newUser = user.addUser("dust", "goodPassword")
     self.assertIsNone(user.authenticateUser("dust", "badPassword"))
     self.assertEqual(user.authenticateUser("dust", "goodPassword"),
                      newUser)
     self.assertIsNone(user.authenticateUser("fakeUsername",
                                             "goodPassword"))
コード例 #3
0
def signup():
    error = None
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        email = request.form['email']
        name = request.form['name']

        # Need to check if username is already taken here
        check = check_username(username)
        if check:
            error = 'Username already taken.'
        else:
            addUser(username=username,
                    password=password,
                    name=name,
                    email=email)
            session['username'] = username
            return redirect('/')
    return render_template('signup.html', error=error)
コード例 #4
0
 def test_editUser(self):
     user1 = user.getUser("username")
     user1new = user.editUser(user1, username="******")
     self.assertEqual(user1.id, user1new.id)
     self.assertEqual(user1new.username, "farquad")
     user1 = user.addUser("Test1", "Test1", "Test1")
     self.assertRaises(ValueError,
                       lambda: user.editUser(user1, "Test2", "ah"))
     user1new = user.getUser(user1.id)
     self.assertEqual(user1.username, user1new.username)  #Test rollback
     user1new = user.editUser(user1, password="******")
     self.assertTrue(user.authenticateUser(user1new.username,
                                           "newPassword"))
コード例 #5
0
def generatePopulateDB():
    generateDB()
    user.addUser(username="******",
                 password="******",
                 name="name",
                 email="*****@*****.**")
    user.addUser(username="******", password="******", name="testname")
    user.addUser(username="******",
                 password="******",
                 name="Jeff jeff",
                 email="*****@*****.**")
    user.addUser(username="******", password="******")
    event.createEvent(name="Wake up",
                      owner=user.getUser("test").id,
                      event_type=event.EventType.REMINDER,
                      start_time=datetime.datetime.now())
    event.createEvent(name="Rocks",
                      owner=user.getUser("Jeff").id,
                      description="Granit, Bassalt, Quartz",
                      event_type=event.EventType.NOTE)
    event.createEvent(name="Short party",
                      owner=user.getUser("username").id,
                      event_type=event.EventType.EVENT,
                      start_time=datetime.datetime.now(),
                      end_time=datetime.datetime.now() +
                      datetime.timedelta(hours=3))
    event.createEvent(
        name="Secrets",
        owner=user.getUser("test").id,
        event_type=event.EventType.ENCRYPTED,
        password="******",
        description=
        "Some passwords, SSNs, creditcard numbers, and otherthings you shouldn't trust this app with"
    )
    event.createPage(name="test page",
                     owner=user.getUser("test"),
                     description="This is a test page")
    event.createPage(name="test page 2", owner=user.getUser("test"))
    event.createPage(name="Jeffs stuff", owner=user.getUser("Jeff"))
    page1 = event.createPage(name="more thigns",
                             owner=user.getUser("username"))
    event.createEvent(name="its on a page",
                      owner=user.getUser("username").id,
                      event_type=event.EventType.NOTE,
                      page=page1)