Merge branch '2.3.x'

Closes gh-21770
pull/21872/head
Scott Frederick 5 years ago
commit f3d5416cf4

@ -172,7 +172,7 @@ public class BasicErrorController extends AbstractErrorController {
* @return if the errors attribute should be included * @return if the errors attribute should be included
*/ */
protected boolean isIncludeBindingErrors(HttpServletRequest request, MediaType produces) { protected boolean isIncludeBindingErrors(HttpServletRequest request, MediaType produces) {
switch (getErrorProperties().getIncludeMessage()) { switch (getErrorProperties().getIncludeBindingErrors()) {
case ALWAYS: case ALWAYS:
return true; return true;
case ON_PARAM: case ON_PARAM:

@ -205,50 +205,89 @@ class BasicErrorControllerIntegrationTests {
} }
@Test @Test
void testBindingExceptionForMachineClientWithMessageAndErrorsParamTrue() { void testBindingExceptionForMachineClientWithErrorsParamTrue() {
load("--server.error.include-exception=true", "--server.error.include-message=on-param", load("--server.error.include-exception=true", "--server.error.include-binding-errors=on-param");
"--server.error.include-binding-errors=on-param"); bindingExceptionWithErrors("?errors=true");
bindingExceptionWithMessageAndErrors("?message=true&errors=true");
} }
@Test @Test
void testBindingExceptionForMachineClientWithMessageAndErrorsParamFalse() { void testBindingExceptionForMachineClientWithErrorsParamFalse() {
load("--server.error.include-exception=true", "--server.error.include-message=on-param", load("--server.error.include-exception=true", "--server.error.include-binding-errors=on-param");
"--server.error.include-binding-errors=on-param"); bindingExceptionWithoutErrors("?errors=false");
bindingExceptionWithoutMessageAndErrors("?message=false&errors=false");
} }
@Test @Test
void testBindingExceptionForMachineClientWithMessageAndErrorsParamAbsent() { void testBindingExceptionForMachineClientWithErrorsParamAbsent() {
load("--server.error.include-exception=true", "--server.error.include-message=on-param", load("--server.error.include-exception=true", "--server.error.include-binding-errors=on-param");
"--server.error.include-binding-errors=on-param"); bindingExceptionWithoutErrors("");
bindingExceptionWithoutMessageAndErrors("");
} }
@Test @Test
void testBindingExceptionForMachineClientAlwaysMessageAndErrors() { void testBindingExceptionForMachineClientAlwaysErrors() {
load("--server.error.include-exception=true", "--server.error.include-message=always", load("--server.error.include-exception=true", "--server.error.include-binding-errors=always");
"--server.error.include-binding-errors=always"); bindingExceptionWithErrors("?errors=false");
bindingExceptionWithMessageAndErrors("?message=false&errors=false");
} }
@Test @Test
void testBindingExceptionForMachineClientNeverMessageAndErrors() { void testBindingExceptionForMachineClientNeverErrors() {
load("--server.error.include-exception=true", "--server.error.include-message=never", load("--server.error.include-exception=true", "--server.error.include-binding-errors=never");
"--server.error.include-binding-errors=never"); bindingExceptionWithoutErrors("?errors=true");
bindingExceptionWithoutMessageAndErrors("?message=true&errors=true"); }
@Test
void testBindingExceptionForMachineClientWithMessageParamTrue() {
load("--server.error.include-exception=true", "--server.error.include-message=on-param");
bindingExceptionWithMessage("?message=true");
}
@Test
void testBindingExceptionForMachineClientWithMessageParamFalse() {
load("--server.error.include-exception=true", "--server.error.include-message=on-param");
bindingExceptionWithoutMessage("?message=false");
}
@Test
void testBindingExceptionForMachineClientWithMessageParamAbsent() {
load("--server.error.include-exception=true", "--server.error.include-message=on-param");
bindingExceptionWithoutMessage("");
}
@Test
void testBindingExceptionForMachineClientAlwaysMessage() {
load("--server.error.include-exception=true", "--server.error.include-message=always");
bindingExceptionWithMessage("?message=false");
}
@Test
void testBindingExceptionForMachineClientNeverMessage() {
load("--server.error.include-exception=true", "--server.error.include-message=never");
bindingExceptionWithoutMessage("?message=true");
}
@SuppressWarnings({ "rawtypes" })
private void bindingExceptionWithErrors(String param) {
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind");
assertThat(entity.getBody().containsKey("errors")).isTrue();
} }
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings({ "rawtypes" })
private void bindingExceptionWithMessageAndErrors(String param) { private void bindingExceptionWithoutErrors(String param) {
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind");
assertThat(entity.getBody().containsKey("errors")).isFalse();
}
@SuppressWarnings({ "rawtypes" })
private void bindingExceptionWithMessage(String param) {
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class); ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class,
"Validation failed for object='test'. Error count: 1", "/bind"); "Validation failed for object='test'. Error count: 1", "/bind");
assertThat(entity.getBody().containsKey("errors")).isTrue(); assertThat(entity.getBody().containsKey("errors")).isFalse();
} }
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings({ "rawtypes" })
private void bindingExceptionWithoutMessageAndErrors(String param) { private void bindingExceptionWithoutMessage(String param) {
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class); ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(createUrl("/bind" + param), Map.class);
assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind"); assertErrorAttributes(entity.getBody(), "400", "Bad Request", BindException.class, "", "/bind");
assertThat(entity.getBody().containsKey("errors")).isFalse(); assertThat(entity.getBody().containsKey("errors")).isFalse();

Loading…
Cancel
Save