Поэтому я добавил
Код: Выделить всё
org.springframework.boot
spring-boot-starter-oauth2-resource-server
org.springframework.security
spring-security-test
6.5.5
test
- Защита CSRF отключена в любом случае (сервер ресурсов без сохранения состояния)
- Если веб-безопасность включена, я настраиваю httpSecurity.oauth2ResourceServer и http.authorizeHttpRequests с проверкой роли.
- Если веб-безопасность отключена, я просто звоню:
Код: Выделить всё
httpSecurity.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());
Код: Выделить всё
@RequestMapping(
method = RequestMethod.POST,
value = "/import/{pipeline_name}",
produces = { "application/json" },
consumes = { "application/json" }
)
Модульный тест выглядит следующим образом:
Код: Выделить всё
@WebMvcTest(ImportController.class)
class ImportControllerTest {
@Autowired
private MockMvc mockMvc;
// some more beans and an inner @Configuration class which asks for disabled web security
@Test
@WithMockUser
void someTest() throws Exception {
doNothing().when(someService).doesStuff();
this.mockMvc.perform(
post("/import/test")
.with(jwt())
.contentType(MediaType.APPLICATION_JSON)
.content(someBody)
).andExpect(status().isNoContent());
}
Однако, учитывая эту зависимость, независимо от того, настраиваю ли я сложные средства сопоставления запросов или просто AnyRequest().permitALL(), я получаю статус 404 со следующими журналами:
Код: Выделить всё
o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
.w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.servlet.resource.NoResourceFoundException: No static resource import/test.]
Подробнее здесь: https://stackoverflow.com/questions/797 ... rce-server
Мобильная версия