diff --git a/api/uploadservice.yaml b/api/uploadservice.yaml index 9142714..a80d69f 100644 --- a/api/uploadservice.yaml +++ b/api/uploadservice.yaml @@ -105,82 +105,6 @@ paths: description: INTERNAL SERVER ERROR - server encountered unexpected condition security: - Bearer: [] - /uploads/feedback/new/{feedbackRoomId}: - post: - tags: - - upload-controller - summary: 'Upload a file and send a message to to a Rocket.Chat feedback room - [Authorization: authority for feedback chat]' - operationId: uploadFileToFeedbackRoom - parameters: - - name: feedbackRoomId - in: path - description: Rocket.Chat room id - required: true - schema: - type: string - - name: RCToken - in: header - required: true - schema: - type: string - - name: RCUserId - in: header - required: true - schema: - type: string - requestBody: - content: - multipart/form-data: - schema: - required: - - file - - sendNotification - properties: - msg: - type: string - description: A text message - description: - type: string - description: A description of the file - tmId: - type: string - description: The thread message id (if you want upload a file to - a thread) - fileHeader: - type: string - description: Starting bytes of file which includes mimetype for verification - t: - type: string - description: Type of message - example: "e2e" - file: - type: string - description: File to upload - format: binary - sendNotification: - type: string - description: Flag, whether an email notification should be sent - or not (true/false) - required: true - responses: - 201: - description: CREATED - upload was successfully performed - 400: - description: BAD REQUEST - invalid/incomplete request or body object - 401: - description: UNAUTHORIZED - no/invalid Keycloak token - 403: - description: FORBIDDEN - no/invalid role/authorization - 413: - description: REQUEST ENTITY TOO LARGE - Maximum upload size exceeded - 415: - description: UNSUPPORTED MEDIA TYPE - Type of uploaded file is not allowed - 500: - description: INTERNAL SERVER ERROR - server encountered unexpected condition - security: - - Bearer: [] - components: schemas: MasterKeyDto: diff --git a/services/userservice.yaml b/services/userservice.yaml index e5f7c7b..f4e3b4f 100644 --- a/services/userservice.yaml +++ b/services/userservice.yaml @@ -538,33 +538,6 @@ paths: description: INTERNAL SERVER ERROR - server encountered unexpected condition security: - Bearer: [ ] - /users/mails/messages/feedback/new: - post: - tags: - - user-controller - summary: 'Sends a notification e-mail that a new feedback message/answer has - been written [Authorization: Role: consultant with authority for feedback - chat]' - operationId: sendNewFeedbackMessageNotification - requestBody: - content: - 'application/json': - schema: - $ref: '#/components/schemas/NewMessageNotificationDTO' - required: true - responses: - 200: - description: successful operation - 400: - description: BAD REQUEST - invalid/incomplete request or body object - 401: - description: UNAUTHORIZED - invalid token - 409: - description: CONFLICT - no user e-mail address in db given - 500: - description: INTERNAL SERVER ERROR - server encountered unexpected condition - security: - - Bearer: [ ] /users/consultants: get: tags: @@ -1180,10 +1153,6 @@ components: type: string example: xGklslk2JJKK description: Rocket.Chat room ID - feedbackGroupId: - type: string - example: 8ertjlasdKJA - description: Rocket.Chat feedback room ID askerRcId: type: string example: 8ertjlasdKJA @@ -1198,9 +1167,6 @@ components: messagesRead: type: boolean example: false - feedbackRead: - type: boolean - example: true isTeamSession: type: boolean example: false @@ -1231,35 +1197,11 @@ components: AliasMessageDTO: type: object properties: - forwardMessageDTO: - $ref: '#/components/schemas/ForwardMessageDTO' videoCallMessageDTO: $ref: '#/components/schemas/VideoCallMessageDTO' messageType: $ref: '#/components/schemas/MessageType' - ForwardMessageDTO: - type: object - required: - - message - - timestamp - - username - - rcUserId - properties: - message: - type: string - example: "Lorem ipsum dolor sit amet, consetetur..." - timestamp: - type: string - description: "Full qualified timestamp" - example: "2018-11-15T09:33:00.057Z" - username: - type: string - example: "asker23" - rcUserId: - type: string - example: "ag89h3tjkerg94t" - VideoCallMessageDTO: type: object required: @@ -1283,7 +1225,6 @@ components: enum: - "FURTHER_STEPS" - "UPDATE_SESSION_DATA" - - "FORWARD" - "VIDEOCALL" ConsultantSessionDTO: @@ -1312,10 +1253,6 @@ components: type: string example: xGklslk2JJKK description: Rocket.Chat room ID - feedbackGroupId: - type: string - example: 8ertjlasdKJA - description: Rocket.Chat feedback room ID consultantId: type: string example: 926b9777-4eef-443d-925a-4aa534797bd7 diff --git a/src/main/java/de/caritas/cob/uploadservice/api/authorization/Authority.java b/src/main/java/de/caritas/cob/uploadservice/api/authorization/Authority.java index ca48350..21d392a 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/authorization/Authority.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/authorization/Authority.java @@ -4,7 +4,6 @@ import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.CONSULTANT_DEFAULT; import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.TECHNICAL_DEFAULT; import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.USER_DEFAULT; -import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.USE_FEEDBACK; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -23,7 +22,6 @@ public enum Authority { USER(UserRole.USER, singletonList(USER_DEFAULT)), CONSULTANT(UserRole.CONSULTANT, singletonList(CONSULTANT_DEFAULT)), - U25_CONSULTANT(UserRole.PEER_CONSULTANT, singletonList(USE_FEEDBACK)), TECHNICAL(UserRole.TECHNICAL, singletonList(TECHNICAL_DEFAULT)), ANONYMOUS(UserRole.ANONYMOUS, singletonList(ANONYMOUS_DEFAULT)); @@ -54,7 +52,6 @@ private AuthorityValue() { public static final String CONSULTANT_DEFAULT = PREFIX + "CONSULTANT_DEFAULT"; public static final String USER_DEFAULT = PREFIX + "USER_DEFAULT"; - public static final String USE_FEEDBACK = PREFIX + "USE_FEEDBACK"; public static final String TECHNICAL_DEFAULT = PREFIX + "TECHNICAL_DEFAULT"; public static final String ANONYMOUS_DEFAULT = PREFIX + "ANONYMOUS_DEFAULT"; diff --git a/src/main/java/de/caritas/cob/uploadservice/api/authorization/UserRole.java b/src/main/java/de/caritas/cob/uploadservice/api/authorization/UserRole.java index c7d20f3..a505658 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/authorization/UserRole.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/authorization/UserRole.java @@ -11,7 +11,6 @@ public enum UserRole { USER("user"), CONSULTANT("consultant"), TECHNICAL("technical"), - PEER_CONSULTANT("peer-consultant"), ANONYMOUS("anonymous"); private final String value; diff --git a/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java b/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java index 4dd630c..0ebfd93 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java @@ -11,10 +11,7 @@ import de.caritas.cob.uploadservice.api.service.LogService; import de.caritas.cob.uploadservice.generated.api.controller.UploadsApi; import io.swagger.annotations.Api; -import java.util.Objects; import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -105,54 +102,4 @@ public ResponseEntity uploadFileToRoom( return new ResponseEntity<>(HttpStatus.CREATED); } - - /** - * Upload a file to a Rocket.Chat feedback room with a text message. - * - * @param feedbackRoomId Rocket.Chat feedback room id - * @param rcToken Rocket.Chat token - * @param rcUserId Rocket.Chat user id - * @param file The file object as {@link MultipartFile} - * @param sendNotification Flag, whether an email notification should be sent or not - * @param msg The message - * @param description The description - * @param tmId Rocket.Chat thread message id - * @return a ResponseEntity instance - */ - @TempCleanup - @Override - public ResponseEntity uploadFileToFeedbackRoom( - @PathVariable("feedbackRoomId") String feedbackRoomId, - @RequestHeader String rcToken, - @RequestHeader String rcUserId, - @RequestPart MultipartFile file, - @RequestParam String sendNotification, - @RequestPart(required = false) String t, - @RequestPart(required = false) String fileHeader, - @RequestParam(required = false) String msg, - @RequestParam(required = false) String description, - @RequestParam(required = false) String tmId) { - - RocketChatCredentials rocketChatCredentials = - RocketChatCredentials.builder().rocketChatUserId(rcUserId).rocketChatToken(rcToken).build(); - - RocketChatUploadParameter rocketChatUploadParameter = - RocketChatUploadParameter.builder() - .roomId(feedbackRoomId) - .description(description) - .message(msg) - .file(file) - .tmId(tmId) - .build(); - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, - rocketChatUploadParameter, - parseBoolean(sendNotification), - t, - fileHeader - ); - - return new ResponseEntity<>(HttpStatus.CREATED); - } } diff --git a/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java b/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java index 1528485..4b14564 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java @@ -20,9 +20,6 @@ public class EmailNotificationFacade { @Value("${user.service.api.new.message.notification}") private String userServiceApiSendNewMessageNotificationUrl; - @Value("${user.service.api.new.feedback.message.notification}") - private String userServiceApiSendNewFeedbackMessageNotificationUrl; - @Autowired public EmailNotificationFacade( EmailNotificationHelper emailNotificationHelper, AuthenticatedUser authenticatedUser) { @@ -42,16 +39,4 @@ public void sendEmailNotification(String rcGroupId) { authenticatedUser.getAccessToken(), Optional.ofNullable(TenantContext.getCurrentTenant())); } - - /** - * Sends a new feedback message notification via the UserService (user data needed for sending the - * mail will be read by the UserService, which in turn calls the UploadService). - * - * @param rcGroupId - */ - public void sendFeedbackEmailNotification(String rcGroupId) { - emailNotificationHelper.sendEmailFeedbackNotificationViaUserService( - rcGroupId, - authenticatedUser.getAccessToken(), Optional.ofNullable(TenantContext.getCurrentTenant())); - } } diff --git a/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java b/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java index 7dbbf78..daf6cb8 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java @@ -88,31 +88,6 @@ private UserRole resolveUserRole(AuthenticatedUser authenticatedUser) { : UserRole.ASKER; } - /** - * Upload a file with a message to a Rocket.Chat feedback room. The message and the description - * are encrypted before it is sent to Rocket.Chat. - * - * @param rocketChatCredentials {@link RocketChatCredentials} container - * @param rocketChatUploadParameter {@link RocketChatUploadParameter} container - */ - public void uploadFileToFeedbackRoom( - RocketChatCredentials rocketChatCredentials, - RocketChatUploadParameter rocketChatUploadParameter, - boolean sendNotification, String type, String fileHeader) { - - this.uploadTrackingService.validateUploadLimit(rocketChatUploadParameter.getRoomId()); - - sanitizeAndEncryptParametersAndUploadToRocketChatRoom( - rocketChatCredentials, rocketChatUploadParameter, type, fileHeader); - this.liveEventNotificationService.sendLiveEvent(rocketChatUploadParameter.getRoomId(), - authenticatedUser.getAccessToken(), TenantContext.getCurrentTenantOption()); - this.uploadTrackingService.trackUploadedFileForUser(rocketChatUploadParameter.getRoomId()); - - if (sendNotification) { - emailNotificationFacade.sendFeedbackEmailNotification(rocketChatUploadParameter.getRoomId()); - } - } - private void sanitizeAndEncryptParametersAndUploadToRocketChatRoom( RocketChatCredentials rocketChatCredentials, RocketChatUploadParameter rocketChatUploadParameter, String type, String fileHeader) { diff --git a/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java b/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java index e426d13..c7f6b87 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java @@ -49,16 +49,6 @@ public void sendEmailNotificationViaUserService( sendEmailNotificationCallingMethod(rcGroupId, userControllerApi::sendNewMessageNotification); } - @Async - public void sendEmailFeedbackNotificationViaUserService( - String rcGroupId, String accessToken, - Optional currentTenant) { - var userControllerApi = userServiceApiControllerFactory.createControllerApi(); - addDefaultHeaders(userControllerApi.getApiClient(), accessToken, currentTenant); - sendEmailNotificationCallingMethod(rcGroupId, - userControllerApi::sendNewFeedbackMessageNotification); - } - private void sendEmailNotificationCallingMethod(String rcGroupId, Consumer newMessageNotificationConsumerMethod) { try { NewMessageNotificationDTO notificationDto = new NewMessageNotificationDTO().rcGroupId( diff --git a/src/main/java/de/caritas/cob/uploadservice/config/SecurityConfig.java b/src/main/java/de/caritas/cob/uploadservice/config/SecurityConfig.java index 0d089c7..80d5c1f 100644 --- a/src/main/java/de/caritas/cob/uploadservice/config/SecurityConfig.java +++ b/src/main/java/de/caritas/cob/uploadservice/config/SecurityConfig.java @@ -4,19 +4,13 @@ import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.CONSULTANT_DEFAULT; import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.TECHNICAL_DEFAULT; import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.USER_DEFAULT; -import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.USE_FEEDBACK; import de.caritas.cob.uploadservice.api.authorization.RoleAuthorizationAuthorityMapper; import de.caritas.cob.uploadservice.filter.HttpTenantFilter; import de.caritas.cob.uploadservice.filter.StatelessCsrfFilter; -import org.keycloak.adapters.AdapterDeploymentContext; -import org.keycloak.adapters.KeycloakConfigResolver; -import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; -import org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean; import org.keycloak.adapters.springsecurity.KeycloakConfiguration; import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider; import org.keycloak.adapters.springsecurity.client.KeycloakClientRequestFactory; -import org.keycloak.adapters.springsecurity.config.KeycloakSpringConfigResolverWrapper; import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter; import org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticatedActionsFilter; import org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter; @@ -26,8 +20,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Lazy; -import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -103,8 +95,6 @@ protected void configure(HttpSecurity http) throws Exception { .hasAuthority(TECHNICAL_DEFAULT) .antMatchers("/uploads/new/{roomId:[0-9A-Za-z]+}") .hasAnyAuthority(USER_DEFAULT, CONSULTANT_DEFAULT, ANONYMOUS_DEFAULT) - .antMatchers("/uploads/feedback/new/{feedbackRoomId:[0-9A-Za-z]+}") - .hasAnyAuthority(USE_FEEDBACK) .anyRequest() .denyAll(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0f9277b..62b8fcc 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -47,7 +47,6 @@ springfox.documentation.swagger.v2.path=${springfox.docuPath}/v2/api-docs # UserService API user.service.api.url=:/users user.service.api.new.message.notification=${user.service.api.url}/mails/messages/new -user.service.api.new.feedback.message.notification=${user.service.api.url}/mails/messages/feedback/new user.service.api.liveproxy.url=: # CSRF token csrf.header.property= @@ -111,4 +110,4 @@ management.metrics.mongo.connectionpool.enabled=false spring.zipkin.baseUrl= spring.sleuth.sampler.percentage=1.0 -spring.zipkin.sender.type=web \ No newline at end of file +spring.zipkin.sender.type=web diff --git a/src/test/java/de/caritas/cob/uploadservice/api/authorization/AuthorityTest.java b/src/test/java/de/caritas/cob/uploadservice/api/authorization/AuthorityTest.java index 98cbfd9..ed60ef1 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/authorization/AuthorityTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/authorization/AuthorityTest.java @@ -33,16 +33,6 @@ public void getAuthoritiesByRoleName_Should_ReturnCorrectRoles_ForKeycloakRoleUs assertEquals(1, result.size()); } - @Test - public void getAuthoritiesByRoleName_Should_ReturnCorrectRoles_ForKeycloakRolePeerConsultant() { - - List result = Authority.getAuthoritiesByUserRole(UserRole.PEER_CONSULTANT); - - assertNotNull(result); - assertTrue(result.contains(AuthorityValue.USE_FEEDBACK)); - assertEquals(1, result.size()); - } - @Test public void getAuthoritiesByRoleName_Should_ReturnCorrectRoles_ForKeycloakRoleTechnical() { diff --git a/src/test/java/de/caritas/cob/uploadservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java b/src/test/java/de/caritas/cob/uploadservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java index f22a2d6..3f47c66 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java @@ -28,7 +28,6 @@ public class RoleAuthorizationAuthorityMapperTest { Sets.newSet( UserRole.USER.getValue(), UserRole.CONSULTANT.getValue(), - UserRole.PEER_CONSULTANT.getValue(), UserRole.ANONYMOUS.getValue()); @Test diff --git a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerAuthorizationTestIT.java b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerAuthorizationTestIT.java index fdbc05d..5a5f711 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerAuthorizationTestIT.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerAuthorizationTestIT.java @@ -1,7 +1,6 @@ package de.caritas.cob.uploadservice.api.controller; import static de.caritas.cob.uploadservice.helper.PathConstants.PATH_UPDATE_KEY; -import static de.caritas.cob.uploadservice.helper.PathConstants.PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM; import static de.caritas.cob.uploadservice.helper.PathConstants.PATH_UPLOAD_FILE_TO_ROOM; import static de.caritas.cob.uploadservice.helper.TestConstants.CSRF_COOKIE; import static de.caritas.cob.uploadservice.helper.TestConstants.CSRF_HEADER; @@ -155,54 +154,6 @@ public void uploadFileToRoom_Should_ReturnForbiddenAndCallNoMethods_WhenNoCsrfTo verifyNoMoreInteractions(uploadFacade); } - @Test - public void uploadFileToFeedbackRoom_Should_Return401AndCallNoMethods_WhenNoKeycloakAuthorization() - throws Exception { - - mvc.perform( - post(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .cookie(csrfCookie) - .header(CSRF_HEADER, CSRF_VALUE) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isUnauthorized()); - - verifyNoMoreInteractions(rocketChatService); - verifyNoMoreInteractions(uploadFacade); - } - - @Test - @WithMockUser - public void uploadFileToFeedbackRoom_Should_Return403AndCallNoMethods_WhenNoUserOrConsultantAuthority() - throws Exception { - - mvc.perform( - post(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .cookie(csrfCookie) - .header(CSRF_HEADER, CSRF_VALUE) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isForbidden()); - - verifyNoMoreInteractions(rocketChatService); - verifyNoMoreInteractions(uploadFacade); - } - - @Test - @WithMockUser(authorities = {AuthorityValue.CONSULTANT_DEFAULT, AuthorityValue.USER_DEFAULT}) - public void uploadFileToFeedbackRoom_Should_ReturnForbiddenAndCallNoMethods_WhenNoCsrfTokens() - throws Exception { - - mvc.perform( - post(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isForbidden()); - - verifyNoMoreInteractions(rocketChatService); - verifyNoMoreInteractions(uploadFacade); - } - @Test @WithMockUser(authorities = {AuthorityValue.ANONYMOUS_DEFAULT}) public void uploadFileToRoom_Should_ReturnCreated_When_AnonymousAuthority() diff --git a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTest.java b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTest.java index 6616c39..23a4314 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTest.java @@ -1,7 +1,5 @@ package de.caritas.cob.uploadservice.api.controller; -import static de.caritas.cob.uploadservice.helper.MethodAndParameterConstants.UPLOAD_FILE_TO_FEEDBACK_ROOM_METHOD_NAME; -import static de.caritas.cob.uploadservice.helper.MethodAndParameterConstants.UPLOAD_FILE_TO_FEEDBACK_ROOM_METHOD_PARAMS; import static de.caritas.cob.uploadservice.helper.MethodAndParameterConstants.UPLOAD_FILE_TO_ROOM_METHOD_NAME; import static de.caritas.cob.uploadservice.helper.MethodAndParameterConstants.UPLOAD_FILE_TO_ROOM_METHOD_PARAMS; import static org.junit.Assert.assertNotNull; @@ -10,7 +8,6 @@ import de.caritas.cob.uploadservice.api.facade.UploadFacade; import de.caritas.cob.uploadservice.api.service.EncryptionService; import java.lang.reflect.Method; -import lombok.NonNull; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -40,17 +37,4 @@ public void test_Should_Fail_WhenMethodUploadFileToRoomDoesNotHaveTempCleanupAnn assertNotNull(annotation); } - - @Test - public void test_Should_Fail_WhenMethodUploadFileToFeedbackRoomDoesNotHaveTempCleanupAnnotation() - throws NoSuchMethodException { - - Class classToTest = uploadController.getClass(); - Method methodToTest = - classToTest.getMethod( - UPLOAD_FILE_TO_FEEDBACK_ROOM_METHOD_NAME, UPLOAD_FILE_TO_FEEDBACK_ROOM_METHOD_PARAMS); - TempCleanup annotation = methodToTest.getAnnotation(TempCleanup.class); - - assertNotNull(annotation); - } } diff --git a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java index 822c7f1..e81a97f 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/controller/UploadControllerTestIT.java @@ -1,7 +1,6 @@ package de.caritas.cob.uploadservice.api.controller; import static de.caritas.cob.uploadservice.helper.PathConstants.PATH_UPDATE_KEY; -import static de.caritas.cob.uploadservice.helper.PathConstants.PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM; import static de.caritas.cob.uploadservice.helper.PathConstants.PATH_UPLOAD_FILE_TO_ROOM; import static de.caritas.cob.uploadservice.helper.TestConstants.FORM_PARAM_DESCRIPTION; import static de.caritas.cob.uploadservice.helper.TestConstants.FORM_PARAM_DESCRIPTION_VALUE; @@ -93,25 +92,6 @@ public void uploadFileToRoom_Should_ReturnNotFound_WhenRoomIdIsMissing() throws .andExpect(status().isNotFound()); } - @Test - public void uploadFileToFeedbackRoom_Should_ReturnNotFound_WhenRoomIdIsMissing() - throws Exception { - - MockPart fileToUpload = new MockPart(FORM_PARAM_FILE, "fileToUpload", "content".getBytes()); - - mvc.perform( - multipart(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM) - .part(fileToUpload) - .param(FORM_PARAM_SEND_NOTIFICATION, FORM_PARAM_SEND_NOTIFICATION_TRUE) - .param(FORM_PARAM_DESCRIPTION, FORM_PARAM_DESCRIPTION_VALUE) - .param(FORM_PARAM_MESSAGE, FORM_PARAM_MESSAGE_VALUE) - .param(FORM_PARAM_TMID, FORM_PARAM_TMID_VALUE) - .contentType(MediaType.MULTIPART_FORM_DATA) - .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) - .andExpect(status().isNotFound()); - } - @Test public void uploadFileToRoom_Should_ReturnBadRequest_WhenFileIsMissing() throws Exception { @@ -145,40 +125,6 @@ public void uploadFileToRoom_Should_ReturnBadRequest_WhenSendNotificationIsMissi .andExpect(status().isBadRequest()); } - @Test - public void uploadFileToFeedbackRoom_Should_ReturnBadRequest_WhenFileIsMissing() - throws Exception { - - mvc.perform( - multipart(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .param(FORM_PARAM_SEND_NOTIFICATION, FORM_PARAM_SEND_NOTIFICATION_TRUE) - .param(FORM_PARAM_DESCRIPTION, FORM_PARAM_DESCRIPTION_VALUE) - .param(FORM_PARAM_MESSAGE, FORM_PARAM_MESSAGE_VALUE) - .param(FORM_PARAM_TMID, FORM_PARAM_TMID_VALUE) - .contentType(MediaType.MULTIPART_FORM_DATA) - .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) - .andExpect(status().isBadRequest()); - } - - @Test - public void uploadFileToFeedbackRoom_Should_ReturnBadRequest_WhenSendNotificationIsMissing() - throws Exception { - - MockPart fileToUpload = new MockPart(FORM_PARAM_FILE, "fileToUpload", "content".getBytes()); - - mvc.perform( - multipart(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .part(fileToUpload) - .param(FORM_PARAM_DESCRIPTION, FORM_PARAM_DESCRIPTION_VALUE) - .param(FORM_PARAM_MESSAGE, FORM_PARAM_MESSAGE_VALUE) - .param(FORM_PARAM_TMID, FORM_PARAM_TMID_VALUE) - .contentType(MediaType.MULTIPART_FORM_DATA) - .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) - .andExpect(status().isBadRequest()); - } - @Test public void uploadFileToRoom_Should_ReturnOk_WhenValidRequest() throws Exception { @@ -197,24 +143,6 @@ public void uploadFileToRoom_Should_ReturnOk_WhenValidRequest() throws Exception .andExpect(status().isCreated()); } - @Test - public void uploadFileToFeedbackRoom_Should_ReturnOk_WhenValidRequest() throws Exception { - - MockPart fileToUpload = new MockPart(FORM_PARAM_FILE, "fileToUpload", "content".getBytes()); - - mvc.perform( - multipart(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .part(fileToUpload) - .param(FORM_PARAM_SEND_NOTIFICATION, FORM_PARAM_SEND_NOTIFICATION_TRUE) - .param(FORM_PARAM_DESCRIPTION, FORM_PARAM_DESCRIPTION_VALUE) - .param(FORM_PARAM_MESSAGE, FORM_PARAM_MESSAGE_VALUE) - .param(FORM_PARAM_TMID, FORM_PARAM_TMID_VALUE) - .contentType(MediaType.MULTIPART_FORM_DATA) - .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) - .andExpect(status().isCreated()); - } - @Test public void updateKey_Should_ReturnOk_WhenProvidedWithNewKey() throws Exception { @@ -256,22 +184,6 @@ public void uploadFileToRoom_Should_ReturnOk_When_notRequiredParamsAreMissing() .andExpect(status().isCreated()); } - @Test - public void uploadFileToFeedbackRoom_Should_ReturnOk_When_notRequiredParamsAreMissing() - throws Exception { - - MockPart fileToUpload = new MockPart(FORM_PARAM_FILE, "fileToUpload", "content".getBytes()); - - mvc.perform( - multipart(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .part(fileToUpload) - .param(FORM_PARAM_SEND_NOTIFICATION, FORM_PARAM_SEND_NOTIFICATION_TRUE) - .contentType(MediaType.MULTIPART_FORM_DATA) - .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) - .andExpect(status().isCreated()); - } - @Test public void uploadFileToRoom_Should_ReturnForbiddenWithCustomHeader_When_quotaLimitIsReached() throws Exception { @@ -315,22 +227,4 @@ public void uploadFileToRoom_should_return_unsupported_media_type_on_InvalidFile .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) .andExpect(status().isUnsupportedMediaType()); } - - @Test - public void uploadFileToFeedbackRoom_should_return_unsupported_media_type_on_InvalidFileTypeException() - throws Exception { - doThrow(InvalidFileTypeException.class).when(uploadFacade) - .uploadFileToFeedbackRoom(any(RocketChatCredentials.class), - any(RocketChatUploadParameter.class), anyBoolean(), nullable(String.class), nullable(String.class)); - MockPart fileToUpload = new MockPart(FORM_PARAM_FILE, "fileToUpload", "content".getBytes()); - - mvc.perform( - multipart(PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM + "/" + RC_ROOM_ID) - .part(fileToUpload) - .param(FORM_PARAM_SEND_NOTIFICATION, FORM_PARAM_SEND_NOTIFICATION_TRUE) - .contentType(MediaType.MULTIPART_FORM_DATA) - .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID)) - .andExpect(status().isUnsupportedMediaType()); - } } diff --git a/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java b/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java index 403cce0..9bac85e 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java @@ -24,10 +24,6 @@ public class EmailNotificationFacadeTest { "userServiceApiSendNewMessageNotificationUrl"; private static final String NOTIFICATION_API_URL = "http://caritas.local/service/users/mails/messages/new"; - private static final String FIELD_NAME_NEW_FEEDBACK_MESSAGE_NOTIFICATION = - "userServiceApiSendNewFeedbackMessageNotificationUrl"; - private static final String FEEDBACK_NOTIFICATION_API_URL = - "http://caritas.local/service/users/mails/messages/feedback/new"; private static final String RC_GROUP_ID = "fR2Rz7dmWmHdXE8uz"; @Mock private EmailNotificationHelper emailNotificationHelper; @@ -37,7 +33,6 @@ public class EmailNotificationFacadeTest { @Before public void setup() throws NoSuchFieldException, SecurityException { ReflectionTestUtils.setField(emailNotificationFacade, FIELD_NAME_NEW_MESSAGE_NOTIFICATION, NOTIFICATION_API_URL); - ReflectionTestUtils.setField(emailNotificationFacade, FIELD_NAME_NEW_FEEDBACK_MESSAGE_NOTIFICATION, FEEDBACK_NOTIFICATION_API_URL); } @Test @@ -51,17 +46,4 @@ public void sendEmailNotification_Should_PassSendNewMessageNotificationUrl2Notif .sendEmailNotificationViaUserService( RC_GROUP_ID, KEYCLOAK_ACCESS_TOKEN, Optional.ofNullable((TenantContext.getCurrentTenant()))); } - - @Test - public void - sendFeedbackEmailNotification_Should_PassNewFeedbMsgNotificationUrl2NotificationHelper() { - - when(authenticatedUser.getAccessToken()).thenReturn(KEYCLOAK_ACCESS_TOKEN); - - emailNotificationFacade.sendFeedbackEmailNotification(RC_GROUP_ID); - - verify(emailNotificationHelper, times(1)) - .sendEmailFeedbackNotificationViaUserService( - RC_GROUP_ID, KEYCLOAK_ACCESS_TOKEN, Optional.ofNullable(TenantContext.getCurrentTenant())); - } } diff --git a/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java b/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java index 5fb6bd7..9c82b61 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java @@ -214,83 +214,4 @@ public void uploadFileToRoom_Should_ThrowInternalServerErrorException_WheRocketC uploadFacade.uploadFileToRoom(rocketChatCredentials, rocketChatUploadParameter, false, null, null); } - - /** - * Method: uploadFileToFeedbackRoom - */ - @Test - public void uploadFileToFeedbackRoom_Should_CallServicesCorrectly_WhenNoExceptionIsThrown() - throws Exception { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatUploadParameterSanitizer, times(1)).sanitize(rocketChatUploadParameter); - verify(rocketChatUploadParameterEncrypter, times(1)).encrypt(rocketChatUploadParameter); - verify(rocketChatService, times(1)).roomsUpload(rocketChatCredentials, - rocketChatUploadParameter); - verify(rocketChatService, times(1)).markGroupAsReadForSystemUser( - rocketChatUploadParameter.getRoomId()); - verify(uploadTrackingService, times(1)).validateUploadLimit(any()); - verify(uploadTrackingService, times(1)).trackUploadedFileForUser(any()); - verify(fileService).verifyMimeType(multipartFile); - } - - @Test - public void uploadFileToFeedbackRoom_Should_sendEmailNotification_WhenParamIsTrue() { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, true, null, null); - - verify(emailNotificationFacade, times(1)).sendFeedbackEmailNotification(RC_ROOM_ID); - } - - @Test - public void uploadFileToFeedbackRoom_Should_markGroupAsReadForSystemUser() - throws RocketChatPostMarkGroupAsReadException { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatService, times(1)).markGroupAsReadForSystemUser(RC_ROOM_ID); - } - - @Test - public void uploadFileToFeedbackRoom_Should_uploadToRocketChat() { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatService, times(1)) - .roomsUpload( - Mockito.any(RocketChatCredentials.class), Mockito.any(RocketChatUploadParameter.class)); - } - - @Test - public void uploadFileToFeedbackRoom_Should_EncryptRocketChatParameter() - throws CustomCryptoException { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatUploadParameterEncrypter, times(1)).encrypt(rocketChatUploadParameter); - } - - @Test - public void uploadFileToFeedbackRoom_Should_SanitizeRocketChatParameter() { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatUploadParameterSanitizer, times(1)).sanitize(rocketChatUploadParameter); - } - - @Test - public void uploadFileToFeedbackRoom_Should_sendLiveNotification_When_UploadSucceeds() { - - uploadFacade.uploadFileToFeedbackRoom(rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(this.liveEventNotificationService, times(1)) - .sendLiveEvent(eq(rocketChatUploadParameter.getRoomId()), any(), any()); - } } diff --git a/src/test/java/de/caritas/cob/uploadservice/helper/MethodAndParameterConstants.java b/src/test/java/de/caritas/cob/uploadservice/helper/MethodAndParameterConstants.java index cd71411..4f62362 100644 --- a/src/test/java/de/caritas/cob/uploadservice/helper/MethodAndParameterConstants.java +++ b/src/test/java/de/caritas/cob/uploadservice/helper/MethodAndParameterConstants.java @@ -19,16 +19,4 @@ public class MethodAndParameterConstants { String.class, String.class }; - public static final String UPLOAD_FILE_TO_FEEDBACK_ROOM_METHOD_NAME = "uploadFileToFeedbackRoom"; - public static final Class[] UPLOAD_FILE_TO_FEEDBACK_ROOM_METHOD_PARAMS = - new Class[] { - String.class, - String.class, - String.class, - MultipartFile.class, - String.class, - String.class, - String.class, - String.class - }; } diff --git a/src/test/java/de/caritas/cob/uploadservice/helper/PathConstants.java b/src/test/java/de/caritas/cob/uploadservice/helper/PathConstants.java index 3f597ea..9a3f001 100644 --- a/src/test/java/de/caritas/cob/uploadservice/helper/PathConstants.java +++ b/src/test/java/de/caritas/cob/uploadservice/helper/PathConstants.java @@ -4,5 +4,4 @@ public class PathConstants { public static final String PATH_UPDATE_KEY = "/uploads/messages/key"; public static final String PATH_UPLOAD_FILE_TO_ROOM = "/uploads/new"; - public static final String PATH_UPLOAD_FILE_TO_FEEDBACK_ROOM = "/uploads/feedback/new"; }