Beispiel #1
0
        public IActionResult Scan(URLItem item)
        {
            // Get url from user
            string stringUrl = item.Url;
            bool   isUri     = Uri.IsWellFormedUriString(stringUrl, UriKind.RelativeOrAbsolute);

            if (!isUri)
            {
                return(BadRequest("URL is invalid"));
            }

            // Throw an error if there is no response for this URL
            if (!_scannerService.GetResponse(stringUrl))
            {
                throw new Exception("Something is wrong with file");
            }

            if (_scannerService.GetFileSize() > 209715200)
            {
                return(BadRequest("File size is too big, should be below 200 MB"));
            }

            // Write the response to the user
            item.Result = _virusScanService.GetVirusScanResult();
            item.Sha1   = _scannerService.GetCheckSum();

            _context.URLItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetURL", new { id = item.Id, result = item.Result, sha1 = item.Sha1 }, item));
        }
        public void GetCheckSumShouldReturnAValue()
        {
            _scannerService.GetResponse("http://ipv4.download.thinkbroadband.com/5MB.zip");

            var sha1 = _scannerService.GetCheckSum();

            Assert.NotNull(sha1);
        }