Skip to content

Commit

Permalink
fixing MID-4504
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 12, 2018
1 parent d6bad11 commit c00d85c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 3 deletions.
Expand Up @@ -481,6 +481,7 @@ public ShadowType getLinkedShadow(FocusType focus, String resourceOid, boolean r
// It is safe to ignore this error in this method.
LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + focus
+ " because it no longer exists in repository");
getCurrentResult().muteLastSubresultError();
continue;
}
if (shadowType.getResourceRef().getOid().equals(resourceOid)) {
Expand All @@ -493,6 +494,7 @@ public ShadowType getLinkedShadow(FocusType focus, String resourceOid, boolean r
// It is safe to ignore this error in this method.
LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + focus
+ " because it no longer exists on resource");
getCurrentResult().muteLastSubresultError();
continue;
}
}
Expand Down
Expand Up @@ -37,12 +37,14 @@
import com.evolveum.icf.dummy.resource.DummyAccount;
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.util.TestUtil;
Expand All @@ -63,6 +65,9 @@ public class TestMisc extends AbstractInitializedModelIntegrationTest {
protected static final File ROLE_IMPORT_FILTERS_FILE = new File(TEST_DIR, "role-import-filters.xml");
protected static final String ROLE_IMPORT_FILTERS_OID = "aad19b9a-d511-11e7-8bf7-cfecde275e59";

protected static final File ROLE_SHIP_FILE = new File(TEST_DIR, "role-ship.xml");
protected static final String ROLE_SHIP_OID = "bbd19b9a-d511-11e7-8bf7-cfecde275e59";

protected static final File RESOURCE_SCRIPTY_FILE = new File(TEST_DIR, "resource-dummy-scripty.xml");
protected static final String RESOURCE_SCRIPTY_OID = "399f5308-0447-11e8-91e9-a7f9c4100ffb";
protected static final String RESOURCE_DUMMY_SCRIPTY_NAME = "scripty";
Expand All @@ -82,6 +87,8 @@ public void initSystem(Task initTask, OperationResult initResult)

initDummyResourcePirate(RESOURCE_DUMMY_SCRIPTY_NAME,
RESOURCE_SCRIPTY_FILE, RESOURCE_SCRIPTY_OID, initTask, initResult);

importObjectFromFile(ROLE_SHIP_FILE);
}

@Test
Expand Down Expand Up @@ -327,4 +334,95 @@ public void test500AddHocProvisioningScriptAssignJackResourceScripty() throws Ex
"Mr. POLY JACK SPARROW");
}


/**
* MID-4504
* midpoint.getLinkedShadow fails recomputing without throwing exception during shadow delete
*
* the ship attribute in the role "Ship" has mapping with calling midpoint.getLinkedShadow() on the reosurce which doesn't exist
*/
@Test
public void test600jackAssignRoleShip() throws Exception {
final String TEST_NAME = "test600jackAssignRoleShip";
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();


// WHEN
displayWhen(TEST_NAME);
assignRole(USER_JACK_OID, ROLE_SHIP_OID);

//THEN
displayThen(TEST_NAME);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User before", userAfter);
assertAssignments(userAfter, 2);
assertLinks(userAfter, 1);

PrismReference linkRef = userAfter.findReference(UserType.F_LINK_REF);
assertTrue(!linkRef.isEmpty());

// PrismObject<ShadowType> shadowModel = getShadowModel(linkRef.getOid());

assertDummyAccountAttribute(RESOURCE_DUMMY_SCRIPTY_NAME, USER_JACK_USERNAME, "ship", "ship");

}

@Test
public void test601jackUnassignResourceAccount() throws Exception {
final String TEST_NAME = "test601jackUnassignResourceAccount";
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
display("User before", userBefore);
assertAssignments(userBefore, 2);

// WHEN
displayWhen(TEST_NAME);
unassignAccount(USER_JACK_OID, RESOURCE_SCRIPTY_OID, null);

//THEN
displayThen(TEST_NAME);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertAssignments(userAfter, 1);
assertLinks(userAfter, 1);
}


/**
* MID-4504
* midpoint.getLinkedShadow fails recomputing without throwing exception during shadow delete
*
* first assign role ship, the ship attribute in the role has mapping with calling midpoint.getLinkedShadow()
*/
@Test
public void test602jackUnssigndRoleShip() throws Exception {
final String TEST_NAME = "test602jackUnssigndRoleShip";
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();


// WHEN
displayWhen(TEST_NAME);
unassignRole(USER_JACK_OID, ROLE_SHIP_OID);

//THEN
displayThen(TEST_NAME);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User before", userAfter);
assertAssignments(userAfter, 0);
assertLinks(userAfter, 0);

}

}
Expand Up @@ -21,7 +21,7 @@
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:mr="http://prism.evolveum.com/xml/ns/public/matching-rule-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy"
Expand Down Expand Up @@ -62,8 +62,6 @@

</connectorConfiguration>

<namespace>http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004</namespace>

<schemaHandling>
<objectType>
<kind>account</kind>
Expand Down
34 changes: 34 additions & 0 deletions model/model-intest/src/test/resources/misc/role-ship.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<role oid="bbd19b9a-d511-11e7-8bf7-cfecde275e59"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:piracy="http://midpoint.evolveum.com/xml/ns/samples/piracy">
<name>Space Ship</name>
<description>MID-4504</description>
<inducement>
<construction >
<resourceRef oid="399f5308-0447-11e8-91e9-a7f9c4100ffb" type="c:ResourceType"/>
<kind>account</kind>
<attribute>
<ref>ri:ship</ref>
<outbound>
<strength>strong</strength>
<expression>
<script>
<code>
log.info("####BEFORE calling get on non existent linked shadow")
log.info("###FOCUS " + focus)
shadow = midpoint.getLinkedShadow(focus, "399f5308-0447-11e8-91e9-a7f9c4100ffb") //shadow does not not exist
log.info("####AFTER calling get on non existent linked shadow")
log.info("###SHADOW: " + shadow)
return "ship"
</code>
</script>
</expression>
</outbound>
</attribute>
</construction>
</inducement>
</role>

0 comments on commit c00d85c

Please sign in to comment.