@Bean @ConditionalOnMissingBean public DispatcherFilter remoteDevToolsDispatcherFilter(AccessManager accessManager, Collection<HandlerMapper> mappers) { Dispatcher dispatcher = new Dispatcher(accessManager, mappers); return new DispatcherFilter(dispatcher); }
@Bean public DispatcherFilter filter() { PortProvider port = new StaticPortProvider(this.httpServerPort); TargetServerConnection connection = new SocketTargetServerConnection(port); HttpTunnelServer server = new HttpTunnelServer(connection); HandlerMapper mapper = new UrlHandlerMapper("/httptunnel", new HttpTunnelServerHandler(server)); Collection<HandlerMapper> mappers = Collections.singleton(mapper); Dispatcher dispatcher = new Dispatcher(AccessManager.PERMIT_ALL, mappers); return new DispatcherFilter(dispatcher); }
@Test public void ignoresUnmappedUrl() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI("/restart"); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); filter.doFilter(this.request, this.response, this.chain); assertRestartInvoked(false); }
@Test public void ignoresIfMissingSecretFromRequest() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/restart"); filter.doFilter(this.request, this.response, this.chain); assertRestartInvoked(false); }
@Test public void ignoresInvalidSecretInRequest() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/restart"); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "invalid"); filter.doFilter(this.request, this.response, this.chain); assertRestartInvoked(false); }
@Test public void invokeRestartWithDefaultSetup() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/restart"); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); filter.doFilter(this.request, this.response, this.chain); assertRestartInvoked(true); }
@Test public void invokeRestartWithCustomServerContextPath() throws Exception { loadContext("spring.devtools.remote.secret:supersecret", "server.context-path:/test"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/restart"); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); filter.doFilter(this.request, this.response, this.chain); assertRestartInvoked(true); }
@Test public void invokeTunnelWithDefaultSetup() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/debug"); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); filter.doFilter(this.request, this.response, this.chain); assertTunnelInvoked(true); }
@Test public void invokeTunnelWithCustomServerContextPath() throws Exception { loadContext("spring.devtools.remote.secret:supersecret", "server.context-path:/test"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH + "/debug"); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); filter.doFilter(this.request, this.response, this.chain); assertTunnelInvoked(true); }
@Test public void invokeTunnelWithCustomHeaderName() throws Exception { loadContext("spring.devtools.remote.secret:supersecret", "spring.devtools.remote.secretHeaderName:customheader"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH + "/debug"); this.request.addHeader("customheader", "supersecret"); filter.doFilter(this.request, this.response, this.chain); assertTunnelInvoked(true); }
@Test public void devToolsHealthReturns200() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); this.response.setStatus(500); filter.doFilter(this.request, this.response, this.chain); assertThat(this.response.getStatus()).isEqualTo(200); }
@Test public void devToolsHealthWithCustomServerContextPathReturns200() throws Exception { loadContext("spring.devtools.remote.secret:supersecret", "server.context-path:/test"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI("/test" + DEFAULT_CONTEXT_PATH); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); this.response.setStatus(500); filter.doFilter(this.request, this.response, this.chain); assertThat(this.response.getStatus()).isEqualTo(200); }
@Test public void devToolsHealthReturns200() throws Exception { loadContext("spring.devtools.remote.secret:supersecret"); DispatcherFilter filter = this.context.getBean(DispatcherFilter.class); this.request.setRequestURI(DEFAULT_CONTEXT_PATH); this.request.addHeader(DEFAULT_SECRET_HEADER_NAME, "supersecret"); this.response.setStatus(500); filter.doFilter(this.request, this.response, this.chain); assertThat(this.response.getStatus(), equalTo(200)); }
@Test public void disabledIfRemoteSecretIsMissing() throws Exception { loadContext("a:b"); this.thrown.expect(NoSuchBeanDefinitionException.class); this.context.getBean(DispatcherFilter.class); }
@Bean public DispatcherFilter dispatcherFilter() throws IOException { return new DispatcherFilter(dispatcher()); }