コード例 #1
0
        public void InsertAndDelete_ShouldNoLongerExistAfterDelete()
        {
            // Arrange
            var expectedValue = 0;
            var dbModel       = new OssIndexModel()
            {
                ComponentId = 2,
                Version     = 6072,
                Coordinates = "esse",
                Description = "itaque",
                TypeFormat  = "vero",
                Reference   = "cumque",
                ExpireDate  = DateTime.Now,
                HttpStatus  = 90,
            };

            // Act
            var newId = new OssIndexRepository(AppState.ConnectionString).Insert(dbModel);

            new OssIndexRepository(AppState.ConnectionString).Delete(newId);
            var actualValue = new OssIndexRepository(AppState.ConnectionString)
                              .Select(newId)
                              .Id;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
コード例 #2
0
        public void InsertAndSelect_ShouldEqualInserted()
        {
            // Arrange
            var dbModel = new OssIndexModel()
            {
                ComponentId = 2,
                Version     = 9125,
                Coordinates = "vel",
                Description = "ut",
                TypeFormat  = "vero",
                Reference   = "praesentium",
                ExpireDate  = DateTime.Now,
                HttpStatus  = 6077,
            };
            var expectedValue = new OssIndexRepository(AppState.ConnectionString)
                                .Insert(dbModel);

            // Act
            var actualValue = new OssIndexRepository(AppState.ConnectionString)
                              .Select(expectedValue)
                              .Id;

            // Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
コード例 #3
0
        public void InsertThenUpdate_ShouldReflectChanges()
        {
            // Arrange
            var dummyString = Guid.NewGuid().ToString().Replace("-", "");
            var dbModel     = new OssIndexModel()
            {
                ComponentId = 2,
                Version     = 85,
                Coordinates = dummyString,
                Description = "dolor",
                TypeFormat  = "vero",
                Reference   = "cumque",
                ExpireDate  = DateTime.Now,
                HttpStatus  = 90,
            };

            // Act
            var newId = new OssIndexRepository(AppState.ConnectionString)
                        .Insert(dbModel);

            dummyString = Guid.NewGuid().ToString().Replace("-", "");
            var dbModel2 = new OssIndexRepository(AppState.ConnectionString)
                           .Select(newId);

            dbModel2.Coordinates = dummyString;

            new OssIndexRepository(AppState.ConnectionString)
            .Update(dbModel2);
            var actualValue = new OssIndexRepository(AppState.ConnectionString)
                              .Select(newId)
                              .Coordinates;

            // Assert
            Assert.AreEqual(dummyString, actualValue);
        }
コード例 #4
0
        public int Insert(OssIndexModel obj)
        {
            var storedProc = "sp_insert_oss_index";
            var insertObj  = new
            {
                component_id     = obj.ComponentId,
                version          = obj.Version,
                type_format      = obj.TypeFormat,
                coordinates      = obj.Coordinates,
                description      = obj.Description,
                reference        = obj.Reference,
                expire_date      = obj.ExpireDate,
                http_status      = obj.HttpStatus,
                http_status_date = obj.HttpStatusDate
            };

            return(Insert(storedProc, insertObj));
        }
コード例 #5
0
        public void Update(OssIndexModel obj)
        {
            var storedProc = "sp_update_oss_index";
            var updateObj  = new
            {
                id               = obj.Id,
                component_id     = obj.ComponentId,
                version          = obj.Version,
                type_format      = obj.TypeFormat,
                coordinates      = obj.Coordinates,
                description      = obj.Description,
                reference        = obj.Reference,
                expire_date      = obj.ExpireDate,
                http_status      = obj.HttpStatus,
                http_status_date = obj.HttpStatusDate,
            };

            Update(storedProc, updateObj);
        }
コード例 #6
0
        public void CreateInitialReportShell(int reportId, CoordinatePartsModel coordinatePart)
        {
            // check dbo.component.name on coordinatePart.Name
            // if it exists, return the id
            // else create, return the id
            var component   = _componentRepository.SelectByName(coordinatePart.Name.Trim());
            var componentId = component.Id;

            if (componentId == 0)
            {
                componentId = _componentRepository.Insert(new ComponentModel()
                {
                    Name = coordinatePart.Name.Trim()
                });
            }

            // check dbo.oss_index.component_id
            // if it exists, check `expire_date`
            //    - if older than 30 days, call remote api
            //    - insert results if any to dbo.oss_index_vulnerabilities
            //    - update `expire_date` = NOW
            // else
            //    - create with `expire_date` = NOW
            //    - call remote api
            //    - insert results if any to dbo.oss_index_vulnerabilities
            var ossIndex   = _ossIndexRepository.SelectByComponentId(componentId);
            var ossIndexId = ossIndex.Id;

            if (ossIndexId == 0)
            {
                ossIndex = new OssIndexModel()
                {
                    ComponentId    = componentId,
                    ExpireDate     = DateTime.Now.AddMonths(1),
                    HttpStatus     = (int)HttpStatusCode.Processing,
                    HttpStatusDate = DateTime.Now
                };

                ossIndexId = _ossIndexRepository.Insert(ossIndex);
                ossIndex   = _ossIndexRepository.Select(ossIndexId);
            }

            /* TODO
             *
             * 1. this is always zero as we cannot pass things like `1.4.0` as a decimal, consider deprecating `[vulnuscloud].[dbo].[oss_index].[version]` as this data is already in `[vulnuscloud].[dbo].[oss_index].[coordinates]`
             * 2. [vulnuscloud].[dbo].[oss_index].[coordinates] should be normalized:
             *      `pkg:Nuget/[email protected]`
             *      > pkg: is known, comes from `_coordinatesService`
             *      > Nuget/ should rather be stored as `[vulnuscloud].[dbo].[oss_index].[package_type_id]` - then this links to PackageTypeRepository
             *      > BeITMemcached@ can be read from [vulnuscloud].[dbo].[component].[id] = [vulnuscloud].[dbo].[oss_index].[component_id]
             *      > 1.4.0 could then be stored as [vulnuscloud].[dbo].[oss_index].[version]
             *
             *      [vulnuscloud].[dbo].[oss_index].[coordinates] could then be generated when needed.
             */

            if (decimal.TryParse(coordinatePart.Version, out decimal coordinatePartVersion))
            {
                ossIndex.Version = coordinatePartVersion;
            }

            ossIndex.Coordinates = _coordinatesService.GetCoordinates(coordinatePart);
            _ossIndexRepository.Update(ossIndex);

            _reportLinesRepository.Insert(new ReportLinesModel()
            {
                OssIndexId = ossIndexId,
                ReportId   = reportId
            });
        }