-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscan_test.go
98 lines (72 loc) · 1.95 KB
/
scan_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main_test
import (
"fmt"
"strings"
"testing"
log "github.com/Sirupsen/logrus"
)
const resultString = `>>> Virus 'EICAR-AV-Test' found in file EICAR
`
const versionString = `SAVScan virus detection utility
Copyright (c) 1989-2017 Sophos Limited. All rights reserved.
System time 15:42:06, System date 16 June 2017
Product version : 5.34.0
Engine version : 3.68.0
Virus data version : 5.40
User interface version : 2.03.068
Platform : Linux/AMD64
Released : 30 May 2017
Total viruses (with IDEs) : 13427613
`
func parseSophosVersion(versionOut string) (version string, database string) {
lines := strings.Split(versionOut, "\n")
for _, line := range lines {
if strings.Contains(line, "Product version") {
parts := strings.Split(line, ":")
if len(parts) == 2 {
version = strings.TrimSpace(parts[1])
} else {
log.Error("Umm... ", parts)
}
}
if strings.Contains(line, "Virus data version") {
parts := strings.Split(line, ":")
if len(parts) == 2 {
database = strings.TrimSpace(parts[1])
break
} else {
log.Error("Umm... ", parts)
}
}
}
return
}
func parseSophosOutput(sophosout string) (string, error) {
lines := strings.Split(sophosout, "\n")
for _, line := range lines {
if strings.Contains(line, ">>> Virus") && strings.Contains(line, "found in file") {
parts := strings.Split(line, "'")
fmt.Println(parts)
return strings.TrimSpace(parts[1]), nil
}
}
return "", nil
}
// TestParseResult tests the ParseFSecureOutput function.
func TestParseResult(t *testing.T) {
results, err := parseSophosOutput(resultString)
if err != nil {
t.Log(err)
}
if true {
t.Log("results: ", results)
}
}
// TestParseVersion tests the GetFSecureVersion function.
func TestParseVersion(t *testing.T) {
version, database := parseSophosVersion(versionString)
if true {
t.Log("version: ", version)
t.Log("database: ", database)
}
}