我有一个基本的SpringBoot应用程序。使用Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行的JAR文件。
我有这个测试:
@RunWith(SpringRunner.class)
@WebAppConfiguration
@WebMvcTest
public class MockMvcTests {
// Pull in the application context created by @ContextConfiguration
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@MockBean
private I18NService i18NService;
@MockBean
private EmailService emailService;
@MockBean
private PasswordResetTokenService passwordResetTokenService;
@MockBean
private UserService userService;
@MockBean
private CompanyService companyService;
@MockBean
private UserSecurityService userSecurityService;
@Before
public void setup() {
// Setup MockMVC to use our Spring Configuration
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
/**
*
* @throws Exception
* If anything fails.
*/
@Test
public void getDeviceEventsTest() throws Exception {
this.mockMvc
.perform(get("/deviceevent/list") //
.accept(MediaType.parseMediaType("text/html;charset=UTF-8")))
.andExpect(status().isOk()) //
.andExpect(model().size(1)); //
}
但是运行测试我得到了这个例外
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#authorization.expression('hasRole(''ROLE_ADMIN'')')" (tdk/common/menu:62)
有没有办法绕过授权?