示例#1
0
 def test_delete_user_as_admin(self):
     infos = {'fullname': u'John Doe',
              'email': '*****@*****.**',
              'password': "******"}
     localuser.update_user(u'john', infos)
     self.assertIsInstance(localuser.model.get_user(u'john'), dict)
     localuser.delete_user(u'john')
     self.assertFalse(localuser.model.get_user(u'john'))
     # Also test good behavior trying to remove user that not exixt
     self.assertRaises(localuser.UserNotFound,
                       lambda: localuser.delete_user(u'john'))
示例#2
0
 def test_add_user_as_admin(self):
     infos = {'fullname': u'John Doe',
              'email': '*****@*****.**',
              'password': "******"}
     localuser.update_user(u'john', infos)
     expected = {'username': '******',
                 'fullname': u'John Doe',
                 'email': '*****@*****.**',
                 'sshkey': 'None'}
     ret = localuser.model.get_user(u'john')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
示例#3
0
 def test_delete_user_as_admin(self):
     infos = {
         'fullname': u'John Doe',
         'email': '*****@*****.**',
         'password': "******"
     }
     localuser.update_user(u'john', infos)
     self.assertIsInstance(localuser.model.get_user(u'john'), dict)
     localuser.delete_user(u'john')
     self.assertFalse(localuser.model.get_user(u'john'))
     # Also test good behavior trying to remove user that not exixt
     self.assertRaises(localuser.UserNotFound,
                       lambda: localuser.delete_user(u'john'))
示例#4
0
 def test_unicode_user(self):
     infos = {'fullname': u'うずまきナルト',
              'email': 'hokage@konoha',
              'password': "******"}
     localuser.update_user(u'七代目火影4lyf', infos)
     expected = {'username': u'七代目火影4lyf',
                 'fullname': u'うずまきナルト',
                 'email': 'hokage@konoha',
                 'sshkey': 'None'}
     ret = localuser.model.get_user(u'七代目火影4lyf')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
     authorization = encode(u'七代目火影4lyf'.encode('utf8'), "abc")
     self.assertDictEqual(expected,
                          localuser.bind_user(authorization),
                          localuser.bind_user(authorization))
示例#5
0
 def test_add_user_as_admin(self):
     infos = {
         'fullname': u'John Doe',
         'email': '*****@*****.**',
         'password': "******"
     }
     localuser.update_user(u'john', infos)
     expected = {
         'username': '******',
         'fullname': u'John Doe',
         'email': '*****@*****.**',
         'sshkey': 'None'
     }
     ret = localuser.model.get_user(u'john')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
示例#6
0
 def test_get_user(self):
     infos = {'fullname': u'John Doe',
              'email': '*****@*****.**',
              'password': "******"}
     localuser.update_user(u'john', infos)
     expected = {'username': '******',
                 'email': '*****@*****.**',
                 'fullname': u'John Doe',
                 'sshkey': 'None'}
     ret = localuser.model.get_user(u'john')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
     ret = localuser.model.get_user(u'john')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
     self.assertRaises(localuser.UserNotFound,
                       lambda: localuser.get_user(u'maria'))
示例#7
0
 def test_add_update_user_bad_input(self):
     infos = {
         'fullname': u'John Doe',
         'email': '*****@*****.**',
         'hashed_password': "******"
     }
     self.assertRaises(localuser.InvalidInfosInput,
                       lambda: localuser.update_user(u'john', infos))
示例#8
0
    def test_update_user_as_owner(self):
        infos = {'fullname': u'John Doe',
                 'email': '*****@*****.**',
                 'password': "******"}
        localuser.update_user(u'john', infos)
        # John trying to update its account

        infos = {'fullname': u'Maria Doe',
                 'email': '*****@*****.**',
                 'password': "******"}
        localuser.update_user(u'john', infos)
        expected = {'username': '******',
                    'email': '*****@*****.**',
                    'fullname': u'Maria Doe',
                    'sshkey': 'None'}
        ret = localuser.model.get_user(u'john')
        del ret['hashed_password']
        self.assertDictEqual(ret, expected)
示例#9
0
 def test_bind_user(self):
     base_infos = {'fullname': u'John Doe',
                   'email': '*****@*****.**', }
     infos = {'password': "******"}
     public_infos = {'username': '******', 'sshkey': 'None'}
     infos.update(base_infos)
     public_infos.update(base_infos)
     localuser.update_user(u'john', infos)
     authorization = encode('john', "abc")
     self.assertEqual(public_infos,
                      localuser.bind_user(authorization),
                      localuser.bind_user(authorization))
     authorization = encode('john', "abc123")
     self.assertRaises(localuser.BindForbidden,
                       lambda: localuser.bind_user(authorization))
     authorization = encode('denis', "abc")
     self.assertRaises(localuser.UserNotFound,
                       lambda: localuser.bind_user(authorization))
示例#10
0
 def test_unicode_user(self):
     infos = {
         'fullname': u'うずまきナルト',
         'email': 'hokage@konoha',
         'password': "******"
     }
     localuser.update_user(u'七代目火影4lyf', infos)
     expected = {
         'username': u'七代目火影4lyf',
         'fullname': u'うずまきナルト',
         'email': 'hokage@konoha',
         'sshkey': 'None'
     }
     ret = localuser.model.get_user(u'七代目火影4lyf')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
     authorization = encode(u'七代目火影4lyf'.encode('utf8'), "abc")
     self.assertDictEqual(expected, localuser.bind_user(authorization),
                          localuser.bind_user(authorization))
示例#11
0
 def test_bind_user(self):
     base_infos = {
         'fullname': u'John Doe',
         'email': '*****@*****.**',
     }
     infos = {'password': "******"}
     public_infos = {'username': '******', 'sshkey': 'None'}
     infos.update(base_infos)
     public_infos.update(base_infos)
     localuser.update_user(u'john', infos)
     authorization = encode('john', "abc")
     self.assertEqual(public_infos, localuser.bind_user(authorization),
                      localuser.bind_user(authorization))
     authorization = encode('john', "abc123")
     self.assertRaises(localuser.BindForbidden,
                       lambda: localuser.bind_user(authorization))
     authorization = encode('denis', "abc")
     self.assertRaises(localuser.UserNotFound,
                       lambda: localuser.bind_user(authorization))
示例#12
0
 def test_get_user(self):
     infos = {
         'fullname': u'John Doe',
         'email': '*****@*****.**',
         'password': "******"
     }
     localuser.update_user(u'john', infos)
     expected = {
         'username': '******',
         'email': '*****@*****.**',
         'fullname': u'John Doe',
         'sshkey': 'None'
     }
     ret = localuser.model.get_user(u'john')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
     ret = localuser.model.get_user(u'john')
     del ret['hashed_password']
     self.assertDictEqual(ret, expected)
     self.assertRaises(localuser.UserNotFound,
                       lambda: localuser.get_user(u'maria'))
示例#13
0
    def test_update_user_as_owner(self):
        infos = {
            'fullname': u'John Doe',
            'email': '*****@*****.**',
            'password': "******"
        }
        localuser.update_user(u'john', infos)
        # John trying to update its account

        infos = {
            'fullname': u'Maria Doe',
            'email': '*****@*****.**',
            'password': "******"
        }
        localuser.update_user(u'john', infos)
        expected = {
            'username': '******',
            'email': '*****@*****.**',
            'fullname': u'Maria Doe',
            'sshkey': 'None'
        }
        ret = localuser.model.get_user(u'john')
        del ret['hashed_password']
        self.assertDictEqual(ret, expected)
示例#14
0
 def post(self, username):
     _policy = 'managesf.localuser:create_update'
     if not authorize(_policy, target={'username': username}):
         return abort(401,
                      detail='Failure to comply with policy %s' % _policy)
     infos = request.json if request.content_length else {}
     try:
         ret = localuser.update_user(username, infos)
     except (localuser.InvalidInfosInput, localuser.BadUserInfos) as e:
         abort(400, detail=unicode(e))
     except Exception as e:
         return report_unhandled_error(e)
     if isinstance(ret, dict):
         # user created - set correct status code
         response.status = 201
     return ret
示例#15
0
 def post(self, username):
     _policy = 'managesf.localuser:create_update'
     if not authorize(_policy,
                      target={'username': username}):
         return abort(401,
                      detail='Failure to comply with policy %s' % _policy)
     infos = request.json if request.content_length else {}
     try:
         ret = localuser.update_user(username, infos)
     except (localuser.InvalidInfosInput, localuser.BadUserInfos) as e:
         abort(400, detail=unicode(e))
     except Exception as e:
         return report_unhandled_error(e)
     if isinstance(ret, dict):
         # user created - set correct status code
         response.status = 201
     return ret
示例#16
0
 def test_add_update_user_bad_input(self):
     infos = {'fullname': u'John Doe',
              'email': '*****@*****.**',
              'hashed_password': "******"}
     self.assertRaises(localuser.InvalidInfosInput,
                       lambda: localuser.update_user(u'john', infos))