Hi to everyone!
Could you please suggest how can i write test for secured rest api?
@Path("/data_conf") @Produces(MediaType.APPLICATION_JSON) public class DataResource { @POST @Path("/getData") @Secured("data_policy") public Response getData(@Context SecurityContext context, @NotNull(message = "Payload shouldn't not be null") Configuration configurationData) { ... } }
The SecurityContext context is injected after AuthenticationFilter logic.
Something like this...
@Secured @Provider @Priority(Priorities.AUTHENTICATION) public class AuthenticationFilter {...}
And my test looks like this…
@Test @RunAsClient public void testGetData(@ArquillianResteasyResource("data_conf") ResteasyWebTarget webTarget) { Configuration request = getConfiguration(); Response response = webTarget .path("/getData") .request(MediaType.APPLICATION_JSON).header("Authorization", TOKEN) .post(Entity.json(request)); .... }
But i always get
DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Receiving response: HTTP/1.1 405 Method Not Allowed