HttpRESTHandler implements
        ResponsibleHandler { public void setAllowedHosts(List<String> allowedHosts) { this.allowedHosts = allowedHosts; resolveAllowedHosts(); } HttpRESTHandler(DatabaseConnector<T> dbc);  HttpRESTHandler(CachingDocumentNIO<T> documentIO,
                           PipelineReader pipelineReader, List<String> allowedHosts,
                           boolean isPerformanceLogging); void setRestId(String restId); boolean dispatch(HttpRequest request, HttpResponse response,
                            HttpContext context, ResponsibleHandler... handlers); @Override void handle(final HttpRequest request, final HttpResponse response,
                       final HttpContext context); boolean accessAllowed(HttpContext context); @Override boolean supports(HttpRequest request); @Override String[] getSupportedUrls(); void setAllowedHosts(List<String> allowedHosts); List<String> getAllowedHosts();  }
@Test public void testAccessRestrictions() throws InterruptedException { restHandler.setAllowedHosts(Arrays.asList("localhost")); if (!server.isWorking(System.currentTimeMillis(), 200)) { fail("Failed to connect when allowed hosts contained localhost"); } restHandler.setAllowedHosts(Arrays.asList("127.0.0.1")); if (!server.isWorking(System.currentTimeMillis(), 200)) { fail("Failed to connect when allowed hosts contained 127.0.0.1"); } restHandler.setAllowedHosts(Arrays.asList("127.0.0.2")); if (server.isWorking(System.currentTimeMillis(), 200)) { fail("Server should *not* have been working, since allowed hosts does not contain localhost"); } restHandler.setAllowedHosts(null); if (!server.isWorking(System.currentTimeMillis(), 200)) { fail("Server should have been working, since allowed hosts is null"); } }
@Test(expected = RuntimeException.class) public void testSetAllowedHostsThrowsExceptionWhenUnknownHost() { restHandler.setAllowedHosts(Arrays.asList(findUnknownHost())); }