From 8a1e91bd859e2e4ec047ac762d3f25589570705f Mon Sep 17 00:00:00 2001 From: Yurii Midianyi Date: Wed, 14 Feb 2024 16:09:06 +0200 Subject: [PATCH] fix errors in tests --- .../controller/OwnSecurityControllerTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/test/java/greencity/security/controller/OwnSecurityControllerTest.java b/core/src/test/java/greencity/security/controller/OwnSecurityControllerTest.java index 20f924238..5fe2b974c 100644 --- a/core/src/test/java/greencity/security/controller/OwnSecurityControllerTest.java +++ b/core/src/test/java/greencity/security/controller/OwnSecurityControllerTest.java @@ -23,6 +23,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.http.MediaType; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -174,6 +177,9 @@ void updatePasswordTest() throws Exception { }\ """; + Authentication authentication = new UsernamePasswordAuthenticationToken(principal, null); + SecurityContextHolder.getContext().setAuthentication(authentication); + mockMvc.perform(put(LINK + "/changePassword") .principal(principal) .contentType(MediaType.APPLICATION_JSON) @@ -192,6 +198,9 @@ void hasPassword() { Principal principal = mock(Principal.class); when(principal.getName()).thenReturn("test@mail.com"); + Authentication authentication = new UsernamePasswordAuthenticationToken(principal, null); + SecurityContextHolder.getContext().setAuthentication(authentication); + mockMvc.perform(get(LINK + "/password-status") .principal(principal)) .andExpect(status().isOk()); @@ -205,6 +214,9 @@ void setPassword() { Principal principal = mock(Principal.class); when(principal.getName()).thenReturn("test@mail.com"); + Authentication authentication = new UsernamePasswordAuthenticationToken(principal, null); + SecurityContextHolder.getContext().setAuthentication(authentication); + String content = """ { "password": "String123=",