diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2019-12-06 10:11:44 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2020-01-13 20:46:26 +0100 |
commit | 114efaae21bbf1c8a42c4f17627a0496ce65a2be (patch) | |
tree | de96bdc924b5d4a226b974388554030dfc3df6eb /server/sonar-server-common | |
parent | b8d394da901488b5493e95c0bf98d0ff1139de09 (diff) | |
download | sonarqube-114efaae21bbf1c8a42c4f17627a0496ce65a2be.tar.gz sonarqube-114efaae21bbf1c8a42c4f17627a0496ce65a2be.zip |
SONAR-12725 drop manual vulnerabilities
* drop manual vulnerabilities
* remove issues `from_hotspot` column usage
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsManualVulnerability.java | 36 | ||||
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsNotHotspot.java (renamed from server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsNotHotspotNorManualVulnerability.java) | 4 | ||||
-rw-r--r-- | server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java | 64 | ||||
-rw-r--r-- | server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowForSecurityHotspotsTest.java | 125 |
4 files changed, 23 insertions, 206 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsManualVulnerability.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsManualVulnerability.java deleted file mode 100644 index 7a465d01406..00000000000 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsManualVulnerability.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 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.issue.workflow; - -import org.sonar.api.issue.Issue; -import org.sonar.api.rules.RuleType; -import org.sonar.core.issue.DefaultIssue; - -/** - * The vulnerability originally come from a hotspot that was moved to vulnerability by a security auditor. - */ -enum IsManualVulnerability implements Condition { - INSTANCE; - - @Override - public boolean matches(Issue issue) { - return ((DefaultIssue) issue).type() == RuleType.VULNERABILITY && ((DefaultIssue) issue).isFromHotspot(); - } -} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsNotHotspotNorManualVulnerability.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsNotHotspot.java index bf0c43078df..7e086119622 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsNotHotspotNorManualVulnerability.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IsNotHotspot.java @@ -23,11 +23,11 @@ import org.sonar.api.issue.Issue; import org.sonar.api.rules.RuleType; import org.sonar.core.issue.DefaultIssue; -enum IsNotHotspotNorManualVulnerability implements Condition { +enum IsNotHotspot implements Condition { INSTANCE; @Override public boolean matches(Issue issue) { - return ((DefaultIssue) issue).type() != RuleType.SECURITY_HOTSPOT && !((DefaultIssue) issue).isFromHotspot(); + return ((DefaultIssue) issue).type() != RuleType.SECURITY_HOTSPOT; } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java index fd7046b917a..c8c56bb9dc6 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java @@ -75,31 +75,31 @@ public class IssueWorkflow implements Startable { // confirm .transition(Transition.builder(DefaultTransitions.CONFIRM) .from(STATUS_OPEN).to(STATUS_CONFIRMED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(null)) .build()) .transition(Transition.builder(DefaultTransitions.CONFIRM) .from(STATUS_REOPENED).to(STATUS_CONFIRMED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(null)) .build()) // resolve as fixed .transition(Transition.builder(DefaultTransitions.RESOLVE) .from(STATUS_OPEN).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_FIXED)) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) .transition(Transition.builder(DefaultTransitions.RESOLVE) .from(STATUS_REOPENED).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_FIXED)) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) .transition(Transition.builder(DefaultTransitions.RESOLVE) .from(STATUS_CONFIRMED).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_FIXED)) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) @@ -107,31 +107,31 @@ public class IssueWorkflow implements Startable { // reopen .transition(Transition.builder(DefaultTransitions.UNCONFIRM) .from(STATUS_CONFIRMED).to(STATUS_REOPENED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(null)) .build()) .transition(Transition.builder(DefaultTransitions.REOPEN) .from(STATUS_RESOLVED).to(STATUS_REOPENED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(null)) .build()) // resolve as false-positive .transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE) .from(STATUS_OPEN).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_FALSE_POSITIVE), UnsetAssignee.INSTANCE) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) .transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE) .from(STATUS_REOPENED).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_FALSE_POSITIVE), UnsetAssignee.INSTANCE) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) .transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE) .from(STATUS_CONFIRMED).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_FALSE_POSITIVE), UnsetAssignee.INSTANCE) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) @@ -139,19 +139,19 @@ public class IssueWorkflow implements Startable { // resolve as won't fix .transition(Transition.builder(DefaultTransitions.WONT_FIX) .from(STATUS_OPEN).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_WONT_FIX), UnsetAssignee.INSTANCE) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) .transition(Transition.builder(DefaultTransitions.WONT_FIX) .from(STATUS_REOPENED).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_WONT_FIX), UnsetAssignee.INSTANCE) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()) .transition(Transition.builder(DefaultTransitions.WONT_FIX) .from(STATUS_CONFIRMED).to(STATUS_RESOLVED) - .conditions(IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(IsNotHotspot.INSTANCE) .functions(new SetResolution(RESOLUTION_WONT_FIX), UnsetAssignee.INSTANCE) .requiredProjectPermission(UserRole.ISSUE_ADMIN) .build()); @@ -165,39 +165,13 @@ public class IssueWorkflow implements Startable { .functions(new SetResolution(RESOLUTION_FIXED)) .requiredProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN) .build()) - .transition(Transition.builder(DefaultTransitions.RESOLVE_AS_REVIEWED) - .from(STATUS_OPEN).to(STATUS_REVIEWED) - .conditions(new HasType(RuleType.VULNERABILITY), IsManualVulnerability.INSTANCE) - .functions(new SetType(RuleType.SECURITY_HOTSPOT), new SetResolution(RESOLUTION_FIXED)) - .requiredProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN) - .build()) - - .transition(Transition.builder(DefaultTransitions.OPEN_AS_VULNERABILITY) - .from(STATUS_REVIEWED).to(STATUS_OPEN) - .conditions(new HasType(RuleType.SECURITY_HOTSPOT)) - .functions(new SetResolution(null), new SetType(RuleType.VULNERABILITY)) - .requiredProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN) - .build()) - .transition(Transition.builder(DefaultTransitions.OPEN_AS_VULNERABILITY) - .from(STATUS_TO_REVIEW).to(STATUS_OPEN) - .conditions(new HasType(RuleType.SECURITY_HOTSPOT)) - .functions(new SetType(RuleType.VULNERABILITY)) - .requiredProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN) - .build()) .transition(Transition.builder(DefaultTransitions.RESET_AS_TO_REVIEW) .from(STATUS_REVIEWED).to(STATUS_TO_REVIEW) .conditions(new HasType(RuleType.SECURITY_HOTSPOT)) .functions(new SetResolution(null)) .requiredProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN) - .build()) - .transition(Transition.builder(DefaultTransitions.RESET_AS_TO_REVIEW) - .from(STATUS_OPEN).to(STATUS_TO_REVIEW) - .conditions(new HasType(RuleType.VULNERABILITY), IsManualVulnerability.INSTANCE) - .functions(new SetType(RuleType.SECURITY_HOTSPOT), new SetResolution(null)) - .requiredProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN) - .build()) - ; + .build()); } private static void buildAutomaticTransitions(StateMachine.Builder builder) { @@ -243,7 +217,7 @@ public class IssueWorkflow implements Startable { // Reopen issues that are marked as resolved but that are still alive. .transition(Transition.builder("automaticreopen") .from(STATUS_RESOLVED).to(STATUS_REOPENED) - .conditions(new NotCondition(IsBeingClosed.INSTANCE), new HasResolution(RESOLUTION_FIXED), IsNotHotspotNorManualVulnerability.INSTANCE) + .conditions(new NotCondition(IsBeingClosed.INSTANCE), new HasResolution(RESOLUTION_FIXED), IsNotHotspot.INSTANCE) .functions(new SetResolution(null), UnsetCloseDate.INSTANCE) .automatic() .build()) @@ -253,7 +227,7 @@ public class IssueWorkflow implements Startable { .conditions( new PreviousStatusWas(STATUS_OPEN), new HasResolution(RESOLUTION_REMOVED, RESOLUTION_FIXED), - IsNotHotspotNorManualVulnerability.INSTANCE) + IsNotHotspot.INSTANCE) .functions(RestoreResolutionFunction.INSTANCE, UnsetCloseDate.INSTANCE) .automatic() .build()) @@ -262,7 +236,7 @@ public class IssueWorkflow implements Startable { .conditions( new PreviousStatusWas(STATUS_REOPENED), new HasResolution(RESOLUTION_REMOVED, RESOLUTION_FIXED), - IsNotHotspotNorManualVulnerability.INSTANCE) + IsNotHotspot.INSTANCE) .functions(RestoreResolutionFunction.INSTANCE, UnsetCloseDate.INSTANCE) .automatic() .build()) @@ -271,7 +245,7 @@ public class IssueWorkflow implements Startable { .conditions( new PreviousStatusWas(STATUS_CONFIRMED), new HasResolution(RESOLUTION_REMOVED, RESOLUTION_FIXED), - IsNotHotspotNorManualVulnerability.INSTANCE) + IsNotHotspot.INSTANCE) .functions(RestoreResolutionFunction.INSTANCE, UnsetCloseDate.INSTANCE) .automatic() .build()) @@ -280,7 +254,7 @@ public class IssueWorkflow implements Startable { .conditions( new PreviousStatusWas(STATUS_RESOLVED), new HasResolution(RESOLUTION_REMOVED, RESOLUTION_FIXED), - IsNotHotspotNorManualVulnerability.INSTANCE) + IsNotHotspot.INSTANCE) .functions(RestoreResolutionFunction.INSTANCE, UnsetCloseDate.INSTANCE) .automatic() .build()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowForSecurityHotspotsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowForSecurityHotspotsTest.java index d63b4f6cf3a..5b915f3f6b4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowForSecurityHotspotsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowForSecurityHotspotsTest.java @@ -31,7 +31,6 @@ import org.apache.commons.lang.time.DateUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.api.issue.DefaultTransitions; -import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.core.issue.DefaultIssue; @@ -44,7 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.RESOLUTION_REMOVED; import static org.sonar.api.issue.Issue.STATUS_CLOSED; -import static org.sonar.api.issue.Issue.STATUS_OPEN; import static org.sonar.api.issue.Issue.STATUS_RESOLVED; import static org.sonar.api.issue.Issue.STATUS_REVIEWED; import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW; @@ -93,7 +91,7 @@ public class IssueWorkflowForSecurityHotspotsTest { List<Transition> transitions = underTest.outTransitions(issue); - assertThat(keys(transitions)).containsExactlyInAnyOrder("resolveasreviewed", "openasvulnerability"); + assertThat(keys(transitions)).containsExactlyInAnyOrder("resolveasreviewed"); } @Test @@ -103,17 +101,7 @@ public class IssueWorkflowForSecurityHotspotsTest { List<Transition> transitions = underTest.outTransitions(issue); - assertThat(keys(transitions)).containsExactlyInAnyOrder("openasvulnerability", "resetastoreview"); - } - - @Test - public void list_out_vulnerability_transitions_in_status_open() { - underTest.start(); - DefaultIssue issue = new DefaultIssue().setType(RuleType.VULNERABILITY).setResolution(RESOLUTION_FIXED).setStatus(STATUS_OPEN).setIsFromHotspot(true); - - List<Transition> transitions = underTest.outTransitions(issue); - - assertThat(keys(transitions)).containsExactlyInAnyOrder("resolveasreviewed", "resetastoreview"); + assertThat(keys(transitions)).containsExactlyInAnyOrder("resetastoreview"); } @Test @@ -121,7 +109,6 @@ public class IssueWorkflowForSecurityHotspotsTest { underTest.start(); DefaultIssue issue = new DefaultIssue() .setType(RuleType.SECURITY_HOTSPOT) - .setIsFromHotspot(true) .setStatus(STATUS_TO_REVIEW); boolean result = underTest.doManualTransition(issue, DefaultTransitions.RESOLVE_AS_REVIEWED, IssueChangeContext.createUser(new Date(), "USER1")); @@ -132,45 +119,10 @@ public class IssueWorkflowForSecurityHotspotsTest { } @Test - public void open_as_vulnerability_from_to_review() { - underTest.start(); - DefaultIssue issue = new DefaultIssue() - .setType(RuleType.SECURITY_HOTSPOT) - .setIsFromHotspot(true) - .setStatus(STATUS_TO_REVIEW) - .setResolution(null); - - boolean result = underTest.doManualTransition(issue, DefaultTransitions.OPEN_AS_VULNERABILITY, IssueChangeContext.createUser(new Date(), "USER1")); - - assertThat(result).isTrue(); - assertThat(issue.type()).isEqualTo(RuleType.VULNERABILITY); - assertThat(issue.getStatus()).isEqualTo(Issue.STATUS_OPEN); - assertThat(issue.resolution()).isNull(); - } - - @Test - public void open_as_vulnerability_from_reviewed() { - underTest.start(); - DefaultIssue issue = new DefaultIssue() - .setType(RuleType.SECURITY_HOTSPOT) - .setIsFromHotspot(true) - .setResolution(RESOLUTION_FIXED) - .setStatus(STATUS_REVIEWED); - - boolean result = underTest.doManualTransition(issue, DefaultTransitions.OPEN_AS_VULNERABILITY, IssueChangeContext.createUser(new Date(), "USER1")); - - assertThat(result).isTrue(); - assertThat(issue.type()).isEqualTo(RuleType.VULNERABILITY); - assertThat(issue.getStatus()).isEqualTo(Issue.STATUS_OPEN); - assertThat(issue.resolution()).isNull(); - } - - @Test public void reset_as_to_review_from_reviewed() { underTest.start(); DefaultIssue issue = new DefaultIssue() .setType(RuleType.SECURITY_HOTSPOT) - .setIsFromHotspot(true) .setStatus(STATUS_REVIEWED) .setResolution(RESOLUTION_FIXED); @@ -182,22 +134,6 @@ public class IssueWorkflowForSecurityHotspotsTest { } @Test - public void reset_as_to_review_from_opened_as_vulnerability() { - underTest.start(); - DefaultIssue issue = new DefaultIssue() - .setType(RuleType.VULNERABILITY) - .setIsFromHotspot(true) - .setStatus(STATUS_OPEN) - .setResolution(null); - - boolean result = underTest.doManualTransition(issue, DefaultTransitions.RESET_AS_TO_REVIEW, IssueChangeContext.createUser(new Date(), "USER1")); - assertThat(result).isTrue(); - assertThat(issue.type()).isEqualTo(RuleType.SECURITY_HOTSPOT); - assertThat(issue.getStatus()).isEqualTo(STATUS_TO_REVIEW); - assertThat(issue.resolution()).isNull(); - } - - @Test public void automatically_close_resolved_security_hotspots_in_status_to_review() { underTest.start(); DefaultIssue issue = new DefaultIssue() @@ -236,26 +172,6 @@ public class IssueWorkflowForSecurityHotspotsTest { } @Test - public void automatically_close_hotspots_opened_as_vulnerability() { - underTest.start(); - DefaultIssue issue = new DefaultIssue() - .setType(RuleType.VULNERABILITY) - .setResolution(null) - .setStatus(STATUS_OPEN) - .setIsFromHotspot(true) - .setNew(false) - .setBeingClosed(true); - Date now = new Date(); - - underTest.doAutomaticTransition(issue, IssueChangeContext.createScan(now)); - - assertThat(issue.resolution()).isEqualTo(RESOLUTION_FIXED); - assertThat(issue.status()).isEqualTo(STATUS_CLOSED); - assertThat(issue.closeDate()).isNotNull(); - assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); - } - - @Test @UseDataProvider("allStatusesLeadingToClosed") public void do_not_automatically_reopen_closed_issues_of_security_hotspots(String previousStatus) { DefaultIssue[] issues = Arrays.stream(SUPPORTED_RESOLUTIONS_FOR_UNCLOSING) @@ -292,43 +208,6 @@ public class IssueWorkflowForSecurityHotspotsTest { assertThat(issue.resolution()).isNull(); } - @Test - @UseDataProvider("allStatusesLeadingToClosed") - public void do_not_automatically_reopen_closed_issues_of_manual_vulnerability(String previousStatus) { - DefaultIssue[] issues = Arrays.stream(SUPPORTED_RESOLUTIONS_FOR_UNCLOSING) - .map(resolution -> { - DefaultIssue issue = newClosedIssue(resolution); - setStatusPreviousToClosed(issue, previousStatus); - issue.setIsFromHotspot(true); - return issue; - }) - .toArray(DefaultIssue[]::new); - Date now = new Date(); - underTest.start(); - - Arrays.stream(issues).forEach(issue -> { - underTest.doAutomaticTransition(issue, IssueChangeContext.createScan(now)); - - assertThat(issue.status()).isEqualTo(STATUS_CLOSED); - assertThat(issue.updateDate()).isNull(); - }); - } - - @Test - public void do_not_allow_to_doManualTransition_when_condition_fails() { - underTest.start(); - DefaultIssue issue = new DefaultIssue() - .setKey("ABCDE") - // Detect is only available on hotspot - .setType(RuleType.VULNERABILITY) - .setIsFromHotspot(false) - .setStatus(STATUS_OPEN) - .setResolution(null) - .setRuleKey(XOO_X1); - - assertThat(underTest.doManualTransition(issue, DefaultTransitions.RESET_AS_TO_REVIEW, IssueChangeContext.createScan(new Date()))).isFalse(); - } - private Collection<String> keys(List<Transition> transitions) { return transitions.stream().map(Transition::key).collect(MoreCollectors.toList()); } |