Skip to content

Commit

Permalink
SLVS-1503 Fix breaking change in SlCore caused by renaming parameter …
Browse files Browse the repository at this point in the history
…issuesByFileUri to hotspotsByFileUri in raiseHotspots method.
  • Loading branch information
gabriela-trutan-sonarsource authored and vnaskos-sonar committed Oct 10, 2024
1 parent 6498da7 commit 811c7d3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void RaiseIssues_RaisesFinding()
[TestMethod]
public void RaiseHotspots_RaisesFinding()
{
var raiseIssueParams = new RaiseFindingParams<RaisedHotspotDto>(default, default, default, default);
var raiseIssueParams = new RaiseHotspotParams(default, default, default, default);
var raisedFindingProcessor = Substitute.For<IRaisedFindingProcessor>();
var testSubject = CreateTestSubject(raisedFindingProcessor: raisedFindingProcessor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public void DidChangeAnalysisReadiness(DidChangeAnalysisReadinessParams paramete
public void RaiseIssues(RaiseFindingParams<RaisedIssueDto> parameters)
=> raisedFindingProcessor.RaiseFinding(parameters);

public void RaiseHotspots(RaiseFindingParams<RaisedHotspotDto> parameters)
public void RaiseHotspots(RaiseHotspotParams parameters)
=> raisedFindingProcessor.RaiseFinding(parameters);
}
78 changes: 78 additions & 0 deletions src/SLCore.UnitTests/Listener/Analysis/RaiseIssuesParamsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,82 @@ [new ImpactDto(SoftwareQuality.SECURITY, ImpactSeverity.HIGH)],
deserialized.Should().BeEquivalentTo(expected, options =>
options.ComparingByMembers<RaiseFindingParams<RaisedIssueDto>>().ComparingByMembers<RaisedIssueDto>());
}

[TestMethod]
public void RaiseHotspotParams_DeserializedCorrectly()
{
var expected = new RaiseHotspotParams("SLVS_Bound_VS2019",
new Dictionary<FileUri, List<RaisedHotspotDto>>
{
{
new FileUri("file:///C:/Users/developer/Documents/Repos/sonarlint-visualstudio-sampleprojects%20AAA%20ЖЖЖЖ/bound/sonarcloud/SLVS_Samples_Bound_VS2019/Secrets/ShouldExclude/Excluded.yml"),
[new RaisedHotspotDto(Guid.Parse("10bd4422-7d55-402f-889c-e080dbe4c781"),
null,
"secrets:S6336",
"Make sure this Alibaba Cloud Access Key Secret gets revoked, changed, and removed from the code.",
IssueSeverity.BLOCKER,
RuleType.VULNERABILITY,
CleanCodeAttribute.TRUSTWORTHY,
[new ImpactDto(SoftwareQuality.SECURITY, ImpactSeverity.HIGH)],
DateTimeOffset.FromUnixTimeMilliseconds(1718182975467),
true,
false,
new TextRangeDto(14, 24, 14, 54),
[],
[],
null,
VulnerabilityProbability.HIGH,
HotspotStatus.TO_REVIEW)]
}
},
false,
Guid.Parse("11ec4b5a-8ff6-4211-ab95-8c16eb8c7f0a"));

var serialized =
"""
{
"configurationScopeId": "SLVS_Bound_VS2019",
"hotspotsByFileUri": {
"file:///C:/Users/developer/Documents/Repos/sonarlint-visualstudio-sampleprojects%20AAA%20ЖЖЖЖ/bound/sonarcloud/SLVS_Samples_Bound_VS2019/Secrets/ShouldExclude/Excluded.yml": [
{
"id": "10bd4422-7d55-402f-889c-e080dbe4c781",
"serverKey": null,
"ruleKey": "secrets:S6336",
"primaryMessage": "Make sure this Alibaba Cloud Access Key Secret gets revoked, changed, and removed from the code.",
"severity": "BLOCKER",
"type": "VULNERABILITY",
"cleanCodeAttribute": "TRUSTWORTHY",
"impacts": [
{
"softwareQuality": "SECURITY",
"impactSeverity": "HIGH"
}
],
"introductionDate": 1718182975467,
"isOnNewCode": true,
"resolved": false,
"textRange": {
"startLine": 14,
"startLineOffset": 24,
"endLine": 14,
"endLineOffset": 54
},
"flows": [],
"quickFixes": [],
"ruleDescriptionContextKey": null,
"vulnerabilityProbability": "HIGH",
"status": "TO_REVIEW"
}
]
},
"isIntermediatePublication": false,
"analysisId": "11ec4b5a-8ff6-4211-ab95-8c16eb8c7f0a"
}
""";

var deserialized = JsonConvert.DeserializeObject<RaiseHotspotParams>(serialized);

deserialized.Should().BeEquivalentTo(expected, options =>
options.ComparingByMembers<RaiseHotspotParams>().ComparingByMembers<RaisedHotspotDto>());
}
}
2 changes: 1 addition & 1 deletion src/SLCore/Listener/Analysis/IAnalysisListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ internal interface IAnalysisListener : ISLCoreListener

void RaiseIssues(RaiseFindingParams<RaisedIssueDto> parameters);

void RaiseHotspots(RaiseFindingParams<RaisedHotspotDto> parameters);
void RaiseHotspots(RaiseHotspotParams parameters);
}
7 changes: 7 additions & 0 deletions src/SLCore/Listener/Analysis/RaiseFindingParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@
namespace SonarLint.VisualStudio.SLCore.Listener.Analysis;

public record RaiseFindingParams<T>(string configurationScopeId, Dictionary<FileUri, List<T>> issuesByFileUri, bool isIntermediatePublication, Guid? analysisId) where T : RaisedFindingDto;

public record RaiseHotspotParams(
string configurationScopeId,
Dictionary<FileUri, List<RaisedHotspotDto>> hotspotsByFileUri,
bool isIntermediatePublication,
Guid? analysisId)
: RaiseFindingParams<RaisedHotspotDto>(configurationScopeId, hotspotsByFileUri, isIntermediatePublication, analysisId);

0 comments on commit 811c7d3

Please sign in to comment.