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());
}
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());
}
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());
}
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());
}
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"));
}
Aggregations