Admin-stored API key with env fallback; scan drive/mail/IMAP uploads. Fail-open if VT down, 422 on malware; migration for virus_scan_status.
41 lines
992 B
Go
41 lines
992 B
Go
package filescan
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/orgpolicy"
|
|
)
|
|
|
|
type stubPolicyLoader struct {
|
|
fp orgpolicy.FilePolicies
|
|
}
|
|
|
|
func (s stubPolicyLoader) FilePolicies(ctx context.Context) (orgpolicy.FilePolicies, error) {
|
|
return s.fp, nil
|
|
}
|
|
|
|
func (s stubPolicyLoader) ScanEnabled(ctx context.Context) (bool, string, error) {
|
|
if s.fp.VirusScanEnabled && s.fp.VirusTotalAPIKey != "" {
|
|
return true, s.fp.VirusTotalAPIKey, nil
|
|
}
|
|
return false, "", nil
|
|
}
|
|
|
|
func TestScannerDisabledReturnsSkipped(t *testing.T) {
|
|
scanner := &Scanner{
|
|
policies: stubPolicyLoader{fp: orgpolicy.FilePolicies{VirusScanEnabled: false}},
|
|
}
|
|
data, result, err := scanner.ScanReader(context.Background(), "test.txt", bytes.NewReader([]byte("hello")), 5)
|
|
if err != nil {
|
|
t.Fatalf("ScanReader: %v", err)
|
|
}
|
|
if result.Status != "skipped" {
|
|
t.Fatalf("status = %q, want skipped", result.Status)
|
|
}
|
|
if string(data) != "hello" {
|
|
t.Fatalf("data = %q", data)
|
|
}
|
|
}
|