def test_update_terms_of_use_for_user(session): # pylint: disable=unused-argument """Assert that a terms of use can be updated for a user.""" UserService.save_from_jwt_token(TestJwtClaims.user_test) updated_user = UserService.update_terms_of_use(TestJwtClaims.user_test, True, 1) dictionary = updated_user.as_dict() assert dictionary['userTerms']['isTermsOfUseAccepted'] is True
def test_terms_of_service_prev_version(session, monkeypatch): # pylint: disable=unused-argument """Assert that a terms of use can be updated for a user.""" patch_token_info(TestJwtClaims.user_test, monkeypatch) UserService.save_from_jwt_token() # update TOS with old version updated_user = UserService.update_terms_of_use(True, 1) dictionary = updated_user.as_dict() assert dictionary['user_terms']['isTermsOfUseAccepted'] is True # accepted version from previous step was old.so comparison should return false updated_user = UserService.save_from_jwt_token() dictionary = updated_user.as_dict() assert dictionary['user_terms']['isTermsOfUseAccepted'] is False # update TOS with latest version updated_user = UserService.update_terms_of_use(True, get_tos_latest_version()) dictionary = updated_user.as_dict() assert dictionary['user_terms']['isTermsOfUseAccepted'] is True # accepted version from previous step is latest.so comparison should return true updated_user = UserService.save_from_jwt_token() dictionary = updated_user.as_dict() assert dictionary['user_terms']['isTermsOfUseAccepted'] is True
def test_user_save_by_token(session): # pylint: disable=unused-argument """Assert that a user can be created by token.""" user = UserService.save_from_jwt_token(TestJwtClaims.user_test) assert user is not None dictionary = user.as_dict() assert dictionary['username'] == TestJwtClaims.user_test['preferred_username'] assert dictionary['keycloakGuid'] == TestJwtClaims.user_test['sub']
def get(): """Return a JSON object that includes user detail information.""" token = g.jwt_oidc_token_info user = User.find_by_jwt_token(token) if not user: user = User.save_from_jwt_token(token) return jsonify(user.asdict()), 200
def test_bcros_user_save_by_token(session, monkeypatch): # pylint: disable=unused-argument """Assert that a user can be created by token.""" patch_token_info(TestJwtClaims.anonymous_bcros_role, monkeypatch) user = UserService.save_from_jwt_token() assert user is not None dictionary = user.as_dict() assert dictionary['username'] == TestJwtClaims.anonymous_bcros_role[ 'preferred_username'] assert dictionary['keycloak_guid'] == TestJwtClaims.anonymous_bcros_role[ 'sub']
def get(): """Return a JSON object that includes user detail information""" current_span = tracer.active_span token = g.jwt_oidc_token_info user = User.find_by_jwt_token(token) if not user: user = User.save_from_jwt_token(token) current_span.log_kv({'userinfo': user.asdict()}) return jsonify(user.asdict()), 200
def test_bcros_user_update_by_token(session): # pylint: disable=unused-argument """Assert that a user can be created by token.""" user_model = factory_user_model(TestUserInfo.user_bcros) user = UserService(user_model) dictionary = user.as_dict() assert dictionary.get('keycloak_guid', None) is None user = UserService.save_from_jwt_token(TestJwtClaims.anonymous_bcros_role) assert user is not None dictionary = user.as_dict() assert dictionary['username'] == TestJwtClaims.anonymous_bcros_role['preferred_username'] assert dictionary['keycloak_guid'] == TestJwtClaims.anonymous_bcros_role['sub']
def test_user_save_by_token_no_token(session): # pylint: disable=unused-argument """Assert that a user cannot be created from an empty token.""" user = UserService.save_from_jwt_token(None) assert user is None
def test_user_save_by_token_fail(session): # pylint: disable=unused-argument """Assert that a user cannot not be created.""" with patch.object(UserModel, 'create_from_jwt_token', return_value=None): user = UserService.save_from_jwt_token(TestJwtClaims.user_test) assert user is None