#63 added security test to test the whitelisted endpoints

This commit is contained in:
Fabio Formosa
2022-10-01 15:48:01 +02:00
parent 727403d420
commit 44d6854bc5
2 changed files with 7 additions and 10 deletions

View File

@@ -2,6 +2,8 @@ package it.fabioformosa.quartzmanager.security;
import it.fabioformosa.quartzmanager.security.controllers.TestController;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
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.context.SpringBootTest;
@@ -45,10 +47,11 @@ public class SecurityControllerTest {
.andExpect(status().isUnauthorized());
}
@Test
void givenAnAnonymousUser_whenRequestedSwaggerResource_thenShouldReturn2xx() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/swagger-ui.html"))
.andExpect(status().isOk());
@ParameterizedTest
@ValueSource(strings = {"/swagger-ui.html", "/v3/api-docs/**", "/swagger-resources/**", "/webjars/**"})
void givenAnAnonymousUser_whenRequestedAnEndpointInWhitelist_thenShouldnotReturnForbidden(String whitelistEndpoint) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(whitelistEndpoint))
.andExpect(status().isNotFound());
}
@Test

View File

@@ -18,12 +18,6 @@ public class TestController {
}
@ResponseStatus(HttpStatus.OK)
@GetMapping("/swagger-ui.html")
public void getSwaggerUI(){
}
@ResponseStatus(HttpStatus.OK)
@GetMapping(QUARTZ_MANAGER + "/scheduler")
public void getQuartzManagerScheduler(){