Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1503 Address breaking change from SlCore 10.7 #5735

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);