Adds tests showing how mapping locals are handled

Change-Id: If24ab712cc818885f18c6e52cf670d0525dbd75c
This commit is contained in:
David Stanek 2017-01-10 16:11:23 +00:00
parent 169e66ab88
commit 2a79614c35

View File

@ -825,3 +825,89 @@ class TestUnicodeAssertionData(unit.BaseTestCase):
full_name = '%s %s' % (fn, ln)
user_name = values.get('user', {}).get('name')
self.assertEqual(full_name, user_name)
class TestMappingLocals(unit.BaseTestCase):
mapping_split = {
'rules': [
{
'local': [
{
'user': {'name': '{0}'},
},
{
'group': {'id': 'd34db33f'}
}
],
'remote': [
{'type': 'idp_username'}
]
}
]
}
mapping_combined = {
'rules': [
{
'local': [
{
'user': {'name': '{0}'},
'group': {'id': 'd34db33f'}
}
],
'remote': [
{'type': 'idp_username'}
]
}
]
}
mapping_with_duplicate = {
'rules': [
{
'local': [
{'user': {'name': 'test_{0}'}},
{'user': {'name': '{0}'}}
],
'remote': [{'type': 'idp_username'}]
}
]
}
assertion = {
'idp_username': 'a_user'
}
def process(self, rules):
rp = mapping_utils.RuleProcessor(FAKE_MAPPING_ID, rules)
return rp.process(self.assertion)
def test_local_list_gets_squashed_into_a_single_dictionary(self):
expected = {
'user': {
'name': 'a_user',
'domain': {'id': 'Federated'},
'type': 'ephemeral'
},
'projects': [],
'group_ids': ['d34db33f'],
'group_names': []
}
mapped_split = self.process(self.mapping_split['rules'])
mapped_combined = self.process(self.mapping_combined['rules'])
self.assertEqual(expected, mapped_split)
self.assertEqual(mapped_split, mapped_combined)
def test_when_local_list_gets_squashed_first_dict_wins(self):
expected = {
'user': {
'name': 'test_a_user',
'domain': {'id': 'Federated'},
'type': 'ephemeral'
},
'projects': [],
'group_ids': [],
'group_names': []
}
mapped = self.process(self.mapping_with_duplicate['rules'])
self.assertEqual(expected, mapped)