2222import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
2323import org .springframework .boot .test .context .SpringBootTest ;
2424import org .springframework .data .mongodb .core .MongoTemplate ;
25+ import org .springframework .security .core .authority .SimpleGrantedAuthority ;
2526import org .springframework .security .oauth2 .jwt .Jwt ;
2627import org .springframework .security .oauth2 .jwt .JwtDecoder ;
2728import org .springframework .test .context .ActiveProfiles ;
3738import static org .mockito .ArgumentMatchers .anyString ;
3839import static org .mockito .Mockito .doNothing ;
3940import static org .mockito .Mockito .when ;
41+ import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .jwt ;
4042import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
4143import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
4244import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
@@ -114,6 +116,17 @@ void admin_should_access_reader_allowed_services(String endpointURI) throws Exce
114116 .andExpect (status ().is (oneOf (200 ,404 )));
115117 }
116118
119+ @ Test
120+ @ DisplayName ("Reader should access schedule/all endpoint" )
121+ void reader_should_access_schedules_services () throws Exception {
122+ mockMvc .perform (
123+ get ("/schedule/all" ).with (jwt ()
124+ .authorities (new SimpleGrantedAuthority ("ROLE_READER" )))
125+ )
126+ .andExpect (status ().is (oneOf (200 ,404 )));
127+ }
128+
129+
117130 /**
118131 * Tests that users with the "USER_KRAFTWERK" role can access read-only endpoints.
119132 */
@@ -166,17 +179,7 @@ void invalid_user_should_not_access_reader_allowed_services(String endpointURI)
166179 .andExpect (status ().isForbidden ());
167180 }
168181
169- /**
170- * Test that reader can access the schedule/all endpoint.
171- */
172- @ Test
173- @ DisplayName ("Reader should access schedule/all endpoint" )
174- void reader_should_access_schedules_services () throws Exception {
175- Jwt jwt = generateJwt (List .of ("lecteur_traiter" ), READER );
176- when (jwtDecoder .decode (anyString ())).thenReturn (jwt );
177- mockMvc .perform (get ("/schedule/all" ).header ("Authorization" , "bearer token_blabla" ))
178- .andExpect (status ().is (oneOf (200 ,404 )));
179- }
182+
180183
181184 /**
182185 * Test that reader can not access other schedule endpoints.
@@ -203,6 +206,8 @@ void kraftwerk_users_should_not_access_schedules_services() throws Exception{
203206 .andExpect (status ().is (oneOf (200 ,404 )));
204207 }
205208
209+
210+
206211 /**
207212 * Test that admins can access the schedule endpoints.
208213 */
0 commit comments