-
Notifications
You must be signed in to change notification settings - Fork 94
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
Adding Rule SARIF2011 #1948
Merged
eddynaka
merged 3 commits into
features/sarif-validation-rules
from
users/ednakamu/sarif-2011
Jun 30, 2020
Merged
Adding Rule SARIF2011 #1948
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Sarif.Multitool/Rules/SARIF2011.ProvideContextRegion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
using Microsoft.Json.Pointer; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules | ||
{ | ||
public class ProvideContextRegion : SarifValidationSkimmerBase | ||
{ | ||
/// <summary> | ||
/// SARIF2011 | ||
/// </summary> | ||
public override string Id => RuleId.ProvideContextRegion; | ||
|
||
/// <summary> | ||
/// Placeholder | ||
/// </summary> | ||
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2011_ProvideContextRegion_FullDescription_Text }; | ||
|
||
protected override IEnumerable<string> MessageResourceNames => new string[] { | ||
nameof(RuleResources.SARIF2011_ProvideContextRegion_Note_Default_Text) | ||
}; | ||
|
||
public override FailureLevel DefaultLevel => FailureLevel.Note; | ||
|
||
protected override void Analyze(Result result, string resultPointer) | ||
{ | ||
if (result.Locations != null) | ||
{ | ||
string locationsPointer = resultPointer.AtProperty(SarifPropertyName.Locations); | ||
for (int i = 0; i < result.Locations.Count; i++) | ||
{ | ||
AnalyzeLocation(result.Locations[i], locationsPointer.AtIndex(i)); | ||
} | ||
} | ||
} | ||
|
||
private void AnalyzeLocation(Location location, string locationPointer) | ||
{ | ||
if (location.PhysicalLocation?.Region != null) | ||
{ | ||
if (location.PhysicalLocation?.ContextRegion == null) | ||
{ | ||
string physicalLocationPointer = locationPointer.AtProperty(SarifPropertyName.PhysicalLocation); | ||
|
||
// {0}: Placeholder | ||
LogResult( | ||
physicalLocationPointer, | ||
nameof(RuleResources.SARIF2011_ProvideContextRegion_Note_Default_Text)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ta/Multitool/ValidateCommand/ExpectedOutputs/SARIF2011.ProvideContextRegion_Invalid.sarif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "SARIF Functional Testing", | ||
"rules": [ | ||
{ | ||
"id": "SARIF2011", | ||
"name": "ProvideContextRegion", | ||
"shortDescription": { | ||
"text": "Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text." | ||
}, | ||
"fullDescription": { | ||
"text": "Placeholder_SARIF2011_ProvideContextRegion_FullDescription_Text" | ||
}, | ||
"messageStrings": { | ||
"Note_Default": { | ||
"text": "{0}: Placeholder" | ||
} | ||
}, | ||
"helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" | ||
} | ||
] | ||
} | ||
}, | ||
"invocations": [ | ||
{ | ||
"toolConfigurationNotifications": [ | ||
{ | ||
"message": { | ||
"text": "Rule 'SARIF2002' was explicitly disabled by the user. As result, this tool run cannot be used for compliance or other auditing processes that require a comprehensive analysis." | ||
}, | ||
"descriptor": { | ||
"id": "WRN999.RuleExplicitlyDisabled" | ||
} | ||
}, | ||
{ | ||
"message": { | ||
"text": "Rule 'SARIF2006' was explicitly disabled by the user. As result, this tool run cannot be used for compliance or other auditing processes that require a comprehensive analysis." | ||
}, | ||
"descriptor": { | ||
"id": "WRN999.RuleExplicitlyDisabled" | ||
} | ||
} | ||
], | ||
"executionSuccessful": true | ||
} | ||
], | ||
"artifacts": [ | ||
{ | ||
"location": { | ||
"uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF2011.ProvideContextRegion_Invalid.sarif", | ||
"uriBaseId": "TEST_DIR" | ||
} | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"ruleId": "SARIF2011", | ||
"ruleIndex": 0, | ||
"level": "note", | ||
"message": { | ||
"id": "Note_Default", | ||
"arguments": [ | ||
"runs[0].results[0].locations[0].physicalLocation" | ||
] | ||
}, | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"index": 0 | ||
}, | ||
"region": { | ||
"startLine": 26, | ||
"startColumn": 35 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
46 changes: 46 additions & 0 deletions
46
...Data/Multitool/ValidateCommand/ExpectedOutputs/SARIF2011.ProvideContextRegion_Valid.sarif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "SARIF Functional Testing" | ||
} | ||
}, | ||
"invocations": [ | ||
{ | ||
"toolConfigurationNotifications": [ | ||
{ | ||
"message": { | ||
"text": "Rule 'SARIF2002' was explicitly disabled by the user. As result, this tool run cannot be used for compliance or other auditing processes that require a comprehensive analysis." | ||
}, | ||
"descriptor": { | ||
"id": "WRN999.RuleExplicitlyDisabled" | ||
} | ||
}, | ||
{ | ||
"message": { | ||
"text": "Rule 'SARIF2006' was explicitly disabled by the user. As result, this tool run cannot be used for compliance or other auditing processes that require a comprehensive analysis." | ||
}, | ||
"descriptor": { | ||
"id": "WRN999.RuleExplicitlyDisabled" | ||
} | ||
} | ||
], | ||
"executionSuccessful": true | ||
} | ||
], | ||
"artifacts": [ | ||
{ | ||
"location": { | ||
"uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF2011.ProvideContextRegion_Valid.sarif", | ||
"uriBaseId": "TEST_DIR" | ||
} | ||
} | ||
], | ||
"results": [], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
41 changes: 41 additions & 0 deletions
41
...if/TestData/Multitool/ValidateCommand/Inputs/SARIF2011.ProvideContextRegion_Invalid.sarif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "CodeScanner", | ||
"version": "1.0" | ||
} | ||
}, | ||
"versionControlProvenance": [ | ||
{ | ||
"repositoryUri": "https://github.com/microsoft/sarif-sdk" | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"ruleId": "TST0001", | ||
"level": "error", | ||
"message": { | ||
"text": "Some testing occurred." | ||
}, | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "src/test.c" | ||
}, | ||
"region": { | ||
"startLine": 3 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
45 changes: 45 additions & 0 deletions
45
...arif/TestData/Multitool/ValidateCommand/Inputs/SARIF2011.ProvideContextRegion_Valid.sarif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "CodeScanner", | ||
"version": "1.0" | ||
} | ||
}, | ||
"versionControlProvenance": [ | ||
{ | ||
"repositoryUri": "https://github.com/microsoft/sarif-sdk" | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"ruleId": "TST0001", | ||
"level": "error", | ||
"message": { | ||
"text": "Some testing occurred." | ||
}, | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "src/test.c" | ||
}, | ||
"region": { | ||
"startLine": 3 | ||
}, | ||
"contextRegion": { | ||
"startLine": 2, | ||
"endLine": 4 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, this necessary because
SARIF2003.ProvideVersionControlProvenance
is"note"-level and so is this rule. #ByDesign