diff --git a/src/Sarif.Multitool.FunctionalTests/Rules/ContextRegionRequiresRegionTests.cs b/src/Sarif.Multitool.FunctionalTests/Rules/ContextRegionRequiresRegionTests.cs new file mode 100644 index 000000000..d9a47a0e0 --- /dev/null +++ b/src/Sarif.Multitool.FunctionalTests/Rules/ContextRegionRequiresRegionTests.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Xunit; + +namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules +{ + public class ContextRegionRequiresRegionTests : ValidationSkimmerTestsBase + { + [Fact(DisplayName = nameof(ContextRegionRequiresRegion_ReportsInvalidSarif))] + public void ContextRegionRequiresRegion_ReportsInvalidSarif() + { + // We need to disable compatibility transformations for any files that require + // a malformed schema or malformed JSON, as this code fixes those things up + Verify("Invalid.sarif", disablePrereleaseCompatibilityTransform: true); + } + + [Fact(DisplayName = nameof(ContextRegionRequiresRegion_AcceptsValidSarif))] + public void ContextRegionRequiresRegion_AcceptsValidSarif() + { + Verify("Valid.sarif"); + } + } +} diff --git a/src/Sarif.Multitool.FunctionalTests/Rules/DoNotUseFriendlyNameAsRuleIdTests.cs b/src/Sarif.Multitool.FunctionalTests/Rules/DoNotUseFriendlyNameAsRuleIdTests.cs index 2d009fd31..c4f5a1b17 100644 --- a/src/Sarif.Multitool.FunctionalTests/Rules/DoNotUseFriendlyNameAsRuleIdTests.cs +++ b/src/Sarif.Multitool.FunctionalTests/Rules/DoNotUseFriendlyNameAsRuleIdTests.cs @@ -8,15 +8,9 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules public class DoNotUseFriendlyNameAsRuleIdTests : ValidationSkimmerTestsBase { [Fact(DisplayName = nameof(DoNotUseFriendlyNameAsRuleId_ReportsInvalidSarif))] - public void DoNotUseFriendlyNameAsRuleId_ReportsInvalidSarif() - { - Verify("Invalid.sarif"); - } + public void DoNotUseFriendlyNameAsRuleId_ReportsInvalidSarif() => Verify("Invalid.sarif"); [Fact(DisplayName = nameof(DoNotUseFriendlyNameAsRuleId_AcceptsValidSarif))] - public void DoNotUseFriendlyNameAsRuleId_AcceptsValidSarif() - { - Verify("Valid.sarif"); - } + public void DoNotUseFriendlyNameAsRuleId_AcceptsValidSarif() => Verify("Valid.sarif"); } } diff --git a/src/Sarif.Multitool.FunctionalTests/Rules/UrisMustBeValidTests.cs b/src/Sarif.Multitool.FunctionalTests/Rules/UrisMustBeValidTests.cs index 207e3d93f..efa4fe9a1 100644 --- a/src/Sarif.Multitool.FunctionalTests/Rules/UrisMustBeValidTests.cs +++ b/src/Sarif.Multitool.FunctionalTests/Rules/UrisMustBeValidTests.cs @@ -18,59 +18,14 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules public class UrisMustBeValidTests : ValidationSkimmerTestsBase { - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidFileLocationUri))] - public void UrisMustBeValid_InvalidFileLocationUri() - { - Verify("InvalidFileLocationUri.sarif"); - } + [Fact(DisplayName = nameof(UrisMustBeValid_ReportsInvalidSarif))] + public void UrisMustBeValid_ReportsInvalidSarif() => + // We need to disable compatibility transformations for any files that require + // a malformed schema or malformed JSON, as this code fixes those things up + Verify("Invalid.sarif", disablePrereleaseCompatibilityTransform: true); - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidResultWorkItemUri))] - public void UrisMustBeValid_InvalidResultWorkItemUri() - { - Verify("InvalidResultWorkItemUri.sarif"); - } + [Fact(DisplayName = nameof(UrisMustBeValid_AcceptsValidSarif))] - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidRuleHelpUri))] - public void UrisMustBeValid_InvalidRuleHelpUri() - { - Verify("InvalidRuleHelpUri.sarif"); - } - - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidSarifLogSchemaUri))] - public void UrisMustBeValid_InvalidSarifLogSchemaUri() - { - Verify("InvalidSarifLogSchemaUri.sarif", disablePrereleaseCompatibilityTransform: true); - } - - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidToolDownloadUri))] - public void UrisMustBeValid_InvalidToolDownloadUri() - { - Verify("InvalidToolDownloadUri.sarif"); - } - - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidUriInFilePropertyName))] - public void UrisMustBeValid_InvalidUriInFilePropertyName() - { - Verify("InvalidUriInFilePropertyName.sarif"); - } - - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidUriInOriginalUriBaseIds))] - public void UrisMustBeValid_InvalidUriInOriginalUriBaseIds() - { - Verify("InvalidUriInOriginalUriBaseIds.sarif"); - } - - [Fact(DisplayName = nameof(UrisMustBeValid_InvalidVersionControlDetailsUri))] - public void UrisMustBeValid_InvalidVersionControlDetailsUri() - { - Verify("InvalidVersionControlDetailsUri.sarif"); - } - - [Fact(DisplayName = nameof(UrisMustBeValid_ValidUris))] - - public void UrisMustBeValid_ValidUris() - { - Verify("ValidUris.sarif"); - } + public void UrisMustBeValid_AcceptsValidSarif() => Verify("Valid.sarif"); } } diff --git a/src/Sarif.Multitool.FunctionalTests/Rules/ValidationSkimmerTestsBase.cs b/src/Sarif.Multitool.FunctionalTests/Rules/ValidationSkimmerTestsBase.cs index 8ca593757..06a4e03c1 100644 --- a/src/Sarif.Multitool.FunctionalTests/Rules/ValidationSkimmerTestsBase.cs +++ b/src/Sarif.Multitool.FunctionalTests/Rules/ValidationSkimmerTestsBase.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Linq; using FluentAssertions; using Microsoft.CodeAnalysis.Sarif.Driver; using Microsoft.CodeAnalysis.Sarif.Writers; @@ -120,9 +121,17 @@ protected void Verify(string testFileName, bool disablePrereleaseCompatibilityTr resultsWereVerified.Should().BeTrue(); } + // Every validation message begins with a placeholder "{0}: " that specifies the + // result location, for example, "runs[0].results[0].locations[0].physicalLocation". + // Verify that those detected result locations match the expected locations. private void Verify(Run run, ExpectedValidationResults expectedResults) { run.Results.Count.Should().Be(expectedResults.ResultCount); + + string[] detectedResultLocations = run.Results.Select(r => r.Message.Arguments[0]).OrderBy(loc => loc).ToArray(); + string[] expectedResultLocations = expectedResults.ResultLocationPointers.OrderBy(loc => loc).ToArray(); + + detectedResultLocations.Should().ContainInOrder(expectedResultLocations); } } } \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/ContextRegionRequiresRegion/Invalid.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/ContextRegionRequiresRegion/Invalid.sarif new file mode 100644 index 000000000..3b9f6118f --- /dev/null +++ b/src/Sarif.Multitool.FunctionalTests/TestData/ContextRegionRequiresRegion/Invalid.sarif @@ -0,0 +1,37 @@ +{ + "$schema": "http://json.schemastore.org/sarif-2.0.0", + "version": "2.0.0", + "runs": [ + { + "tool": { + "name": "CodeScanner" + }, + "results": [ + { + "ruleId": "TST0001", + "level": "error", + "locations": [ + { + "physicalLocation": { + "fileLocation": { + "uri": "src/test.c" + }, + "contextRegion": { + "startLine": 2, + "endLine": 4 + } + } + } + ] + } + ], + "properties": { + "expectedResults": { + "resultLocationPointers": [ + "runs[0].results[0].locations[0].physicalLocation" + ] + } + } + } + ] +} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/ContextRegionRequiresRegion/Valid.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/ContextRegionRequiresRegion/Valid.sarif new file mode 100644 index 000000000..6fd6aeffd --- /dev/null +++ b/src/Sarif.Multitool.FunctionalTests/TestData/ContextRegionRequiresRegion/Valid.sarif @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/sarif-2.0.0", + "version": "2.0.0", + "runs": [ + { + "tool": { + "name": "CodeScanner" + }, + "results": [ + { + "ruleId": "TST0001", + "level": "error", + "locations": [ + { + "physicalLocation": { + "fileLocation": { + "uri": "src/test.c" + }, + "region": { + "startLine": 3 + }, + "contextRegion": { + "startLine": 2, + "endLine": 4 + } + } + } + ] + } + ], + "properties": { + "expectedResults": { + "resultLocationPointers": [] + } + } + } + ] +} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif index 39a6ef753..15fb67a73 100644 --- a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif +++ b/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif @@ -22,6 +22,14 @@ } } } + }, + "properties": { + "expectedResults": { + "resultLocationPointers": [ + "runs[0].resources.rules.RULE0001", + "runs[0].resources.rules['RULE0002-1']" + ] + } } } ] diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid_Expected.sarif deleted file mode 100644 index 04af964eb..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid_Expected.sarif +++ /dev/null @@ -1,126 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1001", - "level": "warning", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/resources/rules/RULE0001", - "RULE0001" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif" - }, - "region": { - "startLine": 12, - "startColumn": 23 - } - } - } - ] - }, - { - "ruleId": "SARIF1001", - "level": "warning", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/resources/rules/RULE0002-1", - "RULE0002" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif" - }, - "region": { - "startLine": 18, - "startColumn": 25 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1001": { - "id": "SARIF1001", - "name": { - "text": "DoNotUseFriendlyNameAsRuleId" - }, - "shortDescription": { - "text": "Do not use the same string for a rule's id and name properties. The id property ..." - }, - "fullDescription": { - "text": "Do not use the same string for a rule's id and name properties. The id property must be a stable, opaque identifer such as \"SARIF1001\". The name property should be a string that is understandable to an end user, such as \"DoNotUserFriendlyNameAsRuleId\"." - }, - "messageStrings": { - "Default": "{0}: The name and id properties of rule \"{1}\" are the same." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "LGOLDING-HOME-3": { - "mimeType": "application/octet-stream" - }, - "Larry%20Golding": { - "mimeType": "application/octet-stream" - }, - "file://lgolding-home-3/": { - "mimeType": "application/octet-stream" - }, - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-09-03T16:35:49.089Z", - "endTime": "2018-09-03T16:35:49.831Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Invalid.sarif" - } - }, - "message": { - "text": "Analyzing 'Invalid.sarif'..." - }, - "level": "note", - "time": "2018-09-03T16:35:49.435Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid.sarif index 535281640..42a67f069 100644 --- a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid.sarif +++ b/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid.sarif @@ -22,6 +22,11 @@ } } } + }, + "properties": { + "expectedResults": { + "resultLocationPointers": [] + } } } ] diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid_Expected.sarif deleted file mode 100644 index cd0213bb7..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid_Expected.sarif +++ /dev/null @@ -1,54 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [], - "files": { - "LGOLDING-HOME-3": { - "mimeType": "application/octet-stream" - }, - "Larry%20Golding": { - "mimeType": "application/octet-stream" - }, - "file://lgolding-home-3/": { - "mimeType": "application/octet-stream" - } - }, - "invocations": [ - { - "startTime": "2018-09-03T16:35:50.179Z", - "endTime": "2018-09-03T16:35:50.886Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/DoNotUseFriendlyNameAsRuleId/Valid.sarif" - } - }, - "message": { - "text": "Analyzing 'Valid.sarif'..." - }, - "level": "note", - "time": "2018-09-03T16:35:50.523Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif index 19ab79228..c6c7c2b81 100644 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif +++ b/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif @@ -31,7 +31,19 @@ { "repositoryUri": "example.com/my-project" } - ] + ], + "properties": { + "expectedResults": { + "resultLocationPointers": [ + "$schema", + "runs[0].tool.downloadUri", + "runs[0].results[0].workItemUris[0]", + "runs[0].originalUriBaseIds.SRCROOT", + "runs[0].resources.rules.TST0001.helpUri", + "runs[0].versionControlProvenance[0].repositoryUri" + ] + } + } } ] } \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid_Expected.sarif deleted file mode 100644 index a1741740d..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid_Expected.sarif +++ /dev/null @@ -1,213 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1015", - "level": "error", - "message": { - "messageId": "Default", - "arguments": [ - "/$schema", - "json.schemastore.org/sarif-2.0.0" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - }, - "region": { - "startLine": 2, - "startColumn": 47 - } - } - } - ] - }, - { - "ruleId": "SARIF1015", - "level": "error", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/originalUriBaseIds/SRCROOT", - "Code/sarif-sdk/src" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - }, - "region": { - "startLine": 20, - "startColumn": 20 - } - } - } - ] - }, - { - "ruleId": "SARIF1015", - "level": "error", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/results/0/workItemUris/0", - "example.com/my-project/issues/42" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - }, - "region": { - "startLine": 15, - "startColumn": 46 - } - } - } - ] - }, - { - "ruleId": "SARIF1015", - "level": "error", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/resources/rules/TST0001/helpUri", - "www.example.com/rules/tst0001.html" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - }, - "region": { - "startLine": 26, - "startColumn": 59 - } - } - } - ] - }, - { - "ruleId": "SARIF1015", - "level": "error", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/tool/downloadUri", - "tools/codescanner/download.html" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - }, - "region": { - "startLine": 8, - "startColumn": 56 - } - } - } - ] - }, - { - "ruleId": "SARIF1015", - "level": "error", - "message": { - "messageId": "Default", - "arguments": [ - "/runs/0/versionControlProvenance/0/repositoryUri", - "example.com/my-project" - ] - }, - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - }, - "region": { - "startLine": 32, - "startColumn": 51 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1015": { - "id": "SARIF1015", - "name": { - "text": "UriMustBeAbsolute" - }, - "shortDescription": { - "text": "Certain URIs are required to be absolute." - }, - "fullDescription": { - "text": "Certain URIs are required to be absolute." - }, - "messageStrings": { - "Default": "{0}: The value of this property is required to be an absolute URI, but \"{1}\" is a relative URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-09-12T22:04:27.330Z", - "endTime": "2018-09-12T22:04:28.483Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UriMustBeAbsolute/Invalid.sarif" - } - }, - "message": { - "text": "Analyzing 'Invalid.sarif'..." - }, - "level": "note", - "time": "2018-09-12T22:04:27.879Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/Invalid.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/Invalid.sarif new file mode 100644 index 000000000..9a7000846 --- /dev/null +++ b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/Invalid.sarif @@ -0,0 +1,61 @@ +{ + "$schema": "ht%tp://json.schemastore.org/sarif-2.0.0", + "version": "2.0.0", + "runs": [ + { + "tool": { + "name": "CodeScanner", + "downloadUri": "ht%tp://www.example.com/tools/codescanner/download.html" + }, + "originalUriBaseIds": { + "SRCROOT": { + "uri": "fi%le:///c:/Code/sarif-sdk/src" + } + }, + "results": [ + { + "ruleId": "TST0001", + "level": "error", + "analysisTarget": { + "uri": "fi&le:///c:/src/file.c" + }, + "workItemUris": [ + "ht&tp://example.com/my-project/issues/42" + ] + } + ], + "files": { + "fi%le:///c:/src/file.c": { + "mimeType": "text/x-c" + } + }, + "versionControlProvenance": [ + { + "repositoryUri": "ht%tps://example.com/my-project" + } + ], + "resources": { + "rules": { + "TST0001": { + "id": "TST0001", + "helpUri": "ht%tp://www.example.com/rules/tst0001.html" + } + } + }, + "properties": { + "expectedResults": { + "resultLocationPointers": [ + "$schema", + "runs[0].tool.downloadUri", + "runs[0].originalUriBaseIds.SRCROOT.uri", + "runs[0].results[0].analysisTarget.uri", + "runs[0].results[0].workItemUris[0]", + "runs[0].files['fi%le:///c:/src/file.c']", + "runs[0].versionControlProvenance[0].repositoryUri", + "runs[0].resources.rules.TST0001.helpUri" + ] + } + } + } + ] +} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri.sarif deleted file mode 100644 index 40b80b0b8..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri.sarif +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "results": [ - { - "ruleId": "TST0001", - "level": "error", - "analysisTarget": { - "uri": "fi&le:///c:/src/file.c" - } - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri_Expected.sarif deleted file mode 100644 index a1b85a73c..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/results/0/analysisTarget/uri", - "fi&le:///c:/src/file.c" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri.sarif" - }, - "region": { - "startLine": 14, - "startColumn": 43 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:47.640Z", - "endTime": "2018-08-15T23:04:48.453Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidFileLocationUri.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidFileLocationUri.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:48.006Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri.sarif deleted file mode 100644 index e5236337a..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri.sarif +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "results": [ - { - "ruleId": "TST0001", - "level": "error", - "workItemUris": [ - "ht&tp://example.com/my-project/issues/42" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri_Expected.sarif deleted file mode 100644 index b60fc1bc1..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/results/0/workItemUris/0", - "ht&tp://example.com/my-project/issues/42" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri.sarif" - }, - "region": { - "startLine": 14, - "startColumn": 54 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:48.763Z", - "endTime": "2018-08-15T23:04:49.550Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidResultWorkItemUri.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidResultWorkItemUri.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:49.142Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri.sarif deleted file mode 100644 index bda00f448..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri.sarif +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "resources": { - "rules": { - "TST0001": { - "id": "TST0001", - "helpUri": "ht%tp://www.example.com/rules/tst0001.html" - } - } - } - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri_Expected.sarif deleted file mode 100644 index adfa77a6b..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/resources/rules/TST0001/helpUri", - "ht%tp://www.example.com/rules/tst0001.html" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri.sarif" - }, - "region": { - "startLine": 13, - "startColumn": 67 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:49.865Z", - "endTime": "2018-08-15T23:04:50.659Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidRuleHelpUri.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidRuleHelpUri.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:50.238Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri.sarif deleted file mode 100644 index c5a6cfb80..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri.sarif +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "ht%tp://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "results": [] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri_Expected.sarif deleted file mode 100644 index 53dc34a2c..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/$schema", - "ht%tp://json.schemastore.org/sarif-2.0.0" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri.sarif" - }, - "region": { - "startLine": 2, - "startColumn": 55 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:50.971Z", - "endTime": "2018-08-15T23:04:51.751Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidSarifLogSchemaUri.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidSarifLogSchemaUri.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:51.316Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri.sarif deleted file mode 100644 index 0443a4515..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri.sarif +++ /dev/null @@ -1,13 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner", - "downloadUri": "ht%tp://www.example.com/tools/codescanner/download.html" - }, - "results": [] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri_Expected.sarif deleted file mode 100644 index bd1f83b09..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/tool/downloadUri", - "ht%tp://www.example.com/tools/codescanner/download.html" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri.sarif" - }, - "region": { - "startLine": 8, - "startColumn": 80 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:52.065Z", - "endTime": "2018-08-15T23:04:52.853Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidToolDownloadUri.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidToolDownloadUri.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:52.402Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName.sarif deleted file mode 100644 index 4638a40d3..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName.sarif +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "results": [], - "files": { - "fi%le:///c:/src/file.c": { - "mimeType": "text/x-c" - } - } - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName_Expected.sarif deleted file mode 100644 index cdb4ceb85..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/files/fi%le:~1~1~1c:~1src~1file.c", - "fi%le:///c:/src/file.c" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName.sarif" - }, - "region": { - "startLine": 11, - "startColumn": 35 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:53.170Z", - "endTime": "2018-08-15T23:04:53.959Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInFilePropertyName.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidUriInFilePropertyName.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:53.502Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds.sarif deleted file mode 100644 index 648ea8267..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds.sarif +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "originalUriBaseIds": { - "SRCROOT": "fi%le:///c:/Code/sarif-sdk/src" - }, - "results": [] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds_Expected.sarif deleted file mode 100644 index 6fe7d4c21..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/originalUriBaseIds/SRCROOT", - "fi%le:///c:/Code/sarif-sdk/src" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds.sarif" - }, - "region": { - "startLine": 11, - "startColumn": 20 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:54.278Z", - "endTime": "2018-08-15T23:04:55.063Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidUriInOriginalUriBaseIds.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidUriInOriginalUriBaseIds.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:54.611Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri.sarif deleted file mode 100644 index 5042555f9..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri.sarif +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "CodeScanner" - }, - "results": [], - "versionControlProvenance": [ - { - "uri": "ht%tps://example.com/my-project" - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri_Expected.sarif deleted file mode 100644 index a3b6cfe7d..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri_Expected.sarif +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [ - { - "ruleId": "SARIF1003", - "level": "error", - "message": { - "arguments": [ - "/runs/0/versionControlProvenance/0/repositoryUri", - "ht%tps://example.com/my-project" - ] - }, - "ruleMessageId": "Default", - "locations": [ - { - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri.sarif" - }, - "region": { - "startLine": 12, - "startColumn": 60 - } - } - } - ] - } - ], - "resources": { - "rules": { - "SARIF1003": { - "id": "SARIF1003", - "name": { - "text": "UrisMustBeValid" - }, - "shortDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "fullDescription": { - "text": "Specify a valid URI reference for every URI-valued property." - }, - "messageStrings": { - "Default": "{0}: The string \"{1}\" is not a valid URI reference." - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.0/csprd01/sarif-v2.0-csprd01.html" - } - } - }, - "files": { - "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri.sarif": { - "mimeType": "application/sarif-json" - } - }, - "invocations": [ - { - "startTime": "2018-08-15T23:04:55.393Z", - "endTime": "2018-08-15T23:04:56.427Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/InvalidVersionControlDetailsUri.sarif" - } - }, - "message": { - "text": "Analyzing 'InvalidVersionControlDetailsUri.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:55.740Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/Valid.sarif similarity index 90% rename from src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris.sarif rename to src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/Valid.sarif index 33e19a1d3..3add9866d 100644 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris.sarif +++ b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/Valid.sarif @@ -41,7 +41,12 @@ { "uri": "https://example.com/my-project" } - ] + ], + "properties": { + "expectedResults": { + "resultLocationPointers": [] + } + } } ] } \ No newline at end of file diff --git a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris_Expected.sarif b/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris_Expected.sarif deleted file mode 100644 index b5da6a02f..000000000 --- a/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris_Expected.sarif +++ /dev/null @@ -1,43 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/sarif-2.0.0", - "version": "2.0.0", - "runs": [ - { - "tool": { - "name": "Sarif.Multitool", - "fullName": "Sarif.Multitool 2.0.0.0", - "version": "2.0.0.0", - "semanticVersion": "2.0.0", - "sarifLoggerVersion": "2.0.0.0", - "language": "en-US", - "properties": { - "Comments": "Command line tool to perform transformations of input files to SARIF.", - "CompanyName": "Microsoft", - "ProductName": "Microsoft SARIF SDK" - } - }, - "results": [], - "invocations": [ - { - "startTime": "2018-08-15T23:04:56.825Z", - "endTime": "2018-08-15T23:04:57.666Z", - "toolNotifications": [ - { - "id": "MSG001.AnalyzingTarget", - "physicalLocation": { - "fileLocation": { - "uri": "file:///C:/Code/sarif-sdk/src/Sarif.Multitool.FunctionalTests/TestData/UrisMustBeValid/ValidUris.sarif" - } - }, - "message": { - "text": "Analyzing 'ValidUris.sarif'..." - }, - "level": "note", - "time": "2018-08-15T23:04:57.252Z" - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Sarif.Multitool/Rules/ContextRegionRequiresRegion.cs b/src/Sarif.Multitool/Rules/ContextRegionRequiresRegion.cs new file mode 100644 index 000000000..730df1c0e --- /dev/null +++ b/src/Sarif.Multitool/Rules/ContextRegionRequiresRegion.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Generic; + +namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules +{ + public class ContextRegionRequiresRegion : SarifValidationSkimmerBase + { + private readonly Message _fullDescription = new Message + { + Text = RuleResources.SARIF1016_ContextRegionRequiresRegion + }; + + public override Message FullDescription => _fullDescription; + + public override ResultLevel DefaultLevel => ResultLevel.Error; + + /// + /// SARIF1016 + /// + public override string Id => RuleId.ContextRegionRequiresRegion; + + protected override IEnumerable MessageResourceNames => new string[] + { + nameof(RuleResources.SARIF1016_Default) + }; + + protected override void Analyze(PhysicalLocation physicalLocation, string physicalLocationPointer) + { + if (physicalLocation.ContextRegion != null && physicalLocation.Region == null) + { + LogResult(physicalLocationPointer, nameof(RuleResources.SARIF1016_Default)); + } + } + } +} diff --git a/src/Sarif.Multitool/Rules/RuleId.cs b/src/Sarif.Multitool/Rules/RuleId.cs index 94bbbc10d..2a2b47184 100644 --- a/src/Sarif.Multitool/Rules/RuleId.cs +++ b/src/Sarif.Multitool/Rules/RuleId.cs @@ -16,5 +16,6 @@ public static class RuleId public const string EndColumnMustNotBeLessThanStartColumn = "SARIF1013"; public const string UriBaseIdRequiresRelativeUri = "SARIF1014"; public const string UriMustBeAbsolute = "SARIF1015"; + public const string ContextRegionRequiresRegion = "SARIF1016"; } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs index 553616bac..e18cdcd7e 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.Designer.cs +++ b/src/Sarif.Multitool/Rules/RuleResources.Designer.cs @@ -266,5 +266,23 @@ internal static string SARIF1015_UriMustBeAbsolute { return ResourceManager.GetString("SARIF1015_UriMustBeAbsolute", resourceCulture); } } + + /// + /// Looks up a localized string similar to If the "contextRegion" property is present, the "region" property must also be present.. + /// + internal static string SARIF1016_ContextRegionRequiresRegion { + get { + return ResourceManager.GetString("SARIF1016_ContextRegionRequiresRegion", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This "physicalLocation" object contains a "contextRegion" property, but it does not contain a "region" property.. + /// + internal static string SARIF1016_Default { + get { + return ResourceManager.GetString("SARIF1016_Default", resourceCulture); + } + } } } diff --git a/src/Sarif.Multitool/Rules/RuleResources.resx b/src/Sarif.Multitool/Rules/RuleResources.resx index b2dd3839e..dddd0d245 100644 --- a/src/Sarif.Multitool/Rules/RuleResources.resx +++ b/src/Sarif.Multitool/Rules/RuleResources.resx @@ -186,4 +186,10 @@ Certain URIs are required to be absolute. + + If the "contextRegion" property is present, the "region" property must also be present. + + + This "physicalLocation" object contains a "contextRegion" property, but it does not contain a "region" property. + \ No newline at end of file diff --git a/src/Sarif.Multitool/Rules/UrisMustBeValid.cs b/src/Sarif.Multitool/Rules/UrisMustBeValid.cs index f0279a855..41696a75b 100644 --- a/src/Sarif.Multitool/Rules/UrisMustBeValid.cs +++ b/src/Sarif.Multitool/Rules/UrisMustBeValid.cs @@ -97,7 +97,7 @@ protected override void Analyze(Run run, string runPointer) foreach (string key in run.OriginalUriBaseIds.Keys) { - AnalyzeUri(run.OriginalUriBaseIds[key].Uri, originalUriBaseIdsPointer.AtProperty(key)); + AnalyzeUri(run.OriginalUriBaseIds[key].Uri, originalUriBaseIdsPointer.AtProperty(key).AtProperty(SarifPropertyName.Uri)); } } }