コード例 #1
0
        public void FortifyConverter_Convert_KingdomIsInProperties()
        {
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(FortifyConverterTests.GetBasicIssue());

            result.PropertyNames.Count.Should().Be(1);
            result.GetProperty("kingdom").Should().Be("king");
        }
コード例 #2
0
        public void FortifyConverter_Convert_KingdomIsInProperties()
        {
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(FortifyConverterTests.GetBasicIssue());

            result.Properties.Should().Equal(new Dictionary <string, string>
            {
                { "kingdom", "king" }
            });
        }
コード例 #3
0
        public void FortifyConverter_Convert_FullMessageUsesAbstractCustomIfPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.AbstractCustom = "Some abstract custom message";
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.AreEqual("Some abstract custom message", result.FullMessage);
        }
コード例 #4
0
        public void FortifyConverter_Convert_ConcatenatesAbstractsIfBothPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.Abstract       = "Some abstract message";
            builder.AbstractCustom = "Some abstract custom message";
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.AreEqual("Some abstract message" + Environment.NewLine + "Some abstract custom message",
                            result.FullMessage);
        }
コード例 #5
0
        public void FortifyConverter_Convert_FillsInFortifyRuleIdIfPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();
            Result  result  = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.IsTrue(result.Properties == null || !result.Properties.ContainsKey("fortifyRuleId"),
                          "Fortify RuleID was filled in when no ruleId was present.");

            builder.RuleId = "abc";
            result         = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());
            Assert.AreEqual("abc", result.Properties["fortifyRuleId"]);
        }
コード例 #6
0
        public void FortifyConverter_Convert_FillsInCweIfPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();
            Result  result  = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.IsTrue(result.Properties == null || !result.Properties.ContainsKey("cwe"),
                          "CWE was filled in when no CWEs were present.");

            builder.CweIds = ImmutableArray.Create(24, 42, 1729);
            result         = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());
            Assert.AreEqual("24, 42, 1729", result.Properties["cwe"]);
        }
コード例 #7
0
        public void FortifyConverter_Convert_FillsInPriorityIfFriorityPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();
            Result  result  = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.IsTrue(result.Properties == null || !result.Properties.ContainsKey("priority"),
                          "Priority was set to a null value.");

            builder.Priority = "HIGH";
            result           = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());
            Assert.AreEqual("HIGH", result.Properties["priority"]);
        }
コード例 #8
0
        public void FortifyConverter_Convert_UsesPrimaryAsMainLocation()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.Source = FortifyConverterTests.s_dummyPathSourceElement;
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.AreEqual(1, result.Locations.Count);
            Assert.AreEqual("filePath", result.Locations[0].ResultFile[0].Uri.ToString());
            Assert.AreEqual(new Region {
                StartLine = 1729
            }, result.Locations[0].ResultFile[0].Region);
        }
コード例 #9
0
        public void FortifyConverter_Convert_UsesPrimaryAsMainLocation()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.Source = FortifyConverterTests.s_dummyPathSourceElement;
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.Equal(1, result.Locations.Count);
            Assert.Equal("filePath", result.Locations.First().PhysicalLocation.FileLocation.Uri.ToString());
            Assert.True(result.Locations.First().PhysicalLocation.Region.ValueEquals(new Region {
                StartLine = 1729
            }));
        }
コード例 #10
0
        public void FortifyConverter_Convert_ToolFingerprintIsIid()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.InstanceId = "a";
            Result resultA = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.AreEqual("a", resultA.ToolFingerprint);

            builder.InstanceId = null; // IID is optional
            Result resultNull = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.IsNull(resultNull.ToolFingerprint);
        }
コード例 #11
0
        public void FortifyConverter_Convert_ToolFingerprintIsIid()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.InstanceId = "a";
            Result resultA = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.True(resultA.PartialFingerprints.Values.Contains("a"));

            builder.InstanceId = null; // IID is optional
            Result resultNull = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.Null(resultNull.PartialFingerprints);
        }
コード例 #12
0
        public void FortifyConverter_Convert_FillsInExecutionFlowWhenSourceIsPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.Source = FortifyConverterTests.s_dummyPathSourceElement;
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.AreEqual(1, result.ExecutionFlows.Count);
            IList <AnnotatedCodeLocation> flow = result.ExecutionFlows[0];

            Assert.AreEqual("sourceFilePath", flow[0].PhysicalLocation[0].Uri.ToString());
            Assert.AreEqual(new Region {
                StartLine = 42
            }, flow[0].PhysicalLocation[0].Region);
            Assert.AreEqual("filePath", flow[1].PhysicalLocation[0].Uri.ToString());
            Assert.AreEqual(new Region {
                StartLine = 1729
            }, flow[1].PhysicalLocation[0].Region);
        }
コード例 #13
0
        public void FortifyConverter_Convert_FillsInCodeFlowWhenSourceIsPresent()
        {
            Builder builder = FortifyConverterTests.GetBasicBuilder();

            builder.Source = FortifyConverterTests.s_dummyPathSourceElement;
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(builder.ToImmutable());

            Assert.Equal(1, result.CodeFlows.Count);
            IList <ThreadFlowLocation> flowLocations = result.CodeFlows.First().ThreadFlows.First().Locations;

            Assert.Equal("sourceFilePath", flowLocations[0].Location.PhysicalLocation.FileLocation.Uri.ToString());
            Assert.True(flowLocations[0].Location.PhysicalLocation.Region.ValueEquals(new Region {
                StartLine = 42
            }));
            Assert.Equal("filePath", flowLocations[1].Location.PhysicalLocation.FileLocation.Uri.ToString());
            Assert.True(flowLocations[1].Location.PhysicalLocation.Region.ValueEquals(new Region {
                StartLine = 1729
            }));
        }
コード例 #14
0
        public void FortifyConverter_Convert_RuleIdIsKingdomAndCategory()
        {
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(FortifyConverterTests.GetBasicIssue());

            Assert.AreEqual("cat", result.RuleId);
        }
コード例 #15
0
 private static FortifyIssue GetBasicIssue()
 {
     return(FortifyConverterTests.GetBasicBuilder().ToImmutable());
 }
コード例 #16
0
        public void FortifyConverter_Convert_FullMessageFallsBackToCategoryIfNoAbstractPresent()
        {
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(FortifyConverterTests.GetBasicIssue());

            result.FullMessage.Should().Contain("cat");
        }
コード例 #17
0
        public void FortifyConverter_Convert_ShortMessageIsUnset()
        {
            Result result = FortifyConverter.ConvertFortifyIssueToSarifIssue(FortifyConverterTests.GetBasicIssue());

            Assert.IsNull(result.ShortMessage);
        }