From b28fecc973521ffe0b61f2183ec91437fc87eb51 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 4 Oct 2018 23:34:05 +0200 Subject: [PATCH 4/6] hobo_notify: deprovision by setting the deleted flag (#24430) --- tests/test_hobo_notify.py | 88 +++++++++++++++++++++++++++++++++++++++ wcs/ctl/hobo_notify.py | 3 +- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/tests/test_hobo_notify.py b/tests/test_hobo_notify.py index 1a497062..4d22ceea 100644 --- a/tests/test_hobo_notify.py +++ b/tests/test_hobo_notify.py @@ -5,6 +5,7 @@ from quixote import cleanup from wcs.qommon.http_request import HTTPRequest from wcs.ctl.hobo_notify import CmdHoboNotify from wcs.roles import Role +from wcs.qommon import storage as st from utilities import create_temporary_pub, clean_temporary_pub @@ -684,3 +685,90 @@ def test_process_notification_role_with_errors(pub): CmdHoboNotify.process_notification(notification) assert e.value.args == ('invalid role',) assert Role.count() == 0 + + +def test_process_user_deprovision(pub): + User = pub.user_class + + # setup an hobo profile + from wcs.ctl.check_hobos import CmdCheckHobos + User.wipe() + Role.wipe() + CmdCheckHobos().update_profile(PROFILE, pub) + + user = User() + user.name = 'Pierre' + user.name_identifiers = ['a' * 32] + user.store() + + notification = { + u'@type': u'deprovision', + u'issuer': 'http://idp.example.net/idp/saml/metadata', + u'audience': [u'test'], + u'objects': { + u'@type': 'user', + u'data': [ + { + u'uuid': u'a' * 32, + } + ] + } + } + + assert User.count() == 1 + assert len(User.select([st.Equal('deleted', True)])) == 0 + CmdHoboNotify.process_notification(notification) + assert User.count() == 1 + assert len(User.select([st.Equal('deleted', True)])) == 1 + User.clean_deleted_users() + assert User.count() == 0 + + +def test_process_user_deprovision_with_data(pub): + from wcs.formdef import FormDef + + User = pub.user_class + + # setup an hobo profile + from wcs.ctl.check_hobos import CmdCheckHobos + User.wipe() + FormDef.wipe() + CmdCheckHobos().update_profile(PROFILE, pub) + + user = User() + user.name = 'Pierre' + user.name_identifiers = ['a' * 32] + user.store() + + formdef = FormDef() + formdef.name = 'foobar' + formdef.url_name = 'foobar' + formdef.fields = [] + formdef.store() + data_class = formdef.data_class() + + formdata = data_class() + formdata.user_id = user.id + formdata.store() + + notification = { + u'@type': u'deprovision', + u'issuer': 'http://idp.example.net/idp/saml/metadata', + u'audience': [u'test'], + u'objects': { + u'@type': 'user', + u'data': [ + { + u'uuid': u'a' * 32, + } + ] + } + } + + assert User.count() == 1 + assert len(User.select([st.Equal('deleted', True)])) == 0 + CmdHoboNotify.process_notification(notification) + assert User.count() == 1 + assert len(User.select([st.Equal('deleted', True)])) == 1 + User.clean_deleted_users() + assert User.count() == 1 diff --git a/wcs/ctl/hobo_notify.py b/wcs/ctl/hobo_notify.py index 26c4b824..55bc26e0 100644 --- a/wcs/ctl/hobo_notify.py +++ b/wcs/ctl/hobo_notify.py @@ -207,7 +207,8 @@ class CmdHoboNotify(Command): uuid = o['uuid'] users = User.get_users_with_name_identifier(uuid) for user in users: - user.remove_self() + user.deleted = True + user.store() except Exception, e: publisher.notify_of_exception(sys.exc_info(), context='[PROVISIONNING]') -- 2.18.0