Beispiel #1
0
 def test_generate_token(self):
     user = User(test=True)
     user = user.find_by_username('*****@*****.**')
     token = user.get_token() # Detects test db mode from instance
     expected_decoded = {
         'username': '******',
         'type': 'agent'
     }
     s = Serializer('NOT_SO_SECRET_KEY')
     decoded = s.loads(token)
     self.assertEqual(expected_decoded, decoded)
Beispiel #2
0
 def test_verify_token_valid_and_not_expired(self):
     s = Serializer('NOT_SO_SECRET_KEY', expires_in = 30)
     valid_token = s.dumps(
         {
             'username': '******',
             'type': 'agent'
         }
     )
     verify_result = User.verify_token(valid_token)
     expected = True
     self.assertEqual(expected, verify_result)
Beispiel #3
0
 def test_verify_token_valid_but_expired(self):
     s = Serializer('NOT_SO_SECRET_KEY', expires_in = 0)
     valid_expired_token = s.dumps(
         {
             'username': '******',
             'type': 'agent'
         }
     )
     time.sleep(1)
     token_is_valid = User.verify_token(valid_expired_token)
     self.assertFalse(token_is_valid)
Beispiel #4
0
 def populate_test_users(cls):
     client = MongoClient()
     db = client.featkeeper_test
     collection = db.users
     user = User(test=True)
     UserModel = user.UserModel
     admin_user = UserModel({
         '_id': ObjectId('56d3d524402e5f1cfc123340'),
         'username': '******',
         'hashim':
         'pbkdf2:sha1:1000$jtKuDWVP$a5c1e9ec705182e4d6d8dcd301e0e718732cd88a',
         'type': 'admin',
         'created_at': '2016-03-02 23:35:19',
         'access_is_enabled': 1
     })
     admin_user.save()
     agent_user_1 = UserModel({
         '_id': ObjectId('56d3d524402e5f1cfc124340'),
         'username': '******',
         'hashim':
         'pbkdf2:sha1:1000$Y9kglHda$6a2190090d720c9ea929bb65818563fb22cfb026',
         'type': 'agent',
         'created_at': '2016-03-02 23:38:15',
         'access_is_enabled': 1
     })
     agent_user_1.save()
     agent_user_2 = UserModel({
         '_id': ObjectId('56d3d524402e5f1cfc125340'),
         'username': '******',
         'hashim':
         'pbkdf2:sha1:1000$B0mPc4td$4fdc169569d2beea30dba590c2bf053b8b4e42fa',
         'type': 'agent',
         'created_at': '2016-02-28 23:40:10',
         'access_is_enabled': 0
     })
     agent_user_2.save()
Beispiel #5
0
 def test_agent_auth_succesful(self):
     username = '******'
     password = '******'
     user = User(test=True)
     user_type = user.auth(username, password)
     self.assertEqual('agent', user_type)
Beispiel #6
0
 def test_verify_password(self):
     user = User(test=True)
     user.set_password('1234') # setting makes dependant of previous test, remove!
     self.assertFalse(user.verify_password('testSetPassword'))
Beispiel #7
0
 def test_set_password(self):
     user = User(test=True)
     user.set_password('testSetPassword')
     self.assertRegexpMatches(user.hashim, 'pbkdf2:sha1:1000\$[a-zA-Z0-9_]{8}\$*[a-zA-Z0-9_]{40}')
Beispiel #8
0
 def test_verify_token_invalid(self):
     invalid_fake_token = '1nv4lidT0k3n'
     token_is_valid = User.verify_token(invalid_fake_token)
     self.assertFalse(token_is_valid)
Beispiel #9
0
 def test_default_is_agent(self):
     user = User(test=True)
     self.assertEqual(user.type, 'agent')
Beispiel #10
0
 def test_use_test_db(self):
     user = User(test=True)
     self.assertEqual('featkeeper_test', user.db.name)
Beispiel #11
0
 def test_use_dev_db(self):
     user = User()
     self.assertEqual('featkeeper', user.db.name)
Beispiel #12
0
 def test_auth_failed_user_disabled(self):
     username = '******'
     password = '******'
     user = User(test=True)
     user_type = user.auth(username, password)
     self.assertFalse(user_type)
Beispiel #13
0
 def test_auth_failed_wrong_password(self):
     username = '******'
     password = '******'
     user = User(test=True)
     user_type = user.auth(username, password)
     self.assertFalse(user_type)
Beispiel #14
0
 def test_auth_failed_nonexistent_user(self):
     username = '******'
     password = '******'
     user = User(test=True)
     user_type = user.auth(username, password)
     self.assertFalse(user_type)
Beispiel #15
0
 def test_admin_auth_succesful(self):
     username = '******'
     password = '******'
     user = User(test=True)
     user_type = user.auth(username, password)
     self.assertEqual('admin', user_type)