33import fr .insee .genesis .domain .ports .api .ScheduleApiPort ;
44import fr .insee .genesis .domain .ports .api .SurveyUnitApiPort ;
55import fr .insee .genesis .infrastructure .repository .LunaticJsonMongoDBRepository ;
6- import fr .insee .genesis .infrastructure .repository .LunaticXmlMongoDBRepository ;
76import fr .insee .genesis .infrastructure .repository .RundeckExecutionDBRepository ;
87import fr .insee .genesis .infrastructure .repository .ScheduleMongoDBRepository ;
98import fr .insee .genesis .infrastructure .repository .SurveyUnitMongoDBRepository ;
1211import org .junit .jupiter .params .ParameterizedTest ;
1312import org .junit .jupiter .params .provider .Arguments ;
1413import org .junit .jupiter .params .provider .MethodSource ;
15- import org .mockito .MockedStatic ;
1614import org .springframework .beans .factory .annotation .Autowired ;
1715import org .springframework .beans .factory .annotation .Value ;
1816import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
2119import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
2220import org .springframework .boot .test .context .SpringBootTest ;
2321import org .springframework .data .mongodb .core .MongoTemplate ;
24- import org .springframework .http .MediaType ;
2522import org .springframework .security .oauth2 .jwt .Jwt ;
2623import org .springframework .security .oauth2 .jwt .JwtDecoder ;
27- import org .springframework .security .test .context .support .WithMockUser ;
2824import org .springframework .test .context .ActiveProfiles ;
2925import org .springframework .test .context .bean .override .mockito .MockitoBean ;
3026import org .springframework .test .web .servlet .MockMvc ;
3430import java .util .Map ;
3531import java .util .stream .Stream ;
3632
37- import static org .mockito .ArgumentMatchers .any ;
38- import static org .mockito .ArgumentMatchers .anyInt ;
3933import static org .mockito .ArgumentMatchers .anyString ;
4034import static org .mockito .Mockito .doNothing ;
41- import static org .mockito .Mockito .mockStatic ;
4235import static org .mockito .Mockito .when ;
43- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .put ;
44- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
4536import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
37+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
4638import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
4739
4840@ SpringBootTest
5143@ EnableAutoConfiguration (exclude = {MongoAutoConfiguration .class , MongoDataAutoConfiguration .class })
5244class ControllerAccessTest {
5345
54- // JWT claim properties loaded from application properties
46+ /* // JWT claim properties loaded from application properties
5547 @Value("${fr.insee.genesis.security.token.oidc-claim-role}")
5648 private String claimRoleDotRoles;
5749 @Value("${fr.insee.genesis.security.token.oidc-claim-username}")
@@ -72,8 +64,6 @@ class ControllerAccessTest {
7264 @MockitoBean
7365 private LunaticJsonMongoDBRepository lunaticJsonMongoDBRepository;
7466 @MockitoBean
75- private LunaticXmlMongoDBRepository lunaticXmlMongoDBRepository ;
76- @ MockitoBean
7767 private RundeckExecutionDBRepository rundeckExecutionDBRepository;
7868 @MockitoBean
7969 private ScheduleMongoDBRepository scheduleMongoDBRepository;
@@ -85,9 +75,9 @@ class ControllerAccessTest {
8575 private static final String ADMIN = "ADMIN";
8676 private static final String READER = "READER";
8777
88- /**
78+ */ /**
8979 * Provides a stream of URIs that are allowed for reader.
90- */
80+ */ /*
9181 private static Stream<Arguments> endpointsReader(){
9282 return Stream.of(
9383 Arguments.of("/questionnaires/with-campaigns"),
@@ -101,9 +91,9 @@ private static Stream<Arguments> endpointsReader(){
10191 );
10292 }
10393
104- /**
94+ */ /**
10595 * Tests that users with the "ADMIN" role can access read-only endpoints.
106- */
96+ */ /*
10797 @ParameterizedTest
10898 @MethodSource("endpointsReader")
10999 @DisplayName("Admins should access reader-allowed services")
@@ -114,9 +104,9 @@ void admin_should_access_reader_allowed_services(String endpointURI) throws Exce
114104 .andExpect(status().isOk());
115105 }
116106
117- /**
107+ */ /**
118108 * Tests that users with the "USER_KRAFTWERK" role can access read-only endpoints.
119- */
109+ */ /*
120110 @ParameterizedTest
121111 @MethodSource("endpointsReader")
122112 @DisplayName("Kraftwerk users should access reader-allowed services")
@@ -127,9 +117,9 @@ void kraftwerk_users_should_access_reader_allowed_services(String endpointURI) t
127117 .andExpect(status().isOk());
128118 }
129119
130- /**
120+ */ /**
131121 * Tests that users with the "USER_PLATINE" role can access read-only endpoints.
132- */
122+ */ /*
133123 @ParameterizedTest
134124 @MethodSource("endpointsReader")
135125 @DisplayName("Platine users should access reader-allowed services")
@@ -140,9 +130,9 @@ void platine_users_should_access_reader_allowed_services(String endpointURI) thr
140130 .andExpect(status().isOk());
141131 }
142132
143- /**
133+ */ /**
144134 * Tests that users with the "READER" role can access read-only endpoints.
145- */
135+ */ /*
146136 @ParameterizedTest
147137 @MethodSource("endpointsReader")
148138 @DisplayName("Readers should access reader-allowed services")
@@ -153,9 +143,9 @@ void reader_should_access_reader_allowed_services(String endpointURI) throws Exc
153143 .andExpect(status().isOk());
154144 }
155145
156- /**
146+ */ /**
157147 * Tests that users with invalid role are denied.
158- */
148+ */ /*
159149 @ParameterizedTest
160150 @MethodSource("endpointsReader")
161151 @DisplayName("User with invalid roles should not access reader-allowed services")
@@ -166,9 +156,9 @@ void invalid_user_should_not_access_reader_allowed_services(String endpointURI)
166156 .andExpect(status().isForbidden());
167157 }
168158
169- /**
159+ */ /**
170160 * Test that reader can access the schedule/all endpoint.
171- */
161+ */ /*
172162 @Test
173163 @DisplayName("Reader should access schedule/all endpoint")
174164 void reader_should_access_schedules_services() throws Exception{
@@ -178,9 +168,9 @@ void reader_should_access_schedules_services() throws Exception{
178168 .andExpect(status().isOk());
179169 }
180170
181- /**
171+ */ /**
182172 * Test that reader can not access other schedule endpoints.
183- */
173+ */ /*
184174 @Test
185175 @DisplayName("Reader should not access other schedule endpoints")
186176 void reader_should_not_access_other_schedules_services() throws Exception{
@@ -191,9 +181,9 @@ void reader_should_not_access_other_schedules_services() throws Exception{
191181 .andExpect(status().isForbidden());
192182 }
193183
194- /**
184+ */ /**
195185 * Test that kraftwerk users can't access the schedule endpoints.
196- */
186+ */ /*
197187 @Test
198188 @DisplayName("Kraftwerk users should access schedules service")
199189 void kraftwerk_users_should_not_access_schedules_services() throws Exception{
@@ -203,9 +193,9 @@ void kraftwerk_users_should_not_access_schedules_services() throws Exception{
203193 .andExpect(status().isOk());
204194 }
205195
206- /**
196+ */ /**
207197 * Test that admins can access the schedule endpoints.
208- */
198+ */ /*
209199 @Test
210200 @DisplayName("Admins should access schedules service")
211201 void admins_should_access_schedules_services() throws Exception{
@@ -215,25 +205,25 @@ void admins_should_access_schedules_services() throws Exception{
215205 .andExpect(status().isOk());
216206 }
217207
218- /**
208+ */ /**
219209 * Test that invalid roles can't access the schedule endpoints.
220- */
210+ */ /*
221211 @Test
222212 @DisplayName("Invalid roles should not access schedules service")
223213 void invalid_roles_should_access_schedules_services() throws Exception{
224214 Jwt jwt = generateJwt(List.of("invalid_role"), "invalid_role");
225215 when(jwtDecoder.decode(anyString())).thenReturn(jwt);
226216 mockMvc.perform(get("/schedule/all").header("Authorization", "bearer token_blabla"))
227217 .andExpect(status().isForbidden());
228- }
218+ }*/
229219
230- /**
220+ /* */ /**
231221 * Generates a mock JWT token with specified roles and username.
232222 *
233223 * @param roles List of roles assigned to the user.
234224 * @param name Username for the JWT.
235225 * @return A mock Jwt object.
236- */
226+ */ /*
237227 public Jwt generateJwt(List<String> roles, String name) {
238228 Date issuedAt = new Date();
239229 Date expiresAT = Date.from((new Date()).toInstant().plusSeconds(100));
@@ -245,6 +235,6 @@ public Jwt generateJwt(List<String> roles, String name) {
245235 claimName, name
246236 )
247237 );
248- }
238+ }*/
249239
250240}
0 commit comments