From 459348f1fc3273909d7b678edd9658383e364c5f Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Wed, 27 Sep 2023 14:08:52 +0200 Subject: [PATCH] SONAR-20578 move web-related code to new submodule --- server/sonar-webserver-webapi-v2/build.gradle | 3 +- .../DefaultGithubPermissionsController.java | 136 -------- .../GithubPermissionsController.java | 67 ---- .../permissions/controller/package-info.java | 23 -- .../model/RestGithubPermissionsMapping.java | 25 -- .../GithubPermissionMappingUpdateRequest.java | 24 -- .../GithubPermissionsMappingPostRequest.java | 35 -- .../request/PermissionMappingUpdate.java | 86 ----- .../permissions/request/RestPermissions.java | 50 --- .../permissions/request/package-info.java | 23 -- .../GithubPermissionsMappingRestResponse.java | 26 -- .../permissions/response/package-info.java | 23 -- .../permissions/model => }/package-info.java | 2 +- .../v2/config/PlatformLevel4WebConfig.java | 17 +- ...efaultGithubPermissionsControllerTest.java | 324 ------------------ .../sonar/server/v2/api/ControllerTester.java | 0 .../platformlevel/PlatformLevel4.java | 2 + 17 files changed, 7 insertions(+), 859 deletions(-) delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsController.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/GithubPermissionsController.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/package-info.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/RestGithubPermissionsMapping.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionMappingUpdateRequest.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionsMappingPostRequest.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/PermissionMappingUpdate.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/RestPermissions.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/package-info.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/GithubPermissionsMappingRestResponse.java delete mode 100644 server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/package-info.java rename server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/{github/permissions/model => }/package-info.java (94%) delete mode 100644 server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsControllerTest.java rename server/sonar-webserver-webapi-v2/src/{test => testFixtures}/java/org/sonar/server/v2/api/ControllerTester.java (100%) diff --git a/server/sonar-webserver-webapi-v2/build.gradle b/server/sonar-webserver-webapi-v2/build.gradle index 183c5598094..93b98d477a2 100644 --- a/server/sonar-webserver-webapi-v2/build.gradle +++ b/server/sonar-webserver-webapi-v2/build.gradle @@ -17,11 +17,12 @@ dependencies { testImplementation 'javax.servlet:javax.servlet-api' testImplementation 'org.mockito:mockito-core' - testImplementation 'org.springframework:spring-test' testImplementation 'org.skyscreamer:jsonassert:1.5.1' testImplementation project(':sonar-testing-harness') testImplementation testFixtures(project(':server:sonar-server-common')) testImplementation testFixtures(project(':server:sonar-webserver-auth')) + + testFixturesApi 'org.springframework:spring-test' } diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsController.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsController.java deleted file mode 100644 index eb3fcea29db..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsController.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.controller; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.sonar.server.common.github.permissions.GithubPermissionsMapping; -import org.sonar.server.common.github.permissions.GithubPermissionsMappingService; -import org.sonar.server.common.github.permissions.PermissionMappingChange; -import org.sonar.server.common.github.permissions.SonarqubePermissions; -import org.sonar.server.common.permission.Operation; -import org.sonar.server.user.UserSession; -import org.sonar.server.v2.api.github.permissions.model.RestGithubPermissionsMapping; -import org.sonar.server.v2.api.github.permissions.request.GithubPermissionMappingUpdateRequest; -import org.sonar.server.v2.api.github.permissions.request.GithubPermissionsMappingPostRequest; -import org.sonar.server.v2.api.github.permissions.request.PermissionMappingUpdate; -import org.sonar.server.v2.api.github.permissions.request.RestPermissions; -import org.sonar.server.v2.api.github.permissions.response.GithubPermissionsMappingRestResponse; - -import static org.sonar.api.web.UserRole.ADMIN; -import static org.sonar.api.web.UserRole.CODEVIEWER; -import static org.sonar.api.web.UserRole.ISSUE_ADMIN; -import static org.sonar.api.web.UserRole.SCAN; -import static org.sonar.api.web.UserRole.SECURITYHOTSPOT_ADMIN; -import static org.sonar.api.web.UserRole.USER; - -public class DefaultGithubPermissionsController implements GithubPermissionsController { - - private final UserSession userSession; - private final GithubPermissionsMappingService githubPermissionsMappingService; - - public DefaultGithubPermissionsController(UserSession userSession, GithubPermissionsMappingService githubPermissionsMappingService) { - this.userSession = userSession; - this.githubPermissionsMappingService = githubPermissionsMappingService; - } - - @Override - public GithubPermissionsMappingRestResponse fetchAll() { - userSession.checkIsSystemAdministrator(); - List permissionsMapping = githubPermissionsMappingService.getPermissionsMapping(); - return new GithubPermissionsMappingRestResponse(toRestResources(permissionsMapping)); - } - - @Override - public RestGithubPermissionsMapping updateMapping(String githubRole, GithubPermissionMappingUpdateRequest request) { - userSession.checkIsSystemAdministrator(); - PermissionMappingUpdate update = request.permissions(); - Set changes = new HashSet<>(); - - update.getUser().map(shouldAddPermission -> toPermissionMappingChange(githubRole, USER, shouldAddPermission)).applyIfDefined(changes::add); - update.getCodeViewer().map(shouldAddPermission -> toPermissionMappingChange(githubRole, CODEVIEWER, shouldAddPermission)).applyIfDefined(changes::add); - update.getIssueAdmin().map(shouldAddPermission -> toPermissionMappingChange(githubRole, ISSUE_ADMIN, shouldAddPermission)).applyIfDefined(changes::add); - update.getSecurityHotspotAdmin().map(shouldAddPermission -> toPermissionMappingChange(githubRole, SECURITYHOTSPOT_ADMIN, shouldAddPermission)).applyIfDefined(changes::add); - update.getAdmin().map(shouldAddPermission -> toPermissionMappingChange(githubRole, ADMIN, shouldAddPermission)).applyIfDefined(changes::add); - update.getScan().map(shouldAddPermission -> toPermissionMappingChange(githubRole, SCAN, shouldAddPermission)).applyIfDefined(changes::add); - - githubPermissionsMappingService.updatePermissionsMappings(changes); - - return toRestGithubPermissionMapping(githubPermissionsMappingService.getPermissionsMappingForGithubRole(githubRole)); - - } - - @Override - public void deleteMapping(String githubRole) { - userSession.checkIsSystemAdministrator(); - githubPermissionsMappingService.deletePermissionMappings(githubRole); - } - - private static PermissionMappingChange toPermissionMappingChange(String githubRole, String sonarqubePermission, boolean shouldAddPermission) { - return new PermissionMappingChange(githubRole, sonarqubePermission, shouldAddPermission ? Operation.ADD : Operation.REMOVE); - } - - private static List toRestResources(List permissionsMapping) { - return permissionsMapping.stream() - .map(DefaultGithubPermissionsController::toRestGithubPermissionMapping) - .toList(); - } - - @Override - public RestGithubPermissionsMapping createMapping(GithubPermissionsMappingPostRequest request) { - userSession.checkIsSystemAdministrator(); - GithubPermissionsMapping githubPermissionsMapping = new GithubPermissionsMapping(request.githubRole(), false, toSonarqubePermissions(request.permissions())); - return toRestGithubPermissionMapping(githubPermissionsMappingService.createPermissionMapping(githubPermissionsMapping)); - } - - private static SonarqubePermissions toSonarqubePermissions(RestPermissions restPermissions) { - SonarqubePermissions.Builder sonarqubePermissionsBuilder = SonarqubePermissions.Builder.builder(); - - sonarqubePermissionsBuilder.user(restPermissions.user()); - sonarqubePermissionsBuilder.codeViewer(restPermissions.codeViewer()); - sonarqubePermissionsBuilder.issueAdmin(restPermissions.issueAdmin()); - sonarqubePermissionsBuilder.securityHotspotAdmin(restPermissions.securityHotspotAdmin()); - sonarqubePermissionsBuilder.admin(restPermissions.admin()); - sonarqubePermissionsBuilder.scan(restPermissions.scan()); - - return sonarqubePermissionsBuilder.build(); - } - - private static RestGithubPermissionsMapping toRestGithubPermissionMapping(GithubPermissionsMapping githubPermissionsMapping) { - return new RestGithubPermissionsMapping( - githubPermissionsMapping.githubRole(), - githubPermissionsMapping.githubRole(), - githubPermissionsMapping.isBaseRole(), - toRestPermissions(githubPermissionsMapping.permissions())); - } - - private static RestPermissions toRestPermissions(SonarqubePermissions permissions) { - return new RestPermissions( - permissions.user(), - permissions.codeViewer(), - permissions.issueAdmin(), - permissions.securityHotspotAdmin(), - permissions.admin(), - permissions.scan() - ); - } - -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/GithubPermissionsController.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/GithubPermissionsController.java deleted file mode 100644 index 3c7083fb08a..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/GithubPermissionsController.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.controller; - -import io.swagger.v3.oas.annotations.Operation; -import javax.validation.Valid; -import org.sonar.server.v2.WebApiEndpoints; -import org.sonar.server.v2.api.github.permissions.model.RestGithubPermissionsMapping; -import org.sonar.server.v2.api.github.permissions.request.GithubPermissionMappingUpdateRequest; -import org.sonar.server.v2.api.github.permissions.request.GithubPermissionsMappingPostRequest; -import org.sonar.server.v2.api.github.permissions.response.GithubPermissionsMappingRestResponse; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -import static org.sonar.server.v2.WebApiEndpoints.JSON_MERGE_PATCH_CONTENT_TYPE; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - -@RequestMapping(WebApiEndpoints.GITHUB_PERMISSIONS_ENDPOINT) -@RestController -public interface GithubPermissionsController { - - @GetMapping(produces = APPLICATION_JSON_VALUE) - @ResponseStatus(HttpStatus.OK) - @Operation(summary = "Fetch the GitHub permissions mapping", description = "Requires Administer System permission.") - GithubPermissionsMappingRestResponse fetchAll(); - - @PatchMapping(path = "/{githubRole}", consumes = JSON_MERGE_PATCH_CONTENT_TYPE, produces = APPLICATION_JSON_VALUE) - @ResponseStatus(HttpStatus.OK) - @Operation(summary = "Update a single GitHub permission mapping", description = "Requires Administer System permission.") - RestGithubPermissionsMapping updateMapping(@PathVariable("githubRole") String githubRole, @Valid @RequestBody GithubPermissionMappingUpdateRequest request); - - @DeleteMapping(path = "/{githubRole}") - @ResponseStatus(HttpStatus.NO_CONTENT) - @Operation(summary = "Delete a single GitHub permission mapping", description = "Requires Administer System permission.") - void deleteMapping(@PathVariable("githubRole") String githubRole); - - @PostMapping(consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) - @ResponseStatus(HttpStatus.OK) - @Operation(summary = "Create a permission mapping for a GitHub custom role", description = "Requires Administer System permission.") - RestGithubPermissionsMapping createMapping(@Valid @RequestBody GithubPermissionsMappingPostRequest request); - -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/package-info.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/package-info.java deleted file mode 100644 index 659fa0dc6fc..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/controller/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.v2.api.github.permissions.controller; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/RestGithubPermissionsMapping.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/RestGithubPermissionsMapping.java deleted file mode 100644 index 1952c7c9d19..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/RestGithubPermissionsMapping.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.model; - -import org.sonar.server.v2.api.github.permissions.request.RestPermissions; - -public record RestGithubPermissionsMapping(String id, String githubRole, boolean isBaseRole, RestPermissions permissions) { -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionMappingUpdateRequest.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionMappingUpdateRequest.java deleted file mode 100644 index a7e5e0a322d..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionMappingUpdateRequest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.request; - -public record GithubPermissionMappingUpdateRequest( - PermissionMappingUpdate permissions) { -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionsMappingPostRequest.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionsMappingPostRequest.java deleted file mode 100644 index 8ff8e54c3cd..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/GithubPermissionsMappingPostRequest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.request; - -import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; - -public record GithubPermissionsMappingPostRequest( - @NotNull - @Schema(description = "Custom role name on GitHub (case-sensitive)") - String githubRole, - - @NotNull - @Valid - @Schema(description = "Permissions") - RestPermissions permissions) { -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/PermissionMappingUpdate.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/PermissionMappingUpdate.java deleted file mode 100644 index f82cb45cd2a..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/PermissionMappingUpdate.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.request; - -import io.swagger.v3.oas.annotations.media.Schema; -import org.sonar.server.v2.common.model.UpdateField; - -public class PermissionMappingUpdate { - private UpdateField user = UpdateField.undefined(); - private UpdateField codeViewer = UpdateField.undefined(); - private UpdateField issueAdmin = UpdateField.undefined(); - private UpdateField securityHotspotAdmin = UpdateField.undefined(); - private UpdateField admin = UpdateField.undefined(); - private UpdateField scan = UpdateField.undefined(); - - @Schema(implementation = Boolean.class) - public UpdateField getUser() { - return user; - } - - public void setUser(Boolean user) { - this.user = UpdateField.withValue(user); - } - - @Schema(implementation = Boolean.class) - public UpdateField getCodeViewer() { - return codeViewer; - } - - public void setCodeViewer(Boolean codeViewer) { - this.codeViewer = UpdateField.withValue(codeViewer); - } - - @Schema(implementation = Boolean.class) - public UpdateField getIssueAdmin() { - return issueAdmin; - } - - public void setIssueAdmin(Boolean issueAdmin) { - this.issueAdmin = UpdateField.withValue(issueAdmin); - } - - @Schema(implementation = Boolean.class) - public UpdateField getSecurityHotspotAdmin() { - return securityHotspotAdmin; - } - - public void setSecurityHotspotAdmin(Boolean securityHotspotAdmin) { - this.securityHotspotAdmin = UpdateField.withValue(securityHotspotAdmin); - } - - @Schema(implementation = Boolean.class) - public UpdateField getAdmin() { - return admin; - } - - public void setAdmin(Boolean admin) { - this.admin = UpdateField.withValue(admin); - } - - @Schema(implementation = Boolean.class) - public UpdateField getScan() { - return scan; - } - - public void setScan(Boolean scan) { - this.scan = UpdateField.withValue(scan); - } -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/RestPermissions.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/RestPermissions.java deleted file mode 100644 index 15ed5286ee6..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/RestPermissions.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.request; - -import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.constraints.NotNull; - -public record RestPermissions( - @NotNull - @Schema(description = "Browse") - Boolean user, - - @NotNull - @Schema(description = "See Source Code") - Boolean codeViewer, - - @NotNull - @Schema(description = "Administer Issues") - Boolean issueAdmin, - - @NotNull - @Schema(description = "Administer Security Hotspots") - Boolean securityHotspotAdmin, - - @NotNull - @Schema(description = "Administer") - Boolean admin, - - @NotNull - @Schema(description = "Execute Analysis") - Boolean scan -) { -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/package-info.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/package-info.java deleted file mode 100644 index 2aa3f056235..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/request/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.v2.api.github.permissions.request; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/GithubPermissionsMappingRestResponse.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/GithubPermissionsMappingRestResponse.java deleted file mode 100644 index 07f83933562..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/GithubPermissionsMappingRestResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.response; - -import java.util.List; -import org.sonar.server.v2.api.github.permissions.model.RestGithubPermissionsMapping; - -public record GithubPermissionsMappingRestResponse(List githubPermissionsMappings) { -} diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/package-info.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/package-info.java deleted file mode 100644 index 90961cb4322..00000000000 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/response/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.v2.api.github.permissions.response; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/package-info.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/package-info.java similarity index 94% rename from server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/package-info.java rename to server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/package-info.java index a242c4d880f..1bcb4c2be02 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/github/permissions/model/package-info.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/package-info.java @@ -18,6 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @ParametersAreNonnullByDefault -package org.sonar.server.v2.api.github.permissions.model; +package org.sonar.server.v2.api; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/PlatformLevel4WebConfig.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/PlatformLevel4WebConfig.java index 4b3796c7a64..32801254bb1 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/PlatformLevel4WebConfig.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/PlatformLevel4WebConfig.java @@ -20,10 +20,6 @@ package org.sonar.server.v2.config; import javax.annotation.Nullable; -import org.sonar.core.util.UuidFactory; -import org.sonar.db.DbClient; -import org.sonar.db.provisioning.GithubPermissionsMappingDao; -import org.sonar.server.common.github.permissions.GithubPermissionsMappingService; import org.sonar.server.common.health.CeStatusNodeCheck; import org.sonar.server.common.health.DbConnectionNodeCheck; import org.sonar.server.common.health.EsStatusNodeCheck; @@ -35,7 +31,6 @@ import org.sonar.server.health.HealthChecker; import org.sonar.server.platform.NodeInformation; import org.sonar.server.user.SystemPasscode; import org.sonar.server.user.UserSession; -import org.sonar.server.v2.api.github.permissions.controller.DefaultGithubPermissionsController; import org.sonar.server.v2.api.system.controller.DefaultLivenessController; import org.sonar.server.v2.api.system.controller.HealthController; import org.sonar.server.v2.api.system.controller.LivenessController; @@ -43,11 +38,13 @@ import org.sonar.server.v2.api.user.controller.DefaultUserController; import org.sonar.server.v2.api.user.controller.UserController; import org.sonar.server.v2.api.user.converter.UsersSearchRestResponseGenerator; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @Configuration @Import(CommonWebConfig.class) +@ComponentScan("com.sonar.github.provisioning.permissions.web.config") public class PlatformLevel4WebConfig { @Bean @@ -80,14 +77,4 @@ public class PlatformLevel4WebConfig { return new DefaultUserController(userSession, userService, usersSearchResponseGenerator); } - @Bean - public GithubPermissionsMappingService githubPermissionsMappingService(DbClient dbClient, GithubPermissionsMappingDao githubPermissionsMappingDao, UuidFactory uuidFactory) { - return new GithubPermissionsMappingService(dbClient, githubPermissionsMappingDao, uuidFactory); - } - - @Bean - public DefaultGithubPermissionsController githubPermissionsController(UserSession userSession, GithubPermissionsMappingService githubPermissionsMappingService) { - return new DefaultGithubPermissionsController(userSession, githubPermissionsMappingService); - } - } diff --git a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsControllerTest.java b/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsControllerTest.java deleted file mode 100644 index bb4b9f63965..00000000000 --- a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/github/permissions/controller/DefaultGithubPermissionsControllerTest.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.v2.api.github.permissions.controller; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.util.List; -import java.util.Set; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.sonar.server.common.github.permissions.GithubPermissionsMapping; -import org.sonar.server.common.github.permissions.GithubPermissionsMappingService; -import org.sonar.server.common.github.permissions.PermissionMappingChange; -import org.sonar.server.common.github.permissions.SonarqubePermissions; -import org.sonar.server.common.permission.Operation; -import org.sonar.server.exceptions.NotFoundException; -import org.sonar.server.tester.UserSessionRule; -import org.sonar.server.v2.api.ControllerTester; -import org.sonar.server.v2.api.github.permissions.model.RestGithubPermissionsMapping; -import org.sonar.server.v2.api.github.permissions.request.GithubPermissionsMappingPostRequest; -import org.sonar.server.v2.api.github.permissions.request.RestPermissions; -import org.sonar.server.v2.api.github.permissions.response.GithubPermissionsMappingRestResponse; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.sonar.server.common.github.permissions.GithubPermissionsMappingService.READ_GITHUB_ROLE; -import static org.sonar.server.v2.WebApiEndpoints.GITHUB_PERMISSIONS_ENDPOINT; -import static org.sonar.server.v2.WebApiEndpoints.JSON_MERGE_PATCH_CONTENT_TYPE; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -public class DefaultGithubPermissionsControllerTest { - - public static final String GITHUB_ROLE = "role1"; - private static final Gson gson = new GsonBuilder().create(); - public static final GithubPermissionsMappingPostRequest GITHUB_PERMISSIONS_MAPPING_POST_REQUEST = - new GithubPermissionsMappingPostRequest(GITHUB_ROLE, new RestPermissions(true, true, true, true, true, true)); - - @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); - private final GithubPermissionsMappingService githubPermissionsMappingService = mock(); - private final MockMvc mockMvc = ControllerTester.getMockMvc(new DefaultGithubPermissionsController(userSession, githubPermissionsMappingService)); - - @Test - public void fetchMapping_whenUserIsNotAdministrator_shouldReturnForbidden() throws Exception { - userSession.logIn().setNonSystemAdministrator(); - - mockMvc.perform(get(GITHUB_PERMISSIONS_ENDPOINT)) - .andExpectAll( - status().isForbidden(), - content().json("{\"message\":\"Insufficient privileges\"}")); - } - - @Test - public void fetchMapping_whenMappingSet_shouldReturnMapping() throws Exception { - userSession.logIn().setSystemAdministrator(); - - List mapping = List.of( - new GithubPermissionsMapping(GITHUB_ROLE, false, new SonarqubePermissions(true, false, true, false, true, false)), - new GithubPermissionsMapping("role2", true, new SonarqubePermissions(false, true, false, true, false, true))); - when(githubPermissionsMappingService.getPermissionsMapping()).thenReturn(mapping); - - MvcResult mvcResult = mockMvc.perform(get(GITHUB_PERMISSIONS_ENDPOINT)) - .andExpect(status().isOk()) - .andReturn(); - - GithubPermissionsMappingRestResponse response = gson.fromJson(mvcResult.getResponse().getContentAsString(), GithubPermissionsMappingRestResponse.class); - assertThat(response.githubPermissionsMappings()).isEqualTo(toRestResources(mapping)); - } - - private static List toRestResources(List permissionsMapping) { - return permissionsMapping.stream() - .map(DefaultGithubPermissionsControllerTest::toRestGithubPermissionMapping) - .toList(); - } - - private static RestGithubPermissionsMapping toRestGithubPermissionMapping(GithubPermissionsMapping permissionMapping) { - return new RestGithubPermissionsMapping( - permissionMapping.githubRole(), - permissionMapping.githubRole(), - permissionMapping.isBaseRole(), - toRestPermissions(permissionMapping.permissions())); - } - - private static RestPermissions toRestPermissions(SonarqubePermissions permissions) { - return new RestPermissions( - permissions.user(), - permissions.codeViewer(), - permissions.issueAdmin(), - permissions.securityHotspotAdmin(), - permissions.admin(), - permissions.scan() - ); - } - - @Test - public void updateMapping_whenUserIsNotAdministrator_shouldReturnForbidden() throws Exception { - userSession.logIn().setNonSystemAdministrator(); - - mockMvc.perform( - patch(GITHUB_PERMISSIONS_ENDPOINT + "/" + GITHUB_ROLE) - .contentType(JSON_MERGE_PATCH_CONTENT_TYPE) - .content(""" - { - "user": true, - "codeViewer": false, - "admin": true - } - """)) - .andExpectAll( - status().isForbidden(), - content().json("{\"message\":\"Insufficient privileges\"}")); - } - - @Test - public void updateMapping_shouldUpdateMapping() throws Exception { - userSession.logIn().setSystemAdministrator(); - GithubPermissionsMapping updatedRolePermissions = new GithubPermissionsMapping(GITHUB_ROLE, false, new SonarqubePermissions(true, false, false, true, true, false)); - - when(githubPermissionsMappingService.getPermissionsMappingForGithubRole(GITHUB_ROLE)).thenReturn(updatedRolePermissions); - - MvcResult mvcResult = mockMvc.perform( - patch(GITHUB_PERMISSIONS_ENDPOINT + "/" + GITHUB_ROLE) - .contentType(JSON_MERGE_PATCH_CONTENT_TYPE) - .content(""" - { - "permissions": { - "user": true, - "codeViewer": false, - "admin": true - } - } - """)) - .andExpect(status().isOk()) - .andReturn(); - - RestGithubPermissionsMapping response = gson.fromJson(mvcResult.getResponse().getContentAsString(), RestGithubPermissionsMapping.class); - - RestGithubPermissionsMapping expectedResponse = new RestGithubPermissionsMapping(GITHUB_ROLE, GITHUB_ROLE, false, - new RestPermissions(true, false, false, true, true, false)); - assertThat(response).isEqualTo(expectedResponse); - - ArgumentCaptor> permissionMappingChangesCaptor = ArgumentCaptor.forClass(Set.class); - verify(githubPermissionsMappingService).updatePermissionsMappings(permissionMappingChangesCaptor.capture()); - assertThat(permissionMappingChangesCaptor.getValue()) - .containsExactlyInAnyOrder( - new PermissionMappingChange(GITHUB_ROLE, "codeviewer", Operation.REMOVE), - new PermissionMappingChange(GITHUB_ROLE, "user", Operation.ADD), - new PermissionMappingChange(GITHUB_ROLE, "admin", Operation.ADD)); - } - - @Test - public void deleteMapping_whenUserIsNotAdministrator_shouldReturnForbidden() throws Exception { - userSession.logIn().setNonSystemAdministrator(); - mockMvc - .perform(delete(GITHUB_PERMISSIONS_ENDPOINT + "/" + READ_GITHUB_ROLE)) - .andExpectAll( - status().isForbidden(), - content().json("{\"message\":\"Insufficient privileges\"}")); - } - - @Test - public void deleteMapping_whenTryingToDeleteBaseRole_shouldReturnBadRequest() throws Exception { - userSession.logIn().setSystemAdministrator(); - doThrow(new IllegalArgumentException("Bad request")).when(githubPermissionsMappingService).deletePermissionMappings(READ_GITHUB_ROLE); - mockMvc - .perform(delete(GITHUB_PERMISSIONS_ENDPOINT + "/" + READ_GITHUB_ROLE)) - .andExpectAll( - status().isBadRequest(), - content().json("{\"message\":\"Bad request\"}")); - } - - @Test - public void deleteMapping_whenNoMappingsExistForACustomRole_shouldReturnNotFound() throws Exception { - userSession.logIn().setSystemAdministrator(); - doThrow(new NotFoundException("Role not found")).when(githubPermissionsMappingService).deletePermissionMappings(READ_GITHUB_ROLE); - mockMvc - .perform(delete(GITHUB_PERMISSIONS_ENDPOINT + "/" + READ_GITHUB_ROLE)) - .andExpectAll( - status().isNotFound(), - content().json("{\"message\":\"Role not found\"}")); - } - - @Test - public void deleteMapping_whenTryingToDeleteCustomRole_shouldReturnNoContent() throws Exception { - userSession.logIn().setSystemAdministrator(); - mockMvc - .perform(delete(GITHUB_PERMISSIONS_ENDPOINT + "/" + GITHUB_ROLE)) - .andExpect( - status().isNoContent()); - - verify(githubPermissionsMappingService).deletePermissionMappings(GITHUB_ROLE); - } - - @Test - public void createMapping_whenNotAdmin_shouldReturnForbidden() throws Exception { - userSession.logIn().setNonSystemAdministrator(); - mockMvc - .perform( - post(GITHUB_PERMISSIONS_ENDPOINT) - .contentType(APPLICATION_JSON_VALUE) - .content(gson.toJson(GITHUB_PERMISSIONS_MAPPING_POST_REQUEST))) - .andExpectAll( - status().isForbidden(), - content().json("{\"message\":\"Insufficient privileges\"}")); - } - - @Test - public void createMapping_whenRoleExists_shouldReturnBadRequest() throws Exception { - userSession.logIn().setSystemAdministrator(); - - when(githubPermissionsMappingService.createPermissionMapping(any())) - .thenThrow(new IllegalArgumentException("Exception message")); - - mockMvc - .perform( - post(GITHUB_PERMISSIONS_ENDPOINT) - .contentType(APPLICATION_JSON_VALUE) - .content(gson.toJson(GITHUB_PERMISSIONS_MAPPING_POST_REQUEST))) - .andExpectAll( - status().isBadRequest(), - content().json("{\"message\":\"Exception message\"}")); - } - - @Test - public void createMapping_whenMissingPermission_shouldReturnBadRequest() throws Exception { - userSession.logIn().setSystemAdministrator(); - - mockMvc - .perform( - post(GITHUB_PERMISSIONS_ENDPOINT) - .contentType(APPLICATION_JSON_VALUE) - .content(""" - { - "githubRole": "customRole", - "permissions": { - "user": false, - "codeViewer": false, - "issueAdmin": false, - "securityHotspotAdmin": false, - "admin": false - } - } - """)) - .andExpectAll( - status().isBadRequest(), - content().json("{\"message\":\"Value {} for field permissions.scan was rejected. Error: must not be null.\"}")); - } - - @Test - public void createMapping_whenWrongType_shouldReturnBadRequest() throws Exception { - userSession.logIn().setSystemAdministrator(); - - mockMvc - .perform( - post(GITHUB_PERMISSIONS_ENDPOINT) - .contentType(APPLICATION_JSON_VALUE) - .content(""" - { - "githubRole": "customRole", - "permissions": { - "user": false, - "codeViewer": false, - "issueAdmin": true, - "securityHotspotAdmin": false, - "admin": true, - "scan": "notABooleanType" - } - } - """)) - .andExpect(status().isBadRequest()); - } - @Test - public void createMapping_whenValidRequest_shouldReturnMapping() throws Exception { - userSession.logIn().setSystemAdministrator(); - - GithubPermissionsMapping githubPermissionsMapping = new GithubPermissionsMapping(GITHUB_ROLE, false, new SonarqubePermissions(true, true, true, true, true, true)); - when(githubPermissionsMappingService.createPermissionMapping(githubPermissionsMapping)).thenReturn(githubPermissionsMapping); - - MvcResult mvcResult = mockMvc - .perform( - post(GITHUB_PERMISSIONS_ENDPOINT) - .contentType(APPLICATION_JSON_VALUE) - .content(gson.toJson(GITHUB_PERMISSIONS_MAPPING_POST_REQUEST))) - .andExpect(status().isOk()) - .andReturn(); - - RestGithubPermissionsMapping response = gson.fromJson(mvcResult.getResponse().getContentAsString(), RestGithubPermissionsMapping.class); - - RestGithubPermissionsMapping expectedResponse = new RestGithubPermissionsMapping(GITHUB_ROLE, GITHUB_ROLE, false, new RestPermissions(true, true, true, true, true, true)); - assertThat(response).isEqualTo(expectedResponse); - - } - -} diff --git a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/ControllerTester.java b/server/sonar-webserver-webapi-v2/src/testFixtures/java/org/sonar/server/v2/api/ControllerTester.java similarity index 100% rename from server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/api/ControllerTester.java rename to server/sonar-webserver-webapi-v2/src/testFixtures/java/org/sonar/server/v2/api/ControllerTester.java diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 7345e963bf0..c80ef2ed1e8 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -75,6 +75,7 @@ import org.sonar.server.branch.ws.BranchWsModule; import org.sonar.server.ce.CeModule; import org.sonar.server.ce.projectdump.ProjectExportWsModule; import org.sonar.server.ce.ws.CeWsModule; +import org.sonar.server.common.github.permissions.GithubPermissionsMappingService; import org.sonar.server.component.ComponentCleanerService; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.ComponentService; @@ -548,6 +549,7 @@ public class PlatformLevel4 extends PlatformLevel { GithubApplicationHttpClientImpl.class, GithubProvisioningConfigValidator.class, GithubProvisioningWs.class, + GithubPermissionsMappingService.class, BitbucketCloudRestClientConfiguration.class, BitbucketServerRestClient.class, GitlabHttpClient.class, -- 2.39.5