Skip to content

Commit

Permalink
displayExpectedException() applied across tests where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Mar 16, 2020
1 parent 85dd538 commit 85332b3
Show file tree
Hide file tree
Showing 29 changed files with 117 additions and 265 deletions.
Expand Up @@ -87,11 +87,9 @@ public void testPrismParseXxe() throws Exception {

AssertJUnit.fail("Unexpected success");
} catch (IllegalStateException e) {
// THEN
System.out.println("Expected exception: "+e);
displayExpectedException(e);
assertTrue("Unexpected exception message: "+e.getMessage(), e.getMessage().contains("DOCTYPE"));
}

}

@Test
Expand All @@ -102,10 +100,8 @@ public void testPrismParseDomXxe() {

AssertJUnit.fail("Unexpected success");
} catch (IllegalStateException e) {
// THEN
System.out.println("Expected exception: "+e);
displayExpectedException(e);
assertTrue("Unexpected exception message: "+e.getMessage(), e.getMessage().contains("DOCTYPE"));
}

}
}
Expand Up @@ -425,23 +425,18 @@ protected <V extends PrismValue, D extends ItemDefinition> void evaluateExpressi
expressionContext.getContextDescription(), expressionContext.getTask(), result);

} catch (SecurityViolationException e) {
// Exception may happen here, or it may happen later.
// Expected
logger.debug("Expected exception", e);
displayExpectedException(e);
assertTrue("Wrong exception message: " + e.getMessage(), e.getMessage().contains("Access to script language"));
return;
}

logger.debug("Starting evaluation of expression (expecting security violation): {}", expression);
try {

expression.evaluate(expressionContext, result);

AssertJUnit.fail("Unexpected success of expression evaluation");

} catch (SecurityViolationException e) {
// Expected
logger.debug("Expected exception", e);
displayExpectedException(e);
assertTrue("Wrong exception message: " + e.getMessage(),
e.getMessage().contains("Access to expression evaluator")
|| e.getMessage().contains("Access to Groovy method"));
Expand Down Expand Up @@ -499,7 +494,7 @@ protected ExpressionProfile compileExpressionProfile(String profileName) throws
ExpressionProfiles profiles = compiler.compile(expressions);
ExpressionProfile profile = profiles.getProfile(profileName);
if (profile == null) {
throw new SchemaException("Profile '" + profile + "' not found in system config");
throw new SchemaException("Profile '" + profileName + "' not found in system config");
}
return profile;
}
Expand Down
Expand Up @@ -380,8 +380,7 @@ protected void evaluateAndAssertStringScalarExpressionRestricted(
List<PrismPropertyValue<String>> expressionResultList = evaluateStringExpression(fileName, testName, variables);
AssertJUnit.fail("Expression " + testName + ": unexpected success, result value: " + expressionResultList);
} catch (SecurityViolationException e) {
System.out.println("Expected exception: " + e);
logger.debug("Expected exception", e);
displayExpectedException(e);
}
}

Expand Down
Expand Up @@ -372,10 +372,8 @@ public void test300SortToWavesXYZCircular() throws Exception {

AssertJUnit.fail("Unexpected success");
} catch (PolicyViolationException e) {
// This is expected
displayException("Expected exception", e);
displayExpectedException(e);
}

}

private LensProjectionContext fillContextWithDummyElaineAccount(
Expand Down
Expand Up @@ -179,8 +179,7 @@ private void doTestModifyPasswordExpectFailure(String password) throws Exception

fail("Expected PolicyViolationException but didn't get one.");
} catch (PolicyViolationException ex) {
// this is expected
displayException("expected exception", ex);
displayExpectedException(ex);
result.computeStatus();
TestUtil.assertFailure(result);
}
Expand Down
Expand Up @@ -626,16 +626,14 @@ public void test200AddUnresolvable() throws Exception {

assertFocusModificationSanity(context);

// WHEN
when();
try {
clockwork.run(context, task, result);
then();
fail("unexpected success");
} catch (ObjectNotFoundException e) {
then();
System.out.println("Expected exception: " + e);
e.printStackTrace(System.out);
displayExpectedException(e);
if (!e.getMessage().contains("No policy constraint named 'unresolvable' could be found")) {
fail("Exception message was not as expected: " + e.getMessage());
}
Expand All @@ -662,8 +660,7 @@ public void test210AddCyclic() throws Exception {
fail("unexpected success");
} catch (SchemaException e) {
then();
System.out.println("Expected exception: " + e);
e.printStackTrace(System.out);
displayExpectedException(e);
if (!e.getMessage().contains("Trying to resolve cyclic reference to constraint")) {
fail("Exception message was not as expected: " + e.getMessage());
}
Expand Down Expand Up @@ -747,8 +744,7 @@ public void test230AddAmbiguous() throws Exception {
fail("unexpected success");
} catch (SchemaException e) {
then();
System.out.println("Expected exception: " + e);
e.printStackTrace(System.out);
displayExpectedException(e);
if (!e.getMessage().contains("Conflicting definitions of 'constraint-B'")) {
fail("Exception message was not as expected: " + e.getMessage());
}
Expand Down Expand Up @@ -779,8 +775,7 @@ public void test300ModifyInducement() throws Exception {
fail("unexpected success");
} catch (PolicyViolationException e) {
then();
System.out.println("Expected exception: " + e);
e.printStackTrace(System.out);
displayExpectedException(e);
if (!getTranslatedMessage(e).contains("Role \"Immutable inducements\" is to be modified")) {
fail("Exception message was not as expected: " + getTranslatedMessage(e));
}
Expand Down Expand Up @@ -859,8 +854,7 @@ public void test330AddInducement() throws Exception {
fail("unexpected success");
} catch (PolicyViolationException e) {
then();
System.out.println("Expected exception: " + e);
e.printStackTrace(System.out);
displayExpectedException(e);
if (!getTranslatedMessage(e).contains("Role \"No inducements add or delete\" is to be modified")) {
fail("Exception message was not as expected: " + getTranslatedMessage(e));
}
Expand Down Expand Up @@ -891,8 +885,7 @@ public void test340AddInducementViaExpression() throws Exception {
fail("unexpected success");
} catch (PolicyViolationException e) {
then();
System.out.println("Expected exception: " + e);
e.printStackTrace(System.out);
displayExpectedException(e);
if (!getTranslatedMessage(e).contains("Role \"No inducements add or delete (expression)\" is to be modified")) {
fail("Exception message was not as expected: " + getTranslatedMessage(e));
}
Expand Down
Expand Up @@ -633,9 +633,7 @@ public void test269DeleteBarbossaDummyAccount() throws Exception {
"there is no focus context";
assert false : "The operation was successful but it should throw expcetion";
} catch (PolicyViolationException e) {
// THEN: success
// this is expected
displayException("Expected exception", e);
displayExpectedException(e);
}

}
Expand Down

0 comments on commit 85332b3

Please sign in to comment.