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); }
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); }
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))); } }
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)); }
public async Task <ActionResult> Index() { await virusScanner.ScanFileAsync(Encoding.ASCII.GetBytes("test"), User.GetAccessToken()); return(View()); }