From c15a73b2105527ed3f53970a94e7726b52bffaad Mon Sep 17 00:00:00 2001 From: Laurent Caouissin Date: Thu, 25 Jan 2024 15:45:25 +0100 Subject: [PATCH] test: fix test with auth --- pom.xml | 5 +++ .../utils/AuthenticatedUserTestHelper.java | 35 +++++++++++++++++ .../controllers/ContextControllerTest.java | 17 ++++++-- .../api/controllers/ModeControllerTest.java | 18 +++++++-- .../QuestionnaireControllerTest.java | 39 ++++++++++++++----- .../controllers/SurveyUnitControllerTest.java | 27 ++++++++++--- src/test/resources/application-test.yaml | 7 ++++ 7 files changed, 128 insertions(+), 20 deletions(-) create mode 100644 src/main/java/fr/insee/publicenemy/api/utils/AuthenticatedUserTestHelper.java diff --git a/pom.xml b/pom.xml index c66543a..059e99c 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,11 @@ spring-boot-starter-test test + + org.springframework.security + spring-security-test + test + com.h2database diff --git a/src/main/java/fr/insee/publicenemy/api/utils/AuthenticatedUserTestHelper.java b/src/main/java/fr/insee/publicenemy/api/utils/AuthenticatedUserTestHelper.java new file mode 100644 index 0000000..0a510e6 --- /dev/null +++ b/src/main/java/fr/insee/publicenemy/api/utils/AuthenticatedUserTestHelper.java @@ -0,0 +1,35 @@ +package fr.insee.publicenemy.api.utils; + +import fr.insee.publicenemy.api.configuration.auth.AuthConstants; +import fr.insee.publicenemy.api.configuration.auth.AuthorityRoleEnum; +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class AuthenticatedUserTestHelper { + + public JwtAuthenticationToken getUser() { + return getAuthenticatedUser( + AuthorityRoleEnum.ADMIN, AuthorityRoleEnum.DESIGNER); + } + public JwtAuthenticationToken getAuthenticatedUser(AuthorityRoleEnum... roles) { + List authorities = new ArrayList<>(); + for (AuthorityRoleEnum role : roles) { + authorities.add(new SimpleGrantedAuthority(AuthConstants.ROLE_PREFIX + role.name())); + } + + Map headers = Map.of("typ", "JWT"); + Map claims = Map.of("preferred_username", "dupont-identifier", "name", "Jean Dupont"); + + Jwt jwt = new Jwt("token-value", Instant.MIN, Instant.MAX, headers, claims); + return new JwtAuthenticationToken(jwt, authorities, "dupont-identifier"); + } +} \ No newline at end of file diff --git a/src/test/java/fr/insee/publicenemy/api/controllers/ContextControllerTest.java b/src/test/java/fr/insee/publicenemy/api/controllers/ContextControllerTest.java index 0ff8074..bb6b712 100644 --- a/src/test/java/fr/insee/publicenemy/api/controllers/ContextControllerTest.java +++ b/src/test/java/fr/insee/publicenemy/api/controllers/ContextControllerTest.java @@ -2,13 +2,18 @@ import fr.insee.publicenemy.api.application.domain.model.Context; import fr.insee.publicenemy.api.application.ports.I18nMessagePort; +import fr.insee.publicenemy.api.utils.AuthenticatedUserTestHelper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.RequestPostProcessor; import java.util.Arrays; import java.util.List; @@ -16,16 +21,21 @@ import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(ContextController.class) -@ContextConfiguration(classes = ContextController.class) +@SpringBootTest +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureMockMvc class ContextControllerTest { @MockBean private I18nMessagePort i18nService; + private final AuthenticatedUserTestHelper authenticatedUserTestHelper = new AuthenticatedUserTestHelper(); + @Autowired private MockMvc mockMvc; @@ -37,7 +47,8 @@ public void init() { @Test void onGetContextsReturnsAllContexts() throws Exception { List contextNames = Arrays.stream(Context.values()).map(Enum::name).toList(); - mockMvc.perform(get("/api/contexts")) + mockMvc.perform(get("/api/contexts") + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.size()", is(2))) .andExpect(jsonPath("$[0].name", is(contextNames.get(0)))) diff --git a/src/test/java/fr/insee/publicenemy/api/controllers/ModeControllerTest.java b/src/test/java/fr/insee/publicenemy/api/controllers/ModeControllerTest.java index d493868..b5750d5 100644 --- a/src/test/java/fr/insee/publicenemy/api/controllers/ModeControllerTest.java +++ b/src/test/java/fr/insee/publicenemy/api/controllers/ModeControllerTest.java @@ -1,28 +1,40 @@ package fr.insee.publicenemy.api.controllers; import fr.insee.publicenemy.api.application.domain.model.Mode; +import fr.insee.publicenemy.api.utils.AuthenticatedUserTestHelper; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; import static org.hamcrest.Matchers.is; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(ModeController.class) -@ContextConfiguration(classes = ModeController.class) +@SpringBootTest +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureMockMvc class ModeControllerTest { @Autowired private MockMvc mockMvc; + private final AuthenticatedUserTestHelper authenticatedUserTestHelper = new AuthenticatedUserTestHelper(); + @Test void onGetModesReturnsAllModes() throws Exception { Mode[] modes = Mode.values(); - mockMvc.perform(get("/api/modes")) + mockMvc.perform(get("/api/modes") + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.size()", is(modes.length))); } diff --git a/src/test/java/fr/insee/publicenemy/api/controllers/QuestionnaireControllerTest.java b/src/test/java/fr/insee/publicenemy/api/controllers/QuestionnaireControllerTest.java index 257231e..87bf7cf 100644 --- a/src/test/java/fr/insee/publicenemy/api/controllers/QuestionnaireControllerTest.java +++ b/src/test/java/fr/insee/publicenemy/api/controllers/QuestionnaireControllerTest.java @@ -11,11 +11,13 @@ import fr.insee.publicenemy.api.application.usecase.DDIUseCase; import fr.insee.publicenemy.api.application.usecase.QuestionnaireUseCase; import fr.insee.publicenemy.api.application.usecase.SurveyUnitCsvUseCase; +import fr.insee.publicenemy.api.configuration.auth.AuthorityRoleEnum; import fr.insee.publicenemy.api.controllers.dto.ContextRest; import fr.insee.publicenemy.api.controllers.dto.ModeRest; import fr.insee.publicenemy.api.controllers.dto.QuestionnaireAddRest; import fr.insee.publicenemy.api.controllers.dto.QuestionnaireRest; import fr.insee.publicenemy.api.controllers.exceptions.ApiExceptionComponent; +import fr.insee.publicenemy.api.utils.AuthenticatedUserTestHelper; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,12 +26,15 @@ import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockPart; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -43,12 +48,14 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -@WebMvcTest(QuestionnaireController.class) -@ContextConfiguration(classes = QuestionnaireController.class) -@Slf4j +@SpringBootTest +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureMockMvc class QuestionnaireControllerTest { @MockBean private QuestionnaireUseCase questionnaireUseCase; @@ -70,6 +77,8 @@ class QuestionnaireControllerTest { @Autowired private MockMvc mockMvc; + + private final AuthenticatedUserTestHelper authenticatedUserTestHelper = new AuthenticatedUserTestHelper(); private List questionnaires; private Questionnaire questionnaire; @@ -105,7 +114,8 @@ void onGetQuestionnairesShouldFetchAllQuestionnaires() throws Exception { when(questionnaireUseCase.getQuestionnaires()).thenReturn(questionnaires); - mockMvc.perform(get("/api/questionnaires")) + mockMvc.perform(get("/api/questionnaires") + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.size()", is(questionnaires.size()))); } @@ -115,7 +125,8 @@ void onGetQuestionnaireShouldFetchQuestionnaireAttributes() throws Exception { Long id = questionnaire.getId(); when(questionnaireUseCase.getQuestionnaire(id)).thenReturn(questionnaire); - mockMvc.perform(get("/api/questionnaires/{id}", id)) + mockMvc.perform(get("/api/questionnaires/{id}", id) + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(questionnaireRest.id().intValue()))) .andExpect(jsonPath("$.poguesId", is(questionnaireRest.poguesId()))) @@ -132,7 +143,8 @@ void onGetSurveyUnitsDataReturnCSV() throws Exception { byte[] data = "\"att1\",\"att2\"".getBytes(); when(questionnaireUseCase.getSurveyUnitData(id)).thenReturn(data); - MvcResult result = mockMvc.perform(get("/api/questionnaires/{id}/data", id)) + MvcResult result = mockMvc.perform(get("/api/questionnaires/{id}/data", id) + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andReturn(); @@ -152,6 +164,7 @@ void onAddQuestionnaireShouldFetchQuestionnaireAttributes() throws Exception { questionnaireMockPart.getHeaders().setContentType(MediaType.APPLICATION_JSON); mockMvc.perform(multipart("/api/questionnaires/add").file(surveyUnitMockPart).part(questionnaireMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(questionnaireRest.id().intValue()))) @@ -168,7 +181,8 @@ void onGetQuestionnaireFromPoguesShouldFetchQuestionnaireAttributes() throws Exc String poguesId = questionnaire.getPoguesId(); when(ddiUseCase.getQuestionnaire(poguesId)).thenReturn(questionnaire); - mockMvc.perform(get("/api/questionnaires/pogues/{poguesId}", poguesId)) + mockMvc.perform(get("/api/questionnaires/pogues/{poguesId}", poguesId) + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.poguesId", is(questionnaireRest.poguesId()))) .andExpect(jsonPath("$.label", is(questionnaireRest.label()))) @@ -192,6 +206,7 @@ void onSaveQuestionnaireShouldFetchQuestionnaireAttributes(String surveyUnitData questionnaire.getContext(), questionnaire.getSurveyUnitData())).thenReturn(questionnaire); mockMvc.perform(multipart("/api/questionnaires/{id}", id).part(contextMockPart).file(surveyUnitMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(questionnaireRest.id().intValue()))) @@ -214,6 +229,7 @@ void onSaveQuestionnaireWhenEmptyDataShouldFetchDataFromQuestionnaire() throws E Long id = questionnaire.getId(); mockMvc.perform(multipart("/api/questionnaires/{id}", id).part(contextMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()); verify(questionnaireUseCase, times(1)).getSurveyUnitData(id); @@ -223,7 +239,8 @@ void onSaveQuestionnaireWhenEmptyDataShouldFetchDataFromQuestionnaire() throws E void onDeleteQuestionnaireShouldReturnEmptyJsonObject() throws Exception { Long id = questionnaire.getId(); - mockMvc.perform(delete("/api/questionnaires/{id}/delete", id)) + mockMvc.perform(delete("/api/questionnaires/{id}/delete", id) + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(content().json("{}")); } @@ -243,6 +260,7 @@ void onAddQuestionnaireWhenGlobalErrorsOnCsvSchemaReturnGenericErrorMessages() t SurveyUnitsGlobalValidationException surveyUnitsValidationException = new SurveyUnitsGlobalValidationException("main error message", new ArrayList<>()); when(surveyUnitCsvUseCase.validateSurveyUnits(surveyUnitData, "l8wwljbo")).thenThrow(surveyUnitsValidationException); mockMvc.perform(multipart("/api/questionnaires/add").file(surveyUnitMockPart).part(questionnaireMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isBadRequest()); @@ -266,7 +284,10 @@ void onAddQuestionnaireWhenSpecificErrorsOnCsvSchemaReturnGenericErrorMessages() SurveyUnitsSpecificValidationException surveyUnitsSpecificValidationException = new SurveyUnitsSpecificValidationException("main error message", new ArrayList<>()); when(surveyUnitCsvUseCase.validateSurveyUnits(surveyUnitData, "l8wwljbo")).thenThrow(surveyUnitsSpecificValidationException); - mockMvc.perform(multipart("/api/questionnaires/add").file(surveyUnitMockPart).part(questionnaireMockPart) + mockMvc.perform(multipart("/api/questionnaires/add") + .file(surveyUnitMockPart) + .part(questionnaireMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isBadRequest()); diff --git a/src/test/java/fr/insee/publicenemy/api/controllers/SurveyUnitControllerTest.java b/src/test/java/fr/insee/publicenemy/api/controllers/SurveyUnitControllerTest.java index 7c6ca5d..297e587 100644 --- a/src/test/java/fr/insee/publicenemy/api/controllers/SurveyUnitControllerTest.java +++ b/src/test/java/fr/insee/publicenemy/api/controllers/SurveyUnitControllerTest.java @@ -19,15 +19,20 @@ import fr.insee.publicenemy.api.controllers.exceptions.ApiExceptionComponent; import fr.insee.publicenemy.api.infrastructure.csv.SurveyUnitCsvHeaderLine; import fr.insee.publicenemy.api.infrastructure.csv.SurveyUnitStateData; +import fr.insee.publicenemy.api.infrastructure.i18n.I18nMessageServiceImpl; +import fr.insee.publicenemy.api.utils.AuthenticatedUserTestHelper; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -43,13 +48,16 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(SurveyUnitController.class) -@ContextConfiguration(classes = SurveyUnitController.class) -@Slf4j +@SpringBootTest +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureMockMvc class SurveyUnitControllerTest { @MockBean private QueenUseCase queenUseCase; @@ -72,6 +80,8 @@ class SurveyUnitControllerTest { @Autowired private MockMvc mockMvc; + private final AuthenticatedUserTestHelper authenticatedUserTestHelper = new AuthenticatedUserTestHelper(); + @Mock private List surveyUnits; @@ -91,7 +101,8 @@ void onGetSurveyUnitsShouldFetchAllSurveyUnits() throws Exception { Mode cawi = Mode.valueOf("CAWI"); String questionnaireModelId = String.format("%s-%s", questionnaireId, cawi.name()); when(queenUseCase.getSurveyUnits(questionnaireModelId)).thenReturn(surveyUnits); - mockMvc.perform(get("/api/questionnaires/{questionnaireId}/modes/{mode}/survey-units", questionnaireId, cawi.name())) + mockMvc.perform(get("/api/questionnaires/{questionnaireId}/modes/{mode}/survey-units", questionnaireId, cawi.name()) + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andExpect(jsonPath("$.surveyUnits.size()", is(surveyUnits.size()))) .andExpect(jsonPath("$.questionnaireModelId", is(questionnaireModelId))); @@ -106,7 +117,8 @@ void onGetCsvSchemaReturnsCSVHeaders() throws Exception { headers.add("Header3"); SurveyUnitCsvHeaderLine headerLine = new SurveyUnitCsvHeaderLine(headers); when(csvUseCase.getHeadersLine(poguesId)).thenReturn(headerLine); - MvcResult result = mockMvc.perform(get("/api/questionnaires/{poguesId}/csv", poguesId)) + MvcResult result = mockMvc.perform(get("/api/questionnaires/{poguesId}/csv", poguesId) + .with(authentication(authenticatedUserTestHelper.getUser()))) .andExpect(status().isOk()) .andReturn(); assertEquals("\"Header1\",\"Header2\",\"Header3\"\n", result.getResponse().getContentAsString()); @@ -120,6 +132,7 @@ void onCheckCorrectCsvSchemaReturnsEmptyWarningMessages() throws Exception { when(csvUseCase.validateSurveyUnits(surveyUnitData, poguesId)).thenReturn(new ArrayList<>()); MockMultipartFile surveyUnitMockPart = new MockMultipartFile("surveyUnitData", "file", MediaType.MULTIPART_FORM_DATA_VALUE, surveyUnitData); MvcResult result = mockMvc.perform(multipart("/api/questionnaires/{poguesId}/checkdata", poguesId).file(surveyUnitMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()) .andReturn(); @@ -137,6 +150,7 @@ void onCheckInCorrectCsvSchemaReturnsWarningMessages() throws Exception { when(messageService.getMessage(eq(code), any())).thenReturn(code); MockMultipartFile surveyUnitMockPart = new MockMultipartFile("surveyUnitData", "file", MediaType.MULTIPART_FORM_DATA_VALUE, surveyUnitData); MvcResult result = mockMvc.perform(multipart("/api/questionnaires/{poguesId}/checkdata", poguesId).file(surveyUnitMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isOk()) .andReturn(); @@ -155,6 +169,7 @@ void onCheckInCorrectCsvSchemaReturnGlobalErrorMessages() throws Exception { when(csvUseCase.validateSurveyUnits(surveyUnitData, poguesId)).thenThrow(surveyUnitsValidationException); MockMultipartFile surveyUnitMockPart = new MockMultipartFile("surveyUnitData", "file", MediaType.MULTIPART_FORM_DATA_VALUE, surveyUnitData); mockMvc.perform(multipart("/api/questionnaires/{poguesId}/checkdata", poguesId).file(surveyUnitMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isBadRequest()) .andReturn(); @@ -185,6 +200,7 @@ void onCheckInCorrectCsvSchemaReturnSpecificErrorMessages() throws Exception { when(csvUseCase.validateSurveyUnits(surveyUnitData, poguesId)).thenThrow(ex); MockMultipartFile surveyUnitMockPart = new MockMultipartFile("surveyUnitData", "file", MediaType.MULTIPART_FORM_DATA_VALUE, surveyUnitData); mockMvc.perform(multipart("/api/questionnaires/{poguesId}/checkdata", poguesId).file(surveyUnitMockPart) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.MULTIPART_FORM_DATA)) .andExpect(status().isBadRequest()) .andReturn(); @@ -199,6 +215,7 @@ void onResetSurveyUnitCallResetService() throws Exception { when(questionnaireUseCase.getSurveyUnitData(11L)).thenReturn(surveyUnitData); mockMvc.perform(put("/api/survey-units/{surveyUnitId}/reset", surveyUnitId) + .with(authentication(authenticatedUserTestHelper.getUser())) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn(); diff --git a/src/test/resources/application-test.yaml b/src/test/resources/application-test.yaml index 511fc1c..c6795c4 100644 --- a/src/test/resources/application-test.yaml +++ b/src/test/resources/application-test.yaml @@ -1,6 +1,7 @@ application: mode: handle-only-cawi: false + corsOrigins: '*' spring: datasource: driver-class-name: org.h2.Driver @@ -16,3 +17,9 @@ spring: enabled: true change-log: classpath:/db/changelog/test/init-schema-test.xml contexts: test + feature: + oidc: + enabled: false + swagger: + enabled: true +