def _create_identity_provider_and_mapping(self): # Create an identity provider idp_id = data_utils.rand_uuid_hex() self._create_idp(idp_id, fixtures.idp_ref(enabled=True)) # Create a mapping rule mapping_id = data_utils.rand_uuid_hex() self.mappings_client.create_mapping_rule( mapping_id, fixtures.mapping_ref()) self.addCleanup(self.mappings_client.delete_mapping_rule, mapping_id) return idp_id, mapping_id
def _create_identity_provider_and_mapping(self): # Create an identity provider idp_id = data_utils.rand_uuid_hex() self._create_idp(idp_id, fixtures.idp_ref(enabled=True)) # Create a mapping rule mapping_id = data_utils.rand_uuid_hex() self.mappings_client.create_mapping_rule(mapping_id, fixtures.mapping_ref()) self.addCleanup(self.mappings_client.delete_mapping_rule, mapping_id) return idp_id, mapping_id
def test_mapping_rule_update(self): mapping_id = data_utils.rand_uuid_hex() mapping_ref = fixtures.mapping_ref() mapping = self._create_mapping_rule(mapping_id, mapping_ref) new_local = [{'group': {'id': data_utils.rand_uuid_hex()}}] mapping_ref['rules'][0]['local'] = new_local mapping = self.mappings_client.update_mapping_rule( mapping_id, mapping_ref)['mapping'] self._assert_mapping_rules_attributes(mapping, mapping_id, mapping_ref) mapping_get = self.mappings_client.show_mapping_rule( mapping_id)['mapping'] self._assert_mapping_rules_attributes(mapping_get, mapping_id, mapping)
def test_update_mapping_from_identity_provider_protocol(self): idp_id, mapping_id = self._create_identity_provider_and_mapping() # Add a protocol to the identity provider protocol_id = data_utils.rand_uuid_hex() protocol = self._create_protocol(idp_id, protocol_id, mapping_id) # Create another mapping new_mapping_id = data_utils.rand_uuid_hex() self.mappings_client.create_mapping_rule( new_mapping_id, fixtures.mapping_ref()) # Update the identity provider protocol protocol = self.idps_client.update_protocol_mapping( idp_id, protocol_id, new_mapping_id)['protocol'] self._assert_protocol_attributes(protocol, protocol_id, new_mapping_id)
def test_mapping_rule_update(self): mapping_id = data_utils.rand_uuid_hex() mapping_ref = fixtures.mapping_ref() mapping = self._create_mapping_rule(mapping_id, mapping_ref) new_local = [{'group': {'id': data_utils.rand_uuid_hex()}}] mapping_ref['rules'][0]['local'] = new_local mapping = self.mappings_client.update_mapping_rule( mapping_id, mapping_ref)['mapping'] self._assert_mapping_rules_attributes( mapping, mapping_id, mapping_ref) mapping_get = self.mappings_client.show_mapping_rule(mapping_id)[ 'mapping'] self._assert_mapping_rules_attributes( mapping_get, mapping_id, mapping)
def test_update_mapping_from_identity_provider_protocol(self): idp_id, mapping_id = self._create_identity_provider_and_mapping() # Add a protocol to the identity provider protocol_id = data_utils.rand_uuid_hex() protocol = self._create_protocol(idp_id, protocol_id, mapping_id) # Create another mapping new_mapping_id = data_utils.rand_uuid_hex() self.mappings_client.create_mapping_rule(new_mapping_id, fixtures.mapping_ref()) # Update the identity provider protocol protocol = self.idps_client.update_protocol_mapping( idp_id, protocol_id, new_mapping_id)['protocol'] self._assert_protocol_attributes(protocol, protocol_id, new_mapping_id)
class MappingRulesTest(base.BaseIdentityTest): _MAPPING_REF = fixtures.mapping_ref() def _assert_mapping_rules_attributes(self, mapping, mapping_id, mapping_ref=None): self.assertIn('id', mapping) self.assertEqual(mapping_id, mapping['id']) self.assertIn('rules', mapping) if mapping_ref: self.assertCountEqual(mapping_ref['rules'], mapping['rules']) def _create_mapping_rule(self, mapping_id, mapping_ref): mapping = self.mappings_client.create_mapping_rule( mapping_id, mapping_ref)['mapping'] self.addCleanup(self.mappings_client.delete_mapping_rule, mapping_id) return mapping @decorators.idempotent_id('4ca48c01-b6da-4759-acb6-007e15ad712a') def test_mapping_rules_create(self): mapping_id = data_utils.rand_uuid_hex() mapping = self._create_mapping_rule(mapping_id, self._MAPPING_REF) self._assert_mapping_rules_attributes(mapping, mapping_id, self._MAPPING_REF) @decorators.attr(type=['negative']) @decorators.idempotent_id('341dac45-ce1f-4f15-afdc-1f9a7d7d7c40') def test_mapping_rules_create_without_mandatory_attributes_fails(self): mapping_id = data_utils.rand_uuid_hex() self.assertRaises(lib_exc.BadRequest, self.mappings_client.create_mapping_rule, mapping_id, {}) @decorators.idempotent_id('8db213e3-1db0-48c6-863c-7a3ed23577ec') def test_mapping_rules_get(self): mapping_id = data_utils.rand_uuid_hex() mapping_create = self._create_mapping_rule(mapping_id, self._MAPPING_REF) mapping_get = self.mappings_client.show_mapping_rule( mapping_id)['mapping'] self._assert_mapping_rules_attributes(mapping_get, mapping_id, mapping_create) @decorators.idempotent_id('bb80b242-2a6a-4d29-b45f-4035be574a6e') def test_mapping_rules_list(self): mapping_ids = [] for _ in range(3): mapping_id = data_utils.rand_uuid_hex() self._create_mapping_rule(mapping_id, self._MAPPING_REF) mapping_ids.append(mapping_id) mappings_list = self.mappings_client.list_mapping_rules()['mappings'] fetched_ids = [mapping['id'] for mapping in mappings_list] for mapping_id in mapping_ids: self.assertIn(mapping_id, fetched_ids) @decorators.idempotent_id('1fc5d104-faf5-4809-8c89-29b5c1666a96') def test_mapping_rule_update(self): mapping_id = data_utils.rand_uuid_hex() mapping_ref = fixtures.mapping_ref() mapping = self._create_mapping_rule(mapping_id, mapping_ref) new_local = [{'group': {'id': data_utils.rand_uuid_hex()}}] mapping_ref['rules'][0]['local'] = new_local mapping = self.mappings_client.update_mapping_rule( mapping_id, mapping_ref)['mapping'] self._assert_mapping_rules_attributes(mapping, mapping_id, mapping_ref) mapping_get = self.mappings_client.show_mapping_rule( mapping_id)['mapping'] self._assert_mapping_rules_attributes(mapping_get, mapping_id, mapping)