Esempio n. 1
0
        public async void PostScan_GivenFile_ScannerShouldBeCalled()
        {
            var file = A.Dummy <byte[]>();

            await controller.Scan(file);

            A.CallTo(() => scanner.ScanFileAsync(file, string.Empty)).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 2
0
        public async Task <byte[]> GetFileBytes(HttpPostedFileBase file, string token)
        {
            byte[] fileBytes;

            using (var memoryStream = new MemoryStream())
            {
                await file.InputStream.CopyToAsync(memoryStream);

                fileBytes = memoryStream.ToArray();
            }

            if (await virusScanner.ScanFileAsync(fileBytes, token) == ScanResult.Virus)
            {
                throw new VirusFoundException(string.Format("Virus found in file {0}", file.FileName));
            }

            return(fileBytes);
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Scan(byte[] file)
        {
            try
            {
                var result = await virusScanner.ScanFileAsync(file, string.Empty);

                return(Ok(result));
            }
            catch (AuthenticationException ex)
            {
                return(this.StatusCode(HttpStatusCode.Unauthorized, new HttpError(ex, includeErrorDetail: true)));
            }
            catch (SecurityException ex)
            {
                return(this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true)));
            }
            catch (IOException ex)
            {
                return(this.StatusCode(HttpStatusCode.InternalServerError, new HttpError(ex, includeErrorDetail: true)));
            }
        }
Esempio n. 4
0
        private async Task <RuleResult <BulkFileRules> > GetVirusScan(HttpPostedFileBase file, string token)
        {
            var result = MessageLevel.Success;

            byte[] fileBytes;

            using (var memoryStream = new MemoryStream())
            {
                await file.InputStream.CopyToAsync(memoryStream);

                fileBytes = memoryStream.ToArray();

                FileBytes = fileBytes;
            }

            if (await virusScanner.ScanFileAsync(fileBytes, token) == ScanResult.Virus)
            {
                result = MessageLevel.Error;
            }

            return(new RuleResult <BulkFileRules>(BulkFileRules.Virus, result));
        }
Esempio n. 5
0
        public async Task <ActionResult> Index()
        {
            await virusScanner.ScanFileAsync(Encoding.ASCII.GetBytes("test"), User.GetAccessToken());

            return(View());
        }