diff --git a/golang/vaas/go.mod b/golang/vaas/go.mod index 83e68cd4..9e8863b6 100644 --- a/golang/vaas/go.mod +++ b/golang/vaas/go.mod @@ -1,6 +1,6 @@ module github.com/GDATASoftwareAG/vaas/golang/vaas -go 1.22.2 +go 1.22 require ( github.com/Noooste/websocket v1.0.3 @@ -10,21 +10,15 @@ require ( ) require ( - github.com/Noooste/fhttp v1.0.11 // indirect - github.com/Noooste/utls v1.2.7 // indirect + github.com/Noooste/fhttp v1.0.12 // indirect + github.com/Noooste/utls v1.2.9 // indirect github.com/andybalholm/brotli v1.1.0 // indirect - github.com/cloudflare/circl v1.3.7 // indirect + github.com/cloudflare/circl v1.3.8 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect - github.com/klauspost/compress v1.17.7 // indirect + github.com/klauspost/compress v1.17.8 // indirect github.com/kr/pretty v0.3.1 // indirect - github.com/onsi/ginkgo/v2 v2.15.0 // indirect - github.com/onsi/gomega v1.30.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/quic-go/quic-go v0.42.0 // indirect - github.com/refraction-networking/utls v1.6.3 // indirect golang.org/x/crypto v0.22.0 // indirect - golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/golang/vaas/go.sum b/golang/vaas/go.sum index 8b4ba05f..5373c232 100644 --- a/golang/vaas/go.sum +++ b/golang/vaas/go.sum @@ -1,61 +1,41 @@ -github.com/Noooste/fhttp v1.0.11 h1:tpVXalX6gCkNaUA694RJ/bIUh2Ypzg8vXKJMnS9mpDM= -github.com/Noooste/fhttp v1.0.11/go.mod h1:CMVxKOhNheqJN5HYE4Rlvz2SRdV8Uv7YWmi6OwmB/Bk= -github.com/Noooste/utls v1.2.7 h1:NLlRybZDzW+dXk/Uavb2E+pWeK+GAH2XkWq3g+C/WA0= -github.com/Noooste/utls v1.2.7/go.mod h1:MRUEmRiDO6ORKziZ2ObNwMjxy0vRviJ91JF1qVa0loM= +github.com/Noooste/fhttp v1.0.12 h1:2N15bIATKaC6q+LVyRGyxPyuqEPvwAS3Uk1peC3YVHU= +github.com/Noooste/fhttp v1.0.12/go.mod h1:CMVxKOhNheqJN5HYE4Rlvz2SRdV8Uv7YWmi6OwmB/Bk= +github.com/Noooste/utls v1.2.9 h1:VLNs0WmPFjswU4PxXTHl0AY4sarHi+638c3cSI9Hsng= +github.com/Noooste/utls v1.2.9/go.mod h1:dHM5MlRyB/ieog9axOxkEh4qZRgw5xA406y7sEdVmoQ= github.com/Noooste/websocket v1.0.3 h1:drW7tvZ3YqzqI9wApnaH1Q0syFMXO7gbLlsBWjZvMNA= github.com/Noooste/websocket v1.0.3/go.mod h1:Qhw0Rtuju/fPPbcb3R5XGq7poa51qPDL462jTltl9nQ= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= -github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= -github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cloudflare/circl v1.3.8 h1:j+V8jJt09PoeMFIu2uh5JUyEaIHTXVOHslFoLNAKqwI= +github.com/cloudflare/circl v1.3.8/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= -github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= -github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= -github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= -github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= -github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/quic-go/quic-go v0.42.0 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM= -github.com/quic-go/quic-go v0.42.0/go.mod h1:132kz4kL3F9vxhW3CtQJLDVwcFe5wdWeJXXijhsO57M= -github.com/refraction-networking/utls v1.6.3 h1:MFOfRN35sSx6K5AZNIoESsBuBxS2LCgRilRIdHb6fDc= -github.com/refraction-networking/utls v1.6.3/go.mod h1:yil9+7qSl+gBwJqztoQseO6Pr3h62pQoY1lXiNR/FPs= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8= -golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= -golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/golang/vaas/pkg/messages/detection.go b/golang/vaas/pkg/messages/detection.go deleted file mode 100644 index 41a2d532..00000000 --- a/golang/vaas/pkg/messages/detection.go +++ /dev/null @@ -1,9 +0,0 @@ -// Package messages provides structures for handling communication messages between the client and the VaaS server. -package messages - -// TokenResponse represents a response containing an access token. -type Detection struct { - Engine int `json:"engine"` - FileName string `json:"file_name"` - Virus string `json:"virus"` -} diff --git a/golang/vaas/pkg/messages/lib_magic.go b/golang/vaas/pkg/messages/lib_magic.go deleted file mode 100644 index 7704c62d..00000000 --- a/golang/vaas/pkg/messages/lib_magic.go +++ /dev/null @@ -1,8 +0,0 @@ -// Package messages provides structures for handling communication messages between the client and the VaaS server. -package messages - -// TokenResponse represents a response containing an access token. -type LibMagic struct { - FileType string `json:"file_type"` - MimeType string `json:"mime_type"` -} diff --git a/golang/vaas/pkg/messages/vaas_verdict.go b/golang/vaas/pkg/messages/vaas_verdict.go index f76c3ece..bf3c7555 100644 --- a/golang/vaas/pkg/messages/vaas_verdict.go +++ b/golang/vaas/pkg/messages/vaas_verdict.go @@ -3,9 +3,10 @@ package messages // VaasVerdict represents the verdict information returned by the VaaS server. type VaasVerdict struct { - Verdict Verdict - Sha256 string - ErrMsg string - Detections []Detection - LibMagic LibMagic + Verdict Verdict + Sha256 string + ErrMsg string + Detection string + MimeType string + FileType string } diff --git a/golang/vaas/pkg/messages/verdict_response.go b/golang/vaas/pkg/messages/verdict_response.go index 863d71e6..3071f92e 100644 --- a/golang/vaas/pkg/messages/verdict_response.go +++ b/golang/vaas/pkg/messages/verdict_response.go @@ -3,14 +3,15 @@ package messages // VerdictResponse represents the response containing the verdict information. type VerdictResponse struct { - Kind string `json:"kind"` - Sha256 string `json:"sha256"` - GUID string `json:"guid"` - Verdict Verdict `json:"verdict"` - URL string `json:"url"` - UploadToken string `json:"upload_token"` - Detections []Detection `json:"detections"` - LibMagic LibMagic `json:"lib_magic"` + Kind string `json:"kind"` + Sha256 string `json:"sha256"` + GUID string `json:"guid"` + Verdict Verdict `json:"verdict"` + URL string `json:"url"` + UploadToken string `json:"upload_token"` + Detection string `json:"detection"` + FileType string `json:"file_type"` + MimeType string `json:"mime_type"` } // IsValid checks if the VerdictResponse is valid. diff --git a/golang/vaas/pkg/vaas/vaas.go b/golang/vaas/pkg/vaas/vaas.go index 5b7eae7e..e3d7e481 100644 --- a/golang/vaas/pkg/vaas/vaas.go +++ b/golang/vaas/pkg/vaas/vaas.go @@ -184,7 +184,8 @@ func (v *vaas) ForSha256List(ctx context.Context, sha256List []string) ([]msg.Va defer waitGroup.Done() verdict, err := v.ForSha256(ctx, sha256) if err != nil { - verdict = msg.VaasVerdict{Sha256: sha256, Verdict: msg.Error, ErrMsg: err.Error(), Detections: verdict.Detections, LibMagic: verdict.LibMagic} + verdict = msg.VaasVerdict{Sha256: sha256, Verdict: msg.Error, ErrMsg: err.Error(), + Detection: verdict.Detection, FileType: verdict.FileType, MimeType: verdict.MimeType} } verdicts[i] = verdict }(i, sha256) @@ -352,10 +353,11 @@ func (v *vaas) ForUrl(ctx context.Context, url string) (msg.VaasVerdict, error) } return msg.VaasVerdict{ - Verdict: response.Verdict, - Sha256: response.Sha256, - Detections: response.Detections, - LibMagic: response.LibMagic, + Verdict: response.Verdict, + Sha256: response.Sha256, + Detection: response.Detection, + MimeType: response.MimeType, + FileType: response.FileType, }, nil } @@ -410,10 +412,11 @@ func (v *vaas) ForStream(ctx context.Context, stream io.Reader, contentLength in response = <-responseChan return msg.VaasVerdict{ - Verdict: response.Verdict, - Sha256: response.Sha256, - Detections: response.Detections, - LibMagic: response.LibMagic, + Verdict: response.Verdict, + Sha256: response.Sha256, + Detection: response.Detection, + MimeType: response.MimeType, + FileType: response.FileType, }, nil } @@ -492,10 +495,11 @@ func (v *vaas) forFileWithSha(ctx context.Context, data io.Reader, sha256 string } return msg.VaasVerdict{ - Verdict: response.Verdict, - Sha256: response.Sha256, - Detections: response.Detections, - LibMagic: response.LibMagic, + Verdict: response.Verdict, + Sha256: response.Sha256, + Detection: response.Detection, + FileType: response.FileType, + MimeType: response.MimeType, }, nil } diff --git a/golang/vaas/pkg/vaas/vaas_test.go b/golang/vaas/pkg/vaas/vaas_test.go index ffbd8701..7c71f254 100644 --- a/golang/vaas/pkg/vaas/vaas_test.go +++ b/golang/vaas/pkg/vaas/vaas_test.go @@ -339,18 +339,16 @@ func TestVaas_ForStream_WithStreamFromUrl_RetunsMaliciousWithDetectionsAndMimeTy t.Errorf("verdict should be %v, got %v", msg.Malicious, verdict.Verdict) } - if verdict.LibMagic.MimeType != "text/plain" { - t.Errorf("expected mime type to be text/plain, got %v", verdict.LibMagic.MimeType) + if verdict.MimeType != "text/plain" { + t.Errorf("expected mime type to be text/plain, got %v", verdict.MimeType) } - if len(verdict.Detections) == 0 { - t.Errorf("expected detections, got none") + if verdict.Detection == "" { + t.Errorf("expected a detection, got empty string") } - for _, detection := range verdict.Detections { - if detection.Virus == "EICAR_TEST_FILE" { - return - } + if verdict.Detection != "EICAR-Test-File" { + t.Errorf("detection has to be EICAR-Test-File, got %v", verdict.Detection) } } 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(); }