diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 38753e692bd327fdefded2c32c8439f43b47e16a..66e642e2be9815452ae454b56c6e782aad5bd1b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -80,6 +80,13 @@ build-table-service: script: - "make build-table-service" +build-user-service: + stage: build-backend + needs: + - build-metadata-db + script: + - "make build-user-service" + build-metadata-service: stage: build-backend needs: @@ -114,6 +121,23 @@ test-identifier-service: junit: ./dbrepo-identifier-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' +test-user-service: + stage: test-backend + needs: + - build-user-service + script: + - "make test-user-service" + - "cat ./dbrepo-user-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + artifacts: + when: always + paths: + - ./dbrepo-user-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-user-service/rest-service/target/surefire-reports/ + expire_in: 1 days + reports: + junit: ./dbrepo-user-service/rest-service/target/surefire-reports/TEST-*.xml + coverage: '/Total.*?([0-9]{1,3})%/' + test-container-service: stage: test-backend needs: @@ -300,6 +324,7 @@ build-docker: - build-metadata-service - build-semantics-service - build-analyse-service + - build-user-service script: - cp .env.unix.example .env - make build-docker diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java index c921c04d94dd15d6a96a130c4aa7bade0ff6b5eb..44ce21e70ac1cd81ac576b786a9e32986cbe20fc 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java @@ -4,10 +4,7 @@ import at.tuwien.api.database.ViewBriefDto; import at.tuwien.api.database.ViewCreateDto; import at.tuwien.api.database.ViewDto; import at.tuwien.api.database.query.QueryResultDto; -import at.tuwien.api.database.query.QueryTypeDto; -import at.tuwien.api.database.table.TableHistoryDto; import at.tuwien.api.error.ApiErrorDto; -import at.tuwien.config.QueryConfig; import at.tuwien.entities.database.Database; import at.tuwien.entities.database.View; import at.tuwien.exception.*; @@ -26,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.Authentication; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -110,6 +108,16 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "401", + description = "Credentials missing", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Credentials missing", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "Database or user could not be found", content = {@Content( @@ -139,7 +147,12 @@ public class ViewEndpoint { UserNotFoundException { log.debug("endpoint create view, containerId={}, databaseId={}, data={}, principal={}", containerId, databaseId, data, principal); + /* check */ final Database database = databaseService.find(containerId, databaseId); + if (!database.getOwner().getUsername().equals(principal.getName())) { + log.error("Failed to create view: not the database owner"); + throw new NotAllowedException("Failed to create view: not the database owner"); + } log.trace("create view for database {}", database); final View view; view = viewService.create(containerId, databaseId, data, principal); @@ -198,6 +211,16 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "401", + description = "Credentials missing", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Credentials missing", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "Database, view or user could not be found", content = {@Content( @@ -224,9 +247,15 @@ public class ViewEndpoint { @NotNull @PathVariable("viewId") Long viewId, @NotNull Principal principal) throws DatabaseNotFoundException, ViewNotFoundException, UserNotFoundException, DatabaseConnectionException, - ViewMalformedException, QueryMalformedException { + ViewMalformedException, QueryMalformedException, NotAllowedException { log.debug("endpoint delete view, containerId={}, databaseId={}, viewId={}, principal={}", containerId, databaseId, viewId, principal); + /* check */ + final Database database = databaseService.find(containerId, databaseId); + if (!database.getOwner().getUsername().equals(principal.getName())) { + log.error("Failed to delete view: not the database owner"); + throw new NotAllowedException("Failed to delete view: not the database owner"); + } viewService.delete(containerId, databaseId, viewId, principal); return ResponseEntity.accepted() .build(); @@ -247,6 +276,16 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "401", + description = "Credentials missing", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Credentials missing", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "Database, view, container or user could not be found", content = {@Content( @@ -296,8 +335,19 @@ public class ViewEndpoint { containerId, databaseId, viewId, principal, page, size); /* check */ endpointValidator.validateDataParams(page, size); - /* find */ final Database database = databaseService.find(containerId, databaseId); + if (!database.getIsPublic()) { + if (principal == null) { + log.error("Failed to view data of private view: principal is null"); + throw new NotAllowedException("Failed to view data of private view: principal is null"); + } + final Authentication authentication = (Authentication) principal; + if (authentication.getAuthorities().stream().noneMatch(a -> a.getAuthority().equals("view-database-view-data"))) { + log.error("Failed to view data of private view: role missing"); + throw new NotAllowedException("Failed to view data of private view: role missing"); + } + } + /* find */ log.trace("find view data for database {}", database); final View view = viewService.findById(databaseId, viewId, principal); final QueryResultDto result = queryService.viewFindAll(containerId, databaseId, view, page, size, principal); @@ -312,12 +362,12 @@ public class ViewEndpoint { @Timed(value = "view.data.count", description = "Time needed to retrieve data count from a view") @Operation(summary = "Find view data count", security = @SecurityRequirement(name = "bearerAuth")) public ResponseEntity<Long> count(@NotNull @PathVariable("id") Long containerId, - @NotNull @PathVariable("databaseId") Long databaseId, - @NotNull @PathVariable("viewId") Long viewId, - Principal principal) - throws DatabaseNotFoundException, NotAllowedException, ViewNotFoundException, PaginationException, - QueryStoreException, DatabaseConnectionException, TableMalformedException, QueryMalformedException, - ImageNotSupportedException, ColumnParseException, UserNotFoundException, ContainerNotFoundException, ViewMalformedException { + @NotNull @PathVariable("databaseId") Long databaseId, + @NotNull @PathVariable("viewId") Long viewId, + Principal principal) + throws DatabaseNotFoundException, ViewNotFoundException, QueryStoreException, DatabaseConnectionException, + TableMalformedException, QueryMalformedException, ImageNotSupportedException, UserNotFoundException, + ContainerNotFoundException { log.debug("endpoint find view data count, containerId={}, databaseId={}, viewId={}, principal={}", containerId, databaseId, viewId, principal); /* find */ diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java index 228f1feda50d6010afa6cf576ca17a8f3d8c0456..570de559f4403ce15eea42c32c796c44d2d571af 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java @@ -27,6 +27,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.AccessDeniedException; import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -75,322 +76,200 @@ public class ViewEndpointUnitTest extends BaseUnitTest { @Autowired private ViewEndpoint viewEndpoint; - @Test - public void findAll_publicAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException { - - /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, null, null); - } - @Test @WithAnonymousUser - public void findAll_publicAnonymous2_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException { - - /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, null, null); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void findAll_publicRead_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException { - - /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void findAll_publicWriteOwn_succeeds() throws UserNotFoundException, NotAllowedException, + public void findAll_publicAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); + findAll_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void findAll_publicWriteAll_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + public void findAll_publicHasRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, null); } @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void findAll_publicOwner_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + public void findAll_publicHasRoleHasAccess_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_3_DEVELOPER_READ_ACCESS); } - @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void findAll_privateResearcher_fails() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void findAll_publicNoRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, null); - } - - @Test - public void create_publicAnonymous_succeeds() { - - /* test */ - assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, null, null); - }); + findAll_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, null); } @Test @WithAnonymousUser - public void create_publicAnonymous2_succeeds() { + public void create_publicAnonymous_succeeds() { /* test */ - assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, null, null); + assertThrows(AccessDeniedException.class, () -> { + create_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, null, null, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void create_publicRead_fails() { + @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + public void create_publicHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + create_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void create_publicWriteOwn_fails() { + @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + public void create_publicHasRoleHasAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); + create_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void create_publicWriteAll_succeeds() { + @WithMockUser(username = USER_2_USERNAME) + public void create_publicNoRole_fails() { /* test */ - assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + assertThrows(AccessDeniedException.class, () -> { + create_generic(CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, null); }); } - @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void create_publicOwner_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, DatabaseConnectionException, ViewMalformedException, QueryMalformedException { - - /* test */ - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); - } - - @Test - public void find_publicAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException { - - /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); - } - @Test @WithAnonymousUser - public void find_publicAnonymous2_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException { - - /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void find_publicRead_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException { - - /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void find_publicWriteOwn_succeeds() throws UserNotFoundException, NotAllowedException, + public void find_publicAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); + find_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void find_publicWriteAll_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"find-database-view"}) + public void find_publicHasRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + find_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void find_publicOwner_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void find_publicNoRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + find_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void find_privateResearcher_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void find_publicHasRoleHasAccess_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_4_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, null); - } - - @Test - public void delete_publicAnonymous_fails() { - - /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); - }); + find_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @WithAnonymousUser - public void delete_publicAnonymous2_fails() { - - /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); - }); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void delete_publicRead_succeeds() { + public void delete_publicAnonymous_fails() { /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, null, null, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void delete_publicWriteOwn_succeeds() { + @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-database-view"}) + public void delete_publicHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void delete_publicWriteAll_succeeds() { + @WithMockUser(username = USER_2_USERNAME) + public void delete_publicNoRole_fails() { /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + @WithMockUser(username = USER_3_USERNAME, authorities = {"delete-database-view"}) public void delete_publicOwner_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, ViewMalformedException, QueryMalformedException { /* test */ - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); - } - - @Test - public void data_publicAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, - QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, - ContainerNotFoundException, PaginationException, ViewMalformedException { - - /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_5_ID, DATABASE_3, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS); } @Test @WithAnonymousUser - public void data_publicAnonymous2_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, - QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, - ContainerNotFoundException, PaginationException, ViewMalformedException { - - /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void data_publicRead_succeeds() throws UserNotFoundException, NotAllowedException, + public void data_publicAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + data_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void data_publicWriteOwn_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void data_publicNoRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); + data_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DATA_STEWARD"}) - public void data_publicWriteAll_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"view-database-view-data"}) + public void data_publicHasRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); + data_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void data_publicOwner_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"view-database-view-data"}) + public void data_publicHasRoleHasAccess_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); - } - - @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void data_privateResearcher_succeeds() throws UserNotFoundException, QueryStoreException, - NotAllowedException, DatabaseConnectionException, TableMalformedException, QueryMalformedException, - ColumnParseException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException, - PaginationException, ViewNotFoundException, ViewMalformedException { - - /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_4_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, null); + data_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } /* ################################################################################################### */ @@ -398,222 +277,198 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* ################################################################################################### */ @Test + @WithAnonymousUser public void findAll_privateAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, null, null, null); - } - - @Test - public void findAll_privateRead_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException { - - /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, null, null); } @Test - public void findAll_privateWriteOwn_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + public void findAll_privateHasRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, null); } @Test - public void findAll_privateWriteAll_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + public void findAll_privateHasRoleHasAccess_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_DEVELOPER_READ_ACCESS); } @Test - public void findAll_privateOwner_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void findAll_privateNoRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, null); } @Test + @WithAnonymousUser public void create_privateAnonymous_succeeds() { /* test */ - assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, null, null, null); + assertThrows(AccessDeniedException.class, () -> { + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, null, null); }); } @Test - public void create_privateRead_fails() { + @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + public void create_privateHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, null); }); } @Test - public void create_privateWriteOwn_fails() { + @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + public void create_privateHasRoleHasAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @Test - public void create_privateWriteAll_fails() { + @WithMockUser(username = USER_2_USERNAME) + public void create_privateNoRole_fails() { /* test */ - assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS); + assertThrows(AccessDeniedException.class, () -> { + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, null); }); } @Test - public void create_privateOwner_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, DatabaseConnectionException, ViewMalformedException, QueryMalformedException { - - /* test */ - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); - } - - @Test + @WithAnonymousUser public void find_privateAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, null, null, null); - } - - @Test - public void find_privateRead_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException { - - /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); } @Test - public void find_privateWriteOwn_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"find-database-view"}) + public void find_privateHasRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - public void find_privateWriteAll_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void find_privateNoRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - public void find_privateOwner_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void find_privateHasRoleHasAccess_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test + @WithAnonymousUser public void delete_privateAnonymous_fails() { /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, null, null, null); - }); - } - - @Test - public void delete_privateRead_fails() { - - /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); }); } @Test - public void delete_privateWriteOwn_fails() { + @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-database-view"}) + public void delete_privateHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @Test - public void delete_privateWriteAll_fails() { + @WithMockUser(username = USER_2_USERNAME) + public void delete_privateNoRole_fails() { /* test */ - assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @Test + @WithMockUser(username = USER_1_USERNAME, authorities = {"delete-database-view"}) public void delete_privateOwner_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, ViewMalformedException, QueryMalformedException { /* test */ - delete_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); - } - - @Test - public void data_privateAnonymous_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, - QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, - ContainerNotFoundException, PaginationException, ViewMalformedException { - - /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, null, null, null); + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test - public void data_privateRead_succeeds() throws UserNotFoundException, NotAllowedException, - DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, - QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, - ContainerNotFoundException, PaginationException, ViewMalformedException { + @WithAnonymousUser + public void data_privateAnonymous_fails() { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); + assertThrows(NotAllowedException.class, () -> { + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, null, null, null); + }); } @Test - public void data_privateWriteOwn_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME) + public void data_privateNoRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - public void data_privateWriteAll_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"view-database-view-data"}) + public void data_privateHasRole_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test - public void data_privateOwner_succeeds() throws UserNotFoundException, NotAllowedException, + @WithMockUser(username = USER_2_USERNAME, authorities = {"view-database-view-data"}) + public void data_privateHasRoleHasAccess_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } /* ################################################################################################### */ @@ -743,9 +598,6 @@ public class ViewEndpointUnitTest extends BaseUnitTest { UserNotFoundException, NotAllowedException, ViewNotFoundException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, TableMalformedException, ColumnParseException, ImageNotSupportedException, ContainerNotFoundException, PaginationException, ViewMalformedException { - final ExecuteStatementDto statement = ExecuteStatementDto.builder() - .statement(VIEW_1_QUERY) - .build(); final Long page = 0L; final Long size = 2L; diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java index ba53952bab69043e081cd65e2cd7c7d8d1a9c62f..ee513b6340e03404d64e799f1520fbaf2a4f389b 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java @@ -15,6 +15,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; @@ -24,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.*; @Log4j2 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @SpringBootTest @ExtendWith(SpringExtension.class) public class ContainerServiceIntegrationTest extends BaseUnitTest { diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java index 3aa94579fa6bcda0b2ff8858004a569acdc67e75..75c544c54e7a622bf05e6fa7b985bef2c3c7fca9 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java @@ -23,6 +23,8 @@ import org.junit.rules.Timeout; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; @@ -45,6 +47,7 @@ import static org.mockito.Mockito.when; @Log4j2 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @SpringBootTest @ExtendWith(SpringExtension.class) public class QueryServiceIntegrationTest extends BaseUnitTest { diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java index e3ce2fde0edc29217ec55ecb7d02f0ff150174e2..c920b40be75479300f942871b98113fd3ac4dc25 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java @@ -18,6 +18,8 @@ import org.apache.http.auth.BasicUserPrincipal; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; @@ -38,6 +40,7 @@ import static org.mockito.Mockito.when; @Log4j2 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @ExtendWith(SpringExtension.class) @SpringBootTest public class StoreServiceIntegrationModifyTest extends BaseUnitTest { diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java index d46ed5511838620cf06c3d156e9f8ed67bbab466..af081233297bfd2d93fd13469c9aaaf4e8c0b04a 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java @@ -17,6 +17,8 @@ import org.apache.http.auth.BasicUserPrincipal; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -33,6 +35,7 @@ import static org.mockito.Mockito.when; @Log4j2 @ExtendWith(SpringExtension.class) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @SpringBootTest public class StoreServiceIntegrationReadTest extends BaseUnitTest { diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java index 9eaa311b103932e1163d278189873063f0856084..8422cf1dc619087822cf5d020bc1e5798faa8ea8 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java @@ -15,6 +15,8 @@ import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.security.test.context.support.WithAnonymousUser; @@ -32,6 +34,7 @@ import static org.mockito.Mockito.when; @Log4j2 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @SpringBootTest @ExtendWith(SpringExtension.class) public class TableServiceIntegrationReadTest extends BaseUnitTest { @@ -100,7 +103,7 @@ public class TableServiceIntegrationReadTest extends BaseUnitTest { /* metadata db */ h2Utils.runScript("schema.sql"); /* metadata db */ - imageRepository.save(IMAGE_1_SIMPLE); + imageRepository.save(IMAGE_1); realmRepository.save(REALM_DBREPO); userRepository.save(USER_1_SIMPLE); userRepository.save(USER_2_SIMPLE); diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java index 7cbd93be7ff914ad0ecf4f3505b2d34afb42ae40..a586a6514e94318a638f820c027d2cec58eecf20 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java @@ -14,6 +14,8 @@ import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; @@ -28,6 +30,7 @@ import static org.mockito.Mockito.when; @Log4j2 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @SpringBootTest @ExtendWith(SpringExtension.class) public class TableServiceUnitTest extends BaseUnitTest { diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java index 0f4b2f9f3fd6cd56b2c53fa04c18553b1bceebf8..2d264ca8905f2a8ff03da5d7c1b9c31419884cbe 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java @@ -21,6 +21,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; @@ -40,6 +42,7 @@ import static org.mockito.Mockito.when; @Log4j2 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@EnableAutoConfiguration(exclude= RabbitAutoConfiguration.class) @SpringBootTest @ExtendWith(SpringExtension.class) public class ViewServiceIntegrationTest extends BaseUnitTest {