Exemplo n.º 1
0
 def load(cls, json):
     instance = StorageModel()
     entity_json = json['entity'] if 'entity' in json else None
     permissions_json = json[
         'permissions'] if 'permissions' in json else None
     if not entity_json:
         return None
     instance.identifier = entity_json['id']
     instance.name = entity_json['name']
     instance.mask = entity_json['mask']
     instance.type = entity_json['type']
     instance.path = entity_json[
         'pathMask'] if 'pathMask' in entity_json else None
     if 'owner' in entity_json and entity_json['owner'].lower(
     ) != 'unauthorized':
         user = UserModel()
         user.username = entity_json['owner']
         instance.users.append(user)
     if permissions_json is not None:
         for permission_json in permissions_json:
             if 'sid' in permission_json and 'mask' in permission_json:
                 mask = int(permission_json['mask'])
                 if mask & 1 == 1 and mask & 4 == 4:
                     sid_json = permission_json['sid']
                     if 'principal' in sid_json and sid_json[
                             'principal'] and 'name' in sid_json:
                         user = UserModel()
                         user.username = sid_json['name']
                         instance.users.append(user)
     return instance
Exemplo n.º 2
0
    def test_create_user(self):
        username = '******'

        # Read parameters
        user = UserModel()
        user.username = username
        user.email = '*****@*****.**'
        user.setPassword('000000')
        user.project = 'ReLDI'
        user.requests_limit = 1000
        user.requests_made = 0
        user.status = 'active'
        user.role = 'admin'
        user.logRequest()
        user.logRequest()
        user.save()

        dbUser = UserModel.getByUsername(user.username)

        self.assertEqual(dbUser.username, username)
        self.assertEqual(dbUser.project, 'ReLDI')
        self.assertEqual(dbUser.requests_limit, 1000)
        self.assertEqual(dbUser.requests_made, 2)
        self.assertEqual(dbUser.status, 'active')
        self.assertEqual(dbUser.role, 'admin')
Exemplo n.º 3
0
    def test_update_user(self):
        username = '******'
        password = '******'
        # Read parameters
        user = UserModel()
        user.username = username
        user.email = '*****@*****.**'
        user.setPassword(password)
        user.project = 'ReLDI'
        user.requests_limit = 1000
        user.requests_made = 0
        user.status = 'active'
        user.role = 'admin'
        user.save()

        dbUser = UserModel.getByUsername(user.username)

        new_username = '******'
        dbUser.username = new_username
        dbUser.project = 'RelDI2'
        dbUser.requests_limit = 2000
        dbUser.requests_made = 4
        dbUser.status = 'blocked'
        dbUser.role = 'user'
        dbUser.save()

        dbUser = UserModel.getByUsername(new_username)
        self.assertEqual(dbUser.username, new_username)
        self.assertEqual(dbUser.project, 'RelDI2')
        self.assertEqual(dbUser.requests_limit, 2000)
        self.assertEqual(dbUser.requests_made, 4)
        self.assertEqual(dbUser.status, 'blocked')
        self.assertEqual(dbUser.role, 'user')
Exemplo n.º 4
0
    def test_login_user_invalid(self):

        username = '******'
        password = '******'
        # Read parameters
        user = UserModel()
        user.username = username
        user.email = '*****@*****.**'
        user.setPassword(password)
        user.project = 'ReLDI'
        user.requests_limit = 1000
        user.requests_made = 0
        user.status = 'active'
        user.role = 'admin'
        user.save()

        dbUser = UserModel.getByUsername(user.username)
        with self.assertRaises(ValueError):
            token = dbUser.generateToken('not this password')
Exemplo n.º 5
0
    def test_login_user(self):

        username = '******'
        password = '******'
        # Read parameters
        user = UserModel()
        user.username = username
        user.email = '*****@*****.**'
        user.setPassword(password)
        user.project = 'ReLDI'
        user.requests_limit = 1000
        user.requests_made = 0
        user.status = 'active'
        user.role = 'admin'
        user.save()

        dbUser = UserModel.getByUsername(user.username)
        token = dbUser.generateToken(password)
        self.assertIsNotNone(token)
Exemplo n.º 6
0
    def test_status_block_user(self):
        username = '******'
        password = '******'
        user = UserModel()
        user.username = username
        user.email = '*****@*****.**'
        user.setPassword(password)
        user.project = 'ReLDI'
        user.requests_limit = 1000
        user.requests_made = 0
        user.status = 'active'
        user.role = 'admin'
        user.save()

        dbUser = UserModel.getByUsername(user.username)

        dbUser.block()

        self.assertEqual(dbUser.status, 'blocked')
Exemplo n.º 7
0
    def test_delete_user(self):
        username = '******'
        # Read parameters
        user = UserModel()
        user.username = username
        user.email = '*****@*****.**'
        user.setPassword('000000')
        user.project = 'ReLDI'
        user.requests_limit = 1000
        user.requests_made = 0
        user.status = 'active'
        user.role = 'admin'
        user.save()

        dbUser = UserModel.getByUsername(user.username)
        self.assertIsNotNone(dbUser)

        dbUser.delete()
        dbUser = UserModel.getByUsername(user.username)
        self.assertIsNone(dbUser)