From 7d0a1f2f2b3a6ad00ad2ba01b3460f38f8126ed2 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 16:05:02 -0700 Subject: [PATCH 1/5] renaming ruleid and tested --- src/Sarif.Multitool/Rules/RuleId.cs | 2 +- .../Rules/RuleResources.Designer.cs | 51 ++++++++++--------- src/Sarif.Multitool/Rules/RuleResources.resx | 4 +- ...SARIF1004.UriBaseIdRequiresRelativeUri.cs} | 6 +-- .../Multitool/ValidateCommandTests.cs | 4 +- ...riBaseIdRequiresRelativeUri_Invalid.sarif} | 42 +++++++-------- ....UriBaseIdRequiresRelativeUri_Valid.sarif} | 2 +- ...riBaseIdRequiresRelativeUri_Invalid.sarif} | 0 ....UriBaseIdRequiresRelativeUri_Valid.sarif} | 0 9 files changed, 58 insertions(+), 53 deletions(-) rename src/Sarif.Multitool/Rules/{SARIF1014.UriBaseIdRequiresRelativeUri.cs => SARIF1004.UriBaseIdRequiresRelativeUri.cs} (86%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif => SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif} (94%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif => SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif} (91%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif => SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif} (100%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif => SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif} (100%) diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index 9d4816de4..fd8428a8d 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -10,7 +10,7 @@ public static class RuleId public const string InvocationPropertiesMustBeConsistent = "SARIF1006"; public const string AuthorHighQualityMessages = "SARIF2001"; public const string RegionPropertiesMustBeConsistent = "SARIF1007"; - public const string UriBaseIdRequiresRelativeUri = "SARIF1014"; + public const string UriBaseIdRequiresRelativeUri = "SARIF1004"; public const string UriMustBeAbsolute = "SARIF1005"; public const string PhysicalLocationPropertiesMustBeConsistent = "SARIF1008"; public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009"; diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index e878b8b77..1df5c8a1a 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -96,6 +96,24 @@ internal static string SARIF1002_UrisMustBeValid_FullDescription_Text { } } + /// + /// Looks up a localized string similar to {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference.. + /// + internal static string SARIF1004_Default { + get { + return ResourceManager.GetString("SARIF1004_Default", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference.. + /// + internal static string SARIF1004_UriBaseIdRequiresRelativeUri { + get { + return ResourceManager.GetString("SARIF1004_UriBaseIdRequiresRelativeUri", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0}: The value of this property is required to be an absolute URI, but "{1}" is a relative URI reference.. /// @@ -138,7 +156,8 @@ internal static string SARIF1006_InvocationPropertiesMustBeConsistent_FullDescri /// internal static string SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColumnMustNotPrecedeStartColumn_Text { get { - return ResourceManager.GetString("SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColumnMustNotPrecedeStartColumn_Text", resourceCulture); + return ResourceManager.GetString("SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColumnMustNotPrecedeStartColu" + + "mn_Text", resourceCulture); } } @@ -147,7 +166,8 @@ internal static string SARIF1007_RegionPropertiesMustBeConsistent_Error_EndColum /// internal static string SARIF1007_RegionPropertiesMustBeConsistent_Error_EndLineMustNotPrecedeStartLine_Text { get { - return ResourceManager.GetString("SARIF1007_RegionPropertiesMustBeConsistent_Error_EndLineMustNotPrecedeStartLine_Text", resourceCulture); + return ResourceManager.GetString("SARIF1007_RegionPropertiesMustBeConsistent_Error_EndLineMustNotPrecedeStartLine_T" + + "ext", resourceCulture); } } @@ -165,7 +185,8 @@ internal static string SARIF1007_RegionPropertiesMustBeConsistent_FullDescriptio /// internal static string SARIF1008_PhysicalLocationPropertiesMustBeConsistent_Error_ContextRegionRequiresRegion_Text { get { - return ResourceManager.GetString("SARIF1008_PhysicalLocationPropertiesMustBeConsistent_Error_ContextRegionRequiresRegion_Text", resourceCulture); + return ResourceManager.GetString("SARIF1008_PhysicalLocationPropertiesMustBeConsistent_Error_ContextRegionRequiresR" + + "egion_Text", resourceCulture); } } @@ -183,7 +204,8 @@ internal static string SARIF1008_PhysicalLocationPropertiesMustBeConsistent_Full /// internal static string SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error_TargetArrayMustBeLongEnough_Text { get { - return ResourceManager.GetString("SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error_TargetArrayMustBeLongEnough_Text", resourceCulture); + return ResourceManager.GetString("SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error_TargetArrayMustBeLongEn" + + "ough_Text", resourceCulture); } } @@ -192,7 +214,8 @@ internal static string SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error /// internal static string SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error_TargetArrayMustExist_Text { get { - return ResourceManager.GetString("SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error_TargetArrayMustExist_Text", resourceCulture); + return ResourceManager.GetString("SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Error_TargetArrayMustExist_Te" + + "xt", resourceCulture); } } @@ -250,24 +273,6 @@ internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { } } - /// - /// Looks up a localized string similar to {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference.. - /// - internal static string SARIF1014_Default { - get { - return ResourceManager.GetString("SARIF1014_Default", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference.. - /// - internal static string SARIF1014_UriBaseIdRequiresRelativeUri { - get { - return ResourceManager.GetString("SARIF1014_UriBaseIdRequiresRelativeUri", resourceCulture); - } - } - /// /// Looks up a localized string similar to In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file.. /// diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index 5bee270fe..f3159f411 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -141,10 +141,10 @@ Messages should consist of one or more complete sentences, ending with a period. - + {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference. - + If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference. diff --git a/src/Sarif.Multitool/Rules/SARIF1014.UriBaseIdRequiresRelativeUri.cs b/src/Sarif.Multitool/Rules/SARIF1004.UriBaseIdRequiresRelativeUri.cs similarity index 86% rename from src/Sarif.Multitool/Rules/SARIF1014.UriBaseIdRequiresRelativeUri.cs rename to src/Sarif.Multitool/Rules/SARIF1004.UriBaseIdRequiresRelativeUri.cs index 5a17c83d1..76ce8fc61 100644 --- a/src/Sarif.Multitool/Rules/SARIF1014.UriBaseIdRequiresRelativeUri.cs +++ b/src/Sarif.Multitool/Rules/SARIF1004.UriBaseIdRequiresRelativeUri.cs @@ -10,7 +10,7 @@ public class UriBaseIdRequiresRelativeUri : SarifValidationSkimmerBase { public override MultiformatMessageString FullDescription => new MultiformatMessageString { - Text = RuleResources.SARIF1014_UriBaseIdRequiresRelativeUri + Text = RuleResources.SARIF1004_UriBaseIdRequiresRelativeUri }; public override FailureLevel DefaultLevel => FailureLevel.Error; @@ -19,7 +19,7 @@ public class UriBaseIdRequiresRelativeUri : SarifValidationSkimmerBase protected override IEnumerable MessageResourceNames => new string[] { - nameof(RuleResources.SARIF1014_Default) + nameof(RuleResources.SARIF1004_Default) }; protected override void Analyze(ArtifactLocation fileLocation, string fileLocationPointer) @@ -28,7 +28,7 @@ protected override void Analyze(ArtifactLocation fileLocation, string fileLocati { LogResult( fileLocationPointer.AtProperty(SarifPropertyName.Uri), - nameof(RuleResources.SARIF1014_Default), + nameof(RuleResources.SARIF1004_Default), fileLocation.Uri.OriginalString); } } diff --git a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs index e4f14f192..3aafa83c0 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -80,11 +80,11 @@ public void SARIF1007_RegionPropertiesMustBeConsistent_Invalid() /********** END PROBLEMATIC TESTS*******/ [Fact] - public void SARIF1014_UriBaseIdRequiresRelativeUri_Valid() + public void SARIF1004_UriBaseIdRequiresRelativeUri_Valid() => RunTest(MakeValidTestFileName(RuleId.UriBaseIdRequiresRelativeUri, nameof(RuleId.UriBaseIdRequiresRelativeUri))); [Fact] - public void SARIF1014_UriBaseIdRequiresRelativeUri_Invalid() + public void SARIF1004_UriBaseIdRequiresRelativeUri_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.UriBaseIdRequiresRelativeUri, nameof(RuleId.UriBaseIdRequiresRelativeUri))); [Fact] diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif similarity index 94% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif index c755231b8..f7bbb544c 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif @@ -8,7 +8,7 @@ "name": "SARIF Functional Testing", "rules": [ { - "id": "SARIF1014", + "id": "SARIF1004", "name": "UriBaseIdRequiresRelativeUri", "shortDescription": { "text": "If a fileLocation object contains a \"uriBaseId\" property, the value of the \"uri\" property must be a relative URI reference." @@ -34,14 +34,14 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif", "uriBaseId": "TEST_DIR" } } ], "results": [ { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -66,7 +66,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -91,7 +91,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -116,7 +116,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -141,7 +141,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -166,7 +166,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -191,7 +191,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -216,7 +216,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -241,7 +241,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -266,7 +266,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -291,7 +291,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -316,7 +316,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -341,7 +341,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -366,7 +366,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -391,7 +391,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -416,7 +416,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -441,7 +441,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -466,7 +466,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { @@ -491,7 +491,7 @@ ] }, { - "ruleId": "SARIF1014", + "ruleId": "SARIF1004", "ruleIndex": 0, "level": "error", "message": { diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif similarity index 91% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif index d810bac03..02c48a9ae 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif @@ -16,7 +16,7 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif", "uriBaseId": "TEST_DIR" } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1014.UriBaseIdRequiresRelativeUri_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1014.UriBaseIdRequiresRelativeUri_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif From 904518c4dae5d64073ef69756f30d1b5b9cbca0d Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 16:08:51 -0700 Subject: [PATCH 2/5] rulename changed and tested --- src/Sarif.Multitool/Rules/RuleId.cs | 2 +- src/Sarif.Multitool/Rules/RuleResources.Designer.cs | 4 ++-- src/Sarif.Multitool/Rules/RuleResources.resx | 2 +- ...tiveUri.cs => SARIF1004.ExpressUriBaseIdsCorrectly.cs} | 6 +++--- .../Multitool/ValidateCommandTests.cs | 8 ++++---- ...=> SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif} | 4 ++-- ...f => SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif} | 2 +- ...=> SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif} | 0 ...f => SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif} | 0 9 files changed, 14 insertions(+), 14 deletions(-) rename src/Sarif.Multitool/Rules/{SARIF1004.UriBaseIdRequiresRelativeUri.cs => SARIF1004.ExpressUriBaseIdsCorrectly.cs} (83%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif => SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif} (99%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif => SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif} (91%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif => SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif} (100%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif => SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif} (100%) diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index fd8428a8d..259220877 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -10,7 +10,7 @@ public static class RuleId public const string InvocationPropertiesMustBeConsistent = "SARIF1006"; public const string AuthorHighQualityMessages = "SARIF2001"; public const string RegionPropertiesMustBeConsistent = "SARIF1007"; - public const string UriBaseIdRequiresRelativeUri = "SARIF1004"; + public const string ExpressUriBaseIdsCorrectly = "SARIF1004"; public const string UriMustBeAbsolute = "SARIF1005"; public const string PhysicalLocationPropertiesMustBeConsistent = "SARIF1008"; public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009"; diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 1df5c8a1a..72e41f07f 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -108,9 +108,9 @@ internal static string SARIF1004_Default { /// /// Looks up a localized string similar to If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference.. /// - internal static string SARIF1004_UriBaseIdRequiresRelativeUri { + internal static string SARIF1004_ExpressUriBaseIdsCorrectly { get { - return ResourceManager.GetString("SARIF1004_UriBaseIdRequiresRelativeUri", resourceCulture); + return ResourceManager.GetString("SARIF1004_ExpressUriBaseIdsCorrectly", resourceCulture); } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index f3159f411..bb1ece5d2 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -144,7 +144,7 @@ {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference. - + If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference. diff --git a/src/Sarif.Multitool/Rules/SARIF1004.UriBaseIdRequiresRelativeUri.cs b/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs similarity index 83% rename from src/Sarif.Multitool/Rules/SARIF1004.UriBaseIdRequiresRelativeUri.cs rename to src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs index 76ce8fc61..a1e02e278 100644 --- a/src/Sarif.Multitool/Rules/SARIF1004.UriBaseIdRequiresRelativeUri.cs +++ b/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs @@ -6,16 +6,16 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules { - public class UriBaseIdRequiresRelativeUri : SarifValidationSkimmerBase + public class ExpressUriBaseIdsCorrectly : SarifValidationSkimmerBase { public override MultiformatMessageString FullDescription => new MultiformatMessageString { - Text = RuleResources.SARIF1004_UriBaseIdRequiresRelativeUri + Text = RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly }; public override FailureLevel DefaultLevel => FailureLevel.Error; - public override string Id => RuleId.UriBaseIdRequiresRelativeUri; + public override string Id => RuleId.ExpressUriBaseIdsCorrectly; protected override IEnumerable MessageResourceNames => new string[] { diff --git a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs index 3aafa83c0..dd80aa1eb 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -80,12 +80,12 @@ public void SARIF1007_RegionPropertiesMustBeConsistent_Invalid() /********** END PROBLEMATIC TESTS*******/ [Fact] - public void SARIF1004_UriBaseIdRequiresRelativeUri_Valid() - => RunTest(MakeValidTestFileName(RuleId.UriBaseIdRequiresRelativeUri, nameof(RuleId.UriBaseIdRequiresRelativeUri))); + public void SARIF1004_ExpressUriBaseIdsCorrectly_Valid() + => RunTest(MakeValidTestFileName(RuleId.ExpressUriBaseIdsCorrectly, nameof(RuleId.ExpressUriBaseIdsCorrectly))); [Fact] - public void SARIF1004_UriBaseIdRequiresRelativeUri_Invalid() - => RunTest(MakeInvalidTestFileName(RuleId.UriBaseIdRequiresRelativeUri, nameof(RuleId.UriBaseIdRequiresRelativeUri))); + public void SARIF1004_ExpressUriBaseIdsCorrectly_Invalid() + => RunTest(MakeInvalidTestFileName(RuleId.ExpressUriBaseIdsCorrectly, nameof(RuleId.ExpressUriBaseIdsCorrectly))); [Fact] public void SARIF1005_UriMustBeAbsolute_Valid() diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif similarity index 99% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif index f7bbb544c..1148115ad 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif @@ -9,7 +9,7 @@ "rules": [ { "id": "SARIF1004", - "name": "UriBaseIdRequiresRelativeUri", + "name": "ExpressUriBaseIdsCorrectly", "shortDescription": { "text": "If a fileLocation object contains a \"uriBaseId\" property, the value of the \"uri\" property must be a relative URI reference." }, @@ -34,7 +34,7 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif", "uriBaseId": "TEST_DIR" } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif similarity index 91% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif index 02c48a9ae..986046616 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif @@ -16,7 +16,7 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif", "uriBaseId": "TEST_DIR" } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.UriBaseIdRequiresRelativeUri_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif From 4b91432979c9b16099f6b4b2dc8f5dcf7d8581a6 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 16:11:34 -0700 Subject: [PATCH 3/5] description resx changed --- src/Sarif.Multitool/Rules/RuleResources.Designer.cs | 4 ++-- src/Sarif.Multitool/Rules/RuleResources.resx | 2 +- .../Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 72e41f07f..a516f5559 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -108,9 +108,9 @@ internal static string SARIF1004_Default { /// /// Looks up a localized string similar to If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference.. /// - internal static string SARIF1004_ExpressUriBaseIdsCorrectly { + internal static string SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text { get { - return ResourceManager.GetString("SARIF1004_ExpressUriBaseIdsCorrectly", resourceCulture); + return ResourceManager.GetString("SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text", resourceCulture); } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index bb1ece5d2..2412813d7 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -144,7 +144,7 @@ {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference. - + If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference. diff --git a/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs b/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs index a1e02e278..c1852a557 100644 --- a/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs +++ b/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs @@ -10,7 +10,7 @@ public class ExpressUriBaseIdsCorrectly : SarifValidationSkimmerBase { public override MultiformatMessageString FullDescription => new MultiformatMessageString { - Text = RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly + Text = RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text }; public override FailureLevel DefaultLevel => FailureLevel.Error; From c900b8557ca1b57ba9f793efd56b948a7b21d70f Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 16:34:47 -0700 Subject: [PATCH 4/5] merged test cases into one rule --- src/Sarif.Multitool/Rules/RuleId.cs | 1 - .../Rules/RuleResources.Designer.cs | 42 ++--- src/Sarif.Multitool/Rules/RuleResources.resx | 8 +- .../SARIF1004.ExpressUriBaseIdsCorrectly.cs | 46 +++++- ...ARIF1018.InvalidUriInOriginalUriBaseIds.cs | 66 -------- .../Multitool/ValidateCommandTests.cs | 8 - ...4.ExpressUriBaseIdsCorrectly_Invalid.sarif | 146 ++++++++++++++---- ...validUriInOriginalUriBaseIds_Invalid.sarif | 128 --------------- ...InvalidUriInOriginalUriBaseIds_Valid.sarif | 28 ---- ...4.ExpressUriBaseIdsCorrectly_Invalid.sarif | 15 ++ ...004.ExpressUriBaseIdsCorrectly_Valid.sarif | 20 +++ ...validUriInOriginalUriBaseIds_Invalid.sarif | 30 ---- ...InvalidUriInOriginalUriBaseIds_Valid.sarif | 35 ----- 13 files changed, 219 insertions(+), 354 deletions(-) delete mode 100644 src/Sarif.Multitool/Rules/SARIF1018.InvalidUriInOriginalUriBaseIds.cs delete mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif delete mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif delete mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif delete mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index 259220877..2c2846b4b 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -14,7 +14,6 @@ public static class RuleId public const string UriMustBeAbsolute = "SARIF1005"; public const string PhysicalLocationPropertiesMustBeConsistent = "SARIF1008"; public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009"; - public const string InvalidUriInOriginalUriBaseIds = "SARIF1018"; public const string RuleIdMustBeConsistent = "SARIF1010"; public const string ReferenceFinalSchema = "SARIF1011"; public const string ProvideSchema = "SARIF2008"; diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index a516f5559..5702e0ea5 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -96,17 +96,35 @@ internal static string SARIF1002_UrisMustBeValid_FullDescription_Text { } } + /// + /// Looks up a localized string similar to {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds is not an absolute URI.. + /// + internal static string SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text { + get { + return ResourceManager.GetString("SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference.. /// - internal static string SARIF1004_Default { + internal static string SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text { + get { + return ResourceManager.GetString("SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash.. + /// + internal static string SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text { get { - return ResourceManager.GetString("SARIF1004_Default", resourceCulture); + return ResourceManager.GetString("SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text", resourceCulture); } } /// - /// Looks up a localized string similar to If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference.. + /// Looks up a localized string similar to Placeholder_SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text. /// internal static string SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text { get { @@ -282,24 +300,6 @@ internal static string SARIF1018_InvalidUriInOriginalUriBaseIds { } } - /// - /// Looks up a localized string similar to {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash.. - /// - internal static string SARIF1018_LacksTrailingSlash { - get { - return ResourceManager.GetString("SARIF1018_LacksTrailingSlash", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds is not an absolute URI.. - /// - internal static string SARIF1018_NotAbsolute { - get { - return ResourceManager.GetString("SARIF1018_NotAbsolute", resourceCulture); - } - } - /// /// Looks up a localized string similar to Messages should consist of one or more complete sentences, ending with a period.. /// diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index 2412813d7..a2c9ddde3 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -141,11 +141,11 @@ Messages should consist of one or more complete sentences, ending with a period. - + {0}: This fileLocation object contains a "uriBaseId" property, which means that the value of the "uri" property must be a relative URI reference, but "{1}" is an absolute URI reference. - If a fileLocation object contains a "uriBaseId" property, the value of the "uri" property must be a relative URI reference. + Placeholder_SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text {0}: The value of this property is required to be an absolute URI, but "{1}" is a relative URI reference. @@ -168,10 +168,10 @@ In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file. - + {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash. - + {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds is not an absolute URI. diff --git a/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs b/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs index c1852a557..6c9d30b89 100644 --- a/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs +++ b/src/Sarif.Multitool/Rules/SARIF1004.ExpressUriBaseIdsCorrectly.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using Microsoft.Json.Pointer; @@ -19,7 +20,9 @@ public class ExpressUriBaseIdsCorrectly : SarifValidationSkimmerBase protected override IEnumerable MessageResourceNames => new string[] { - nameof(RuleResources.SARIF1004_Default) + nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text), + nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text), + nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text) }; protected override void Analyze(ArtifactLocation fileLocation, string fileLocationPointer) @@ -28,9 +31,48 @@ protected override void Analyze(ArtifactLocation fileLocation, string fileLocati { LogResult( fileLocationPointer.AtProperty(SarifPropertyName.Uri), - nameof(RuleResources.SARIF1004_Default), + nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdRequiresRelativeUri_Text), fileLocation.Uri.OriginalString); } } + + protected override void Analyze(Run run, string runPointer) + { + if (run.OriginalUriBaseIds != null) + { + string originalUriBaseIdsPointer = runPointer.AtProperty(SarifPropertyName.OriginalUriBaseIds); + + foreach (string uriBaseId in run.OriginalUriBaseIds.Keys) + { + AnalyzeOriginalUriBaseIdsEntry(uriBaseId, run.OriginalUriBaseIds[uriBaseId], originalUriBaseIdsPointer.AtProperty(uriBaseId)); + } + } + } + + private void AnalyzeOriginalUriBaseIdsEntry(string uriBaseId, ArtifactLocation artifactLocation, string pointer) + { + if (artifactLocation.Uri == null) { return; } + + // If it's not a well-formed URI of _any_ kind, then don't bother triggering this rule. + // Rule SARIF1003, UrisMustBeValid, will catch it. + // Check for well-formedness first, before attempting to create a Uri object, to + // avoid having to do a try/catch. Unfortunately Uri.TryCreate will return true + // even for a malformed URI string. + string uriString = artifactLocation.Uri.OriginalString; + if (uriString != null && Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute)) + { + var uri = new Uri(uriString, UriKind.RelativeOrAbsolute); + + if (artifactLocation.UriBaseId == null && !uri.IsAbsoluteUri) + { + LogResult(pointer, nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_TopLevelUriBaseIdMustBeAbsolute_Text), uriString, uriBaseId); + } + + if (!uriString.EndsWith("/")) + { + LogResult(pointer, nameof(RuleResources.SARIF1004_ExpressUriBaseIdsCorrectly_Error_UriBaseIdValueMustEndWithSlash_Text), uriString, uriBaseId); + } + } + } } } diff --git a/src/Sarif.Multitool/Rules/SARIF1018.InvalidUriInOriginalUriBaseIds.cs b/src/Sarif.Multitool/Rules/SARIF1018.InvalidUriInOriginalUriBaseIds.cs deleted file mode 100644 index 23ce7b124..000000000 --- a/src/Sarif.Multitool/Rules/SARIF1018.InvalidUriInOriginalUriBaseIds.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using Microsoft.Json.Pointer; - -namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules -{ - public class InvalidUriInOriginalUriBaseIds : SarifValidationSkimmerBase - { - public override MultiformatMessageString FullDescription => new MultiformatMessageString - { - Text = RuleResources.SARIF1018_InvalidUriInOriginalUriBaseIds - }; - - public override FailureLevel DefaultLevel => FailureLevel.Error; - - public override string Id => RuleId.InvalidUriInOriginalUriBaseIds; - - protected override IEnumerable MessageResourceNames => new string[] - { - nameof(RuleResources.SARIF1018_NotAbsolute), - nameof(RuleResources.SARIF1018_LacksTrailingSlash) - }; - - protected override void Analyze(Run run, string runPointer) - { - if (run.OriginalUriBaseIds != null) - { - string originalUriBaseIdsPointer = runPointer.AtProperty(SarifPropertyName.OriginalUriBaseIds); - - foreach (string uriBaseId in run.OriginalUriBaseIds.Keys) - { - AnalyzeOriginalUriBaseIdsEntry(uriBaseId, run.OriginalUriBaseIds[uriBaseId], originalUriBaseIdsPointer.AtProperty(uriBaseId)); - } - } - } - - private void AnalyzeOriginalUriBaseIdsEntry(string uriBaseId, ArtifactLocation artifactLocation, string pointer) - { - if (artifactLocation.Uri == null) { return; } - - // If it's not a well-formed URI of _any_ kind, then don't bother triggering this rule. - // Rule SARIF1003, UrisMustBeValid, will catch it. - // Check for well-formedness first, before attempting to create a Uri object, to - // avoid having to do a try/catch. Unfortunately Uri.TryCreate will return true - // even for a malformed URI string. - string uriString = artifactLocation.Uri.OriginalString; - if (uriString != null && Uri.IsWellFormedUriString(uriString, UriKind.RelativeOrAbsolute)) - { - var uri = new Uri(uriString, UriKind.RelativeOrAbsolute); - - if (artifactLocation.UriBaseId == null && !uri.IsAbsoluteUri) - { - LogResult(pointer, nameof(RuleResources.SARIF1018_NotAbsolute), uriString, uriBaseId); - } - - if (!uriString.EndsWith("/")) - { - LogResult(pointer, nameof(RuleResources.SARIF1018_LacksTrailingSlash), uriString, uriBaseId); - } - } - } - } -} diff --git a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs index dd80aa1eb..a28478dbe 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -111,14 +111,6 @@ public void SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Valid() public void SARIF1009_IndexPropertiesMustBeConsistentWithArrays_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.IndexPropertiesMustBeConsistentWithArrays, nameof(RuleId.IndexPropertiesMustBeConsistentWithArrays))); - [Fact] - public void SARIF1018_InvalidUriInOriginalUriBaseIds_Valid() - => RunTest(MakeValidTestFileName(RuleId.InvalidUriInOriginalUriBaseIds, nameof(RuleId.InvalidUriInOriginalUriBaseIds))); - - [Fact] - public void SARIF1018_InvalidUriInOriginalUriBaseIds_Invalid() - => RunTest(MakeInvalidTestFileName(RuleId.InvalidUriInOriginalUriBaseIds, nameof(RuleId.InvalidUriInOriginalUriBaseIds))); - [Fact] public void SARIF1010_RuleIdMustBeConsistent_Valid() => RunTest(MakeValidTestFileName(RuleId.RuleIdMustBeConsistent, nameof(RuleId.RuleIdMustBeConsistent))); diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif index 1148115ad..c4f7d98bc 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif @@ -11,14 +11,20 @@ "id": "SARIF1004", "name": "ExpressUriBaseIdsCorrectly", "shortDescription": { - "text": "If a fileLocation object contains a \"uriBaseId\" property, the value of the \"uri\" property must be a relative URI reference." + "text": "Placeholder_SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text." }, "fullDescription": { - "text": "If a fileLocation object contains a \"uriBaseId\" property, the value of the \"uri\" property must be a relative URI reference." + "text": "Placeholder_SARIF1004_ExpressUriBaseIdsCorrectly_FullDescription_Text" }, "messageStrings": { - "Default": { + "Error_UriBaseIdRequiresRelativeUri": { "text": "{0}: This fileLocation object contains a \"uriBaseId\" property, which means that the value of the \"uri\" property must be a relative URI reference, but \"{1}\" is an absolute URI reference." + }, + "Error_TopLevelUriBaseIdMustBeAbsolute": { + "text": "{0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds is not an absolute URI." + }, + "Error_UriBaseIdValueMustEndWithSlash": { + "text": "{0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash." } }, "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" @@ -45,7 +51,85 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_TopLevelUriBaseIdMustBeAbsolute", + "arguments": [ + "runs[0].originalUriBaseIds.PROJECT_ROOT", + "project", + "PROJECT_ROOT" + ] + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "index": 0 + }, + "region": { + "startLine": 100, + "startColumn": 25 + } + } + } + ] + }, + { + "ruleId": "SARIF1004", + "ruleIndex": 0, + "level": "error", + "message": { + "id": "Error_UriBaseIdValueMustEndWithSlash", + "arguments": [ + "runs[0].originalUriBaseIds.PROJECT_ROOT", + "project", + "PROJECT_ROOT" + ] + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "index": 0 + }, + "region": { + "startLine": 100, + "startColumn": 25 + } + } + } + ] + }, + { + "ruleId": "SARIF1004", + "ruleIndex": 0, + "level": "error", + "message": { + "id": "Error_UriBaseIdValueMustEndWithSlash", + "arguments": [ + "runs[0].originalUriBaseIds.SOURCE_ROOT", + "src", + "SOURCE_ROOT" + ] + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "index": 0 + }, + "region": { + "startLine": 106, + "startColumn": 24 + } + } + } + ] + }, + { + "ruleId": "SARIF1004", + "ruleIndex": 0, + "level": "error", + "message": { + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].conversion.analysisToolLogFiles[0].uri", "file:///C:/src/file.c" @@ -70,7 +154,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].analysisTarget.uri", "file:///C:/src/file.c" @@ -83,7 +167,7 @@ "index": 0 }, "region": { - "startLine": 115, + "startLine": 130, "startColumn": 42 } } @@ -95,7 +179,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].attachments[0].artifactLocation.uri", "file:///C:/src/file.c" @@ -108,7 +192,7 @@ "index": 0 }, "region": { - "startLine": 177, + "startLine": 192, "startColumn": 46 } } @@ -120,7 +204,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].locations[0].physicalLocation.artifactLocation.uri", "file:///C:/src/file.c" @@ -133,7 +217,7 @@ "index": 0 }, "region": { - "startLine": 122, + "startLine": 137, "startColumn": 48 } } @@ -145,7 +229,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].codeFlows[0].threadFlows[0].locations[0].location.physicalLocation.artifactLocation.uri", "file:///C:/src/file.c" @@ -158,7 +242,7 @@ "index": 0 }, "region": { - "startLine": 153, + "startLine": 168, "startColumn": 58 } } @@ -170,7 +254,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].provenance.conversionSources[0].artifactLocation.uri", "file:///C:/src/file.c" @@ -183,7 +267,7 @@ "index": 0 }, "region": { - "startLine": 186, + "startLine": 201, "startColumn": 48 } } @@ -195,7 +279,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].stacks[0].frames[0].location.physicalLocation.artifactLocation.uri", "file:///C:/src/file.c" @@ -208,7 +292,7 @@ "index": 0 }, "region": { - "startLine": 135, + "startLine": 150, "startColumn": 54 } } @@ -220,7 +304,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].relatedLocations[0].physicalLocation.artifactLocation.uri", "file:///C:/src/file.c" @@ -233,7 +317,7 @@ "index": 0 }, "region": { - "startLine": 168, + "startLine": 183, "startColumn": 48 } } @@ -245,7 +329,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].results[0].fixes[0].artifactChanges[0].artifactLocation.uri", "file:///C:/src/file.c" @@ -258,7 +342,7 @@ "index": 0 }, "region": { - "startLine": 197, + "startLine": 212, "startColumn": 50 } } @@ -270,7 +354,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].artifacts[0].location.uri", "file:///C:/src/file.c" @@ -283,7 +367,7 @@ "index": 0 }, "region": { - "startLine": 102, + "startLine": 117, "startColumn": 42 } } @@ -295,7 +379,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].executableLocation.uri", "file:///C:/src/file.c" @@ -320,7 +404,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].responseFiles[0].uri", "file:///C:/src/file.c" @@ -345,7 +429,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].stdin.uri", "file:///c:/log/in.txt" @@ -370,7 +454,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].stdout.uri", "file:///c:/log/out.txt" @@ -395,7 +479,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].stderr.uri", "file:///c:/log/err.txt" @@ -420,7 +504,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].stdoutStderr.uri", "file:///c:/log/out-err.txt" @@ -445,7 +529,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].toolExecutionNotifications[0].locations[0].physicalLocation.artifactLocation.uri", "file:///C:/src/file.c" @@ -470,7 +554,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].invocations[0].toolConfigurationNotifications[0].locations[0].physicalLocation.artifactLocation.uri", "file:///C:/src/file.c" @@ -495,7 +579,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "Default", + "id": "Error_UriBaseIdRequiresRelativeUri", "arguments": [ "runs[0].versionControlProvenance[0].mappedTo.uri", "file:///C:/src/file.c" diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif deleted file mode 100644 index 82e99fb1e..000000000 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif +++ /dev/null @@ -1,128 +0,0 @@ -{ - "$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": "SARIF1018", - "name": "InvalidUriInOriginalUriBaseIds", - "shortDescription": { - "text": "In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent." - }, - "fullDescription": { - "text": "In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file." - }, - "messageStrings": { - "NotAbsolute": { - "text": "{0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds is not an absolute URI." - }, - "LacksTrailingSlash": { - "text": "{0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash." - } - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" - } - ] - } - }, - "invocations": [ - { - "executionSuccessful": true - } - ], - "artifacts": [ - { - "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif", - "uriBaseId": "TEST_DIR" - } - } - ], - "results": [ - { - "ruleId": "SARIF1018", - "ruleIndex": 0, - "level": "error", - "message": { - "id": "NotAbsolute", - "arguments": [ - "runs[0].originalUriBaseIds.PROJECT_ROOT", - "project", - "PROJECT_ROOT" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "index": 0 - }, - "region": { - "startLine": 12, - "startColumn": 25 - } - } - } - ] - }, - { - "ruleId": "SARIF1018", - "ruleIndex": 0, - "level": "error", - "message": { - "id": "LacksTrailingSlash", - "arguments": [ - "runs[0].originalUriBaseIds.PROJECT_ROOT", - "project", - "PROJECT_ROOT" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "index": 0 - }, - "region": { - "startLine": 12, - "startColumn": 25 - } - } - } - ] - }, - { - "ruleId": "SARIF1018", - "ruleIndex": 0, - "level": "error", - "message": { - "id": "LacksTrailingSlash", - "arguments": [ - "runs[0].originalUriBaseIds.SOURCE_ROOT", - "src", - "SOURCE_ROOT" - ] - }, - "locations": [ - { - "physicalLocation": { - "artifactLocation": { - "index": 0 - }, - "region": { - "startLine": 18, - "startColumn": 24 - } - } - } - ] - } - ], - "columnKind": "utf16CodeUnits" - } - ] -} \ No newline at end of file diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif deleted file mode 100644 index 56ae676bf..000000000 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$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": [ - { - "executionSuccessful": true - } - ], - "artifacts": [ - { - "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif", - "uriBaseId": "TEST_DIR" - } - } - ], - "results": [], - "columnKind": "utf16CodeUnits" - } - ] -} \ No newline at end of file diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif index bdd3c9425..b8cf3cd74 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Invalid.sarif @@ -8,6 +8,21 @@ "name": "CodeScanner" } }, + "originalUriBaseIds": { + "PROJECT_ROOT": { + "uri": "project", + "description": { + "text": "This artifactLocation has no uriBaseId, so its uri, if present, must be absolute. But it isn't. It also doesn't end with a slash." + } + }, + "SOURCE_ROOT": { + "uri": "src", + "uriBaseId": "PROJECT_ROOT", + "description": { + "text": "This is a regression test for Bug #1862, where we were not checking for a trailing slash on relative URIs." + } + } + }, "invocations": [ { "responseFiles": [ diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif index d989aceeb..0f283d2bd 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1004.ExpressUriBaseIdsCorrectly_Valid.sarif @@ -8,6 +8,26 @@ "name": "CodeScanner" } }, + "originalUriBaseIds": { + "PROJECT_ROOT": { + "description": { + "text": "This artifactLocation has neither a uri nor a uriBaseId. This is fine." + } + }, + "RULES_ROOT": { + "uri": "file:///C:/rules/", + "description": { + "text": "This artifactLocation has no uriBaseId, so its uri, if present, must be absolute." + } + }, + "SOURCE_ROOT": { + "uri": "src/", + "uriBaseId": "PROJECT_ROOT", + "description": { + "text": "This artifactLocation has a uriBaseId so its uri must be relative." + } + } + }, "invocations": [ { "responseFiles": [ diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif deleted file mode 100644 index 689a2661b..000000000 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Invalid.sarif +++ /dev/null @@ -1,30 +0,0 @@ -{ - "$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" - } - }, - "originalUriBaseIds": { - "PROJECT_ROOT": { - "uri": "project", - "description": { - "text": "This artifactLocation has no uriBaseId, so its uri, if present, must be absolute. But it isn't. It also doesn't end with a slash." - } - }, - "SOURCE_ROOT": { - "uri": "src", - "uriBaseId": "PROJECT_ROOT", - "description": { - "text": "This is a regression test for Bug #1862, where we were not checking for a trailing slash on relative URIs." - } - } - }, - "results": [], - "columnKind": "utf16CodeUnits" - } - ] -} \ No newline at end of file diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif deleted file mode 100644 index d2f4aa6e2..000000000 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1018.InvalidUriInOriginalUriBaseIds_Valid.sarif +++ /dev/null @@ -1,35 +0,0 @@ -{ - "$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" - } - }, - "originalUriBaseIds": { - "PROJECT_ROOT": { - "description": { - "text": "This artifactLocation has neither a uri nor a uriBaseId. This is fine." - } - }, - "RULES_ROOT": { - "uri": "file:///C:/rules/", - "description": { - "text": "This artifactLocation has no uriBaseId, so its uri, if present, must be absolute." - } - }, - "SOURCE_ROOT": { - "uri": "src/", - "uriBaseId": "PROJECT_ROOT", - "description": { - "text": "This artifactLocation has a uriBaseId so its uri must be relative. But that is not enforced by SARIF1018; it will be enforced by a separate rule." - } - } - }, - "results": [], - "columnKind": "utf16CodeUnits" - } - ] -} \ No newline at end of file From 2917e8f22fa9c7cd1962abe88555668f80c62aec Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 16:39:36 -0700 Subject: [PATCH 5/5] cleanup and reordering --- src/Sarif.Multitool/Rules/RuleId.cs | 7 +-- .../Rules/RuleResources.Designer.cs | 9 ---- src/Sarif.Multitool/Rules/RuleResources.resx | 3 -- .../Multitool/ValidateCommandTests.cs | 47 ++++++++++--------- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index 2c2846b4b..099109b58 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -7,15 +7,16 @@ public static class RuleId { public const string RuleIdentifiersMustBeValid = "SARIF1001"; public const string UrisMustBeValid = "SARIF1002"; - public const string InvocationPropertiesMustBeConsistent = "SARIF1006"; - public const string AuthorHighQualityMessages = "SARIF2001"; - public const string RegionPropertiesMustBeConsistent = "SARIF1007"; public const string ExpressUriBaseIdsCorrectly = "SARIF1004"; public const string UriMustBeAbsolute = "SARIF1005"; + public const string InvocationPropertiesMustBeConsistent = "SARIF1006"; + public const string RegionPropertiesMustBeConsistent = "SARIF1007"; public const string PhysicalLocationPropertiesMustBeConsistent = "SARIF1008"; public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009"; public const string RuleIdMustBeConsistent = "SARIF1010"; public const string ReferenceFinalSchema = "SARIF1011"; + + public const string AuthorHighQualityMessages = "SARIF2001"; public const string ProvideSchema = "SARIF2008"; } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 5702e0ea5..db0c92508 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -291,15 +291,6 @@ internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { } } - /// - /// Looks up a localized string similar to In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file.. - /// - internal static string SARIF1018_InvalidUriInOriginalUriBaseIds { - get { - return ResourceManager.GetString("SARIF1018_InvalidUriInOriginalUriBaseIds", resourceCulture); - } - } - /// /// Looks up a localized string similar to Messages should consist of one or more complete sentences, ending with a period.. /// diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index a2c9ddde3..8eb62cc77 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -165,9 +165,6 @@ If an object contains a property that is used as an array index, then that array must be present and must contain at least "index + 1" elements. - - In the artifactLocation objects contained in run.originalUriBaseIds, if uriBaseId is absent, then uri must either be an absolute URI or it must be absent. Also, uri must end with a slash, so that it can safely be combined with the relative URIs in artifactLocation objects elsewhere in the log file. - {0}: The URI '{1}' belonging to the '{2}' element of run.originalUriBaseIds does not end with a slash. diff --git a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs index a28478dbe..fa18cb319 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -48,6 +48,22 @@ public void SARIF1002_UrisMustBeValid_Valid() public void SARIF1002_UrisMustBeValid_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.UrisMustBeValid, nameof(RuleId.UrisMustBeValid))); + [Fact] + public void SARIF1004_ExpressUriBaseIdsCorrectly_Valid() + => RunTest(MakeValidTestFileName(RuleId.ExpressUriBaseIdsCorrectly, nameof(RuleId.ExpressUriBaseIdsCorrectly))); + + [Fact] + public void SARIF1004_ExpressUriBaseIdsCorrectly_Invalid() + => RunTest(MakeInvalidTestFileName(RuleId.ExpressUriBaseIdsCorrectly, nameof(RuleId.ExpressUriBaseIdsCorrectly))); + + [Fact] + public void SARIF1005_UriMustBeAbsolute_Valid() + => RunTest(MakeValidTestFileName(RuleId.UriMustBeAbsolute, nameof(RuleId.UriMustBeAbsolute))); + + [Fact] + public void SARIF1005_UriMustBeAbsolute_Invalid() + => RunTest(MakeInvalidTestFileName(RuleId.UriMustBeAbsolute, nameof(RuleId.UriMustBeAbsolute))); + [Fact] public void SARIF1006_InvocationPropertiesMustBeConsistent_Valid() => RunTest(MakeValidTestFileName(RuleId.InvocationPropertiesMustBeConsistent, nameof(RuleId.InvocationPropertiesMustBeConsistent))); @@ -55,13 +71,6 @@ public void SARIF1006_InvocationPropertiesMustBeConsistent_Valid() [Fact] public void SARIF1006_InvocationPropertiesMustBeConsistent_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.InvocationPropertiesMustBeConsistent, nameof(RuleId.InvocationPropertiesMustBeConsistent))); - [Fact] - public void SARIF2001_AuthorHighQualityMessages_Valid() - => RunTest(MakeValidTestFileName(RuleId.AuthorHighQualityMessages, nameof(RuleId.AuthorHighQualityMessages))); - - [Fact] - public void SARIF2001_AuthorHighQualityMessages_Invalid() - => RunTest(MakeInvalidTestFileName(RuleId.AuthorHighQualityMessages, nameof(RuleId.AuthorHighQualityMessages))); /****************** * This set of tests constructs a full file path that exceeds MAX_PATH when running in some AzureDevOps build and test @@ -79,22 +88,6 @@ public void SARIF1007_RegionPropertiesMustBeConsistent_Invalid() /********** END PROBLEMATIC TESTS*******/ - [Fact] - public void SARIF1004_ExpressUriBaseIdsCorrectly_Valid() - => RunTest(MakeValidTestFileName(RuleId.ExpressUriBaseIdsCorrectly, nameof(RuleId.ExpressUriBaseIdsCorrectly))); - - [Fact] - public void SARIF1004_ExpressUriBaseIdsCorrectly_Invalid() - => RunTest(MakeInvalidTestFileName(RuleId.ExpressUriBaseIdsCorrectly, nameof(RuleId.ExpressUriBaseIdsCorrectly))); - - [Fact] - public void SARIF1005_UriMustBeAbsolute_Valid() - => RunTest(MakeValidTestFileName(RuleId.UriMustBeAbsolute, nameof(RuleId.UriMustBeAbsolute))); - - [Fact] - public void SARIF1005_UriMustBeAbsolute_Invalid() - => RunTest(MakeInvalidTestFileName(RuleId.UriMustBeAbsolute, nameof(RuleId.UriMustBeAbsolute))); - [Fact] public void SARIF1008_PhysicalLocationPropertiesMustBeConsistent_Valid() => RunTest(MakeValidTestFileName(RuleId.PhysicalLocationPropertiesMustBeConsistent, nameof(RuleId.PhysicalLocationPropertiesMustBeConsistent))); @@ -127,6 +120,14 @@ public void SARIF1011_ReferenceFinalSchema_Valid() public void SARIF1011_ReferenceFinalSchema_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.ReferenceFinalSchema, nameof(RuleId.ReferenceFinalSchema))); + [Fact] + public void SARIF2001_AuthorHighQualityMessages_Valid() + => RunTest(MakeValidTestFileName(RuleId.AuthorHighQualityMessages, nameof(RuleId.AuthorHighQualityMessages))); + + [Fact] + public void SARIF2001_AuthorHighQualityMessages_Invalid() + => RunTest(MakeInvalidTestFileName(RuleId.AuthorHighQualityMessages, nameof(RuleId.AuthorHighQualityMessages))); + [Fact] public void SARIF2008_ProvideSchema_Valid() => RunTest(MakeValidTestFileName(RuleId.ProvideSchema, nameof(RuleId.ProvideSchema)));