data_transfer: fail importing on empty role uuid (#31083)

This commit is contained in:
Valentin Deniaud 2019-10-08 16:14:51 +02:00
parent 9159c4d70b
commit d177f4a296
2 changed files with 19 additions and 0 deletions

View File

@ -171,6 +171,9 @@ class RoleDeserializer(object):
status = 'updated'
update_model(self._obj, kwargs)
else: # Create role
if 'uuid' in kwargs and not kwargs['uuid']:
raise DataImportError("Cannot import role '%s' with empty uuid"
% kwargs.get('name'))
self._obj = get_role_model().objects.create(**kwargs)
status = 'created'

View File

@ -200,3 +200,19 @@ def test_import_site_update_roles(db, json_fixture):
r1.refresh_from_db()
assert r1.slug == 'slug-updated'
assert r1.name == 'Role second update'
def test_import_site_empty_uuids(db, monkeypatch, json_fixture):
from authentic2.data_transfer import DataImportError
with pytest.raises(DataImportError):
management.call_command('import_site', json_fixture({
'roles': [
{
'uuid': '',
'slug': 'role-slug',
'name': 'role-name',
'ou': None,
'service': None
}
]
}))