diff --git a/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/TestUtil.java b/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/TestUtil.java index 3bd93ab0c3e..87a9c8d9f04 100644 --- a/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/TestUtil.java +++ b/infra/test-util/src/main/java/com/evolveum/midpoint/test/util/TestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Evolveum + * Copyright (c) 2010-2016 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -590,4 +590,9 @@ public static int getJavaMajorVersion() { } } + + public static void assertMessageContains(String message, String expectedSubstring) { + assertTrue("Expected that message will contain substring '"+expectedSubstring+"', but it did not. Message: "+message, + message.contains(expectedSubstring)); + } } diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/AssignmentEvaluator.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/AssignmentEvaluator.java index 7fbc54a217a..aa56f029238 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/AssignmentEvaluator.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/AssignmentEvaluator.java @@ -408,7 +408,11 @@ private PrismObject resolveTarget(AssignmentType assignmentType, ObjectType s } PrismObject target = null; - target = repository.getObject(clazz, oid, null, result); + try { + target = repository.getObject(clazz, oid, null, result); + } catch (SchemaException e) { + throw new SchemaException(e.getMessage() + " in " + sourceDescription, e); + } if (target == null) { throw new IllegalArgumentException("Got null target from repository, oid:"+oid+", class:"+clazz+" (should not happen, probably a bug) in "+sourceDescription); } diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java index 2a5eb9582f9..e7fa879327c 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Evolveum + * Copyright (c) 2010-2016 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,6 +104,15 @@ public class TestStrangeCases extends AbstractInitializedModelIntegrationTest { private static final File ROLE_STUPID_FILE = new File(TEST_DIR, "role-stupid.xml"); private static final String ROLE_STUPID_OID = "12345678-d34d-b33f-f00d-555555550002"; + + private static final File ROLE_BAD_CONSTRUCTION_RESOURCE_REF_FILE = new File(TEST_DIR, "role-bad-construction-resource-ref.xml"); + private static final String ROLE_BAD_CONSTRUCTION_RESOURCE_REF_OID = "54084f2c-eba0-11e5-8278-03ea5d7058d9"; + + private static final File ROLE_META_BAD_CONSTRUCTION_RESOURCE_REF_FILE = new File(TEST_DIR, "role-meta-bad-construction-resource-ref.xml"); + private static final String ROLE_META_BAD_CONSTRUCTION_RESOURCE_REF_OID = "90b931ae-eba8-11e5-977a-b73ba58cf18b"; + + private static final File ROLE_TARGET_BAD_CONSTRUCTION_RESOURCE_REF_FILE = new File(TEST_DIR, "role-target-bad-construction-resource-ref.xml"); + private static final String ROLE_TARGET_BAD_CONSTRUCTION_RESOURCE_REF_OID = "e69b791a-eba8-11e5-80f5-33732b18f10a"; private static final File ROLE_RECURSION_FILE = new File(TEST_DIR, "role-recursion.xml"); private static final String ROLE_RECURSION_OID = "12345678-d34d-b33f-f00d-555555550003"; @@ -140,6 +149,8 @@ public void initSystem(Task initTask, OperationResult initResult) addObject(ROLE_IDIOT_FILE, initTask, initResult); addObject(ROLE_STUPID_FILE, initTask, initResult); addObject(ROLE_RECURSION_FILE, initTask, initResult); + addObject(ROLE_BAD_CONSTRUCTION_RESOURCE_REF_FILE, initTask, initResult); + addObject(ROLE_META_BAD_CONSTRUCTION_RESOURCE_REF_FILE, initTask, initResult); DebugUtil.setDetailedDebugDump(true); } @@ -637,6 +648,88 @@ public void test349UnAssignDeGhoulashConstructionNonExistentResource() throws Ex assertUser(userDeGhoulash, USER_DEGHOULASH_OID, "deghoulash", "Charles DeGhoulash", "Charles", "DeGhoulash"); assertAssignments(userDeGhoulash, 0); } + + @Test + public void test350AssignDeGhoulashRoleBadConstructionResourceRef() throws Exception { + final String TEST_NAME = "test350AssignDeGhoulashRoleBadConstructionResourceRef"; + TestUtil.displayTestTile(this, TEST_NAME); + + // GIVEN + Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); + dummyAuditService.clear(); + + // WHEN + assignRole(USER_DEGHOULASH_OID, ROLE_BAD_CONSTRUCTION_RESOURCE_REF_OID, task, result); + + // THEN + result.computeStatus(); + display("result", result); + TestUtil.assertPartialError(result); + String message = result.getMessage(); + TestUtil.assertMessageContains(message, "role:"+ROLE_BAD_CONSTRUCTION_RESOURCE_REF_OID); + TestUtil.assertMessageContains(message, "Bad resourceRef in construction"); + TestUtil.assertMessageContains(message, "this-oid-does-not-exist"); + + PrismObject userDeGhoulash = getUser(USER_DEGHOULASH_OID); + display("User after change execution", userDeGhoulash); + assertUser(userDeGhoulash, USER_DEGHOULASH_OID, "deghoulash", "Charles DeGhoulash", "Charles", "DeGhoulash"); + assertAssignedRole(userDeGhoulash, ROLE_BAD_CONSTRUCTION_RESOURCE_REF_OID); + } + + @Test + public void test351UnAssignDeGhoulashRoleBadConstructionResourceRef() throws Exception { + final String TEST_NAME = "test351UnAssignDeGhoulashRoleBadConstructionResourceRef"; + TestUtil.displayTestTile(this, TEST_NAME); + + // GIVEN + Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); + dummyAuditService.clear(); + + // WHEN + unassignRole(USER_DEGHOULASH_OID, ROLE_BAD_CONSTRUCTION_RESOURCE_REF_OID, task, result); + + // THEN + result.computeStatus(); + display("result", result); + TestUtil.assertPartialError(result); + String message = result.getMessage(); + TestUtil.assertMessageContains(message, "role:"+ROLE_BAD_CONSTRUCTION_RESOURCE_REF_OID); + TestUtil.assertMessageContains(message, "Bad resourceRef in construction"); + TestUtil.assertMessageContains(message, "this-oid-does-not-exist"); + + PrismObject userDeGhoulash = getUser(USER_DEGHOULASH_OID); + display("User after change execution", userDeGhoulash); + assertUser(userDeGhoulash, USER_DEGHOULASH_OID, "deghoulash", "Charles DeGhoulash", "Charles", "DeGhoulash"); + assertAssignedNoRole(userDeGhoulash); + } + + @Test + public void test360AddRoleTargetBadConstructionResourceRef() throws Exception { + final String TEST_NAME = "test360AddRoleTargetBadConstructionResourceRef"; + TestUtil.displayTestTile(this, TEST_NAME); + + // GIVEN + Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); + dummyAuditService.clear(); + + // WHEN + addObject(ROLE_TARGET_BAD_CONSTRUCTION_RESOURCE_REF_FILE, task, result); + + // THEN + result.computeStatus(); + display("result", result); + TestUtil.assertPartialError(result); + String message = result.getMessage(); + TestUtil.assertMessageContains(message, "role:"+ROLE_META_BAD_CONSTRUCTION_RESOURCE_REF_OID); + TestUtil.assertMessageContains(message, "Bad resourceRef in construction metarole"); + TestUtil.assertMessageContains(message, "this-oid-does-not-exist"); + } @Test public void test400ImportJackMockTask() throws Exception { diff --git a/model/model-intest/src/test/resources/strange/role-bad-construction-resource-ref.xml b/model/model-intest/src/test/resources/strange/role-bad-construction-resource-ref.xml new file mode 100644 index 00000000000..66caedebb08 --- /dev/null +++ b/model/model-intest/src/test/resources/strange/role-bad-construction-resource-ref.xml @@ -0,0 +1,27 @@ + + + Bad resourceRef in construction + + + + account + default + + + diff --git a/model/model-intest/src/test/resources/strange/role-meta-bad-construction-resource-ref.xml b/model/model-intest/src/test/resources/strange/role-meta-bad-construction-resource-ref.xml new file mode 100644 index 00000000000..df623e7529b --- /dev/null +++ b/model/model-intest/src/test/resources/strange/role-meta-bad-construction-resource-ref.xml @@ -0,0 +1,27 @@ + + + Bad resourceRef in construction metarole + + + + generic + whatever + + + diff --git a/model/model-intest/src/test/resources/strange/role-target-bad-construction-resource-ref.xml b/model/model-intest/src/test/resources/strange/role-target-bad-construction-resource-ref.xml new file mode 100644 index 00000000000..d589d64fa6a --- /dev/null +++ b/model/model-intest/src/test/resources/strange/role-target-bad-construction-resource-ref.xml @@ -0,0 +1,23 @@ + + + Bad resourceRef in construction target role + + + +