Search in sources :

Example 1 with PolicyFailureError

use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWithNoTls.

@Test
@Configuration("{\n" + "  \"requireJWT\": true,\n" + "  \"requireSigned\": false,\n" + "  \"requireTransportSecurity\": true,\n" + "  \"stripTokens\": true,\n" + "  \"signingKeyString\": \"" + PUBLIC_KEY_PEM + "\",\n" + "  \"allowedClockSkew\": 0,\n" + "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"will_not_match\" }]\n" + "}")
public void shouldFailWithNoTls() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante").header("Authorization", "Bearer " + Jwts.builder().claim("x", "x").compact());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12009, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 2 with PolicyFailureError

use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWithUnexpectedClaimValue.

@Test
@Configuration("{\n" + "  \"requireJWT\": true,\n" + "  \"requireSigned\": false,\n" + "  \"requireTransportSecurity\": true,\n" + "  \"stripTokens\": true,\n" + "  \"signingKeyString\": \"" + PUBLIC_KEY_PEM + "\",\n" + "  \"allowedClockSkew\": 0,\n" + "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"will_not_match\" }]\n" + "}")
public void shouldFailWithUnexpectedClaimValue() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante").header("Authorization", "Bearer " + unsignedToken());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12009, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 3 with PolicyFailureError

use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWhenTokenInvalid.

@Test
@Configuration("{\n" + "  \"requireJWT\": true,\n" + "  \"requireSigned\": false,\n" + "  \"requireTransportSecurity\": true,\n" + "  \"stripTokens\": true,\n" + "  \"signingKeyString\": \"" + PUBLIC_KEY_PEM + "\",\n" + "  \"allowedClockSkew\": 0,\n" + "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"france frichot\" }]\n" + "}")
public void shouldFailWhenTokenInvalid() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante").header("Authorization", "Bearer <Obviously invalid token>");
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12007, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 4 with PolicyFailureError

use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWithMissingClaim.

@Test
@Configuration("{\n" + "  \"requireJWT\": true,\n" + "  \"requireSigned\": false,\n" + "  \"requireTransportSecurity\": true,\n" + "  \"stripTokens\": true,\n" + "  \"signingKeyString\": \"" + PUBLIC_KEY_PEM + "\",\n" + "  \"allowedClockSkew\": 0,\n" + "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"will_not_match\" }]\n" + "}")
public void shouldFailWithMissingClaim() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante").header("Authorization", "Bearer " + Jwts.builder().claim("x", "x").compact());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12009, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 5 with PolicyFailureError

use of io.apiman.test.policies.PolicyFailureError in project apiman-plugins by apiman.

the class TimeoutPolicyTest method shouldExecute_onSimpleConfiguration.

/**
 * Control the normal execution
 */
@Test
@Configuration("{\"timeoutConnect\" : \"1\", \"timeoutRead\" : \"2\" }")
@BackEndApi(EndPointPropertiesEcho.class)
public void shouldExecute_onSimpleConfiguration() 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 set
    HashMap<?, ?> responseMap = new ObjectMapper().readValue(response.body(), HashMap.class);
    assertEquals("timeoutConnect", "1", responseMap.get("timeouts.connect"));
    assertEquals("timeoutRead", "2", responseMap.get("timeouts.read"));
}
Also used : PolicyTestResponse(io.apiman.test.policies.PolicyTestResponse) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IPolicyTestBackEndApi(io.apiman.test.policies.IPolicyTestBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) Configuration(io.apiman.test.policies.Configuration) Test(org.junit.Test) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest)

Aggregations

ApimanPolicyTest (io.apiman.test.policies.ApimanPolicyTest)24 Configuration (io.apiman.test.policies.Configuration)24 PolicyFailureError (io.apiman.test.policies.PolicyFailureError)24 Test (org.junit.Test)24 PolicyTestRequest (io.apiman.test.policies.PolicyTestRequest)21 PolicyFailure (io.apiman.gateway.engine.beans.PolicyFailure)19 PolicyTestResponse (io.apiman.test.policies.PolicyTestResponse)15 EchoResponse (io.apiman.test.common.mock.EchoResponse)7 BackEndApi (io.apiman.test.policies.BackEndApi)7 IPolicyTestBackEndApi (io.apiman.test.policies.IPolicyTestBackEndApi)7 HashSet (java.util.HashSet)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3