-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathanalyzer_test.go
156 lines (143 loc) · 3.53 KB
/
analyzer_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package insider_test
import (
"context"
"testing"
"github.com/insidersec/insider"
"github.com/insidersec/insider/engine"
"github.com/insidersec/insider/report"
"github.com/insidersec/insider/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type fakeEngine struct {
result report.Result
err error
}
func (e fakeEngine) Scan(ctx context.Context, dir string) (report.Result, error) {
return e.result, e.err
}
type fakeTechAnalyzer struct {
report report.Reporter
err error
}
func (a fakeTechAnalyzer) Analyze(ctx context.Context, dir string) (report.Reporter, error) {
return a.report, a.err
}
func TestAnalyzer(t *testing.T) {
testcases := []struct {
name string
tech insider.TechAnalyzer
engine insider.Engine
err bool
expectedReport report.Reporter
}{
{
name: "Test Analyze with default report generated",
tech: fakeTechAnalyzer{
report: report.Report{
LibraryIssues: []report.LibraryVulnerability{{}, {}},
},
},
engine: fakeEngine{
result: &engine.Result{
Vulnerabilities: []report.Vulnerability{
{CVSS: 0}, {CVSS: 2.3}, {CVSS: 6.7},
},
Size: 10,
},
},
expectedReport: report.Report{
Info: report.SASTInfo{
Size: "10 Bytes",
},
Base: report.Base{
Vulnerabilities: []report.Vulnerability{{CVSS: 0}, {CVSS: 2.3}, {CVSS: 6.7}},
None: 1,
High: 0,
Medium: 1,
Low: 1,
Total: 3,
},
LibraryIssues: []report.LibraryVulnerability{{}, {}},
},
},
{
name: "Test Analyze with Android report generated",
tech: fakeTechAnalyzer{
report: report.AndroidReporter{
AndroidInfo: report.AndroidInfo{
Title: "testing",
},
},
},
engine: fakeEngine{
result: &engine.Result{
Vulnerabilities: []report.Vulnerability{{CVSS: 6.7}, {CVSS: 8.1}, {CVSS: 7.2}, {CVSS: 9.2}},
Size: 57,
},
},
expectedReport: report.AndroidReporter{
AndroidInfo: report.AndroidInfo{
Title: "testing",
Size: "57 Bytes",
},
Base: report.Base{
Vulnerabilities: []report.Vulnerability{{CVSS: 6.7}, {CVSS: 8.1}, {CVSS: 7.2}, {CVSS: 9.2}},
None: 0,
Low: 0,
Medium: 1,
High: 2,
Critical: 1,
Total: 4,
},
},
},
{
name: "Test Analyze with Ios report generated",
tech: fakeTechAnalyzer{
report: report.IOSReporter{
IOSInfo: report.IOSInfo{
AppName: "testing",
},
},
},
engine: fakeEngine{
result: &engine.Result{
Vulnerabilities: []report.Vulnerability{
{CVSS: 3.9}, {CVSS: 4.0}, {CVSS: 6.9}, {CVSS: 7.0}, {CVSS: 8.9}, {CVSS: 9.8},
},
Size: 57,
},
},
expectedReport: report.IOSReporter{
IOSInfo: report.IOSInfo{
AppName: "testing",
Size: "57 Bytes",
},
Base: report.Base{
Vulnerabilities: []report.Vulnerability{
{CVSS: 3.9}, {CVSS: 4.0}, {CVSS: 6.9}, {CVSS: 7.0}, {CVSS: 8.9}, {CVSS: 9.8},
},
None: 0,
Low: 0,
Medium: 1,
High: 2,
Critical: 1,
Total: 4,
},
},
},
}
for _, tt := range testcases {
t.Run(tt.name, func(t *testing.T) {
analyzer := insider.NewAnalyzer(tt.engine, tt.tech, testutil.NewTestLogger(t))
r, err := analyzer.Analyze(context.Background(), "")
if tt.err {
require.NotNil(t, err)
} else {
require.Nil(t, err)
}
assert.Equal(t, tt.expectedReport, r)
})
}
}