コード例 #1
0
ファイル: test_user.py プロジェクト: shabeeb-aot/sbc-auth
def test_update_from_jwt_token(session):  # pylint: disable=unused-argument
    """Assert User is updated from a JWT and an existing User model."""
    token = {
        'preferred_username': '******',
        'firstname': 'Bobby',
        'lasname': 'Joe',
        'realm_access': {
            'roles': ['edit', 'uma_authorization', 'basic']
        },
        'sub': '1b20db59-19a0-4727-affe-c6f64309fd04'
    }
    user = User.create_from_jwt_token(token, 'Bobby', 'Joe')

    updated_token = {
        'preferred_username': '******',
        'firstname': 'Bob',
        'lastname': 'Joe',
        'realm_access': {
            'roles': ['edit', 'uma_authorization', 'basic']
        },
        'sub': '1b20db59-19a0-4727-affe-c6f64309fd04'
    }
    user = User.update_from_jwt_token(user, updated_token, 'Bob', 'Joe')

    assert user.firstname == 'Bob'
コード例 #2
0
def test_create_from_jwt_token(session):
    """Assert User is created from the JWT fields."""
    token = {'preferred_username': '******',
             'realm_access': {'roles': [
                 'edit',
                 'uma_authorization',
                 'basic'
             ]}}
    u = User.create_from_jwt_token(token)
    assert u.id is not None
コード例 #3
0
ファイル: test_user.py プロジェクト: riyazuddinsyed/sbc-auth
def test_create_from_jwt_token(session):
    """Assert User is created from the JWT fields."""
    token = {
        'preferred_username': '******',
        "realm_access": {
            "roles": ["edit", "uma_authorization", "basic"]
        }
    }
    u = User.create_from_jwt_token(token)
    assert u.id is not None
コード例 #4
0
def test_create_from_jwt_token(session):  # pylint: disable=unused-argument
    """Assert User is created from the JWT fields."""
    token = {
        'preferred_username': '******',
        'realm_access': {
            'roles': ['edit', 'uma_authorization', 'basic']
        },
        'sub': '1b20db59-19a0-4727-affe-c6f64309fd04'
    }
    u = User.create_from_jwt_token(token)
    assert u.id is not None
コード例 #5
0
ファイル: user.py プロジェクト: riyazuddinsyed/sbc-auth
    def save_from_jwt_token(cls, token: dict = None):
        if not token:
            return None
        user_dao = UserModel.create_from_jwt_token(token)

        if not user_dao:
            return None

        user = User()
        user._dao = user_dao  # pylint: disable=protected-access
        return user
コード例 #6
0
ファイル: test_user.py プロジェクト: shabeeb-aot/sbc-auth
def test_update_from_jwt_token_no_token(session):  # pylint:disable=unused-argument
    """Assert that a user is not updateable without a token (should return None)."""
    token = {
        'preferred_username': '******',
        'firstname': 'Bobby',
        'lasname': 'Joe',
        'realm_access': {
            'roles': ['edit', 'uma_authorization', 'basic']
        },
        'sub': '1b20db59-19a0-4727-affe-c6f64309fd04'
    }
    existing_user = User.create_from_jwt_token(token, 'Bobby', 'Joe')

    token = None
    user = User.update_from_jwt_token(existing_user, token, 'Bobby', 'Joe')
    assert user is None
コード例 #7
0
ファイル: user.py プロジェクト: sumesh-aot/sbc-auth
    def save_from_jwt_token(cls, token: dict = None):
        """Save user to database (create/update)."""
        if not token:
            return None

        existing_user = UserModel.find_by_jwt_token(token)
        if existing_user is None:
            user_model = UserModel.create_from_jwt_token(token)
        else:
            user_model = UserModel.update_from_jwt_token(token, existing_user)

        if not user_model:
            return None

        user = User(user_model)
        return user
コード例 #8
0
ファイル: user.py プロジェクト: nitheesh-aot/sbc-auth
    def save_from_jwt_token(cls, token: dict, request_json: Dict = None):
        """Save user to database (create/update)."""
        current_app.logger.debug('save_from_jwt_token')
        if not token:
            return None
        request_json = {} if not request_json else request_json

        is_anonymous_user = token.get('accessType',
                                      None) == AccessType.ANONYMOUS.value
        if not is_anonymous_user:
            existing_user = UserModel.find_by_jwt_token(token)
        else:
            existing_user = UserModel.find_by_username(
                token.get('preferred_username'))

        first_name, last_name = User._get_names(existing_user, request_json,
                                                token)

        if existing_user is None:
            user_model = UserModel.create_from_jwt_token(
                token, first_name, last_name)
        else:
            user_model = UserModel.update_from_jwt_token(
                existing_user,
                token,
                first_name,
                last_name,
                is_login=request_json.get('isLogin', False))

        if not user_model:
            return None

        # if accepted , double check if there is a new TOS in place .IF so , update the flag to false
        if user_model.is_terms_of_use_accepted:
            document_type = DocumentType.TERMS_OF_USE_DIRECTOR_SEARCH.value if is_anonymous_user \
                else DocumentType.TERMS_OF_USE.value
            # get the digit version of the terms of service..ie d1 gives 1 ; d2 gives 2..for proper comparison
            latest_version = util.digitify(
                DocumentService.find_latest_version_by_type(document_type))
            current_version = util.digitify(
                user_model.terms_of_use_accepted_version)
            if latest_version > current_version:
                user_model.is_terms_of_use_accepted = False

        user = User(user_model)
        return user
コード例 #9
0
ファイル: test_user.py プロジェクト: shabeeb-aot/sbc-auth
def test_update_terms_of_user_success_with_integer(session):  # pylint:disable=unused-argument
    """Assert User is updated from a JWT with new terms of use."""
    token = {
        'preferred_username': '******',
        'firstname': 'Bobby',
        'lasname': 'Joe',
        'realm_access': {
            'roles': ['edit', 'uma_authorization', 'basic']
        },
        'sub': '1b20db59-19a0-4727-affe-c6f64309fd04'
    }
    user = User.create_from_jwt_token(token, 'Bobby', 'Joe')
    assert user.is_terms_of_use_accepted is False
    assert user.terms_of_use_accepted_version is None

    user = User.update_terms_of_use(token, True, 1)
    assert user.is_terms_of_use_accepted is True
    assert user.terms_of_use_accepted_version == '1'
コード例 #10
0
    def save_from_jwt_token(cls, token: dict = None):
        """Save user to database (create/update)."""
        current_app.logger.debug('save_from_jwt_token')
        if not token:
            return None
        if token.get('accessType', None) != AccessType.ANONYMOUS.value:
            existing_user = UserModel.find_by_jwt_token(token)
        else:
            existing_user = UserModel.find_by_username(token.get('preferred_username'))

        if existing_user is None:
            user_model = UserModel.create_from_jwt_token(token)
        else:
            user_model = UserModel.update_from_jwt_token(token, existing_user)

        if not user_model:
            return None

        user = User(user_model)
        return user
コード例 #11
0
def test_create_from_jwt_token_no_token(session):  # pylint: disable=unused-argument
    """Assert User is not created from an empty token."""
    token = None
    u = User.create_from_jwt_token(token)
    assert u is None
コード例 #12
0
ファイル: test_user.py プロジェクト: saravanpa-aot/sbc-auth
def test_create_from_jwt_token_no_token(session, monkeypatch):  # pylint: disable=unused-argument
    """Assert User is not created from an empty token."""
    patch_token_info(None, monkeypatch)
    u = User.create_from_jwt_token('fname', 'lname')
    assert u is None
コード例 #13
0
def test_create_from_jwt_token_no_token(session):
    """Assert User is not created from an empty token."""
    token = None
    u = User.create_from_jwt_token(token)
    assert u is None