diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 3211a747..dc136a06 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -111,7 +111,5 @@ pub use crate::vaas::Vaas; pub use builder::Builder; pub use cancellation::CancellationToken; pub use connection::Connection; -pub use message::Detection; -pub use message::LibMagic; pub use sha256::Sha256; pub use vaas_verdict::VaasVerdict; diff --git a/rust/src/message/detection.rs b/rust/src/message/detection.rs deleted file mode 100644 index 331348a9..00000000 --- a/rust/src/message/detection.rs +++ /dev/null @@ -1,12 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// Scan engine detection -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub struct Detection { - /// Engine ID - pub engine: i32, - /// File name - pub file_name: String, - /// Virus signature name - pub virus: String, -} diff --git a/rust/src/message/lib_magic.rs b/rust/src/message/lib_magic.rs deleted file mode 100644 index 4f890337..00000000 --- a/rust/src/message/lib_magic.rs +++ /dev/null @@ -1,10 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// File and mime type as classified by https://www.darwinsys.com/file/ -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub struct LibMagic { - /// The file type - pub file_type: String, - /// The mime type - pub mime_type: String, -} diff --git a/rust/src/message/message_type.rs b/rust/src/message/message_type.rs index 89202d24..8e4cc90f 100644 --- a/rust/src/message/message_type.rs +++ b/rust/src/message/message_type.rs @@ -37,7 +37,10 @@ mod tests { "guid": "9dae843d-e947-41db-ad39-ec73704529ed", "verdict": "Clean", "url": null, - "upload_token": null + "upload_token": null, + "detection": "", + "file_type": "", + "mime_type": "" } "# .to_string(); diff --git a/rust/src/message/mod.rs b/rust/src/message/mod.rs index 680441c6..b834ff2d 100644 --- a/rust/src/message/mod.rs +++ b/rust/src/message/mod.rs @@ -2,10 +2,8 @@ mod auth_request; mod auth_response; -mod detection; mod error; mod kind; -mod lib_magic; mod message_type; mod open_id_connect_token_response; mod upload_url; @@ -17,9 +15,7 @@ mod verdict_response; pub(super) use auth_request::AuthRequest; pub(super) use auth_response::AuthResponse; -pub use detection::Detection; pub(super) use error::ErrorResponse; -pub use lib_magic::LibMagic; pub(super) use message_type::MessageType; pub(super) use open_id_connect_token_response::OpenIdConnectTokenResponse; pub(super) use upload_url::UploadUrl; diff --git a/rust/src/message/verdict_response.rs b/rust/src/message/verdict_response.rs index e6a04e26..6d4e0bd9 100644 --- a/rust/src/message/verdict_response.rs +++ b/rust/src/message/verdict_response.rs @@ -1,4 +1,3 @@ -use super::{Detection, LibMagic}; use crate::error::Error; use serde::{Deserialize, Serialize}; use std::convert::TryFrom; @@ -10,8 +9,9 @@ pub struct VerdictResponse { pub verdict: String, pub url: Option, pub upload_token: Option, - pub detections: Option>, - pub lib_magic: Option, + pub detection: Option, + pub file_type: Option, + pub mime_type: Option, } impl TryFrom<&String> for VerdictResponse { @@ -23,11 +23,11 @@ impl TryFrom<&String> for VerdictResponse { #[cfg(test)] mod tests { - use crate::message::{detection::Detection, lib_magic::LibMagic, VerdictResponse}; + use crate::message::VerdictResponse; #[test] fn deserialize() { - let json = r#"{"sha256":"275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f","file_name":null,"verdict":"Malicious","upload_token":null,"url":null,"detections":[{"engine":2,"file_name":"/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118","virus":"EICAR-Test-File"},{"engine":3,"file_name":"/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118","virus":"EICAR_TEST_FILE"}],"lib_magic":{"file_type":"EICAR virus test files","mime_type":"text/plain"},"kind":"VerdictResponse","request_id":"ed7207a5-d65a-4400-b91c-673ff39cfd8b","guid":"ed7207a5-d65a-4400-b91c-673ff39cfd8b"}"#; + let json = r#"{"sha256":"275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f","file_name":null,"verdict":"Malicious","upload_token":null,"url":null,"detection":"EICAR-Test-File","file_type":"EICAR virus test files","mime_type":"text/plain","kind":"VerdictResponse","request_id":"ed7207a5-d65a-4400-b91c-673ff39cfd8b","guid":"ed7207a5-d65a-4400-b91c-673ff39cfd8b"}"#; let verdict_response: VerdictResponse = serde_json::from_str(json).unwrap(); assert_eq!( @@ -38,22 +38,9 @@ mod tests { verdict: "Malicious".to_string(), url: None, upload_token: None, - detections: Some(vec![ - Detection { - engine: 2, - file_name: "/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118".to_string(), - virus: "EICAR-Test-File".to_string() - }, - Detection { - engine: 3, - file_name: "/tmp/scan/051f699f-b21f-4d33-9cdd-d8b2f01e6118".to_string(), - virus: "EICAR_TEST_FILE".to_string() - } - ]), - lib_magic: Some(LibMagic { - file_type: "EICAR virus test files".to_string(), - mime_type: "text/plain".to_string() - }) + detection: Some("EICAR-Test-File".to_string()), + file_type: Some("EICAR virus test files".to_string()), + mime_type: Some("text/plain".to_string()), }, verdict_response ); diff --git a/rust/src/vaas_verdict.rs b/rust/src/vaas_verdict.rs index bebec602..160d81f6 100644 --- a/rust/src/vaas_verdict.rs +++ b/rust/src/vaas_verdict.rs @@ -3,7 +3,7 @@ //! The `VaaSVerdict` is the result of a request for a verdict. It contains the verdict itself and the SHA256 hash of the requested file. use crate::error::Error; -use crate::message::{Detection, LibMagic, Verdict, VerdictResponse}; +use crate::message::{Verdict, VerdictResponse}; use crate::sha256::Sha256; use std::convert::TryFrom; @@ -15,10 +15,12 @@ pub struct VaasVerdict { pub sha256: Sha256, /// Verdict for the file pub verdict: Verdict, - /// Detections - pub detections: Option>, - /// File and mime type as classified by https://www.darwinsys.com/file/ - pub lib_magic: Option, + /// Detection + pub detection: Option, + /// File type as classified by https://www.darwinsys.com/file/ + pub file_type: Option, + /// mime type as classified by https://www.darwinsys.com/file/ + pub mime_type: Option, } impl TryFrom for VaasVerdict { @@ -27,8 +29,9 @@ impl TryFrom for VaasVerdict { Ok(Self { sha256: Sha256::try_from(verdict_response.sha256.as_str())?, verdict: Verdict::try_from(&verdict_response)?, - detections: verdict_response.detections, - lib_magic: verdict_response.lib_magic, + detection: verdict_response.detection, + file_type: verdict_response.file_type, + mime_type: verdict_response.mime_type, }) } } diff --git a/rust/tests/real_api_integration_tests.rs b/rust/tests/real_api_integration_tests.rs index fdf60142..502f9d6b 100644 --- a/rust/tests/real_api_integration_tests.rs +++ b/rust/tests/real_api_integration_tests.rs @@ -4,7 +4,7 @@ use reqwest::Url; use std::convert::TryFrom; use std::ops::Deref; use vaas::auth::authenticators::{ClientCredentials, Password}; -use vaas::{message::Verdict, CancellationToken, Connection, LibMagic, Sha256, Vaas}; +use vaas::{message::Verdict, CancellationToken, Connection, Sha256, Vaas}; async fn get_vaas_with_flags(use_cache: bool, use_hash_lookup: bool) -> Connection { let token_url: Url = dotenv::var("TOKEN_URL") @@ -131,7 +131,8 @@ async fn from_http_response_stream_returns_malicious_verdict() { } #[tokio::test] -async fn from_http_response_stream_no_hash_lookup_no_cache_lookup_returns_malicious_verdict() { +async fn from_http_response_stream_no_hash_lookup_no_cache_lookup_returns_malicious_verdict_and_mimetype_and_detection( +) { let result = reqwest::get("https://secure.eicar.org/eicar.com.txt").await; let vaas = get_vaas_with_flags(false, false).await; @@ -142,6 +143,18 @@ async fn from_http_response_stream_no_hash_lookup_no_cache_lookup_returns_malici let verdict = vaas.for_stream(byte_stream, content_length, &ct).await; assert_eq!(Verdict::Malicious, verdict.as_ref().unwrap().verdict); + assert_eq!( + Some("text/plain"), + verdict.as_ref().unwrap().mime_type.as_deref() + ); + assert_eq!( + Some("EICAR virus test files"), + verdict.as_ref().unwrap().file_type.as_deref() + ); + assert_eq!( + Some("EICAR-Test-File"), + verdict.as_ref().unwrap().detection.as_deref() + ); } #[tokio::test] @@ -291,18 +304,13 @@ async fn for_file_single_malicious_file() { assert_eq!(Verdict::Malicious, verdict.verdict); assert_eq!(Sha256::try_from(&tmp_file).unwrap(), verdict.sha256); - let detections = verdict.detections.unwrap(); - assert_eq!(2, detections[0].engine); - assert_eq!("EICAR-Test-File".to_string(), detections[0].virus); - assert_eq!(3, detections[1].engine); - assert_eq!("EICAR_TEST_FILE".to_string(), detections[1].virus); + assert_eq!("EICAR-Test-File".to_string(), verdict.detection.unwrap()); assert_eq!( - Some(LibMagic { - file_type: "EICAR virus test files".to_string(), - mime_type: "text/plain".to_string() - }), - verdict.lib_magic + "EICAR virus test files".to_string(), + verdict.file_type.unwrap() ); + assert_eq!("text/plain".to_string(), verdict.mime_type.unwrap()); + std::fs::remove_file(&tmp_file).unwrap(); }