Ronny Bräunlich
11/05/2024, 10:06 AM@WithMockUser
annotation. I found this old issue: https://github.com/kotest/kotest/issues/337
The solution mentioned there works but in my opinion, it's pretty ugly. Comparing:
@WithMockUser(authorities = [EDIT_SCHEDULED_CAMPAIGNS])
fun `should handle errors`() {
with
it("should handle errors") {
SecurityContextHolder.getContext().authentication =
PreAuthenticatedAuthenticationToken(null, null, listOf(SimpleGrantedAuthority(EDIT_SCHEDULED_CAMPAIGNS)))
Ronny Bräunlich
11/07/2024, 5:04 AMEmil Kantis
11/07/2024, 7:09 AMdescribe("ErrorHandling") {
extensions(SpringMockUserExtension(EDIT_SOMETHING))
it("should handle errors") {
// ...
}
// any other siblings would also have the mock user injected
}
I think you could define it as a TestCaseExtension
Ronny Bräunlich
11/07/2024, 7:18 AM