ultisuite-backend/internal/filescan/scanner_test.go
R3D347HR4Y b90edf317c
Some checks failed
CI / Go tests (push) Has been cancelled
CI / Integration tests (push) Has been cancelled
CI / DB migrations (push) Has been cancelled
feat(scan): add VirusTotal upload antivirus
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.
2026-06-07 22:05:27 +02:00

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)
}
}