def test_user_password(self, testapp): """ Test password hashing and checking """ admin = User('admin', 'supersafepassword') assert admin.username == 'admin' assert admin.check_password('supersafepassword')
def test_valid_reset_token(self): user = User('test') user.password = '******' user.email = '*****@*****.**' db.session.add(user) # 只有commit了才能拿到id,以便生成token db.session.commit() token = user.generate_reset_token(user.email) self.assertTrue(user.reset_password(token, 'dog')) self.assertTrue(user.check_password('dog'))
def test_invalid_reset_token(self): user1 = User('test1') user2 = User('test2') user1.password = '******' user2.password = '******' user1.email = '*****@*****.**' user2.email = '*****@*****.**' db.session.add(user1) db.session.add(user2) db.session.commit() token = user1.generate_reset_token(user1.email) self.assertFalse(user2.reset_password(token, 'puppy')) self.assertTrue(user2.check_password('dog'))
def test_password_hashing(self): u = User(username='******') u.set_password('cat') self.assertFalse(u.check_password('dog')) self.assertTrue(u.check_password('cat'))
def test_password_hashing(self): u = User(username='******') u.set_password('password') self.assertFalse(u.check_password('wrongPassword')) self.assertTrue(u.check_password('password'))
def test_password_hashing(self): u = User(username='******') u.set_password('Password1') self.assertFalse(u.check_password('password')) self.assertTrue(u.check_password('Password1'))
def test_password_verification(self): user = User('test') user.password = '******' self.assertTrue(user.check_password('cat')) self.assertFalse(user.check_password('dog'))
def test_password_hashing(self): u = User(username="******") u.set_password("warmthecockles") self.assertFalse(u.check_password("titanicSinking")) self.assertTrue(u.check_password("warmthecockles"))