From 1c6d9384e8966bdac1a17e7ceee57f809e0025d2 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 11:59:13 -0700 Subject: [PATCH 1/7] rule id changed and tested --- src/Sarif.Multitool/Rules/RuleId.cs | 2 +- src/Sarif.Multitool/Rules/RuleResources.Designer.cs | 12 ++++++------ src/Sarif.Multitool/Rules/RuleResources.resx | 6 +++--- ...inalSchema.cs => SARIF1011.ReferToFinalSchema.cs} | 10 +++++----- .../Multitool/ValidateCommandTests.cs | 10 +++++----- .../SARIF1002.UrisMustBeValid_Invalid.sarif | 4 ++-- ...if => SARIF1011.ReferToFinalSchema_Invalid.sarif} | 6 +++--- ...arif => SARIF1011.ReferToFinalSchema_Valid.sarif} | 2 +- ...if => SARIF1011.ReferToFinalSchema_Invalid.sarif} | 0 ...arif => SARIF1011.ReferToFinalSchema_Valid.sarif} | 0 10 files changed, 26 insertions(+), 26 deletions(-) rename src/Sarif.Multitool/Rules/{SARIF1020.ReferToFinalSchema.cs => SARIF1011.ReferToFinalSchema.cs} (82%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1020.ReferToFinalSchema_Invalid.sarif => SARIF1011.ReferToFinalSchema_Invalid.sarif} (96%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1020.ReferToFinalSchema_Valid.sarif => SARIF1011.ReferToFinalSchema_Valid.sarif} (93%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1020.ReferToFinalSchema_Invalid.sarif => SARIF1011.ReferToFinalSchema_Invalid.sarif} (100%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1020.ReferToFinalSchema_Valid.sarif => SARIF1011.ReferToFinalSchema_Valid.sarif} (100%) diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index 18dcbe310..fc1e35301 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -17,6 +17,6 @@ public static class RuleId public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009"; public const string InvalidUriInOriginalUriBaseIds = "SARIF1018"; public const string RuleIdMustBeConsistent = "SARIF1010"; - public const string ReferToFinalSchema = "SARIF1020"; + public const string ReferToFinalSchema = "SARIF1011"; } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 0d8169e4e..7329c443b 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -292,27 +292,27 @@ internal static string SARIF1018_NotAbsolute { /// /// Looks up a localized string similar to {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema.. /// - internal static string SARIF1020_ReferenceToOldSchemaVersion { + internal static string SARIF1011_ReferenceToOldSchemaVersion { get { - return ResourceManager.GetString("SARIF1020_ReferenceToOldSchemaVersion", resourceCulture); + return ResourceManager.GetString("SARIF1011_ReferenceToOldSchemaVersion", resourceCulture); } } /// /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. /// - internal static string SARIF1020_ReferToFinalSchema { + internal static string SARIF1011_ReferToFinalSchema { get { - return ResourceManager.GetString("SARIF1020_ReferToFinalSchema", resourceCulture); + return ResourceManager.GetString("SARIF1011_ReferToFinalSchema", resourceCulture); } } /// /// Looks up a localized string similar to {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. /// - internal static string SARIF1020_SchemaReferenceMissing { + internal static string SARIF1011_SchemaReferenceMissing { get { - return ResourceManager.GetString("SARIF1020_SchemaReferenceMissing", resourceCulture); + return ResourceManager.GetString("SARIF1011_SchemaReferenceMissing", resourceCulture); } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index 6724ed660..009094128 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -195,13 +195,13 @@ In every result, at least one of the properties result.ruleId and result.rule.id must be present. If both are present, they must be equal. - + {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema. - + The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. - + {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. diff --git a/src/Sarif.Multitool/Rules/SARIF1020.ReferToFinalSchema.cs b/src/Sarif.Multitool/Rules/SARIF1011.ReferToFinalSchema.cs similarity index 82% rename from src/Sarif.Multitool/Rules/SARIF1020.ReferToFinalSchema.cs rename to src/Sarif.Multitool/Rules/SARIF1011.ReferToFinalSchema.cs index 9e6d53d9c..2cc23f2dd 100644 --- a/src/Sarif.Multitool/Rules/SARIF1020.ReferToFinalSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF1011.ReferToFinalSchema.cs @@ -11,7 +11,7 @@ public class ReferToFinalSchema : SarifValidationSkimmerBase { public override MultiformatMessageString FullDescription => new MultiformatMessageString { - Text = RuleResources.SARIF1020_ReferToFinalSchema + Text = RuleResources.SARIF1011_ReferToFinalSchema }; public override FailureLevel DefaultLevel => FailureLevel.Error; @@ -20,8 +20,8 @@ public class ReferToFinalSchema : SarifValidationSkimmerBase protected override IEnumerable MessageResourceNames => new string[] { - nameof(RuleResources.SARIF1020_ReferenceToOldSchemaVersion), - nameof(RuleResources.SARIF1020_SchemaReferenceMissing) + nameof(RuleResources.SARIF1011_ReferenceToOldSchemaVersion), + nameof(RuleResources.SARIF1011_SchemaReferenceMissing) }; protected override void Analyze(SarifLog log, string logPointer) @@ -33,7 +33,7 @@ private void AnalyzeSchema(Uri schemaUri, string pointer) { if (schemaUri == null) { - LogResult(pointer, nameof(RuleResources.SARIF1020_SchemaReferenceMissing)); + LogResult(pointer, nameof(RuleResources.SARIF1011_SchemaReferenceMissing)); return; } @@ -42,7 +42,7 @@ private void AnalyzeSchema(Uri schemaUri, string pointer) && !schemaUri.OriginalString.EndsWith(VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg) && !schemaUri.OriginalString.EndsWith($"{VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg}.json")) { - LogResult(pointer.AtProperty(SarifPropertyName.Schema), nameof(RuleResources.SARIF1020_ReferenceToOldSchemaVersion), schemaUri.OriginalString); + LogResult(pointer.AtProperty(SarifPropertyName.Schema), nameof(RuleResources.SARIF1011_ReferenceToOldSchemaVersion), schemaUri.OriginalString); return; } } diff --git a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs index 93bcccbd8..9c2afeead 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -133,11 +133,11 @@ public void SARIF1010_RuleIdMustBeConsistent_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.RuleIdMustBeConsistent, nameof(RuleId.RuleIdMustBeConsistent))); [Fact] - public void SARIF1020_SchemaMustBePresentAndConsistent_Valid() + public void SARIF1011_SchemaMustBePresentAndConsistent_Valid() => RunTest(MakeValidTestFileName(RuleId.ReferToFinalSchema, nameof(RuleId.ReferToFinalSchema))); [Fact] - public void SARIF1020_SchemaMustBePresentAndConsistent_Invalid() + public void SARIF1011_SchemaMustBePresentAndConsistent_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.ReferToFinalSchema, nameof(RuleId.ReferToFinalSchema))); private const string ValidTestFileNameSuffix = "_Valid.sarif"; @@ -163,11 +163,11 @@ protected override string ConstructTestOutputFromInputResource(string inputResou // All SARIF rule prefixes require update to current release. // All rules with JSON prefix are low level syntax/deserialization checks. - // We can't transform these test inputs as that operation fixes up erros in the file. - // Also, don't transform the tests for SARIF1020, because that rule examines the actual contents of the $schema + // We can't transform these test inputs as that operation fixes up errors in the file. + // Also, don't transform the tests for SARIF1011, because that rule examines the actual contents of the $schema // property, so we can't change it. bool updateInputsToCurrentSarif = ruleUnderTest.StartsWith("SARIF") - && ruleUnderTest != "SARIF1020" ? true : false; + && ruleUnderTest != "SARIF1011" ? true : false; var validateOptions = new ValidateOptions { diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif index 9301ba494..01e538d32 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif @@ -24,7 +24,7 @@ "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" }, { - "id": "SARIF1020", + "id": "SARIF1011", "name": "ReferToFinalSchema", "shortDescription": { "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema." @@ -310,7 +310,7 @@ ] }, { - "ruleId": "SARIF1020", + "ruleId": "SARIF1011", "ruleIndex": 1, "level": "error", "message": { diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1020.ReferToFinalSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Invalid.sarif similarity index 96% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1020.ReferToFinalSchema_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Invalid.sarif index 2840dca02..0d41211f9 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1020.ReferToFinalSchema_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Invalid.sarif @@ -8,7 +8,7 @@ "name": "SARIF Functional Testing", "rules": [ { - "id": "SARIF1020", + "id": "SARIF1011", "name": "ReferToFinalSchema", "shortDescription": { "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema." @@ -37,14 +37,14 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1020.ReferToFinalSchema_Invalid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1011.ReferToFinalSchema_Invalid.sarif", "uriBaseId": "TEST_DIR" } } ], "results": [ { - "ruleId": "SARIF1020", + "ruleId": "SARIF1011", "ruleIndex": 0, "level": "error", "message": { diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1020.ReferToFinalSchema_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Valid.sarif similarity index 93% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1020.ReferToFinalSchema_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Valid.sarif index 4188f7e6c..3e28e8701 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1020.ReferToFinalSchema_Valid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Valid.sarif @@ -16,7 +16,7 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1020.ReferToFinalSchema_Valid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1011.ReferToFinalSchema_Valid.sarif", "uriBaseId": "TEST_DIR" } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1020.ReferToFinalSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Invalid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1020.ReferToFinalSchema_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Invalid.sarif diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1020.ReferToFinalSchema_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Valid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1020.ReferToFinalSchema_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Valid.sarif From 56477b9ae707b91cc95e23a98738b5ecb5a1d738 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 12:06:08 -0700 Subject: [PATCH 2/7] changing rule name and tested --- src/Sarif.Multitool/Rules/RuleId.cs | 2 +- src/Sarif.Multitool/Rules/RuleResources.Designer.cs | 4 ++-- src/Sarif.Multitool/Rules/RuleResources.resx | 2 +- ...ToFinalSchema.cs => SARIF1011.ReferenceFinalSchema.cs} | 6 +++--- .../Multitool/ValidateCommandTests.cs | 8 ++++---- .../SARIF1002.UrisMustBeValid_Invalid.sarif | 2 +- ...sarif => SARIF1011.ReferenceFinalSchema_Invalid.sarif} | 4 ++-- ...d.sarif => SARIF1011.ReferenceFinalSchema_Valid.sarif} | 2 +- ...sarif => SARIF1011.ReferenceFinalSchema_Invalid.sarif} | 0 ...d.sarif => SARIF1011.ReferenceFinalSchema_Valid.sarif} | 0 10 files changed, 15 insertions(+), 15 deletions(-) rename src/Sarif.Multitool/Rules/{SARIF1011.ReferToFinalSchema.cs => SARIF1011.ReferenceFinalSchema.cs} (90%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1011.ReferToFinalSchema_Invalid.sarif => SARIF1011.ReferenceFinalSchema_Invalid.sarif} (96%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/{SARIF1011.ReferToFinalSchema_Valid.sarif => SARIF1011.ReferenceFinalSchema_Valid.sarif} (92%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1011.ReferToFinalSchema_Invalid.sarif => SARIF1011.ReferenceFinalSchema_Invalid.sarif} (100%) rename src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/{SARIF1011.ReferToFinalSchema_Valid.sarif => SARIF1011.ReferenceFinalSchema_Valid.sarif} (100%) diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index fc1e35301..486d801f3 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -17,6 +17,6 @@ public static class RuleId public const string IndexPropertiesMustBeConsistentWithArrays = "SARIF1009"; public const string InvalidUriInOriginalUriBaseIds = "SARIF1018"; public const string RuleIdMustBeConsistent = "SARIF1010"; - public const string ReferToFinalSchema = "SARIF1011"; + public const string ReferenceFinalSchema = "SARIF1011"; } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 7329c443b..4dda2ab8d 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -301,9 +301,9 @@ internal static string SARIF1011_ReferenceToOldSchemaVersion { /// /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. /// - internal static string SARIF1011_ReferToFinalSchema { + internal static string SARIF1011_ReferenceFinalSchema { get { - return ResourceManager.GetString("SARIF1011_ReferToFinalSchema", resourceCulture); + return ResourceManager.GetString("SARIF1011_ReferenceFinalSchema", resourceCulture); } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index 009094128..50c49b2cd 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -198,7 +198,7 @@ {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema. - + The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. diff --git a/src/Sarif.Multitool/Rules/SARIF1011.ReferToFinalSchema.cs b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs similarity index 90% rename from src/Sarif.Multitool/Rules/SARIF1011.ReferToFinalSchema.cs rename to src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs index 2cc23f2dd..da29db8a0 100644 --- a/src/Sarif.Multitool/Rules/SARIF1011.ReferToFinalSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs @@ -7,16 +7,16 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules { - public class ReferToFinalSchema : SarifValidationSkimmerBase + public class ReferenceFinalSchema : SarifValidationSkimmerBase { public override MultiformatMessageString FullDescription => new MultiformatMessageString { - Text = RuleResources.SARIF1011_ReferToFinalSchema + Text = RuleResources.SARIF1011_ReferenceFinalSchema }; public override FailureLevel DefaultLevel => FailureLevel.Error; - public override string Id => RuleId.ReferToFinalSchema; + public override string Id => RuleId.ReferenceFinalSchema; 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 9c2afeead..94731f3c5 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -133,12 +133,12 @@ public void SARIF1010_RuleIdMustBeConsistent_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.RuleIdMustBeConsistent, nameof(RuleId.RuleIdMustBeConsistent))); [Fact] - public void SARIF1011_SchemaMustBePresentAndConsistent_Valid() - => RunTest(MakeValidTestFileName(RuleId.ReferToFinalSchema, nameof(RuleId.ReferToFinalSchema))); + public void SARIF1011_ReferenceFinalSchema_Valid() + => RunTest(MakeValidTestFileName(RuleId.ReferenceFinalSchema, nameof(RuleId.ReferenceFinalSchema))); [Fact] - public void SARIF1011_SchemaMustBePresentAndConsistent_Invalid() - => RunTest(MakeInvalidTestFileName(RuleId.ReferToFinalSchema, nameof(RuleId.ReferToFinalSchema))); + public void SARIF1011_ReferenceFinalSchema_Invalid() + => RunTest(MakeInvalidTestFileName(RuleId.ReferenceFinalSchema, nameof(RuleId.ReferenceFinalSchema))); private const string ValidTestFileNameSuffix = "_Valid.sarif"; private const string InvalidTestFileNameSuffix = "_Invalid.sarif"; diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif index 01e538d32..03d57ea66 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif @@ -25,7 +25,7 @@ }, { "id": "SARIF1011", - "name": "ReferToFinalSchema", + "name": "ReferenceFinalSchema", "shortDescription": { "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema." }, diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif similarity index 96% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif index 0d41211f9..c0fe0d78d 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif @@ -9,7 +9,7 @@ "rules": [ { "id": "SARIF1011", - "name": "ReferToFinalSchema", + "name": "ReferenceFinalSchema", "shortDescription": { "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema." }, @@ -37,7 +37,7 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1011.ReferToFinalSchema_Invalid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1011.ReferenceFinalSchema_Invalid.sarif", "uriBaseId": "TEST_DIR" } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Valid.sarif similarity index 92% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Valid.sarif index 3e28e8701..e3e4212da 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferToFinalSchema_Valid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Valid.sarif @@ -16,7 +16,7 @@ "artifacts": [ { "location": { - "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1011.ReferToFinalSchema_Valid.sarif", + "uri": "FunctionalTestOutput.ValidateCommand/Inputs.SARIF1011.ReferenceFinalSchema_Valid.sarif", "uriBaseId": "TEST_DIR" } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Invalid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferenceFinalSchema_Valid.sarif similarity index 100% rename from src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferToFinalSchema_Valid.sarif rename to src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF1011.ReferenceFinalSchema_Valid.sarif From bfa33d43f23e5c0c0769a4d15c380afc22c71995 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 12:23:01 -0700 Subject: [PATCH 3/7] description resx id updated --- .../Rules/RuleResources.Designer.cs | 54 +++++++++---------- src/Sarif.Multitool/Rules/RuleResources.resx | 2 +- .../Rules/SARIF1011.ReferenceFinalSchema.cs | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 4dda2ab8d..a792bcb0a 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -208,6 +208,33 @@ internal static string SARIF1010_RuleIdMustBeConsistent_FullDescription_Text { } } + /// + /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. + /// + internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { + get { + return ResourceManager.GetString("SARIF1011_ReferenceFinalSchema_FullDescription_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema.. + /// + internal static string SARIF1011_ReferenceToOldSchemaVersion { + get { + return ResourceManager.GetString("SARIF1011_ReferenceToOldSchemaVersion", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. + /// + internal static string SARIF1011_SchemaReferenceMissing { + get { + return ResourceManager.GetString("SARIF1011_SchemaReferenceMissing", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0}: The value of the "endLine" property is {1}, which is less than the value of the "startLine" property, which is {2}.. /// @@ -289,33 +316,6 @@ internal static string SARIF1018_NotAbsolute { } } - /// - /// Looks up a localized string similar to {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema.. - /// - internal static string SARIF1011_ReferenceToOldSchemaVersion { - get { - return ResourceManager.GetString("SARIF1011_ReferenceToOldSchemaVersion", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. - /// - internal static string SARIF1011_ReferenceFinalSchema { - get { - return ResourceManager.GetString("SARIF1011_ReferenceFinalSchema", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. - /// - internal static string SARIF1011_SchemaReferenceMissing { - get { - return ResourceManager.GetString("SARIF1011_SchemaReferenceMissing", 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 50c49b2cd..cd4ed68d0 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -198,7 +198,7 @@ {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema. - + The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. diff --git a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs index da29db8a0..8af16edb8 100644 --- a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs @@ -11,7 +11,7 @@ public class ReferenceFinalSchema : SarifValidationSkimmerBase { public override MultiformatMessageString FullDescription => new MultiformatMessageString { - Text = RuleResources.SARIF1011_ReferenceFinalSchema + Text = RuleResources.SARIF1011_ReferenceFinalSchema_FullDescription_Text }; public override FailureLevel DefaultLevel => FailureLevel.Error; From 1ca3db3f20b56ff4bbf856e61e5c32000bca07d5 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 12:28:34 -0700 Subject: [PATCH 4/7] resx updated and test cases regened --- src/Sarif.Multitool/Rules/RuleResources.Designer.cs | 12 ++++++------ src/Sarif.Multitool/Rules/RuleResources.resx | 2 +- .../Rules/SARIF1011.ReferenceFinalSchema.cs | 4 ++-- .../SARIF1002.UrisMustBeValid_Invalid.sarif | 4 ++-- .../SARIF1011.ReferenceFinalSchema_Invalid.sarif | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index a792bcb0a..1bc85560e 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -209,20 +209,20 @@ internal static string SARIF1010_RuleIdMustBeConsistent_FullDescription_Text { } /// - /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. + /// Looks up a localized string similar to {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema.. /// - internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { + internal static string SARIF1011_ReferenceFinalSchema_Error_Default_Text { get { - return ResourceManager.GetString("SARIF1011_ReferenceFinalSchema_FullDescription_Text", resourceCulture); + return ResourceManager.GetString("SARIF1011_ReferenceFinalSchema_Error_Default_Text", resourceCulture); } } /// - /// Looks up a localized string similar to {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema.. + /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. /// - internal static string SARIF1011_ReferenceToOldSchemaVersion { + internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { get { - return ResourceManager.GetString("SARIF1011_ReferenceToOldSchemaVersion", resourceCulture); + return ResourceManager.GetString("SARIF1011_ReferenceFinalSchema_FullDescription_Text", resourceCulture); } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index cd4ed68d0..7f1f10571 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -195,7 +195,7 @@ In every result, at least one of the properties result.ruleId and result.rule.id must be present. If both are present, they must be equal. - + {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema. diff --git a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs index 8af16edb8..9ec08ef01 100644 --- a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs @@ -20,7 +20,7 @@ public class ReferenceFinalSchema : SarifValidationSkimmerBase protected override IEnumerable MessageResourceNames => new string[] { - nameof(RuleResources.SARIF1011_ReferenceToOldSchemaVersion), + nameof(RuleResources.SARIF1011_ReferenceFinalSchema_Error_Default_Text), nameof(RuleResources.SARIF1011_SchemaReferenceMissing) }; @@ -42,7 +42,7 @@ private void AnalyzeSchema(Uri schemaUri, string pointer) && !schemaUri.OriginalString.EndsWith(VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg) && !schemaUri.OriginalString.EndsWith($"{VersionConstants.SchemaVersionAsPublishedToSchemaStoreOrg}.json")) { - LogResult(pointer.AtProperty(SarifPropertyName.Schema), nameof(RuleResources.SARIF1011_ReferenceToOldSchemaVersion), schemaUri.OriginalString); + LogResult(pointer.AtProperty(SarifPropertyName.Schema), nameof(RuleResources.SARIF1011_ReferenceFinalSchema_Error_Default_Text), schemaUri.OriginalString); return; } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif index 03d57ea66..7b6effffc 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif @@ -33,7 +33,7 @@ "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." }, "messageStrings": { - "ReferenceToOldSchemaVersion": { + "Error_Default": { "text": "{0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema." }, "SchemaReferenceMissing": { @@ -314,7 +314,7 @@ "ruleIndex": 1, "level": "error", "message": { - "id": "ReferenceToOldSchemaVersion", + "id": "Error_Default", "arguments": [ "$schema", "ht%tp://json.schemastore.org/sarif-2.0.0" diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif index c0fe0d78d..4b9eeab30 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif @@ -17,7 +17,7 @@ "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." }, "messageStrings": { - "ReferenceToOldSchemaVersion": { + "Error_Default": { "text": "{0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema." }, "SchemaReferenceMissing": { @@ -48,7 +48,7 @@ "ruleIndex": 0, "level": "error", "message": { - "id": "ReferenceToOldSchemaVersion", + "id": "Error_Default", "arguments": [ "$schema", "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json" From 65c0b4db4c37669eb71975d17fb110afb1772d5a Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 13:53:52 -0700 Subject: [PATCH 5/7] final changes after splitting the rule in two. --- src/Sarif.Multitool/Rules/RuleId.cs | 1 + .../Rules/RuleResources.Designer.cs | 29 +++++++++----- src/Sarif.Multitool/Rules/RuleResources.resx | 11 +++-- .../Rules/SARIF1011.ReferenceFinalSchema.cs | 5 +-- .../Rules/SARIF2008.ProvideSchema.cs | 40 +++++++++++++++++++ src/Sarif.Multitool/ValidateCommand.cs | 2 + .../Multitool/ValidateCommandTests.cs | 21 ++++++++-- .../SARIF1002.UrisMustBeValid_Invalid.sarif | 7 +--- ...RIF1011.ReferenceFinalSchema_Invalid.sarif | 7 +--- .../SARIF2008.ProvideSchema_Invalid.sarif | 28 +++++++++++++ .../SARIF2008.ProvideSchema_Valid.sarif | 28 +++++++++++++ .../SARIF2008.ProvideSchema_Invalid.sarif | 14 +++++++ .../SARIF2008.ProvideSchema_Valid.sarif | 15 +++++++ 13 files changed, 177 insertions(+), 31 deletions(-) create mode 100644 src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs create mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif create mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Valid.sarif create mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Invalid.sarif create mode 100644 src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Valid.sarif diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index 486d801f3..7c629f313 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -18,5 +18,6 @@ public static class RuleId 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 1bc85560e..209fe19f5 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -218,7 +218,7 @@ internal static string SARIF1011_ReferenceFinalSchema_Error_Default_Text { } /// - /// Looks up a localized string similar to The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. + /// Looks up a localized string similar to The $schema property must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. /// internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { get { @@ -226,15 +226,6 @@ internal static string SARIF1011_ReferenceFinalSchema_FullDescription_Text { } } - /// - /// Looks up a localized string similar to {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. - /// - internal static string SARIF1011_SchemaReferenceMissing { - get { - return ResourceManager.GetString("SARIF1011_SchemaReferenceMissing", resourceCulture); - } - } - /// /// Looks up a localized string similar to {0}: The value of the "endLine" property is {1}, which is less than the value of the "startLine" property, which is {2}.. /// @@ -333,5 +324,23 @@ internal static string SARIF2001_AuthorHighQualityMessages_Warning_TerminateWith return ResourceManager.GetString("SARIF2001_AuthorHighQualityMessages_Warning_TerminateWithPeriod_Text", resourceCulture); } } + + /// + /// Looks up a localized string similar to The $schema property should be present. This enables IDEs to provide Intellisense for SARIF log files.. + /// + internal static string SARIF2008_ProvideSchema_FullDescription_Text { + get { + return ResourceManager.GetString("SARIF2008_ProvideSchema_FullDescription_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files.. + /// + internal static string SARIF2008_ProvideSchema_Warning_Default_Text { + get { + return ResourceManager.GetString("SARIF2008_ProvideSchema_Warning_Default_Text", resourceCulture); + } + } } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index 7f1f10571..dffc227ee 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -199,12 +199,15 @@ {0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema. - The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. - - - {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. + The $schema property must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. {0}: This "{1}" object contains a property "{2}" with value {3}, but "{4}" is absent. + + The $schema property should be present. This enables IDEs to provide Intellisense for SARIF log files. + + + {0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files. + \ No newline at end of file diff --git a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs index 9ec08ef01..628ca1b96 100644 --- a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs @@ -20,8 +20,7 @@ public class ReferenceFinalSchema : SarifValidationSkimmerBase protected override IEnumerable MessageResourceNames => new string[] { - nameof(RuleResources.SARIF1011_ReferenceFinalSchema_Error_Default_Text), - nameof(RuleResources.SARIF1011_SchemaReferenceMissing) + nameof(RuleResources.SARIF1011_ReferenceFinalSchema_Error_Default_Text) }; protected override void Analyze(SarifLog log, string logPointer) @@ -33,7 +32,7 @@ private void AnalyzeSchema(Uri schemaUri, string pointer) { if (schemaUri == null) { - LogResult(pointer, nameof(RuleResources.SARIF1011_SchemaReferenceMissing)); + // If SchemaUri is not present, it will be caught by SARIF2008 rule. return; } diff --git a/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs b/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs new file mode 100644 index 000000000..2cd54ae7c --- /dev/null +++ b/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Json.Pointer; +using System; +using System.Collections.Generic; + +namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules +{ + public class ProvideSchema : SarifValidationSkimmerBase + { + public override MultiformatMessageString FullDescription => new MultiformatMessageString + { + Text = RuleResources.SARIF2008_ProvideSchema_FullDescription_Text + }; + + public override FailureLevel DefaultLevel => FailureLevel.Error; + + public override string Id => RuleId.ProvideSchema; + + protected override IEnumerable MessageResourceNames => new string[] + { + nameof(RuleResources.SARIF2008_ProvideSchema_Warning_Default_Text) + }; + + protected override void Analyze(SarifLog log, string logPointer) + { + AnalyzeSchema(log.SchemaUri, logPointer); + } + + private void AnalyzeSchema(Uri schemaUri, string pointer) + { + if (schemaUri == null) + { + LogResult(pointer, nameof(RuleResources.SARIF2008_ProvideSchema_Warning_Default_Text)); + return; + } + } + } +} diff --git a/src/Sarif.Multitool/ValidateCommand.cs b/src/Sarif.Multitool/ValidateCommand.cs index 75ba6249c..3a3dac69c 100644 --- a/src/Sarif.Multitool/ValidateCommand.cs +++ b/src/Sarif.Multitool/ValidateCommand.cs @@ -60,6 +60,8 @@ protected override void AnalyzeTarget( if (!string.IsNullOrEmpty(sarifText)) { + // DISCUSS IN PR: Deserializing the object here injects "$Schema" property, corrupting our test for + // SARIF2008_ProvideSchema context.InputLogContents = sarifText; context.InputLog = context.InputLogContents != null ? Deserialize(context.InputLogContents) : null; diff --git a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs index 94731f3c5..f6ddfb18b 100644 --- a/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs +++ b/src/Test.FunctionalTests.Sarif/Multitool/ValidateCommandTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using FluentAssertions; using Microsoft.CodeAnalysis.Sarif.Multitool; using Microsoft.CodeAnalysis.Sarif.Multitool.Rules; @@ -140,6 +141,14 @@ public void SARIF1011_ReferenceFinalSchema_Valid() public void SARIF1011_ReferenceFinalSchema_Invalid() => RunTest(MakeInvalidTestFileName(RuleId.ReferenceFinalSchema, nameof(RuleId.ReferenceFinalSchema))); + [Fact] + public void SARIF2008_ProvideSchema_Valid() + => RunTest(MakeValidTestFileName(RuleId.ProvideSchema, nameof(RuleId.ProvideSchema))); + + [Fact] + public void SARIF2008_ProvideSchema_Invalid() + => RunTest(MakeInvalidTestFileName(RuleId.ProvideSchema, nameof(RuleId.ProvideSchema))); + private const string ValidTestFileNameSuffix = "_Valid.sarif"; private const string InvalidTestFileNameSuffix = "_Invalid.sarif"; @@ -164,10 +173,13 @@ protected override string ConstructTestOutputFromInputResource(string inputResou // All SARIF rule prefixes require update to current release. // All rules with JSON prefix are low level syntax/deserialization checks. // We can't transform these test inputs as that operation fixes up errors in the file. - // Also, don't transform the tests for SARIF1011, because that rule examines the actual contents of the $schema - // property, so we can't change it. + // Also, don't transform the tests for SARIF1011 or SARIF2008, because these rules + // examine the actual contents of the $schema property. + + string[] shouldNotTransform = { "SARIF1011", "SARIF2008" }; + bool updateInputsToCurrentSarif = ruleUnderTest.StartsWith("SARIF") - && ruleUnderTest != "SARIF1011" ? true : false; + && !shouldNotTransform.Contains(ruleUnderTest); var validateOptions = new ValidateOptions { @@ -200,7 +212,8 @@ protected override string ConstructTestOutputFromInputResource(string inputResou returnCode.Should().Be(0); - SarifLog actualLog = JsonConvert.DeserializeObject(File.ReadAllText(actualLogFilePath)); + string actualLogFileContents = File.ReadAllText(actualLogFilePath); + SarifLog actualLog = JsonConvert.DeserializeObject(actualLogFileContents); // First, we'll strip any validation results that don't originate with the rule under test var newResults = new List(); diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif index 7b6effffc..4acf296bd 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1002.UrisMustBeValid_Invalid.sarif @@ -27,17 +27,14 @@ "id": "SARIF1011", "name": "ReferenceFinalSchema", "shortDescription": { - "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema." + "text": "The $schema property must refer to the final version of the SARIF 2.1.0 schema." }, "fullDescription": { - "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." + "text": "The $schema property must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." }, "messageStrings": { "Error_Default": { "text": "{0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema." - }, - "SchemaReferenceMissing": { - "text": "{0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." } }, "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif index 4b9eeab30..1e3bf2189 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF1011.ReferenceFinalSchema_Invalid.sarif @@ -11,17 +11,14 @@ "id": "SARIF1011", "name": "ReferenceFinalSchema", "shortDescription": { - "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema." + "text": "The $schema property must refer to the final version of the SARIF 2.1.0 schema." }, "fullDescription": { - "text": "The $schema property should be present, and must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." + "text": "The $schema property must refer to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." }, "messageStrings": { "Error_Default": { "text": "{0}: The $schema property value '{1}' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the $schema property with a URL that refers to the final version of the schema." - }, - "SchemaReferenceMissing": { - "text": "{0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." } }, "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif new file mode 100644 index 000000000..a45a80a2c --- /dev/null +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif @@ -0,0 +1,28 @@ +{ + "$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.SARIF2008.ProvideSchema_Invalid.sarif", + "uriBaseId": "TEST_DIR" + } + } + ], + "results": [], + "columnKind": "utf16CodeUnits" + } + ] +} \ No newline at end of file diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Valid.sarif new file mode 100644 index 000000000..572336196 --- /dev/null +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Valid.sarif @@ -0,0 +1,28 @@ +{ + "$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.SARIF2008.ProvideSchema_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/SARIF2008.ProvideSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Invalid.sarif new file mode 100644 index 000000000..2ca3716a8 --- /dev/null +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Invalid.sarif @@ -0,0 +1,14 @@ +{ + "version": "2.1.0", + "runs": [ + { + "tool": { + "driver": { + "name": "Sarif Functional Testing" + } + }, + "results": [], + "columnKind": "utf16CodeUnits" + } + ] +} \ No newline at end of file diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Valid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Valid.sarif new file mode 100644 index 000000000..a3e5bae05 --- /dev/null +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2008.ProvideSchema_Valid.sarif @@ -0,0 +1,15 @@ +{ + "$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" + } + }, + "results": [], + "columnKind": "utf16CodeUnits" + } + ] +} \ No newline at end of file From 54df61d8245b1cfae36d92d476e9bd6e530e5b09 Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 14:55:24 -0700 Subject: [PATCH 6/7] reviews++ --- .../Rules/SARIF2008.ProvideSchema.cs | 14 ++---- src/Sarif.Multitool/ValidateCommand.cs | 2 - .../SARIF2008.ProvideSchema_Invalid.sarif | 46 ++++++++++++++++++- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs b/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs index 2cd54ae7c..897ec4da4 100644 --- a/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF2008.ProvideSchema.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Json.Pointer; -using System; using System.Collections.Generic; namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules @@ -14,7 +12,7 @@ public class ProvideSchema : SarifValidationSkimmerBase Text = RuleResources.SARIF2008_ProvideSchema_FullDescription_Text }; - public override FailureLevel DefaultLevel => FailureLevel.Error; + public override FailureLevel DefaultLevel => FailureLevel.Warning; public override string Id => RuleId.ProvideSchema; @@ -25,15 +23,9 @@ public class ProvideSchema : SarifValidationSkimmerBase protected override void Analyze(SarifLog log, string logPointer) { - AnalyzeSchema(log.SchemaUri, logPointer); - } - - private void AnalyzeSchema(Uri schemaUri, string pointer) - { - if (schemaUri == null) + if (!Context.InputLogToken.HasProperty("$schema")) { - LogResult(pointer, nameof(RuleResources.SARIF2008_ProvideSchema_Warning_Default_Text)); - return; + LogResult(logPointer, nameof(RuleResources.SARIF2008_ProvideSchema_Warning_Default_Text)); } } } diff --git a/src/Sarif.Multitool/ValidateCommand.cs b/src/Sarif.Multitool/ValidateCommand.cs index 3a3dac69c..75ba6249c 100644 --- a/src/Sarif.Multitool/ValidateCommand.cs +++ b/src/Sarif.Multitool/ValidateCommand.cs @@ -60,8 +60,6 @@ protected override void AnalyzeTarget( if (!string.IsNullOrEmpty(sarifText)) { - // DISCUSS IN PR: Deserializing the object here injects "$Schema" property, corrupting our test for - // SARIF2008_ProvideSchema context.InputLogContents = sarifText; context.InputLog = context.InputLogContents != null ? Deserialize(context.InputLogContents) : null; diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif index a45a80a2c..acc204a51 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2008.ProvideSchema_Invalid.sarif @@ -5,7 +5,25 @@ { "tool": { "driver": { - "name": "SARIF Functional Testing" + "name": "SARIF Functional Testing", + "rules": [ + { + "id": "SARIF2008", + "name": "ProvideSchema", + "shortDescription": { + "text": "The $schema property should be present." + }, + "fullDescription": { + "text": "The $schema property should be present. This enables IDEs to provide Intellisense for SARIF log files." + }, + "messageStrings": { + "Warning_Default": { + "text": "{0}: The SARIF log file does not contain a $schema property. Add a $schema property that refers to the final version of the SARIF 2.1.0 schema. This enables IDEs to provide Intellisense for SARIF log files." + } + }, + "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" + } + ] } }, "invocations": [ @@ -21,7 +39,31 @@ } } ], - "results": [], + "results": [ + { + "ruleId": "SARIF2008", + "ruleIndex": 0, + "message": { + "id": "Warning_Default", + "arguments": [ + "" + ] + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "index": 0 + }, + "region": { + "startLine": 1, + "startColumn": 1 + } + } + } + ] + } + ], "columnKind": "utf16CodeUnits" } ] From 63bb3fa2874480c1b71d84ac2f3ea2611e72a7cc Mon Sep 17 00:00:00 2001 From: Harleen Kaur Kohli Date: Fri, 19 Jun 2020 14:57:22 -0700 Subject: [PATCH 7/7] fix one thing --- src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs index 628ca1b96..2d636c29f 100644 --- a/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs +++ b/src/Sarif.Multitool/Rules/SARIF1011.ReferenceFinalSchema.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Json.Pointer; using System; using System.Collections.Generic; +using Microsoft.Json.Pointer; namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules {