Example #1
0
        public void testSeverity()
        {
            ValuesController vc       = new ValuesController("nvdcve-1.0-2017.json");
            CVEWrapper       cveItems = vc.Get(1, "HIGH");

            Assert.AreEqual(25, cveItems.items.Count);
            Assert.IsFalse(cveItems.items.Any(x => x.severity != "HIGH"));
        }
Example #2
0
        public void page325()
        {
            ValuesController vc       = new ValuesController("nvdcve-1.0-2017.json");
            CVEWrapper       cveItems = vc.Get(325);

            Assert.AreEqual(8, cveItems.items.Count);
            Assert.AreEqual(8083, cveItems.count);
        }
Example #3
0
        public void testJsonLoad()
        {
            ValuesController vc       = new ValuesController("nvdcve-1.0-2017.json");
            CVEWrapper       cveItems = vc.Get();

            Assert.AreEqual(25, cveItems.items.Count);
            Assert.AreEqual(8083, cveItems.count);
        }
Example #4
0
        public void pageZero()
        {
            ValuesController vc       = new ValuesController("nvdcve-1.0-2017.json");
            CVEWrapper       cveItems = vc.Get(0);

            Assert.AreEqual(25, cveItems.items.Count);
            Assert.AreEqual(8083, cveItems.count);
            Assert.AreEqual("CVE-2017-0001", cveItems.items[0].ID);
        }
Example #5
0
        // GET api/values
        public CVEWrapper Get(int page = 1, string sev = "")
        {
            CVE.Models.Schema cveObject = CVE.Models.Schema.FromJson(File.ReadAllText(physicalPath));
            if (page < 1)
            {
                page = 1;
            }
            List <Def_cve_item> wholeList = null;

            if (string.IsNullOrWhiteSpace(sev))
            {
                wholeList = cveObject.CVE_Items.ToList();
            }
            else
            {
                wholeList = cveObject.CVE_Items.Where(x => x.Impact.BaseMetricV3.CvssV3.BaseSeverity.ToString() == sev).ToList();
            }

            if (((page + 1) * PAGE_SIZE) > wholeList.Count)
            {
                page = (wholeList.Count / PAGE_SIZE) + 1;
            }

            int numToSkip = (page - 1) * PAGE_SIZE;

            List <Def_cve_item> sourceList = wholeList.Skip(numToSkip).Take(PAGE_SIZE).ToList();
            CVEWrapper          myWrapper  = new CVEWrapper();

            myWrapper.count = wholeList.Count;
            myWrapper.items = new List <CVEItem>();
            foreach (Def_cve_item myItem in sourceList)
            {
                CVEItem addItem = new CVEItem(myItem);
                myWrapper.items.Add(addItem);
            }
            return(myWrapper);
        }