Skip to content

Commit

Permalink
Fixing bad reference error message (role/assignment) (MID-2802)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 16, 2016
1 parent 4baaf7e commit f28f92e
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 3 deletions.
@@ -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.
Expand Down Expand Up @@ -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));
}
}
Expand Up @@ -408,7 +408,11 @@ private PrismObject<?> resolveTarget(AssignmentType assignmentType, ObjectType s
}

PrismObject<? extends ObjectType> 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);
}
Expand Down
@@ -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.
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<UserType> 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<UserType> 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 {
Expand Down
@@ -0,0 +1,27 @@
<!--
~ Copyright (c) 2016 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<role oid="54084f2c-eba0-11e5-8278-03ea5d7058d9"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3">
<name>Bad resourceRef in construction</name>
<inducement>
<construction>
<resourceRef oid="this-oid-does-not-exist"/>
<kind>account</kind>
<intent>default</intent>
</construction>
</inducement>
</role>
@@ -0,0 +1,27 @@
<!--
~ Copyright (c) 2016 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<role oid="90b931ae-eba8-11e5-977a-b73ba58cf18b"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3">
<name>Bad resourceRef in construction metarole</name>
<inducement>
<construction>
<resourceRef oid="this-oid-does-not-exist"/>
<kind>generic</kind>
<intent>whatever</intent>
</construction>
</inducement>
</role>
@@ -0,0 +1,23 @@
<!--
~ Copyright (c) 2016 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<role oid="e69b791a-eba8-11e5-80f5-33732b18f10a"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3">
<name>Bad resourceRef in construction target role</name>
<assignment>
<targetRef oid="90b931ae-eba8-11e5-977a-b73ba58cf18b" type="RoleType"/>
</assignment>
</role>

0 comments on commit f28f92e

Please sign in to comment.