регистрационном контроллер disallowes отправки поля идентификатора аккаунта следующий:Spring setDisallowedFields не работает
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setDisallowedFields("id");
binder.setRequiredFields("username","password","emailAddress");
}
@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT })
public String handleRegistration(@ModelAttribute Account account, BindingResult result) {
if (result.hasErrors()) {
return "customer/register";
}
бегает следующий тест, чтобы убедиться, что ID не допускаются:
@Test
public void testPutRequestWithIdPassedRegistrationController() throws Exception {
this.mockMvc.perform(post("/customer/register")
.param("id", "1")
.param("username", "shouldBeIgnored")
.param("password", "123")
.param("emailAddress", "[email protected]")
.param("address.country", "RU")
.param("address.city", "Nsk")
.param("address.street", "Lenin"))
.andExpect(model().hasErrors())
.andExpect(view().name("customer/register"));
}
Но тест не пройден причина: java.lang.AssertionError: Ожидаемые ошибки привязки/проверки
Для сравнения здесь приведен тест, который пытается создать учетную запись без прохождения не-NULLABLE поля и она проходит хорошо, это означает, что setRequiredFields
работает отлично:
@Test
public void testPutRequestWithoutNeededFieldsRegistrationController() throws Exception {
this.mockMvc.perform(post("/customer/register"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("customer/register"))
.andExpect(model().hasErrors())
.andExpect(model().errorCount(3));
}
Почему это работает по этому пути? Как я могу убедиться, что id не разрешен?