Projet

Général

Profil

0004-hobo_notify-deprovision-by-setting-the-deleted-flag-.patch

Benjamin Dauvergne, 04 février 2020 16:54

Télécharger (3,9 ko)

Voir les différences:

Subject: [PATCH 4/4] hobo_notify: deprovision by setting the deleted flag
 (#24430)

 tests/test_hobo_notify.py | 88 +++++++++++++++++++++++++++++++++++++++
 wcs/ctl/hobo_notify.py    |  4 +-
 2 files changed, 90 insertions(+), 2 deletions(-)
tests/test_hobo_notify.py
6 6
from wcs.qommon.http_request import HTTPRequest
7 7
from wcs.ctl.hobo_notify import CmdHoboNotify
8 8
from wcs.roles import Role
9
from wcs.qommon import storage as st
9 10

  
10 11
from utilities import create_temporary_pub, clean_temporary_pub
11 12

  
......
723 724
        CmdHoboNotify.process_notification(notification)
724 725
    assert e.value.args == ('invalid role',)
725 726
    assert Role.count() == 0
727

  
728

  
729
def test_process_user_deprovision(pub):
730
    User = pub.user_class
731

  
732
    # setup an hobo profile
733
    from wcs.ctl.check_hobos import CmdCheckHobos
734
    User.wipe()
735
    Role.wipe()
736
    CmdCheckHobos().update_profile(PROFILE, pub)
737

  
738
    user = User()
739
    user.name = 'Pierre'
740
    user.name_identifiers = ['a' * 32]
741
    user.store()
742

  
743
    notification = {
744
        u'@type': u'deprovision',
745
        u'issuer': 'http://idp.example.net/idp/saml/metadata',
746
        u'audience': [u'test'],
747
        u'objects': {
748
            u'@type': 'user',
749
            u'data': [
750
                {
751
                    u'uuid': u'a' * 32,
752
                }
753
            ]
754
        }
755
    }
756

  
757
    assert User.count() == 1
758
    assert len(User.select([st.Equal('deleted', True)])) == 0
759
    CmdHoboNotify.process_notification(notification)
760
    assert User.count() == 1
761
    assert len(User.select([st.Equal('deleted', True)])) == 1
762
    pub.clean_deleted_users()
763
    assert User.count() == 0
764

  
765

  
766
def test_process_user_deprovision_with_data(pub):
767
    from wcs.formdef import FormDef
768

  
769
    User = pub.user_class
770

  
771
    # setup an hobo profile
772
    from wcs.ctl.check_hobos import CmdCheckHobos
773
    User.wipe()
774
    FormDef.wipe()
775
    CmdCheckHobos().update_profile(PROFILE, pub)
776

  
777
    user = User()
778
    user.name = 'Pierre'
779
    user.name_identifiers = ['a' * 32]
780
    user.store()
781

  
782
    formdef = FormDef()
783
    formdef.name = 'foobar'
784
    formdef.url_name = 'foobar'
785
    formdef.fields = []
786
    formdef.store()
787
    data_class = formdef.data_class()
788

  
789
    formdata = data_class()
790
    formdata.user_id = user.id
791
    formdata.store()
792

  
793
    notification = {
794
        u'@type': u'deprovision',
795
        u'issuer': 'http://idp.example.net/idp/saml/metadata',
796
        u'audience': [u'test'],
797
        u'objects': {
798
            u'@type': 'user',
799
            u'data': [
800
                {
801
                    u'uuid': u'a' * 32,
802
                }
803
            ]
804
        }
805
    }
806

  
807
    assert User.count() == 1
808
    assert len(User.select([st.Equal('deleted', True)])) == 0
809
    CmdHoboNotify.process_notification(notification)
810
    assert User.count() == 1
811
    assert len(User.select([st.Equal('deleted', True)])) == 1
812
    pub.clean_deleted_users()
813
    assert User.count() == 1
wcs/ctl/hobo_notify.py
211 211
                    uuid = o['uuid']
212 212
                    users = User.get_users_with_name_identifier(uuid)
213 213
                    for user in users:
214
                        user.remove_self()
215
            except Exception as e:
214
                        user.set_deleted()
215
            except Exception:
216 216
                publisher.notify_of_exception(sys.exc_info(), context='[PROVISIONNING]')
217 217

  
218 218
CmdHoboNotify.register()
219
-