Пример #1
0
        public void MakeUriAbsoluteVisitor_VisitPhysicalLocation_DoesNotSetUriIfNotInDictionary()
        {
            var run = new Run
            {
                OriginalUriBaseIds = new Dictionary <string, ArtifactLocation>
                {
                    ["%TEST%"] = new ArtifactLocation {
                        Uri = new Uri("C:/github/sarif/")
                    }
                }
            };

            // Initializes visitor with run in order to retrieve uri base id mappings
            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();

            visitor.VisitRun(run);

            PhysicalLocation location = new PhysicalLocation()
            {
                ArtifactLocation = new ArtifactLocation {
                    UriBaseId = "%TEST2%", Uri = new Uri("src/file.cs", UriKind.Relative)
                }
            };

            PhysicalLocation newLocation = visitor.VisitPhysicalLocation(location);

            newLocation.ArtifactLocation.UriBaseId.Should().NotBeNull();
            newLocation.ArtifactLocation.Uri.Should().BeEquivalentTo(new Uri("src/file.cs", UriKind.Relative));
        }
Пример #2
0
        public void MakeUriAbsoluteVisitor_CombineUriValidatesArgumentsProperly()
        {
            Uri absoluteUri = new Uri("https://absolute.example.com", UriKind.Absolute);
            Uri relativeUri = new Uri("relative/someResource", UriKind.Relative);

            // First, ensure that our test data succeeds when used properly
            MakeUrisAbsoluteVisitor.CombineUris(
                absoluteBaseUri: absoluteUri,
                relativeUri: relativeUri);

            // Pass relative URI where absolute expected.
            Action action = () =>
            {
                MakeUrisAbsoluteVisitor.CombineUris(
                    absoluteBaseUri: relativeUri,
                    relativeUri: relativeUri);
            };

            action.Should().Throw <ArgumentException>();

            // Pass absolute URI where relative expected.
            action = () =>
            {
                MakeUrisAbsoluteVisitor.CombineUris(
                    absoluteBaseUri: absoluteUri,
                    relativeUri: absoluteUri);
            };

            action.Should().Throw <ArgumentException>();
        }
Пример #3
0
        public void MakeUriAbsoluteVisitor_VisitSarifLog_MultipleRunsWithDifferentProperties_RebasesProperly()
        {
            Run runA = GenerateRunForTest(new Dictionary <string, ArtifactLocation>()
            {
                ["%TEST1%"] = new ArtifactLocation {
                    Uri = new Uri(@"C:\srcroot\")
                },
                ["%TEST2%"] = new ArtifactLocation {
                    Uri = new Uri(@"D:\bld\out\")
                }
            });
            Run runB = GenerateRunForTest(new Dictionary <string, ArtifactLocation>()
            {
                ["%TEST1%"] = new ArtifactLocation {
                    Uri = new Uri(@"C:\src\abc\")
                },
                ["%TEST2%"] = new ArtifactLocation {
                    Uri = new Uri(@"D:\bld\123\")
                }
            });
            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();

            SarifLog log = new SarifLog()
            {
                Runs = new Run[] { runA, runB }
            };
            SarifLog newLog = visitor.VisitSarifLog(log);

            // Validate
            newLog.Runs.Should().HaveCount(2);
            newLog.Runs[0].Artifacts.Should().NotIntersectWith(newLog.Runs[1].Artifacts);
        }
Пример #4
0
        public void MakeUriAbsoluteVisitor_VisitRun_SetsAbsoluteUriForAllApplicableFiles()
        {
            Run run = GenerateRunForTest(new Dictionary <string, ArtifactLocation>()
            {
                ["%TEST1%"] = new ArtifactLocation {
                    Uri = new Uri(@"C:\srcroot\")
                },
                ["%TEST2%"] = new ArtifactLocation {
                    Uri = new Uri(@"D:\bld\out\")
                }
            });

            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();

            Run newRun = visitor.VisitRun(run);

            // Validate.
            newRun.Artifacts[0].Location.Uri.ToString().Should().Be(@"file:///C:/srcroot/src/file1.cs");
            newRun.Artifacts[1].Location.Uri.ToString().Should().Be(@"file:///D:/bld/out/src/file2.dll");
            newRun.Artifacts[2].Location.Uri.ToString().Should().Be(@"file:///C:/srcroot/src/archive.zip");
            newRun.Artifacts[3].Location.Uri.ToString().Should().Be(@"file3.cs");
            newRun.Artifacts[4].Location.Uri.ToString().Should().Be(@"archive2.gz");
            newRun.Artifacts[5].Location.Uri.ToString().Should().Be(@"file4.cs");

            // Operation should zap all uri base ids
            newRun.Artifacts.Where(f => f.Location.UriBaseId != null).Any().Should().BeFalse();
        }
Пример #5
0
        public void MakeUriAbsoluteVisitor_CombineUriFunctionsProperly()
        {
            var testCases = new Tuple <string, string, string>[]
            {
                new Tuple <string, string, string>
                    (@"https://base/", @"relative/file.cpp", "https://base/relative/file.cpp")
            };

            foreach (Tuple <string, string, string> testCase in testCases)
            {
                MakeUrisAbsoluteVisitor.CombineUris(
                    absoluteBaseUri: new Uri(testCase.Item1, UriKind.Absolute),
                    relativeUri: new Uri(testCase.Item2, UriKind.Relative))
                .Should().Be(testCase.Item3);
            }
        }
Пример #6
0
        public void MakeUriAbsoluteVisitor_VisitRun_DoesNotSetAbsoluteUriIfNotApplicable()
        {
            Dictionary <string, ArtifactLocation> uriMapping = new Dictionary <string, ArtifactLocation>()
            {
                ["%TEST3%"] = new ArtifactLocation {
                    Uri = new Uri(@"C:\srcroot\")
                },
                ["%TEST4%"] = new ArtifactLocation {
                    Uri = new Uri(@"D:\bld\out\")
                }
            };

            Run expectedRun = GenerateRunForTest(uriMapping);
            Run actualRun   = expectedRun.DeepClone();

            MakeUrisAbsoluteVisitor visitor = new MakeUrisAbsoluteVisitor();
            Run newRun = visitor.VisitRun(actualRun);

            expectedRun.ValueEquals(actualRun).Should().BeTrue();
        }