use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.
the class TestTolerantAttributes method test105modifyAddNonTolerantAttribute.
@Test
public void test105modifyAddNonTolerantAttribute() throws Exception {
TestUtil.displayTestTile(this, "test105modifyAddNonTolerantAttribute");
// GIVEN
Task task = taskManager.createTaskInstance(TestTolerantAttributes.class.getName() + ".test105modifyAddNonTolerantAttribute");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
ObjectDelta<ShadowType> userDelta = ObjectDelta.createEmptyModifyDelta(ShadowType.class, accountOid, prismContext);
ItemPath drinkItemPath = new ItemPath(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_DUMMY_BLACK_NAMESPACE, "drink"));
assertNotNull("null definition for drink attribute ", accountDefinition.findPropertyDefinition(drinkItemPath));
PropertyDelta propertyDelta = PropertyDelta.createModificationAddProperty(drinkItemPath, accountDefinition.findPropertyDefinition(drinkItemPath), "This should be ignored");
userDelta.addModification(propertyDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
try {
modelService.executeChanges(deltas, ModelExecuteOptions.createReconcile(), task, result);
fail("Expected Policy violation exception, because non-tolerant attribute is modified, but haven't got one.");
} catch (PolicyViolationException ex) {
//this is expected
}
}
use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.
the class TestPreviewChanges method test401ModifyElaineAccountDummyRedDeleteAdd.
/**
* Changing ACCOUNT fullname (add/delete delta), no user changes.
* Attempt to make a change to a single-valued attribute or which there is already a strong mapping.
* As it cannot have both values (from the delta and from the mapping) the preview should fail.
*/
@Test
public void test401ModifyElaineAccountDummyRedDeleteAdd() throws Exception {
final String TEST_NAME = "test401ModifyElaineAccountDummyRedDeleteAdd";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
ObjectDelta<ShadowType> accountDelta = createModifyAccountShadowEmptyDelta(ACCOUNT_SHADOW_ELAINE_DUMMY_RED_OID);
PropertyDelta<String> fullnameDelta = createAttributeAddDelta(getDummyResourceObject(RESOURCE_DUMMY_RED_NAME), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Elaine Threepwood");
fullnameDelta.addValueToDelete(new PrismPropertyValue<String>("Elaine Marley"));
accountDelta.addModification(fullnameDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
display("Input deltas: ", deltas);
try {
// WHEN
ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
display("Preview context", modelContext);
AssertJUnit.fail("Preview unexpectedly succeeded");
} catch (PolicyViolationException e) {
// This is expected
display("Expected exception", e);
}
result.computeStatus();
TestUtil.assertFailure(result);
}
use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.
the class TestStrangeCases method test550AssignCircus.
/**
* Circus resource has a circular dependency. It should fail, but it should
* fail with a proper error.
* MID-3522
*/
@Test
public void test550AssignCircus() throws Exception {
final String TEST_NAME = "test550AssignCircus";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
try {
// WHEN
assignAccount(USER_GUYBRUSH_OID, RESOURCE_DUMMY_CIRCUS_OID, null, task, result);
assertNotReached();
} catch (PolicyViolationException e) {
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertFailure(result);
}
}
use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.
the class AbstractPasswordTest method test222ModifyUserJackPasswordBadContainer.
/**
* Change to password that violates the password policy (but is still OK for yellow resource).
* Use a different delta (container delta instead of property delta).
* MID-2857
*/
@Test
public void test222ModifyUserJackPasswordBadContainer() throws Exception {
final String TEST_NAME = "test222ModifyUserJackPasswordBadContainer";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
ProtectedStringType userPasswordPs = new ProtectedStringType();
userPasswordPs.setClearValue(USER_PASSWORD_1_CLEAR);
PasswordType passwordType = new PasswordType();
passwordType.setValue(userPasswordPs);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, USER_JACK_OID, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD), prismContext, passwordType);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
try {
// WHEN
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("Unexpected success");
} catch (PolicyViolationException e) {
// This is expected
display("Exected exception", e);
}
// THEN
result.computeStatus();
TestUtil.assertFailure(result);
assertJackPasswordsWithHistory(USER_PASSWORD_VALID_1, USER_PASSWORD_A_CLEAR);
}
use of com.evolveum.midpoint.util.exception.PolicyViolationException in project midpoint by Evolveum.
the class AbstractPasswordTest method doTestModifyUserJackPasswordFailureWithHistory.
private void doTestModifyUserJackPasswordFailureWithHistory(final String TEST_NAME, String newPassword, String oldPassword, String... expectedPasswordHistory) throws Exception {
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
try {
// WHEN
modifyUserChangePassword(USER_JACK_OID, newPassword, task, result);
AssertJUnit.fail("Unexpected success");
} catch (PolicyViolationException e) {
// This is expected
display("Exected exception", e);
}
// THEN
result.computeStatus();
TestUtil.assertFailure(result);
assertJackPasswordsWithHistory(oldPassword, expectedPasswordHistory);
}
Aggregations