private void Poll(OpswatMalwareService service, Document document, int timeoutSeconds) { var timeout = DateTime.Now.AddSeconds(timeoutSeconds); while (service.Poll(document) == ServiceStatus.Processing && DateTime.Now < timeout) { AssertPollIntervalTimespan(document); Thread.Sleep(5000); } }
public void Should_be_able_to_handle_a_macro_enabled_spreadsheet() { var configuration = OpswatSection.Configuration(); var service = new OpswatMalwareService(configuration, new OpswatApi(configuration)); var document = new Document(Guid.NewGuid(), Guid.NewGuid(), "sanitize.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".files\\sanitize.xlsm")), "integration-test", "system", DateTime.Now); service.Register(document); Assert.That(document.ContainsProperty("data_id"), Is.True); Assert.That(document.ContainsProperty("sha256"), Is.True); Assert.That(document.ContainsProperty("in_queue"), Is.True); Assert.That(document.GetPropertyValue("status"), Is.EqualTo("inqueue")); Assert.That(document.ContainsProperty("scan_all_result_i"), Is.False); Assert.That(document.ContainsProperty("scan_all_result_a"), Is.False); Assert.That(document.ContainsProperty("progress_percentage"), Is.False); Assert.That(document.ContainsProperty("PollIntervalTimespan"), Is.False); Poll(service, document, 120); Assert.That(document.ContainsProperty("data_id"), Is.True); if (configuration.ShouldSandbox(".xlsx")) { Assert.That(document.ContainsProperty("sandbox_id"), Is.True); } Assert.That(document.ContainsProperty("in_queue"), Is.False); Assert.That(document.ContainsProperty("status"), Is.False); Assert.That(document.ContainsProperty("PollIntervalTimespan"), Is.False); Assert.That(document.GetPropertyValue("scan_all_result_i"), Is.EqualTo("0")); Assert.That(document.GetPropertyValue("scan_all_result_a").ToLowerInvariant(), Is.EqualTo("no threat detected")); Assert.That(document.GetPropertyValue("progress_percentage"), Is.EqualTo("100")); }