Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Aug 18, 2023
1 parent eaff78b commit bb555f1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 38 deletions.
2 changes: 1 addition & 1 deletion clamd/instream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestClamdInstream(t *testing.T) {
name: "eicarcom2.zip",
filepath: "testdata/eicarcom2.zip",
expectedError: &clamd.VirusFoundError{
Name: "Eicar-Signature",
Name: "Win.Test.EICAR_HDB-1",
},
},
}
Expand Down
6 changes: 1 addition & 5 deletions clamd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ type Version struct {
}

func parseVersion(response []byte) (Version, error) {
parts := strings.Split(string(response), " ")
if len(parts) != 2 { //nolint:gomnd
return Version{}, fmt.Errorf("failed to parse version: %s", string(response)) //nolint:goerr113
}

parts := strings.SplitN(string(response), " ", 2) //nolint:gomnd
return Version{
Version: parts[1],
}, nil
Expand Down
4 changes: 2 additions & 2 deletions client/update_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ func TestUpdateFile(t *testing.T) {
expectedErr: &client.APIResponseError{
StatusCode: http.StatusForbidden,
ErrorResponse: &controller.ErrorResponse{
Message: `virus found: Eicar-Signature`,
Message: `virus found: Win.Test.EICAR_HDB-1`,
Data: map[string]any{
"file": "eicarcom2.zip",
"virus": "Eicar-Signature",
"virus": "Win.Test.EICAR_HDB-1",
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions client/upload_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ func TestUploadFile(t *testing.T) {
expectedErr: &client.APIResponseError{
StatusCode: http.StatusForbidden,
ErrorResponse: &controller.ErrorResponse{
Message: `virus found: Eicar-Signature`,
Message: `virus found: Win.Test.EICAR_HDB-1`,
Data: map[string]any{
"file": "eicarcom2.zip",
"virus": "Eicar-Signature",
"virus": "Win.Test.EICAR_HDB-1",
},
},
Response: &controller.UploadFileResponse{
Expand Down Expand Up @@ -159,10 +159,10 @@ func TestUploadFile(t *testing.T) {
},
},
Error: &controller.ErrorResponse{
Message: `virus found: Eicar-Signature`,
Message: `virus found: Win.Test.EICAR_HDB-1`,
Data: map[string]any{
"file": "eicarcom2.zip",
"virus": "Eicar-Signature",
"virus": "Win.Test.EICAR_HDB-1",
},
},
},
Expand Down
12 changes: 3 additions & 9 deletions controller/update_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,9 @@ func (ctrl *Controller) updateFile(ctx *gin.Context) (FileMetadata, *APIError) {
}
defer fileContent.Close()

if err := ctrl.av.ScanReader(fileContent); err != nil {
err.SetData("file", file.Name)

if err := ctrl.reportVirus(
ctx, file.ID, file.Name, err.GetDataString("virus"), ctx.Request.Header,
); err != nil {
return FileMetadata{}, err
}

if err := ctrl.scanAndReportVirus(
ctx, fileContent, file.ID, file.Name, ctx.Request.Header,
); err != nil {
return FileMetadata{}, err
}

Expand Down
34 changes: 17 additions & 17 deletions controller/upload_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,26 @@ func (ctrl *Controller) getMultipartFile(file fileData) (multipart.File, string,
return fileContent, mt.String(), nil
}

func (ctrl *Controller) reportVirus(
func (ctrl *Controller) scanAndReportVirus(
ctx context.Context,
fileContent multipart.File,
fileID string,
filename string,
virus string,
headers http.Header,
) *APIError {
userSession := GetUserSession(headers)
if err := ctrl.av.ScanReader(fileContent); err != nil {
err.SetData("file", filename)

userSession := GetUserSession(headers)

if err := ctrl.metadataStorage.InsertVirus(
ctx, fileID, filename, err.GetDataString("virus"), userSession,
http.Header{"x-hasura-admin-secret": []string{ctrl.hasuraAdminSecret}},
); err != nil {
err := err.ExtendError("problem inserting virus into database")
return err
}

if err := ctrl.metadataStorage.InsertVirus(
ctx, fileID, filename, virus, userSession,
http.Header{"x-hasura-admin-secret": []string{ctrl.hasuraAdminSecret}},
); err != nil {
err := err.ExtendError("problem inserting virus into database")
return err
}

Expand Down Expand Up @@ -104,15 +110,9 @@ func (ctrl *Controller) processFile(
return FileMetadata{}, err
}

if err := ctrl.av.ScanReader(fileContent); err != nil {
err.SetData("file", file.Name)

if err := ctrl.reportVirus(
ctx, file.ID, file.Name, err.GetDataString("virus"), headers,
); err != nil {
return FileMetadata{}, err
}

if err := ctrl.scanAndReportVirus(
ctx, fileContent, file.ID, file.Name, headers,
); err != nil {
return FileMetadata{}, err
}

Expand Down

0 comments on commit bb555f1

Please sign in to comment.