diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 55a042f05..9182cd0d1 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -2451,109 +2451,6 @@ } } }, - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "text/html" : { - "schema" : { - "type" : "string" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "401" : { - "description" : "Unauthorized", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "500" : { - "description" : "Internal Server Error", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/v1/support/request" : { - "post" : { - "tags" : [ "support" ], - "summary" : "getSupportRedirectUrl", - "description" : "Service to retrieve Support contact's form", - "operationId" : "getSupportRedirectUrlUsingPOST", - "parameters" : [ { - "name" : "authenticated", - "in" : "query", - "required" : false, - "style" : "form", - "schema" : { - "type" : "boolean" - } - }, { - "name" : "authorities[0].authority", - "in" : "query", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - }, { - "name" : "credentials", - "in" : "query", - "required" : false, - "style" : "form", - "schema" : { - "type" : "object" - } - }, { - "name" : "details", - "in" : "query", - "required" : false, - "style" : "form", - "schema" : { - "type" : "object" - } - }, { - "name" : "principal", - "in" : "query", - "required" : false, - "style" : "form", - "schema" : { - "type" : "object" - } - } ], - "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/SupportRequestDto" - } - } - } - }, "responses" : { "200" : { "description" : "OK", @@ -2596,7 +2493,6 @@ } } }, - "deprecated" : true, "security" : [ { "bearerAuth" : [ "global" ] } ] @@ -6394,6 +6290,12 @@ "title" : "SupportResponse", "type" : "object", "properties" : { + "actionUrl" : { + "type" : "string" + }, + "jwt" : { + "type" : "string" + }, "redirectUrl" : { "type" : "string" } diff --git a/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/support/SupportResponse.java b/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/support/SupportResponse.java index 0d56f39d3..c58d7a23b 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/support/SupportResponse.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/support/SupportResponse.java @@ -1,13 +1,13 @@ package it.pagopa.selfcare.dashboard.connector.model.support; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; @Data @Builder +@ToString @NoArgsConstructor @AllArgsConstructor public class SupportResponse { private String redirectUrl; + private String jwt; + private String actionUrl; } diff --git a/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportService.java b/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportService.java index ddcd5f0fb..78f5a98a2 100644 --- a/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportService.java +++ b/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportService.java @@ -1,8 +1,8 @@ package it.pagopa.selfcare.dashboard.core; import it.pagopa.selfcare.dashboard.connector.model.support.SupportRequest; +import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse; public interface SupportService { - String sendRequest(SupportRequest supportRequest); - String getSupportRequest(SupportRequest supportRequest); + SupportResponse sendRequest(SupportRequest supportRequest); } diff --git a/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportServiceImpl.java index f40810a6f..0112e92ed 100644 --- a/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/dashboard/core/SupportServiceImpl.java @@ -1,25 +1,23 @@ package it.pagopa.selfcare.dashboard.core; -import freemarker.template.Template; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import it.pagopa.selfcare.dashboard.connector.api.UserRegistryConnector; import it.pagopa.selfcare.dashboard.connector.exception.ResourceNotFoundException; import it.pagopa.selfcare.dashboard.connector.exception.SupportException; import it.pagopa.selfcare.dashboard.connector.model.support.SupportRequest; +import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse; import it.pagopa.selfcare.dashboard.connector.model.support.UserField; import it.pagopa.selfcare.dashboard.connector.model.user.User; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; import org.springframework.util.StringUtils; -import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.Date; +import java.util.EnumSet; +import java.util.Objects; +import java.util.UUID; import static it.pagopa.selfcare.dashboard.connector.model.user.User.Fields.*; @@ -32,26 +30,22 @@ public class SupportServiceImpl implements SupportService { private final String returnTo; private final String actionUrl; private final UserRegistryConnector userRegistryConnector; - @Qualifier("zendeskFreeMarker") - private final FreeMarkerConfigurer freeMarkerConfigurer; private static final EnumSet USER_FIELD_LIST = EnumSet.of(name, familyName, fiscalCode); public SupportServiceImpl(@Value("${support.api.key}") String supportApiKey, @Value("${support.api.zendesk.redirectUri}") String returnTo, @Value("${support.api.zendesk.organization}") String zendeskOrganization, @Value("${support.api.zendesk.actionUri}") String redirectUrl, - FreeMarkerConfigurer freeMarkerConfigurer, UserRegistryConnector userRegistryConnector) { this.supportApiKey = supportApiKey; this.returnTo = returnTo; this.zendeskOrganization = zendeskOrganization; this.actionUrl = redirectUrl; - this.freeMarkerConfigurer = freeMarkerConfigurer; this.userRegistryConnector = userRegistryConnector; } @Override - public String sendRequest(SupportRequest supportRequest) { + public SupportResponse sendRequest(SupportRequest supportRequest) { log.trace("sendRequest start"); log.debug("sendRequest request = {}", supportRequest); @@ -67,43 +61,16 @@ public String sendRequest(SupportRequest supportRequest) { } //Retrieve parameters for submitting form - String redirectUrl = getRedirectUrl(supportRequest); - String jwtString = getJWTString(supportRequest); - - String html; - try { - Map map = Map.of( - "jwt", jwtString, - "returnTo", redirectUrl, - "action", actionUrl - ); - Template freemarkerTemplate = freeMarkerConfigurer.getConfiguration() - .getTemplate("/template-zendesk-form.ftl"); - html = FreeMarkerTemplateUtils.processTemplateIntoString(freemarkerTemplate, map); - } catch (Exception e){ - String errorMessage = "Impossible to retrieve zendesk form template"; - log.error(errorMessage); - throw new SupportException(errorMessage, e); - } - - log.trace("sendRequest end"); - return html; - } - - @Override - public String getSupportRequest(SupportRequest supportRequest) { - log.trace("sendRequest start"); - log.debug("sendRequest request = {}", supportRequest); + final String redirectUrl = getRedirectUrl(supportRequest); final String jwtString = getJWTString(supportRequest); - final String redirectUrl = "https://pagopa.zendesk.com/access/jwt?jwt=" + jwtString; - log.debug("sendRequest result = {}", redirectUrl); - log.trace("sendRequest end"); - String returnUrl = StringUtils.hasText(supportRequest.getProductId()) ? - URLEncoder.encode(returnTo.concat("?product=" + supportRequest.getProductId()), StandardCharsets.UTF_8) : - URLEncoder.encode(returnTo, StandardCharsets.UTF_8); + log.trace("sendRequest end"); - return redirectUrl.concat("&return_to=" + returnUrl); + return SupportResponse.builder() + .jwt(jwtString) + .redirectUrl(redirectUrl) + .actionUrl(actionUrl) + .build(); } private String getJWTString(SupportRequest supportRequest) { @@ -133,7 +100,7 @@ private String getRedirectUrl(SupportRequest supportRequest) { if(Objects.nonNull(supportRequest.getInstitutionId())) { urlBuilder.append(urlBuilder.indexOf("?") != -1 ? "&institution=" + supportRequest.getInstitutionId() - : "?product=" + supportRequest.getInstitutionId()); + : "?institution=" + supportRequest.getInstitutionId()); } return urlBuilder.toString(); } diff --git a/core/src/main/java/it/pagopa/selfcare/dashboard/core/config/CoreConfig.java b/core/src/main/java/it/pagopa/selfcare/dashboard/core/config/CoreConfig.java index ebd093fa1..8bcc119ad 100644 --- a/core/src/main/java/it/pagopa/selfcare/dashboard/core/config/CoreConfig.java +++ b/core/src/main/java/it/pagopa/selfcare/dashboard/core/config/CoreConfig.java @@ -1,13 +1,10 @@ package it.pagopa.selfcare.dashboard.core.config; -import freemarker.cache.ClassTemplateLoader; -import freemarker.cache.TemplateLoader; import freemarker.template.TemplateException; import lombok.extern.slf4j.Slf4j; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; @@ -19,7 +16,6 @@ import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor; -import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import java.net.URL; import java.util.Properties; @@ -33,14 +29,12 @@ class CoreConfig implements AsyncConfigurer { private final URL rootTemplateUrl; - @Autowired public CoreConfig(@Value("${dashboard.notification.template.default-url}") URL rootTemplateUrl) { log.trace("Initializing {}", CoreConfig.class.getSimpleName()); this.rootTemplateUrl = rootTemplateUrl; } - @Bean public freemarker.template.Configuration customFreeMarkerConfiguration() throws TemplateException { Properties settings = new Properties(); @@ -52,29 +46,16 @@ public freemarker.template.Configuration customFreeMarkerConfiguration() throws return configuration; } - @Bean("zendeskFreeMarker") - public FreeMarkerConfigurer freemarkerClassLoaderConfig() { - freemarker.template.Configuration configuration = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_27); - TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), "/template-zendesk"); - configuration.setTemplateLoader(templateLoader); - FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); - freeMarkerConfigurer.setConfiguration(configuration); - return freeMarkerConfigurer; - } - - @Bean public SimpleAsyncUncaughtExceptionHandler simpleAsyncUncaughtExceptionHandler() { return new SimpleAsyncUncaughtExceptionHandler(); } - @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return simpleAsyncUncaughtExceptionHandler(); } - @Bean public DelegatingSecurityContextAsyncTaskExecutor taskExecutor(TaskExecutorBuilder taskExecutorBuilder) { final ThreadPoolTaskExecutor delegate = taskExecutorBuilder.build(); diff --git a/core/src/main/resources/template-zendesk/template-zendesk-form.ftl b/core/src/main/resources/template-zendesk/template-zendesk-form.ftl deleted file mode 100644 index 7664a986b..000000000 --- a/core/src/main/resources/template-zendesk/template-zendesk-form.ftl +++ /dev/null @@ -1,10 +0,0 @@ - - - -
- - -
- - - \ No newline at end of file diff --git a/core/src/test/java/it/pagopa/selfcare/dashboard/core/SupportServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/dashboard/core/SupportServiceImplTest.java index d22c5b67a..7d69d46f7 100644 --- a/core/src/test/java/it/pagopa/selfcare/dashboard/core/SupportServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/dashboard/core/SupportServiceImplTest.java @@ -1,11 +1,10 @@ package it.pagopa.selfcare.dashboard.core; -import freemarker.cache.ClassTemplateLoader; -import freemarker.cache.TemplateLoader; import it.pagopa.selfcare.dashboard.connector.api.UserRegistryConnector; import it.pagopa.selfcare.dashboard.connector.exception.ResourceNotFoundException; import it.pagopa.selfcare.dashboard.connector.exception.SupportException; import it.pagopa.selfcare.dashboard.connector.model.support.SupportRequest; +import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse; import it.pagopa.selfcare.dashboard.connector.model.support.UserField; import it.pagopa.selfcare.dashboard.connector.model.user.CertifiedField; import it.pagopa.selfcare.dashboard.connector.model.user.User; @@ -14,9 +13,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.function.Executable; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; @@ -34,12 +31,12 @@ class SupportServiceImplTest { */ @Test void testSendRequest(){ - FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig(); - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, null); - String url = supportServiceImpl.sendRequest(this.dummySupportRequest()); - assertNotNull(url); - assertTrue(url.contains("jwt")); - assertEquals("", url.substring(0, 6)); + SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "http://www.test.it", "test-organization", "redirectUrl", null); + SupportResponse response = supportServiceImpl.sendRequest(this.dummySupportRequest()); + assertNotNull(response); + assertNotNull(response.getJwt()); + assertNotNull(response.getRedirectUrl()); + assertEquals("http", response.getRedirectUrl().substring(0, 4)); } /** @@ -47,8 +44,7 @@ void testSendRequest(){ */ @Test void testSendRequestWithUserId(){ - FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig(); - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, userRegistryConnector); + SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "http://www.test.it", "test-organization", "redirectUrl", userRegistryConnector); SupportRequest supportRequest = this.dummySupportRequest(); supportRequest.setUserId("userId"); supportRequest.setInstitutionId("institutionId"); @@ -59,10 +55,11 @@ void testSendRequestWithUserId(){ user.setName(certifiedField); user.setFamilyName(certifiedField); when(userRegistryConnector.getUserByInternalId(anyString(), any())).thenReturn(user); - String url = supportServiceImpl.sendRequest(supportRequest); - assertNotNull(url); - assertTrue(url.contains("jwt")); - assertEquals("", url.substring(0, 6)); + SupportResponse response = supportServiceImpl.sendRequest(supportRequest); + assertNotNull(response); + assertNotNull(response.getJwt()); + assertNotNull(response.getRedirectUrl()); + assertEquals("http", response.getRedirectUrl().substring(0, 4)); } /** @@ -70,8 +67,7 @@ void testSendRequestWithUserId(){ */ @Test void testSendRequestUserNotFound(){ - FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig(); - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, null); + SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", null); SupportRequest supportRequest = this.dummySupportRequest(); supportRequest.setUserId("null"); Executable executable = () -> supportServiceImpl.sendRequest(supportRequest); @@ -80,31 +76,20 @@ void testSendRequestUserNotFound(){ Assertions.assertEquals("User with id null not found", e.getMessage()); } - /** - * Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)} - */ - @Test - void testSendRequestThrowException() { - FreeMarkerConfigurer freeMarkerConfigurer = Mockito.mock(FreeMarkerConfigurer.class); - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "test-organization", "redirectUrl", freeMarkerConfigurer, null); - Exception exception = assertThrows(Exception.class, () -> supportServiceImpl.sendRequest(this.dummySupportRequest())); - assertEquals("Impossible to retrieve zendesk form template", exception.getMessage()); - } - /** * Method under test: {@link SupportServiceImpl#sendRequest(SupportRequest)} */ @Test void testSendRequestWithProductId() { - FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig(); - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "", "redirectUrl", freeMarkerConfigurer, null); + SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "http://www.test.it", "", "redirectUrl", null); SupportRequest supportRequest = this.dummySupportRequest(); supportRequest.setProductId("prodottoDiTest"); - String url = supportServiceImpl.sendRequest(supportRequest); - assertNotNull(url); - assertTrue(url.contains("jwt")); - assertTrue(url.contains(supportRequest.getProductId())); - assertEquals("", url.substring(0, 6)); + SupportResponse response = supportServiceImpl.sendRequest(supportRequest); + assertNotNull(response); + assertNotNull(response.getJwt()); + assertNotNull(response.getRedirectUrl()); + assertEquals("http", response.getRedirectUrl().substring(0, 4)); + assertTrue(response.getRedirectUrl().contains(supportRequest.getProductId())); } /** @@ -112,26 +97,10 @@ void testSendRequestWithProductId() { */ @Test void testRequestWithMalformedEmptyKey() { - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("", "", "test", "redirectUrl", null, null); + SupportServiceImpl supportServiceImpl = new SupportServiceImpl("", "", "test", "redirectUrl", null); SupportException exception = assertThrows(SupportException.class, () -> supportServiceImpl.sendRequest(this.dummySupportRequest())); assertEquals("secret key byte array cannot be null or empty.", exception.getMessage()); } - - /** - * Method under test: {@link SupportServiceImpl#getSupportRequest(SupportRequest)} - */ - @Test - void testGetRequestUrlWithProductId() { - FreeMarkerConfigurer freeMarkerConfigurer = freemarkerClassLoaderConfig(); - SupportServiceImpl supportServiceImpl = new SupportServiceImpl("w90kAW1FIIJaMuWbKGyd8GfDkv45tVPiyYvrdLADsK2ANX26", "", "", "redirectUrl", freeMarkerConfigurer, null); - SupportRequest supportRequest = this.dummySupportRequest(); - supportRequest.setProductId("prodottoDiTest"); - String url = supportServiceImpl.getSupportRequest(supportRequest); - assertNotNull(url); - assertTrue(url.contains("jwt")); - assertTrue(url.contains(supportRequest.getProductId())); - assertEquals("http", url.substring(0, 4)); - } private SupportRequest dummySupportRequest() { SupportRequest supportRequest = new SupportRequest(); @@ -142,12 +111,5 @@ private SupportRequest dummySupportRequest() { supportRequest.setUserFields(userField); return supportRequest; } - private FreeMarkerConfigurer freemarkerClassLoaderConfig() { - freemarker.template.Configuration configuration = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_27); - TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), "/template-zendesk"); - configuration.setTemplateLoader(templateLoader); - FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); - freeMarkerConfigurer.setConfiguration(configuration); - return freeMarkerConfigurer; - } + } diff --git a/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/SupportController.java b/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/SupportController.java index 4f01f3097..ccec9ddae 100644 --- a/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/SupportController.java +++ b/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/SupportController.java @@ -4,7 +4,6 @@ import io.swagger.annotations.ApiOperation; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; -import it.pagopa.selfcare.commons.base.logging.LogUtils; import it.pagopa.selfcare.commons.base.security.SelfCareUser; import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse; import it.pagopa.selfcare.dashboard.core.SupportService; @@ -34,32 +33,17 @@ public SupportController(SupportService supportService, } @Tags({@Tag(name = "external-v2"), @Tag(name = "support")}) - @PostMapping(produces = MediaType.TEXT_HTML_VALUE) + @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.OK) @ApiOperation(value = "", notes = "${swagger.dashboard.support.api.sendRequest}") - public String sendSupportRequest(@RequestBody @Valid SupportRequestDto supportRequestDto, + public SupportResponse sendSupportRequest(@RequestBody @Valid SupportRequestDto supportRequestDto, Authentication authentication) { log.trace("sendSupportRequest start"); - log.debug(LogUtils.CONFIDENTIAL_MARKER, "sendSupportRequest request = {}", supportRequestDto); final SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal(); - String url = supportService.sendRequest(supportMapper.toZendeskRequest(supportRequestDto, selfCareUser)); - log.debug("sendSupportRequest result = {}", url); + final SupportResponse supportResponse = supportService.sendRequest(supportMapper.toZendeskRequest(supportRequestDto, selfCareUser)); + log.debug("sendSupportRequest result = {}", supportResponse.toString()); log.trace("sendSupportRequest end"); - return url; + return supportResponse; } - @Deprecated - @PostMapping(value = "/request", produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseStatus(HttpStatus.OK) - @ApiOperation(value = "", notes = "${swagger.dashboard.support.api.sendRequest}") - public SupportResponse getSupportRedirectUrl(@RequestBody @Valid SupportRequestDto supportRequestDto, - Authentication authentication) { - log.trace("sendSupportRequest start"); - log.debug(LogUtils.CONFIDENTIAL_MARKER, "sendSupportRequest request = {}", supportRequestDto); - final SelfCareUser selfCareUser = (SelfCareUser) authentication.getPrincipal(); - final String url = supportService.getSupportRequest(supportMapper.toZendeskRequest(supportRequestDto, selfCareUser)); - log.debug("sendSupportRequest result = {}", url); - log.trace("sendSupportRequest end"); - return SupportResponse.builder().redirectUrl(url).build(); - } } diff --git a/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/SupportControllerTest.java b/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/SupportControllerTest.java index a1598fa20..d2549dce9 100644 --- a/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/SupportControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/SupportControllerTest.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.pagopa.selfcare.commons.base.security.SelfCareUser; +import it.pagopa.selfcare.dashboard.connector.model.support.SupportResponse; import it.pagopa.selfcare.dashboard.core.SupportService; import it.pagopa.selfcare.dashboard.web.model.delegation.DelegationRequestDto; import it.pagopa.selfcare.dashboard.web.model.mapper.SupportMapper; @@ -60,12 +61,15 @@ class SupportControllerTest { @Test void testSendSupportRequest() throws Exception { - String redirectUrl = "test"; + final String redirectUrl = "test"; + final SupportResponse supportResponse = SupportResponse.builder() + .redirectUrl(redirectUrl) + .build(); Authentication authentication = Mockito.mock(Authentication.class); SecurityContext securityContext = Mockito.mock(SecurityContext.class); SecurityContextHolder.setContext(securityContext); when(authentication.getPrincipal()).thenReturn(user); - when(supportService.sendRequest(any())).thenReturn(redirectUrl); + when(supportService.sendRequest(any())).thenReturn(supportResponse); SupportRequestDto supportRequest = new SupportRequestDto(); supportRequest.setEmail("test@gmail.com"); @@ -86,38 +90,6 @@ void testSendSupportRequest() throws Exception { } - /** - * Method under test: {@link SupportController#getSupportRedirectUrl(SupportRequestDto, Authentication)} - */ - @Test - void testSupportRedirectUrl() throws Exception { - - String redirectUrl = "test"; - Authentication authentication = Mockito.mock(Authentication.class); - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - SecurityContextHolder.setContext(securityContext); - when(authentication.getPrincipal()).thenReturn(user); - when(supportService.getSupportRequest(any())).thenReturn(redirectUrl); - - SupportRequestDto supportRequest = new SupportRequestDto(); - supportRequest.setEmail("test@gmail.com"); - String content = (new ObjectMapper()).writeValueAsString(supportRequest); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders - .post("/v1/support/request") - .principal(authentication) - .contentType(MediaType.APPLICATION_JSON) - .content(content); - MvcResult result = MockMvcBuilders.standaloneSetup(supportController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andReturn(); - - String response = result.getResponse().getContentAsString(); - assertNotNull(response); - - } - /** * Method under test: {@link DelegationController#createDelegation(DelegationRequestDto)} */