use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.
the class SoapAuthorizationPolicyTest method testMultipleAllMatch.
@Test
@Configuration("{\r\n" + " \"multiMatch\" : \"all\"," + " \"rules\" : [\r\n" + " { \"action\" : \"reportIncident\", \"role\" : \"role-1\" },\r\n" + " { \"action\" : \"reportIncident\", \"role\" : \"role-2\" }\r\n" + " ]\r\n" + "}")
public void testMultipleAllMatch() throws Throwable {
HashSet<String> userRoles = new HashSet<>();
userRoles.add("other-role");
// Should Fail
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/multi/resource");
try {
request.header("SOAPAction", "reportIncident");
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
send(request);
Assert.fail("Expected a failure response!");
} catch (PolicyFailureError failure) {
PolicyFailure policyFailure = failure.getFailure();
Assert.assertNotNull(policyFailure);
// Expected <Authorization> but was <Other>
Assert.assertEquals(PolicyFailureType.Authorization, policyFailure.getType());
}
userRoles.add("role-1");
// Should Fail
request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/multi/resource");
try {
request.header("SOAPAction", "reportIncident");
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
send(request);
Assert.fail("Expected a failure response!");
} catch (PolicyFailureError failure) {
PolicyFailure policyFailure = failure.getFailure();
Assert.assertNotNull(policyFailure);
Assert.assertEquals(PolicyFailureType.Authorization, policyFailure.getType());
}
userRoles.add("role-2");
// Should Succeed
request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/multi/resource");
request.header("SOAPAction", "reportIncident");
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
PolicyTestResponse response = send(request);
EchoResponse echo = response.entity(EchoResponse.class);
Assert.assertNotNull(echo);
}
use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.
the class SoapAuthorizationPolicyTest method testNoSOAPHeader.
@Test
@Configuration("{\r\n" + " \"rules\" : [\r\n" + " { \"action\" : \"*\", \"role\" : \"role-1\" }\r\n" + " ]\r\n" + "}")
public void testNoSOAPHeader() throws Throwable {
HashSet<String> userRoles = new HashSet<>();
userRoles.add("role-1");
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/invoices/1");
try {
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
send(request);
Assert.fail("expected a failure response");
} catch (PolicyFailureError failure) {
Assert.assertNotNull(failure.getFailure());
Assert.assertEquals(PolicyFailureType.Other, failure.getFailure().getType());
}
}
use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.
the class SoapAuthorizationPolicyTest method testMultipleAnyMatch.
@Test
@Configuration("{\r\n" + " \"multiMatch\" : \"any\"," + " \"rules\" : [\r\n" + " { \"action\" : \"*\", \"role\" : \"user\" },\r\n" + " { \"action\" : \"*\", \"role\" : \"role-1\" },\r\n" + " { \"action\" : \"*\", \"role\" : \"role-2\" },\r\n" + " { \"action\" : \"*\", \"role\" : \"admin\" }\r\n" + " ]\r\n" + "}")
public void testMultipleAnyMatch() throws Throwable {
HashSet<String> userRoles = new HashSet<>();
userRoles.add("other-role");
// Should Fail
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/multi/resource");
try {
request.header("SOAPAction", "reportIncident");
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
send(request);
Assert.fail("Expected a failure response!");
} catch (PolicyFailureError failure) {
PolicyFailure policyFailure = failure.getFailure();
Assert.assertNotNull(policyFailure);
}
userRoles.add("role-1");
// Should Succeed
request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/multi/resource");
request.header("SOAPAction", "reportIncident");
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
PolicyTestResponse response = send(request);
EchoResponse echo = response.entity(EchoResponse.class);
Assert.assertNotNull(echo);
userRoles.add("role-2");
// Should Succeed
request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/multi/resource");
request.header("SOAPAction", "reportIncident");
request.contextAttribute(SoapAuthorizationPolicy.AUTHENTICATED_USER_ROLES, userRoles);
response = send(request);
echo = response.entity(EchoResponse.class);
Assert.assertNotNull(echo);
}
use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.
the class TimeoutPolicyTest method shouldsettingNothing_onEmptyValue.
/**
* Execute with empty value
*/
@Test
@Configuration("{\"timeoutConnect\" : \"\", \"timeoutRead\" : \"\" }")
@BackEndApi(EndPointPropertiesEcho.class)
public void shouldsettingNothing_onEmptyValue() throws PolicyFailureError, Throwable {
// WHEN Execute the policy
PolicyTestResponse response = null;
try {
response = send(PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource"));
} catch (PolicyFailureError ex) {
fail("Configuration error");
}
// THEN timeouts are not set
HashMap<?, ?> responseMap = new ObjectMapper().readValue(response.body(), HashMap.class);
assertFalse("timeoutConnect", responseMap.containsKey("timeouts.connect"));
assertFalse("timeoutRead", responseMap.containsKey("timeouts.read"));
}
Aggregations