Refine error message from Endpoint MVC security
Update the error message to return less information to the client. Details of how to disable security are now written to the log instead. See gh-7605 See gh-7634
This commit is contained in:
@@ -23,9 +23,11 @@ import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
@@ -42,6 +44,9 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class MvcEndpointSecurityInterceptorTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture output = new OutputCapture();
|
||||
|
||||
private MvcEndpointSecurityInterceptor securityInterceptor;
|
||||
|
||||
private TestMvcEndpoint mvcEndpoint;
|
||||
@@ -97,8 +102,13 @@ public class MvcEndpointSecurityInterceptorTests {
|
||||
assertThat(this.securityInterceptor.preHandle(this.request, this.response,
|
||||
this.handlerMethod)).isFalse();
|
||||
verify(this.response).sendError(HttpStatus.UNAUTHORIZED.value(),
|
||||
"Full authentication is required to access this resource. "
|
||||
+ "Consider adding Spring Security or set management.security.enabled to false.");
|
||||
"Full authentication is required to access this resource.");
|
||||
assertThat(this.securityInterceptor.preHandle(this.request, this.response,
|
||||
this.handlerMethod)).isFalse();
|
||||
assertThat(this.output.toString())
|
||||
.containsOnlyOnce("Full authentication is required to access actuator "
|
||||
+ "endpoints. Consider adding Spring Security or set "
|
||||
+ "'management.security.enabled' to false");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user