-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GHAS validation rule - Message must be flattened (#2580)
* Add a GitHub validation rule. * Fix tests * update rule name to FlatternResultMessage * Fix CodeQL warning * Update release history * Rename to ProvideFullyFormattedMessageStrings * rename rule to ProvideFullyFormattedMessageStrings Co-authored-by: Michael C. Fanning <[email protected]>
- Loading branch information
1 parent
ae13732
commit 0e842c2
Showing
13 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
44 changes: 44 additions & 0 deletions
44
src/Sarif.Multitool.Library/Rules/GH1007.ProvideFullyFormattedMessageStrings.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,44 @@ | ||
// 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 ProvideFullyFormattedMessageStrings : SarifValidationSkimmerBase | ||
{ | ||
public override ReportingConfiguration DefaultConfiguration => new ReportingConfiguration | ||
{ | ||
Level = FailureLevel.Error, | ||
Enabled = this.EnabledByDefault | ||
}; | ||
|
||
/// <summary> | ||
/// GH1007 | ||
/// </summary> | ||
public override string Id => RuleId.ProvideFullyFormattedMessageStrings; | ||
|
||
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.GH1007_ProvideFullyFormattedMessageStrings_FullDescription_Text }; | ||
|
||
protected override IEnumerable<string> MessageResourceNames => new string[] { | ||
nameof(RuleResources.GH1007_ProvideFullyFormattedMessageStrings_Error_Default_Text) | ||
}; | ||
|
||
public override bool EnabledByDefault => false; | ||
|
||
protected override void Analyze(Result result, string resultPointer) | ||
{ | ||
if (string.IsNullOrEmpty(result.Message.Text)) | ||
{ | ||
// {0}: The 'text' property of this result message is absent. GitHub Advanced Security code | ||
// scanning will reject this file because it does not support the argumented message now. | ||
// Try to populate the flattened message text in 'message.text' property. | ||
LogResult( | ||
resultPointer.AtProperty(SarifPropertyName.Message), | ||
nameof(RuleResources.GH1007_ProvideFullyFormattedMessageStrings_Error_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
18 changes: 18 additions & 0 deletions
18
src/Sarif.Multitool.Library/Rules/RuleResources.Designer.cs
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
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
72 changes: 72 additions & 0 deletions
72
.../ValidateCommand/ExpectedOutputs/GH1007.ProvideFullyFormattedMessageStrings_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,72 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "SARIF Functional Testing", | ||
"rules": [ | ||
{ | ||
"id": "GH1007", | ||
"name": "ProvideFullyFormattedMessageStrings", | ||
"fullDescription": { | ||
"text": "GitHub Advanced Security code scanning will reject a SARIF file that express result messages with 'message.id' and 'message.arguments' but without the 'message.text' property since the arugmented message format is not supported yet. Please provide fully formatted text in 'message.text' property." | ||
}, | ||
"messageStrings": { | ||
"Error_Default": { | ||
"text": "{0}: The 'text' property of this result message is absent. GitHub Advanced Security code scanning will reject this file because it does not support the argumented message now. Try to provide fully formatted text in 'message.text' property." | ||
} | ||
}, | ||
"defaultConfiguration": { | ||
"enabled": false, | ||
"level": "error" | ||
}, | ||
"helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" | ||
} | ||
] | ||
} | ||
}, | ||
"invocations": [ | ||
{ | ||
"executionSuccessful": true | ||
} | ||
], | ||
"artifacts": [ | ||
{ | ||
"location": { | ||
"uri": "FunctionalTestOutput.ValidateCommand/GH1007.ProvideFullyFormattedMessageStrings_Invalid.sarif", | ||
"uriBaseId": "TEST_DIR" | ||
} | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"ruleId": "GH1007", | ||
"ruleIndex": 0, | ||
"level": "error", | ||
"message": { | ||
"id": "Error_Default", | ||
"arguments": [ | ||
"runs[0].results[0].message" | ||
] | ||
}, | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"index": 0 | ||
}, | ||
"region": { | ||
"startLine": 29, | ||
"startColumn": 22 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
...ol/ValidateCommand/ExpectedOutputs/GH1007.ProvideFullyFormattedMessageStrings_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,28 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "SARIF Functional Testing" | ||
} | ||
}, | ||
"invocations": [ | ||
{ | ||
"executionSuccessful": true | ||
} | ||
], | ||
"artifacts": [ | ||
{ | ||
"location": { | ||
"uri": "FunctionalTestOutput.ValidateCommand/GH1007.ProvideFullyFormattedMessageStrings_Valid.sarif", | ||
"uriBaseId": "TEST_DIR" | ||
} | ||
} | ||
], | ||
"results": [], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
41 changes: 41 additions & 0 deletions
41
...Multitool/ValidateCommand/Inputs/GH1007.ProvideFullyFormattedMessageStrings_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.6.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "SARIF Functional Testing", | ||
"version": "1.2.3", | ||
"rules": [ | ||
{ | ||
"id": "TEST1001", | ||
"fullDescription": { | ||
"text": "Argumented message." | ||
}, | ||
"messageStrings": { | ||
"DoesExist": { | ||
"text": "'{0}' is an apparent access token of '{1}'." | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"results": [ | ||
{ | ||
"ruleId": "TEST1001", | ||
"ruleIndex": 0, | ||
"message": { | ||
"id": "DoesExist", | ||
"arguments": [ | ||
"123456789", | ||
"Alibaba Cloud service" | ||
] | ||
} | ||
} | ||
], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |
31 changes: 31 additions & 0 deletions
31
...a/Multitool/ValidateCommand/Inputs/GH1007.ProvideFullyFormattedMessageStrings_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,31 @@ | ||
{ | ||
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "SARIF Functional Testing", | ||
"version": "1.2.3", | ||
"rules": [ | ||
{ | ||
"id": "TEST1001", | ||
"fullDescription": { | ||
"text": "Argumented message." | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"results": [ | ||
{ | ||
"ruleId": "TEST1001", | ||
"message": { | ||
"text": "'123456789' is an apparent access token of 'Alibaba Cloud service'." | ||
} | ||
} | ||
], | ||
"columnKind": "utf16CodeUnits" | ||
} | ||
] | ||
} |