diff --git a/src/main/java/it/gov/pagopa/payhub/auth/controller/AuthController.java b/src/main/java/it/gov/pagopa/payhub/auth/controller/AuthController.java index 39f31bf1..a201c68b 100644 --- a/src/main/java/it/gov/pagopa/payhub/auth/controller/AuthController.java +++ b/src/main/java/it/gov/pagopa/payhub/auth/controller/AuthController.java @@ -7,7 +7,7 @@ @RequestMapping("/payhub") interface AuthController { - @PostMapping("/auth") + @GetMapping("/auth") @ResponseStatus(code = HttpStatus.OK) void authToken(@RequestParam String token); } \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthControllerTest.java b/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthControllerTest.java index 629cc367..e57d724e 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthControllerTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthControllerTest.java @@ -17,9 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(AuthControllerImpl.class) @@ -35,11 +33,11 @@ class AuthControllerTest { AuthService authServiceMock; @Test - void authToken() throws Exception { + void authTokenOk() throws Exception { doNothing().when(authServiceMock).authToken("token"); MvcResult result = mockMvc.perform( - post("/payhub/auth") + get("/payhub/auth") .param("token", "token") ).andExpect(status().is2xxSuccessful()).andReturn(); @@ -47,11 +45,11 @@ void authToken() throws Exception { } @Test - void authToken1() throws Exception { + void authTokenThrowMissingServletRequestParameterException() throws Exception { doNothing().when(authServiceMock).authToken("token"); MvcResult result = mockMvc.perform( - post("/payhub/auth") + get("/payhub/auth") ).andExpect(status().isBadRequest()).andReturn(); ErrorDTO actual = objectMapper.readValue(result.getResponse().getContentAsString(), diff --git a/src/test/java/it/gov/pagopa/payhub/auth/service/AuthServiceTest.java b/src/test/java/it/gov/pagopa/payhub/auth/service/AuthServiceTest.java index 412e3dce..eaa82da5 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/service/AuthServiceTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/service/AuthServiceTest.java @@ -50,7 +50,7 @@ void clean(){ wireMockServer.stop(); } @Test - void authToken() throws Exception { + void authTokenOk() throws Exception { String token = utils.generateJWK(EXPIRES_AT); Map claimsMap = createJWKClaims(ISS, AUD); diff --git a/src/test/java/it/gov/pagopa/payhub/auth/utils/JWTValidatorTest.java b/src/test/java/it/gov/pagopa/payhub/auth/utils/JWTValidatorTest.java index ef4c35f5..6351fc64 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/utils/JWTValidatorTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/utils/JWTValidatorTest.java @@ -37,7 +37,7 @@ void clean(){ } @Test - void validateToken() throws Exception { + void givenValidTokenThenSuccess() throws Exception { String token = utils.generateJWK(new Date(System.currentTimeMillis() + 3600000)); String urlJwkProvider = utils.getUrlJwkProvider(); @@ -48,7 +48,7 @@ void validateToken() throws Exception { } @Test - void validate_ExpiredToken_ThrowsTokenExpiredException() throws Exception { + void givenTokenThenThrowTokenExpiredException() throws Exception { String expiredToken = utils.generateJWK(new Date(System.currentTimeMillis() - 3600000)); String urlJwkProvider = utils.getUrlJwkProvider(); @@ -56,7 +56,7 @@ void validate_ExpiredToken_ThrowsTokenExpiredException() throws Exception { } @Test - void validate_InvalidToken_ThrowsInvalidTokenException() { + void givenTokenThenThrowInvalidTokenException() { String invalidToken = "your_invalid_token_here"; String urlJwkProvider = "your_jwk_provider_url_here";