Пример #1
0
        public void V2ResultMatcher_RemovedAndAdded()
        {
            Run newRun = SampleRun.DeepClone();

            newRun.Results.RemoveAt(2);

            Result newResult = newRun.Results[0].DeepClone();

            newResult.Locations[0].PhysicalLocation.ArtifactLocation.Uri = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/NEW.pem");
            newResult.PartialFingerprints = null;
            newResult.Message.Text        = "Different Message";
            newRun.Results.Add(newResult);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(4);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(2);

            MatchedResults removed = matches.Where(m => m.CurrentResult == null).First();

            SampleRun.Results[2].Should().BeSameAs(removed.PreviousResult.Result);

            MatchedResults added = matches.Where(m => m.PreviousResult == null).First();

            newResult.Should().BeSameAs(added.CurrentResult.Result);
        }
Пример #2
0
        public void V2ResultMatcher_MessageContainsLineNumbers()
        {
            // Messages have line and column numbers removed before comparison, so results will still be "sufficiently similar"
            // if the message references them and the results move to a different line.

            Run firstRun = SampleRun.DeepClone();

            Result result = firstRun.Results[2];

            result.PartialFingerprints = null;
            result.Message             = new Message()
            {
                Text = $"Found issue on line {result.Locations[0].PhysicalLocation.Region.StartLine}"
            };

            Run secondRun = firstRun.DeepClone();

            result = secondRun.Results[2];
            result.Locations[0].PhysicalLocation.Region.StartLine += 5;
            result.Message = new Message()
            {
                Text = $"Found issue on line {result.Locations[0].PhysicalLocation.Region.StartLine}"
            };

            IEnumerable <MatchedResults> matches = CreateMatchedResults(firstRun, secondRun);

            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().BeEmpty();
        }
Пример #3
0
        //public static OleDbConnection conn = new OleDbConnection("Provider=MSDAORA.1;User ID=gkfqd;Password=123456;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))");

        //public static OracleConnection gkfqd.Common.DbUse.GetOleDbconnection() = new OracleConnection("Datasource =ORCL; User = gkfqd; Password = 123456;");
        #endregion

        #region 初始化
        public gk043()
        {
            try
            {
                InitializeComponent();
                //区县comboBox列表加载
                LoadComboBox();
                //默认选内蒙古自治区
                comboBox1.SelectedIndex = 0;
                //默认年份为 全部
                comboBox4.SelectedIndex = 0;
                //不显示dataGridView1最后一行
                dataGridView1.AllowUserToAddRows = false;
                //默认叠加年份2014
                comboBox4.Text   = "2017";
                comboBox5.Text   = "2017";
                this.x_workspace = new SuperMap.Data.Workspace();
                //this.mapControl1 = new SuperMap.UI.MapControl();
                //m_mapControl.Dock = DockStyle.Fill;
                m_sampleRun = new SampleRun(x_workspace, mapControl1);
                //x_sampleRun = new SampleRun(x_workspace, mapControl1);
                //base.Controls.Add(mapControl1);
                base.Controls.SetChildIndex(mapControl1, 0);
                mapControl1.GeometrySelected += new SuperMap.UI.GeometrySelectedEventHandler(m_mapControl_GeometrySelected);
                // mapControl1.Paint += new PaintEventHandler(m_mapControl_Paint);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Пример #4
0
        public void V2ResultMatcher_MoveWithinFile()
        {
            Run newRun = SampleRun.DeepClone();

            newRun.Results[2].Locations[0].PhysicalLocation.Region.StartLine += 1;

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().BeEmpty();
        }
Пример #5
0
        public void V2ResultMatcher_RenameFile()
        {
            Run newRun = SampleRun.DeepClone();

            newRun.Results[2].Locations[0].PhysicalLocation.ArtifactLocation.Index = -1;
            newRun.Results[2].Locations[0].PhysicalLocation.ArtifactLocation.Uri   = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/public-encrypt/test/test_rsa_privkey_NEW.pem");

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().BeEmpty();
        }
Пример #6
0
        public void V2ResultMatcher_RemoveResult()
        {
            Run newRun = SampleRun.DeepClone();

            newRun.Results.RemoveAt(2);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(4);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(1);

            MatchedResults nonMatch = matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).First();

            SampleRun.Results[2].Should().BeSameAs(nonMatch.PreviousResult.Result);
        }
Пример #7
0
        public void V2ResultMatcher_IgnoresConstantPartialFingerprint()
        {
            // If there's a PartialFingerprint which is useless (the same for every result),
            // the baseliner needs to recognize the situation and disregard that partialFingerprint.

            // Spam had this issue with CanonicalLogicalLocation in JSON files where
            // all user content is in one place (WorkItemHyperLink -> "url")

            Run firstRun  = SampleRun.DeepClone();
            Run secondRun = SampleRun.DeepClone();

            foreach (Result result in firstRun.Results)
            {
                // Give each result a unique (non-matching) and constant fingerprint
                result.PartialFingerprints.Clear();
                result.PartialFingerprints["SecretHash/v1"] = Guid.NewGuid().ToString(SarifConstants.GuidFormat);
                result.PartialFingerprints["Useless/v1"]    = "Constant";

                // Give each result a unique (non-matching) snippet (to ensure fallback doesn't match)
                result.Locations[0].PhysicalLocation.Region.Snippet.Text = Guid.NewGuid().ToString(SarifConstants.GuidFormat);
            }

            foreach (Result result in secondRun.Results)
            {
                // Give each result a unique (non-matching) and constant fingerprint
                result.PartialFingerprints.Clear();
                result.PartialFingerprints["SecretHash/v1"] = Guid.NewGuid().ToString(SarifConstants.GuidFormat);
                result.PartialFingerprints["Useless/v1"]    = "Constant";

                Region region = result.Locations[0].PhysicalLocation.Region;

                // Give each result a unique (non-matching) snippet (to ensure fallback doesn't match)
                region.Snippet.Text = Guid.NewGuid().ToString(SarifConstants.GuidFormat);

                // Ensure each results moves, so none match by where
                region.StartLine += 100;
            }

            // Match the Runs, and confirm *nothing* matches; this requires the constant partialFingerprint not to be trusted
            IEnumerable <MatchedResults> matches = CreateMatchedResults(firstRun, secondRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().BeEmpty();
        }
Пример #8
0
        public void V2ResultMatcher_TwoRulesSameLine()
        {
            // Verify that two Results with identical locations but different RuleIDs sort in a consistent order
            // so that they will be matched with each other.

            // COMPLEX: Getting to the "sufficiently similar" check requires that they don't match beforehand due to:
            //  - Identical where, so the results must move
            //  - Unique identical what, so there must be other unmatched results which share every trait with the ones we're checking

            Run firstRun       = SampleRun.DeepClone();
            int countBeforeAdd = firstRun.Results.Count;

            // Copy the first Result and change the Rule only (they'll have same Message, Fingerprints, Location)
            firstRun.Results[1]        = firstRun.Results[0].DeepClone();
            firstRun.Results[1].RuleId = "NewRuleId";

            // Make another copy of each result and move them so that the results won't have any per-rule unique traits
            firstRun.Results.Add(firstRun.Results[0].DeepClone());
            firstRun.Results.Add(firstRun.Results[1].DeepClone());

            firstRun.Results[countBeforeAdd].Locations[0].PhysicalLocation.Region.StartLine     += 1;
            firstRun.Results[countBeforeAdd + 1].Locations[0].PhysicalLocation.Region.StartLine += 1;

            Run secondRun = firstRun.DeepClone();

            // Move all Results down
            secondRun.Results[0].Locations[0].PhysicalLocation.Region.StartLine += 4;
            secondRun.Results[1].Locations[0].PhysicalLocation.Region.StartLine += 4;

            secondRun.Results[countBeforeAdd].Locations[0].PhysicalLocation.Region.StartLine     += 1;
            secondRun.Results[countBeforeAdd + 1].Locations[0].PhysicalLocation.Region.StartLine += 1;

            // Swap the order of them to reduce the chance they'll sort the same
            Result swap = secondRun.Results[0];

            secondRun.Results[0] = secondRun.Results[1];
            secondRun.Results[1] = swap;

            // Verify all Results match
            IEnumerable <MatchedResults> matches = CreateMatchedResults(firstRun, secondRun);

            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().BeEmpty();
        }
Пример #9
0
        public void V2ResultMatcher_AddResult()
        {
            Run    newRun    = SampleRun.DeepClone();
            Result newResult = newRun.Results[0].DeepClone();

            newResult.Locations[0].PhysicalLocation.ArtifactLocation.Uri = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/NEW.pem");
            newResult.PartialFingerprints = null;
            newResult.Properties          = null;

            newRun.Results.Add(newResult);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(5);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(1);

            MatchedResults nonMatch = matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).First();

            newResult.Should().BeSameAs(nonMatch.CurrentResult.Result);
        }
Пример #10
0
        public void V2ResultMatcher_TwoAdded()
        {
            Run newRun = SampleRun.DeepClone();

            Result newResult = newRun.Results[0].DeepClone();

            newResult.Locations[0].PhysicalLocation.ArtifactLocation.Uri = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/NEW.pem");
            newResult.Message.Text = "Different Message";
            newRun.Results.Add(newResult);

            Result newResult2 = newRun.Results[2].DeepClone();

            newResult.Locations[0].PhysicalLocation.ArtifactLocation.Uri = new Uri("file:///C:/Code/elfie-arriba/XForm/XForm.Web/node_modules/NEW_2.pem");
            newResult.Message.Text = "Different Message";
            newRun.Results.Add(newResult);

            IEnumerable <MatchedResults> matches = CreateMatchedResults(SampleRun, newRun);

            matches.Where(m => m.PreviousResult != null && m.CurrentResult != null).Should().HaveCount(5);
            matches.Where(m => m.PreviousResult == null || m.CurrentResult == null).Should().HaveCount(2);
        }
Пример #11
0
        public void V2ResultMatcher_MatchesFirstAndLastInFile()
        {
            // We want to ensure that the first and last Results in a file are compared.
            // To cover this, we need:
            //  - No unique properties in any results in the file.
            //  - The Result file Uri stays the same. (No file rename)
            //  - The Result moves within the file, but is still first/last.
            //  - The Results just before and after (in the file just before and after) change order

            // To do this, we'll change the URIs of /public-encrypt/test/test.pem and test_rsa_privkey_encrypted.pem to /zzz/test
            // and will move the result in /public-encrypt/test/test_rsa_privkey.pem

            Run firstRun  = SampleRun.DeepClone();
            Run secondRun = SampleRun.DeepClone();

            // Change Uris for Result[1] and Result[3]
            string changeFrom = "/public-encrypt/";
            string changeTo   = "/zzz/";

            ReplaceInUri(secondRun.Artifacts[1].Location, changeFrom, changeTo);
            ReplaceInUri(secondRun.Artifacts[3].Location, changeFrom, changeTo);
            ReplaceInUri(secondRun.Results[1].Locations[0].PhysicalLocation.ArtifactLocation, changeFrom, changeTo);
            ReplaceInUri(secondRun.Results[3].Locations[0].PhysicalLocation.ArtifactLocation, changeFrom, changeTo);

            // Move Result[2]
            Result firstInFile = secondRun.Results[2];

            firstInFile.Locations[0].PhysicalLocation.Region.StartLine  += 1;
            firstInFile.Locations[0].PhysicalLocation.Region.CharOffset += 5;

            // Verify the result matched, and matched the copy from the same file
            IEnumerable <MatchedResults> matches = CreateMatchedResults(firstRun, secondRun);
            MatchedResults match = matches.Where(m => Location.ValueComparer.Equals(m.CurrentResult?.Result?.Locations?.FirstOrDefault(), firstInFile.Locations[0])).FirstOrDefault();

            Assert.NotNull(match.PreviousResult);
            Assert.Equal(
                match.PreviousResult.Result.Locations[0].PhysicalLocation.ArtifactLocation.Uri,
                match.CurrentResult.Result.Locations[0].PhysicalLocation.ArtifactLocation.Uri);
        }