Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement smart validation in SarifCli tool #501

Merged
53 commits merged into from Sep 1, 2016
Merged

Implement smart validation in SarifCli tool #501

53 commits merged into from Sep 1, 2016

Conversation

ghost
Copy link

@ghost ghost commented Aug 23, 2016

We implement the framework for the validator and its functional tests, and we implement the following rules:

  • AnnotatedCodeLocationEssentialIsObsolete
  • AnnotatedCodeLocationIdIsObsolete
  • DoNotUseFriendlyNameAsRuleId
  • EndColumnMustNotBeLessThanStartColumn
  • EndLineMustNotBeLessThanStartLine
  • EndTimeMustBeAfterStartTime
  • HashAlgorithmsMustBeUnique
  • ImportanceMustAppearOnlyInCodeFlowLocations
  • MessagesShouldEndWithPeriod
  • StepMustAppearOnlyInCodeFlowLocations
  • StepValuesMustFormOneBasedSequence
  • UrisMustBeValid
  • UseAbsolutePathsForNestedUriFragments

Subsequent PRs will implement more rules.

The validator is built on the Sarif.Driver framework. The validator performs schema validation in addition to the "smart validation" rules.

The smart validation rules get their location information as follows:

  1. Construct a JSON pointer (such as "/runs/0/rules/SV0001") to represent the logical location of the result.
  2. Evaluate that pointer against a JToken that represents the entire document, producing a JToken that represents the element specified by the pointer.
  3. Extract the location information from the JToken.

We use the JSON Pointer implementation from Microsoft.Json.Pointer, which is obtained from NuGet along with Microsoft.Json.Schema. This is the first use of the JSON Pointer implementation.

Although a skeleton project for the validator already existed, you should read this as completely new code.

NOTE 1: I ran into the circular dependency thing we've seen before, where a project in sarif-sdk (in this case, the new SarifCli and SarifCli.FunctionalTest projects) depends on JSchema, which in turn depends on a different version of sarif-sdk. The comments on commit bf4b015 explain how I fixed it.

NOTE 2: I also took the opportunity to fix our dependency on the foreign checked in binary Microsoft.Json.Schema.dll in the src\References directory. Commits 046c98f, d6de920, and c1e2261 removed the FCIB dependencies, replaced them with NuGet dependencies on Microsoft.Json.Schema and Microsoft.Json.Pointer, and removed the src\References directory.

NOTE 3: I took the opportunity to upgrade our dependency on Microsoft.Json.Schema.ToDotNet from version 0.42.0 to the latest 0.45.0 (commit 00a6e30). As a result, all the files in the Autogenerated directory were modified (the version specified in their GeneratedCode attributes changed from 0.42.0 to 0.45.0.

@ghost ghost assigned ghost and michaelcfanning and unassigned ghost Aug 23, 2016
@@ -0,0 +1,25 @@
{
Copy link
Author

@ghost ghost Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file does not violate the rule. #Closed

Larry Golding added 18 commits August 24, 2016 07:16
The build broke on AppVeyor. I don't know why it built on my machine.

SarifCli had a P2P dependency on Sarif.csproj, which is currently
building version 1.5.28 of Sarif.dll. But SarifCli also has a binary
dependency on a foreign checked in binary (FCIB),
Microsoft.Json.Schema.dll, which in turn took a NuGet dependency on Sarif
version 1.5.25. This broke the build because (for example), the code
tried to assign an object of type "Result from Sarif v1.5.25" to a
variable of type "Result from Sarif v1.5.28".

To fix this, we did the following:

1. Update the JSchema project to take a NuGet dependency on Sarif 1.5.27
    (the latest published version).
2. Bump the JSchema version number from 0.44.0 to 0.45.0.
3. Rebuild JSchema, and publish v0.45.0 of its NuGet packages.
4. Update the FCIBs with the v0.45.0 of the JSchema assemblies.
5. Replace the P2P dependencies on Sarif.Sdk and Sarif.Driver with
    NuGet dependencies on v1.5.27 of the SARIF packages.

This should fix the problem. Again, this builds on my machine, but we
won't know for sure until the AppVeyor build passes.
@@ -31,6 +31,7 @@ test:
- '**\Sarif.FunctionalTests.dll'
- '**\Sarif.ValidationTests.dll'
- '**\Sarif.Viewer.VisualStudio.UnitTests.dll'
- '**\Microsoft.CodeAnalysis.SarifCli.FunctionalTests.dll'
Copy link
Member

@michaelcfanning michaelcfanning Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.CodeAnalysis [](start = 10, length = 22)

Why is this naming convention different? Should be SarifCli.FunctionalTests.dll. #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


In reply to: 76704201 [](ancestors = 76704201)

{
ReportInvalidSchemaErrors(ex, schemaFilePath, logger);
}
catch (Exception ex)
Copy link
Member

@michaelcfanning michaelcfanning Sep 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception ex) [](start = 19, length = 13)

do you need this? doesn't the framework catch unhandled exceptions? one consideration here is the return value of the tool. An unhandled exception should certainly return a non-zero (i.e., non-success code). is that happening? #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Fixed. Removed the handler.


In reply to: 77238313 [](ancestors = 77238313)

@michaelcfanning
Copy link
Member

:shipit:

@ghost
Copy link
Author

ghost commented Sep 1, 2016

Per our discussion, I'll merge this and address the feedback in a separate PR> #Closed

@ghost ghost merged commit d43c42e into microsoft:master Sep 1, 2016
@ghost ghost deleted the smart-validator branch September 1, 2016 19:56
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant