hobo_notify: adapt to change in message format (#8444)
This commit is contained in:
parent
83a10b716e
commit
ebe2e5b071
|
@ -37,26 +37,28 @@ def test_process_notification_wrong_audience():
|
|||
'@type': u'provision',
|
||||
'audience': [u'coin'],
|
||||
'full': True,
|
||||
'objects': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-etat-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'uuid': u'xyz',
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-etat-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'uuid': u'xyz',
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
assert Role.count() == 1
|
||||
assert Role.select()[0].name == 'Service étt civil'
|
||||
|
@ -78,26 +80,27 @@ def test_process_notification():
|
|||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'full': True,
|
||||
'objects': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'uuid': u'xyz',
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'uuid': u'xyz',
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
assert Role.count() == 1
|
||||
assert Role.select()[0].name == 'Service étt civil'
|
||||
|
@ -124,17 +127,20 @@ def test_process_notification():
|
|||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'full': True,
|
||||
'objects': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
CmdHoboNotify.process_notification(notification)
|
||||
assert Role.count() == 1
|
||||
|
@ -150,17 +156,20 @@ def test_process_notification_deprovision():
|
|||
'@type': u'deprovision',
|
||||
'audience': [u'test'],
|
||||
'full': True,
|
||||
'objects': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'uuid': u'xyz',
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'uuid': u'xyz',
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
assert Role.count() == 1
|
||||
assert Role.select()[0].name == 'Service étt civil'
|
||||
|
|
|
@ -62,12 +62,14 @@ class CmdHoboNotify(Command):
|
|||
@classmethod
|
||||
def check_valid_notification(cls, notification):
|
||||
return isinstance(notification, dict) \
|
||||
and '@type' in notification \
|
||||
and notification['@type'] in ['provision', 'deprovision'] \
|
||||
and 'objects' in notification \
|
||||
and 'audience' in notification \
|
||||
and isinstance(notification['audience'], list) \
|
||||
and isinstance(notification['objects'], list)
|
||||
and isinstance(notification['objects'], dict) \
|
||||
and '@type' in notification['objects'] \
|
||||
and 'data' in notification['objects'] \
|
||||
and isinstance(notification['objects']['data'], list)
|
||||
|
||||
@classmethod
|
||||
def process_notification(cls, notification, publisher=None):
|
||||
|
@ -75,24 +77,33 @@ class CmdHoboNotify(Command):
|
|||
action = notification['@type']
|
||||
audience = notification['audience']
|
||||
full = notification['full'] if 'full' in notification else False
|
||||
issuer = notification.get('issuer')
|
||||
|
||||
# Verify tenant is in audience
|
||||
entity_id = get_cfg('sp', {}).get('saml2_providerid')
|
||||
if not entity_id or entity_id not in audience:
|
||||
return
|
||||
|
||||
uuids = set()
|
||||
t = notification['objects']['@type']
|
||||
# Now provision/deprovision
|
||||
for o in notification['objects']:
|
||||
t = o['@type']
|
||||
if t != 'role' \
|
||||
or 'uuid' not in o \
|
||||
or 'name' not in o \
|
||||
or 'description' not in o \
|
||||
or 'emails' not in o \
|
||||
or 'emails_to_members' not in o \
|
||||
or 'slug' not in o:
|
||||
continue
|
||||
getattr(cls, 'provision_' + t)(publisher, issuer, action,
|
||||
notification['objects']['data'],
|
||||
full=full)
|
||||
|
||||
@classmethod
|
||||
def check_valid_role(cls, o):
|
||||
return 'uuid' in o \
|
||||
or 'name' in o \
|
||||
or 'description' in o \
|
||||
or 'emails' in o \
|
||||
or 'emails_to_members' in o \
|
||||
or 'slug' in o
|
||||
|
||||
@classmethod
|
||||
def provision_role(cls, publisher, issuer, action, data, full=False):
|
||||
uuids = set()
|
||||
for o in data:
|
||||
assert cls.check_valid_role(o)
|
||||
uuid = o['uuid'].encode(publisher.site_charset)
|
||||
uuids.add(uuid)
|
||||
slug = o['slug'].encode(publisher.site_charset)
|
||||
|
|
Loading…
Reference in New Issue