@Test public void get_version_missing_api_key() { Configuration config = Configuration.getDefaultConfiguration(); config.global.httpApiAuthEnabled = true; DiagnosticsApi mxBean = mock(DiagnosticsApi.class); HttpHandler httpApi = new HttpHandler(config, mxBean); IHTTPSession session = mock(IHTTPSession.class); when(session.getMethod()).thenReturn(Method.GET); when(session.getUri()).thenReturn("/version"); Response res = httpApi.serve(session); assertThat(res.getStatus()).isEqualTo(Status.FORBIDDEN); }
@Override public Response serve(IHTTPSession session) { if (!apiAuthEnabled || hasValidCredentials(session)) { return respond(session); } return newFixedLengthResponse(Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "Invalid API key\r\n"); }
HttpHandler extends NanoHTTPD { @Override public Response serve(IHTTPSession session) { if (!apiAuthEnabled || hasValidCredentials(session)) { return respond(session); } return newFixedLengthResponse(Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "Invalid API key\r\n"); } }
HttpHandler extends NanoHTTPD { @Override public Response serve(IHTTPSession session) { if (!apiAuthEnabled || hasValidCredentials(session)) { return respond(session); } return newFixedLengthResponse(Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "Invalid API key\r\n"); } HttpHandler(Configuration config, DiagnosticsApi diagnosticsApi); }
HttpHandler extends NanoHTTPD { @Override public Response serve(IHTTPSession session) { if (!apiAuthEnabled || hasValidCredentials(session)) { return respond(session); } return newFixedLengthResponse(Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "Invalid API key\r\n"); } HttpHandler(Configuration config, DiagnosticsApi diagnosticsApi); @Override Response serve(IHTTPSession session); }
HttpHandler extends NanoHTTPD { @Override public Response serve(IHTTPSession session) { if (!apiAuthEnabled || hasValidCredentials(session)) { return respond(session); } return newFixedLengthResponse(Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT, "Invalid API key\r\n"); } HttpHandler(Configuration config, DiagnosticsApi diagnosticsApi); @Override Response serve(IHTTPSession session);  }