From 6a29a994884242a240f7385957903bb278504e17 Mon Sep 17 00:00:00 2001 From: Anita Stanisz <106669481+anita-stanisz-sonarsource@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:03:44 +0200 Subject: [PATCH] SONAR-23142 Fix SSF (#12040) --- .../server/issue/ws/AddCommentActionIT.java | 2 +- .../issue/ws/DeleteCommentActionIT.java | 2 +- .../server/issue/ws/DoTransitionActionIT.java | 2 +- .../server/issue/ws/EditCommentActionIT.java | 2 +- .../sonar/server/issue/ws/SearchActionIT.java | 22 ++++ .../server/issue/ws/SetSeverityActionIT.java | 2 +- .../server/issue/ws/SetTagsActionIT.java | 2 +- .../server/issue/ws/SetTypeActionIT.java | 2 +- .../sonar/server/source/ws/LinesActionIT.java | 10 +- .../sonar/server/source/ws/ScmActionIT.java | 24 +++++ .../ws/LinesActionIT/hide_scmAuthors.json | 12 --- .../source/ws/ScmActionIT/hide_author.json | 5 + .../server/issue/ws/AddCommentAction.java | 2 +- .../sonar/server/issue/ws/AssignAction.java | 2 +- .../server/issue/ws/DeleteCommentAction.java | 2 +- .../server/issue/ws/DoTransitionAction.java | 2 +- .../server/issue/ws/EditCommentAction.java | 2 +- .../org/sonar/server/issue/ws/ListAction.java | 2 +- .../issue/ws/OperationResponseWriter.java | 4 +- .../sonar/server/issue/ws/SearchAction.java | 14 ++- .../server/issue/ws/SearchResponseFormat.java | 34 +++--- .../server/issue/ws/SetSeverityAction.java | 2 +- .../sonar/server/issue/ws/SetTagsAction.java | 2 +- .../sonar/server/issue/ws/SetTypeAction.java | 2 +- .../server/source/ws/IssueSnippetsAction.java | 2 +- .../sonar/server/source/ws/LinesAction.java | 2 +- .../server/source/ws/LinesJsonWriter.java | 7 +- .../org/sonar/server/source/ws/ScmAction.java | 9 +- ...archResponseFormatFormatOperationTest.java | 100 ++++++++++-------- 29 files changed, 172 insertions(+), 105 deletions(-) delete mode 100644 server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/LinesActionIT/hide_scmAuthors.json create mode 100644 server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/ScmActionIT/hide_author.json diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/AddCommentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/AddCommentActionIT.java index 1f57f24af9b..2065ae43eba 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/AddCommentActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/AddCommentActionIT.java @@ -113,7 +113,7 @@ public class AddCommentActionIT { call(issueDto.getKey(), "please fix it"); - verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbTester.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DeleteCommentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DeleteCommentActionIT.java index ec99b6bb6b4..da49b5c1618 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DeleteCommentActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DeleteCommentActionIT.java @@ -75,7 +75,7 @@ public class DeleteCommentActionIT { call(commentDto.getKey()); - verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); assertThat(dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey())).isNotPresent(); verifyContentOfPreloadedSearchResponseData(issueDto); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java index d3337046d71..c740e978cc5 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java @@ -125,7 +125,7 @@ public class DoTransitionActionIT { call(issue.getKey(), "confirm"); - verify(responseWriter).write(eq(issue.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issue.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); verifyContentOfPreloadedSearchResponseData(issue); verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any()); IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/EditCommentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/EditCommentActionIT.java index 02419e3f813..fd3a236db30 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/EditCommentActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/EditCommentActionIT.java @@ -86,7 +86,7 @@ public class EditCommentActionIT { call(commentDto.getKey(), "please have a look"); - verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueChangeDto issueComment = dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey()).get(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java index 4f45dd7f188..5be14479c46 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java @@ -1213,6 +1213,7 @@ public class SearchActionIT { @Test public void search_by_author() { + userSession.logIn(); ComponentDto project = db.components().insertPublicProject().getMainBranchComponent(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDto rule = db.rules().insertIssueRule(); @@ -1243,6 +1244,27 @@ public class SearchActionIT { .isEmpty(); } + @Test + public void hide_author_if_not_logged_in() { + ComponentDto project = db.components().insertPublicProject().getMainBranchComponent(); + ComponentDto file = db.components().insertComponent(newFileDto(project)); + RuleDto rule = db.rules().insertIssueRule(); + db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("leia")); + db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("luke")); + db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("han, solo")); + indexPermissionsAndIssues(); + + SearchWsResponse response = ws.newRequest() + .setMultiParam("author", asList("leia", "han, solo")) + .setParam(FACETS, "author") + .executeProtobuf(SearchWsResponse.class); + + assertThat(response.getIssuesList()) + .extracting(Issue::getAuthor) + .containsExactlyInAnyOrder("", ""); + assertThat(response.getFacets().getFacetsList()).isEmpty(); + } + @Test public void filter_by_test_scope() { ProjectData projectData = db.components().insertPublicProject("PROJECT_ID", diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java index 9eca22c0077..68ee1ca0a8f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java @@ -111,7 +111,7 @@ public class SetSeverityActionIT { call(issueDto.getKey(), MINOR); - verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); verifyContentOfPreloadedSearchResponseData(issueDto); verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any()); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTagsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTagsActionIT.java index c53aa00b7eb..c01516e703f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTagsActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTagsActionIT.java @@ -102,7 +102,7 @@ public class SetTagsActionIT { call(issueDto.getKey(), "bug", "todo"); - verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getTags()).containsOnly("bug", "todo"); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java index 02aef358912..80be6b3d1a1 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java @@ -127,7 +127,7 @@ public class SetTypeActionIT { call(issueDto.getKey(), to.name()); - verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); + verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true)); IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getType()).isEqualTo(to.getDbConstant()); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java index 65ff0b8fc14..17b7caf6b89 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java @@ -50,6 +50,7 @@ import org.sonar.server.ws.WsActionTester; import static java.lang.String.format; import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -69,7 +70,8 @@ public class LinesActionIT { private final HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class); private final SourceService sourceService = new SourceService(db.getDbClient(), htmlSourceDecorator); private final LinesJsonWriter linesJsonWriter = new LinesJsonWriter(htmlSourceDecorator); - private final LinesAction underTest = new LinesAction(TestComponentFinder.from(db), db.getDbClient(), sourceService, linesJsonWriter, userSession); + private final LinesAction underTest = new LinesAction(TestComponentFinder.from(db), db.getDbClient(), sourceService, linesJsonWriter, + userSession); private final WsActionTester tester = new WsActionTester(underTest); @Before @@ -363,10 +365,12 @@ public class LinesActionIT { ComponentDto file = insertFileWithData(data, mainBranch); - tester.newRequest() + String response = tester.newRequest() .setParam("uuid", file.uuid()) .execute() - .assertJson(getClass(), "hide_scmAuthors.json"); + .getInput(); + + assertThat(response).doesNotContain("isaac@asimov.com"); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java index 90bff44de7e..e777708e623 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ScmActionIT.java @@ -73,6 +73,7 @@ public class ScmActionIT { @Test public void show_scm() { + userSessionRule.logIn(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto()) .registerBranches(project.getMainBranchDto()); @@ -90,8 +91,28 @@ public class ScmActionIT { .assertJson(getClass(), "show_scm.json"); } + @Test + public void hide_author_if_not_logged_in() { + userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto()) + .registerBranches(project.getMainBranchDto()); + + dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto() + .setUuid(Uuids.createFast()) + .setProjectUuid(PROJECT_UUID) + .setFileUuid(FILE_UUID) + .setSourceData(DbFileSources.Data.newBuilder().addLines( + newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).build())); + dbSession.commit(); + + tester.newRequest() + .setParam("key", FILE_KEY) + .execute() + .assertJson(getClass(), "hide_author.json"); + } + @Test public void show_scm_from_given_range_lines() { + userSessionRule.logIn(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto()) .registerBranches(project.getMainBranchDto()); @@ -117,6 +138,7 @@ public class ScmActionIT { @Test public void not_group_lines_by_commit() { + userSessionRule.logIn(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto()) .registerBranches(project.getMainBranchDto()); @@ -142,6 +164,7 @@ public class ScmActionIT { @Test public void group_lines_by_commit() { + userSessionRule.logIn(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto()) .registerBranches(project.getMainBranchDto()); @@ -167,6 +190,7 @@ public class ScmActionIT { @Test public void accept_negative_value_in_from_parameter() { + userSessionRule.logIn(); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto()) .registerBranches(project.getMainBranchDto()); diff --git a/server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/LinesActionIT/hide_scmAuthors.json b/server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/LinesActionIT/hide_scmAuthors.json deleted file mode 100644 index 2fd47642208..00000000000 --- a/server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/LinesActionIT/hide_scmAuthors.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "sources": [ - { - "line": 1, - "code": "\u003cp\u003eSOURCE_1\u003c/p\u003e", - "scmRevision": "REVISION_1", - "scmDate": "1974-10-03T03:40:00+0100", - "duplicated": false, - "isNew": false - } - ] -} diff --git a/server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/ScmActionIT/hide_author.json b/server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/ScmActionIT/hide_author.json new file mode 100644 index 00000000000..711dd670d7b --- /dev/null +++ b/server/sonar-webserver-webapi/src/it/resources/org/sonar/server/source/ws/ScmActionIT/hide_author.json @@ -0,0 +1,5 @@ +{ + "scm": [ + [1, "","2015-03-30T12:34:56+0000", "123-456-789"] + ] +} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java index d0173ab9795..14b7a96a709 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java @@ -105,7 +105,7 @@ public class AddCommentAction implements IssuesWsAction { DefaultIssue defaultIssue = issueDto.toDefaultIssue(); issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context); SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, issueDto, defaultIssue, context); - responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response); + responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response, true); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java index e3d68704935..4b355cc478a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java @@ -102,7 +102,7 @@ public class AssignAction implements IssuesWsAction { String assignee = getAssignee(request); String key = request.mandatoryParam(PARAM_ISSUE); SearchResponseData preloadedResponseData = assign(key, assignee); - responseWriter.write(key, preloadedResponseData, request, response); + responseWriter.write(key, preloadedResponseData, request, response, true); } private SearchResponseData assign(String issueKey, @Nullable String login) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java index c11eabca601..7d8ffca8cc8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java @@ -88,7 +88,7 @@ public class DeleteCommentAction implements IssuesWsAction { CommentData commentData = loadCommentData(dbSession, request); deleteComment(dbSession, commentData); IssueDto issueDto = commentData.getIssueDto(); - responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response); + responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response, true); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java index 59454a23870..44c3f178c1b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java @@ -119,7 +119,7 @@ public class DoTransitionAction implements IssuesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { IssueDto issueDto = issueFinder.getByKey(dbSession, issue); SearchResponseData preloadedSearchResponseData = doTransition(dbSession, issueDto, request.mandatoryParam(PARAM_TRANSITION)); - responseWriter.write(issue, preloadedSearchResponseData, request, response); + responseWriter.write(issue, preloadedSearchResponseData, request, response, true); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java index 190fa3752e8..f76abc920a2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java @@ -98,7 +98,7 @@ public class EditCommentAction implements IssuesWsAction { CommentData commentData = loadCommentData(dbSession, toWsRequest(request)); updateComment(dbSession, commentData); IssueDto issueDto = commentData.getIssueDto(); - responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response); + responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response, true); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ListAction.java index 4b4421c8578..59f9c72d270 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/ListAction.java @@ -242,7 +242,7 @@ public class ListAction implements IssuesWsAction { Paging paging = forPageIndex(request.page) .withPageSize(request.pageSize) .andTotal(request.pageSize); - return searchResponseFormat.formatList(additionalFields, data, paging); + return searchResponseFormat.formatList(additionalFields, data, paging, userSession.isLoggedIn()); } private void collectLoggedInUser(SearchResponseLoader.Collector collector) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/OperationResponseWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/OperationResponseWriter.java index 24d1778e7c0..20d7d359699 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/OperationResponseWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/OperationResponseWriter.java @@ -37,11 +37,11 @@ public class OperationResponseWriter { this.format = format; } - public void write(String issueKey, SearchResponseData preloadedResponseData, Request request, Response response) { + public void write(String issueKey, SearchResponseData preloadedResponseData, Request request, Response response, boolean showAuthor) { SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(singletonList(issueKey)); SearchResponseData data = loader.load(preloadedResponseData, collector, ALL_ADDITIONAL_FIELDS, null); - Issues.Operation responseBody = format.formatOperation(data); + Issues.Operation responseBody = format.formatOperation(data, showAuthor); WsUtils.writeProtobuf(responseBody, request, response); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java index 9caf366a7e5..12ddb6f846c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -557,7 +557,7 @@ public class SearchAction implements IssuesWsAction { // FIXME allow long in Paging Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) getTotalHits(result).value); - return searchResponseFormat.formatSearch(additionalFields, data, paging, facets); + return searchResponseFormat.formatSearch(additionalFields, data, paging, facets, userSession.isLoggedIn()); } private static TotalHits getTotalHits(SearchResponse response) { @@ -565,15 +565,21 @@ public class SearchAction implements IssuesWsAction { "results")); } - private static SearchOptions createSearchOptionsFromRequest(SearchRequest request) { + private SearchOptions createSearchOptionsFromRequest(SearchRequest request) { SearchOptions options = new SearchOptions(); options.setPage(request.getPage(), request.getPageSize()); List facets = request.getFacets(); - if (facets != null && !facets.isEmpty()) { - options.addFacets(facets); + + if (facets == null || facets.isEmpty()) { + return options; } + List requestedFacets = new ArrayList<>(facets); + if (!userSession.isLoggedIn()) { + requestedFacets.remove(PARAM_AUTHOR); + } + options.addFacets(requestedFacets); return options; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java index 49e9e0a6cb0..b04eeee8b66 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java @@ -94,19 +94,21 @@ public class SearchResponseFormat { private final TextRangeResponseFormatter textRangeFormatter; private final UserResponseFormatter userFormatter; - public SearchResponseFormat(Durations durations, Languages languages, TextRangeResponseFormatter textRangeFormatter, UserResponseFormatter userFormatter) { + public SearchResponseFormat(Durations durations, Languages languages, TextRangeResponseFormatter textRangeFormatter, + UserResponseFormatter userFormatter) { this.durations = durations; this.languages = languages; this.textRangeFormatter = textRangeFormatter; this.userFormatter = userFormatter; } - SearchWsResponse formatSearch(Set fields, SearchResponseData data, Paging paging, Facets facets) { + SearchWsResponse formatSearch(Set fields, SearchResponseData data, Paging paging, Facets facets, + boolean showAuthor) { SearchWsResponse.Builder response = SearchWsResponse.newBuilder(); formatPaging(paging, response); ofNullable(data.getEffortTotal()).ifPresent(response::setEffortTotal); - response.addAllIssues(createIssues(fields, data)); + response.addAllIssues(createIssues(fields, data, showAuthor)); response.addAllComponents(formatComponents(data)); formatFacets(data, facets, response); if (fields.contains(SearchAdditionalField.RULES)) { @@ -121,23 +123,23 @@ public class SearchResponseFormat { return response.build(); } - Issues.ListWsResponse formatList(Set fields, SearchResponseData data, Paging paging) { + Issues.ListWsResponse formatList(Set fields, SearchResponseData data, Paging paging, boolean showAuthor) { Issues.ListWsResponse.Builder response = Issues.ListWsResponse.newBuilder(); response.setPaging(Common.Paging.newBuilder() .setPageIndex(paging.pageIndex()) .setPageSize(data.getIssues().size())); - response.addAllIssues(createIssues(fields, data)); + response.addAllIssues(createIssues(fields, data, showAuthor)); response.addAllComponents(formatComponents(data)); return response.build(); } - Operation formatOperation(SearchResponseData data) { + Operation formatOperation(SearchResponseData data, boolean showAuthor) { Operation.Builder response = Operation.newBuilder(); if (data.getIssues().size() == 1) { IssueDto dto = data.getIssues().get(0); - response.setIssue(createIssue(ALL_ADDITIONAL_FIELDS, data, dto)); + response.setIssue(createIssue(ALL_ADDITIONAL_FIELDS, data, dto, showAuthor)); } response.addAllComponents(formatComponents(data)); response.addAllRules(formatRules(data).getRulesList()); @@ -159,20 +161,20 @@ public class SearchResponseFormat { .setTotal(paging.total()); } - private List createIssues(Collection fields, SearchResponseData data) { + private List createIssues(Collection fields, SearchResponseData data, boolean showAuthor) { return data.getIssues().stream() - .map(dto -> createIssue(fields, data, dto)) + .map(dto -> createIssue(fields, data, dto, showAuthor)) .toList(); } - private Issue createIssue(Collection fields, SearchResponseData data, IssueDto dto) { + private Issue createIssue(Collection fields, SearchResponseData data, IssueDto dto, boolean showAuthor) { Issue.Builder issueBuilder = Issue.newBuilder(); - addMandatoryFieldsToIssueBuilder(issueBuilder, dto, data); + addMandatoryFieldsToIssueBuilder(issueBuilder, dto, data, showAuthor); addAdditionalFieldsToIssueBuilder(fields, data, dto, issueBuilder); return issueBuilder.build(); } - private void addMandatoryFieldsToIssueBuilder(Issue.Builder issueBuilder, IssueDto dto, SearchResponseData data) { + private void addMandatoryFieldsToIssueBuilder(Issue.Builder issueBuilder, IssueDto dto, SearchResponseData data, boolean showAuthor) { issueBuilder.setKey(dto.getKey()); issueBuilder.setType(Common.RuleType.forNumber(dto.getType())); @@ -204,6 +206,7 @@ public class SearchResponseFormat { issueBuilder.setSeverity(Common.Severity.valueOf(dto.getSeverity())); } ofNullable(data.getUserByUuid(dto.getAssigneeUuid())).ifPresent(assignee -> issueBuilder.setAssignee(assignee.getLogin())); + ofNullable(emptyToNull(dto.getResolution())).ifPresent(issueBuilder::setResolution); issueBuilder.setStatus(dto.getStatus()); ofNullable(dto.getIssueStatus()).map(IssueStatus::name).ifPresent(issueBuilder::setIssueStatus); @@ -221,7 +224,9 @@ public class SearchResponseFormat { ofNullable(emptyToNull(dto.getChecksum())).ifPresent(issueBuilder::setHash); completeIssueLocations(dto, issueBuilder, data); - issueBuilder.setAuthor(nullToEmpty(dto.getAuthorLogin())); + if (showAuthor) { + issueBuilder.setAuthor(nullToEmpty(dto.getAuthorLogin())); + } ofNullable(dto.getIssueCreationDate()).map(DateUtils::formatDateTime).ifPresent(issueBuilder::setCreationDate); ofNullable(dto.getIssueUpdateDate()).map(DateUtils::formatDateTime).ifPresent(issueBuilder::setUpdateDate); ofNullable(dto.getIssueCloseDate()).map(DateUtils::formatDateTime).ifPresent(issueBuilder::setCloseDate); @@ -235,7 +240,8 @@ public class SearchResponseFormat { Optional.ofNullable(dto.getCveId()).ifPresent(issueBuilder::setCveId); } - private static void addAdditionalFieldsToIssueBuilder(Collection fields, SearchResponseData data, IssueDto dto, Issue.Builder issueBuilder) { + private static void addAdditionalFieldsToIssueBuilder(Collection fields, SearchResponseData data, IssueDto dto, + Issue.Builder issueBuilder) { if (fields.contains(ACTIONS)) { issueBuilder.setActions(createIssueActions(data, dto)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java index 68f21d732e7..13bbde31fd2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java @@ -109,7 +109,7 @@ public class SetSeverityAction implements IssuesWsAction { String severity = request.mandatoryParam(PARAM_SEVERITY); try (DbSession session = dbClient.openSession(false)) { SearchResponseData preloadedSearchResponseData = setType(session, issueKey, severity); - responseWriter.write(issueKey, preloadedSearchResponseData, request, response); + responseWriter.write(issueKey, preloadedSearchResponseData, request, response, true); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java index 5879340701b..081955fef7b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java @@ -100,7 +100,7 @@ public class SetTagsAction implements IssuesWsAction { String key = request.mandatoryParam(PARAM_ISSUE); List tags = MoreObjects.firstNonNull(request.paramAsStrings(PARAM_TAGS), Collections.emptyList()); SearchResponseData preloadedSearchResponseData = setTags(key, tags); - responseWriter.write(key, preloadedSearchResponseData, request, response); + responseWriter.write(key, preloadedSearchResponseData, request, response, true); } private SearchResponseData setTags(String issueKey, List tags) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java index c14ade37a00..126c3550e94 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java @@ -113,7 +113,7 @@ public class SetTypeAction implements IssuesWsAction { RuleType ruleType = RuleType.valueOf(request.mandatoryParam(PARAM_TYPE)); try (DbSession session = dbClient.openSession(false)) { SearchResponseData preloadedSearchResponseData = setType(session, issueKey, ruleType); - responseWriter.write(issueKey, preloadedSearchResponseData, request, response); + responseWriter.write(issueKey, preloadedSearchResponseData, request, response, true); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java index b84eb6b6229..e805317ae37 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java @@ -147,7 +147,7 @@ public class IssueSnippetsAction implements SourcesWsAction { componentViewerJsonWriter.writeComponentWithoutFav(writer, projectDto, fileDto, branch, pullRequest); componentViewerJsonWriter.writeMeasures(writer, fileDto, dbSession); writer.endObject(); - linesJsonWriter.writeSource(lineSources, writer, periodDateSupplier); + linesJsonWriter.writeSource(lineSources, writer, periodDateSupplier, userSession.isLoggedIn()); writer.endObject(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java index ccea427077d..41a1a0d2517 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java @@ -150,7 +150,7 @@ public class LinesAction implements SourcesWsAction { "No source found for file '%s' (uuid: %s)", file.getKey(), file.uuid()); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); - linesJsonWriter.writeSource(lines, json, periodDateSupplier); + linesJsonWriter.writeSource(lines, json, periodDateSupplier, userSession.isLoggedIn()); json.endObject(); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java index 34bacaed64e..b23bbd65134 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java @@ -34,7 +34,8 @@ public class LinesJsonWriter { this.htmlSourceDecorator = htmlSourceDecorator; } - public void writeSource(Iterable lines, JsonWriter json, Supplier> periodDateSupplier) { + public void writeSource(Iterable lines, JsonWriter json, Supplier> periodDateSupplier, + boolean showAuthor) { Long periodDate = null; json.name("sources").beginArray(); @@ -43,7 +44,9 @@ public class LinesJsonWriter { .prop("line", line.getLine()) .prop("code", htmlSourceDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols())) .prop("scmRevision", line.getScmRevision()); - json.prop("scmAuthor", line.getScmAuthor()); + if (showAuthor) { + json.prop("scmAuthor", line.getScmAuthor()); + } if (line.hasScmDate()) { json.prop("scmDate", DateUtils.formatDateTime(new Date(line.getScmDate()))); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java index a504735a063..36cc9cba062 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java @@ -104,7 +104,8 @@ public class ScmAction implements SourcesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { ComponentDto file = componentFinder.getByKey(dbSession, fileKey); userSession.checkComponentPermission(UserRole.CODEVIEWER, file); - Iterable sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File '%s' has no sources", fileKey); + Iterable sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File " + + "'%s' has no sources", fileKey); try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); writeSource(sourceLines, commitsByLine, json); @@ -113,7 +114,7 @@ public class ScmAction implements SourcesWsAction { } } - private static void writeSource(Iterable lines, boolean showCommitsByLine, JsonWriter json) { + private void writeSource(Iterable lines, boolean showCommitsByLine, JsonWriter json) { json.name("scm").beginArray(); DbFileSources.Line previousLine = null; @@ -121,8 +122,8 @@ public class ScmAction implements SourcesWsAction { for (DbFileSources.Line lineDoc : lines) { if (hasScm(lineDoc) && (!started || showCommitsByLine || !isSameCommit(previousLine, lineDoc))) { json.beginArray() - .value(lineDoc.getLine()) - .value(lineDoc.getScmAuthor()); + .value(lineDoc.getLine()); + json.value(userSession.isLoggedIn() ? lineDoc.getScmAuthor() : ""); json.value(lineDoc.hasScmDate() ? DateUtils.formatDateTime(new Date(lineDoc.getScmDate())) : null); json.value(lineDoc.getScmRevision()); json.endArray(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java index f68802909fa..422f1d870b3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java @@ -24,11 +24,11 @@ import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Set; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mockito.junit.jupiter.MockitoExtension; import org.sonar.api.issue.IssueStatus; import org.sonar.api.resources.Languages; import org.sonar.api.rules.CleanCodeAttribute; @@ -71,54 +71,62 @@ import static org.sonar.db.user.UserTesting.newUserDto; import static org.sonar.server.issue.index.IssueScope.MAIN; import static org.sonar.server.issue.index.IssueScope.TEST; -@RunWith(MockitoJUnitRunner.class) -public class SearchResponseFormatFormatOperationTest { - @Rule - public DbTester db = DbTester.create(); +@ExtendWith(MockitoExtension.class) +class SearchResponseFormatFormatOperationTest { + @RegisterExtension + DbTester db = DbTester.create(); private final Durations durations = new Durations(); private final Languages languages = mock(Languages.class); private final TextRangeResponseFormatter textRangeResponseFormatter = mock(TextRangeResponseFormatter.class); private final UserResponseFormatter userResponseFormatter = mock(UserResponseFormatter.class); private final Common.User user = mock(Common.User.class); - private final SearchResponseFormat searchResponseFormat = new SearchResponseFormat(durations, languages, textRangeResponseFormatter, userResponseFormatter); + private final SearchResponseFormat searchResponseFormat = new SearchResponseFormat(durations, languages, textRangeResponseFormatter, + userResponseFormatter); private SearchResponseData searchResponseData; private IssueDto issueDto; private ComponentDto componentDto; private UserDto userDto; - @Before - public void setUp() { + @BeforeEach + void setUp() { searchResponseData = newSearchResponseDataMainBranch(); } @Test - public void formatOperation_should_add_components_to_response() { - Operation result = searchResponseFormat.formatOperation(searchResponseData); + void formatOperation_should_add_components_to_response() { + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getComponentsList()).hasSize(1); assertThat(result.getComponentsList().get(0).getKey()).isEqualTo(issueDto.getComponentKey()); } @Test - public void formatOperation_should_add_rules_to_response() { - Operation result = searchResponseFormat.formatOperation(searchResponseData); + void formatOperation_should_add_rules_to_response() { + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getRulesList()).hasSize(1); assertThat(result.getRulesList().get(0).getKey()).isEqualTo(issueDto.getRuleKey().toString()); } @Test - public void formatOperation_should_add_users_to_response() { - Operation result = searchResponseFormat.formatOperation(searchResponseData); + void formatOperation_should_add_users_to_response() { + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getUsersList()).hasSize(1); assertThat(result.getUsers(0)).isSameAs(user); } @Test - public void formatOperation_should_add_issue_to_response() { - Operation result = searchResponseFormat.formatOperation(searchResponseData); + void formatOperation_does_not_add_author_to_response_if_showAuthor_false() { + Operation result = searchResponseFormat.formatOperation(searchResponseData, false); + + assertThat(result.getIssue().getAuthor()).isEmpty(); + } + + @Test + void formatOperation_should_add_issue_to_response() { + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertIssueEqualsIssueDto(result.getIssue(), issueDto); } @@ -155,10 +163,10 @@ public class SearchResponseFormatFormatOperationTest { } @Test - public void formatOperation_should_not_add_issue_when_several_issue() { + void formatOperation_should_not_add_issue_when_several_issue() { searchResponseData = new SearchResponseData(List.of(createIssue(), createIssue())); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue()).isEqualTo(Issue.getDefaultInstance()); } @@ -172,86 +180,86 @@ public class SearchResponseFormatFormatOperationTest { } @Test - public void formatOperation_should_add_branch_on_issue() { + void formatOperation_should_add_branch_on_issue() { String branchName = randomAlphanumeric(5); searchResponseData = newSearchResponseDataBranch(branchName); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getBranch()).isEqualTo(branchName); } @Test - public void formatOperation_should_add_pullrequest_on_issue() { + void formatOperation_should_add_pullrequest_on_issue() { searchResponseData = newSearchResponseDataPr("pr1"); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getPullRequest()).isEqualTo("pr1"); } @Test - public void formatOperation_should_add_project_on_issue() { + void formatOperation_should_add_project_on_issue() { issueDto.setProjectUuid(componentDto.uuid()); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getProject()).isEqualTo(componentDto.getKey()); } @Test - public void formatOperation_should_add_external_rule_engine_on_issue() { + void formatOperation_should_add_external_rule_engine_on_issue() { issueDto.setExternal(true); String expected = randomAlphanumeric(5); issueDto.setRuleKey(EXTERNAL_RULE_REPO_PREFIX + expected, randomAlphanumeric(5)); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getExternalRuleEngine()).isEqualTo(expected); } @Test - public void formatOperation_should_add_effort_and_debt_on_issue() { + void formatOperation_should_add_effort_and_debt_on_issue() { long effort = 60L; issueDto.setEffort(effort); String expected = durations.encode(Duration.create(effort)); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getEffort()).isEqualTo(expected); assertThat(result.getIssue().getDebt()).isEqualTo(expected); } @Test - public void formatOperation_should_add_scope_test_on_issue_when_unit_test_file() { + void formatOperation_should_add_scope_test_on_issue_when_unit_test_file() { componentDto.setQualifier(UNIT_TEST_FILE); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getScope()).isEqualTo(TEST.name()); } @Test - public void formatOperation_should_add_scope_main_on_issue_when_not_unit_test_file() { + void formatOperation_should_add_scope_main_on_issue_when_not_unit_test_file() { componentDto.setQualifier(randomAlphanumeric(5)); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getScope()).isEqualTo(MAIN.name()); } @Test - public void formatOperation_should_add_actions_on_issues() { + void formatOperation_should_add_actions_on_issues() { Set expectedActions = Set.of("actionA", "actionB"); searchResponseData.addActions(issueDto.getKey(), expectedActions); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getActions().getActionsList()).containsExactlyInAnyOrderElementsOf(expectedActions); } @Test - public void formatOperation_should_add_transitions_on_issues() { + void formatOperation_should_add_transitions_on_issues() { Set expectedTransitions = Set.of("transitionone", "transitiontwo"); searchResponseData.addTransitions(issueDto.getKey(), createFakeTransitions(expectedTransitions)); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getTransitions().getTransitionsList()).containsExactlyInAnyOrderElementsOf(expectedTransitions); } @@ -263,30 +271,30 @@ public class SearchResponseFormatFormatOperationTest { } @Test - public void formatOperation_should_add_comments_on_issues() { + void formatOperation_should_add_comments_on_issues() { IssueChangeDto issueChangeDto = newIssueChangeDto(issueDto); searchResponseData.setComments(List.of(issueChangeDto)); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getComments().getCommentsList()).hasSize(1).extracting(Common.Comment::getKey).containsExactly(issueChangeDto.getKey()); } @Test - public void formatOperation_should_not_set_severity_for_security_hotspot_issue() { + void formatOperation_should_not_set_severity_for_security_hotspot_issue() { issueDto.setType(SECURITY_HOTSPOT); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().hasSeverity()).isFalse(); } @Test - public void formatOperation_shouldReturnExpectedIssueStatus() { + void formatOperation_shouldReturnExpectedIssueStatus() { issueDto.setStatus(org.sonar.api.issue.Issue.STATUS_RESOLVED); issueDto.setResolution(org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX); - Operation result = searchResponseFormat.formatOperation(searchResponseData); + Operation result = searchResponseFormat.formatOperation(searchResponseData, true); assertThat(result.getIssue().getIssueStatus()).isEqualTo(IssueStatus.ACCEPTED.name()); } -- 2.39.5