Esempio n. 1
0
    def wrapper(*args, **kwargs):
        pub_key = get_pub_key()
        user = None
        try:
            jwt_header_name, token, tenant = jwt_utils.jwt_tenant(
                request.headers)
        except ValueError:
            # TODO consider using something else like Flask-Login
            # if not JWT information is provided in header, then this is a guest user
            user = AnonymousUser()
        if user is None:
            try:
                # TODO: validate token
                decoded = jwt.decode(token, pub_key, verify=False)
                username = decoded["http://wso2.org/claims/enduser"]
                # remove ant @carbon.super or other nonsense, the tenant
                # we get from the header anyway
                username = username.split("@")[0]
            except Exception as e:
                logger.exception(e)
                abort(400, 'could not decode JWT')

            user = UserService.getUser(username, tenant)
            if not user:
                user = UserService.create(username=username,
                                          jwt=token,
                                          tenant=tenant)
            # In case the JWT was updated for some reason, reset the jwt
            UserService.setJWT(user, token)
        request.current_user = user
        return fn(*args, **kwargs)
Esempio n. 2
0
def test_add_new_user_to_project(userdata):
    user = UserService.getUser("test1", "test")
    data = {
        'project': {
            'name': 'new project',
            'description': 'test'
        },
    }
    proj = ProjectsService.create(data, user)
    ProjectsService.addUserToProject(proj.id, "newUser")
    proj = ProjectsService.get(project_id=proj.id)
    assert len(proj.users) == 2
Esempio n. 3
0
def test_projects_for_user(userdata):
    user = UserService.getUser("test1", "test")
    data = {
        'project': {
            'name': 'new project',
            'description': 'test'
        },
    }
    ProjectsService.create(data, user)
    myProjects = ProjectsService.list(user)
    assert len(myProjects) == 1
    assert myProjects[0].name == 'new project'
Esempio n. 4
0
def test_user_get(userdata):
    user = UserService.getUser("test1", "test")
    assert user.id is not None
    assert user.created is not None