-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathforwarding_config_test.go
More file actions
316 lines (265 loc) · 6.77 KB
/
forwarding_config_test.go
File metadata and controls
316 lines (265 loc) · 6.77 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
package main
import (
"testing"
)
// TestEventForwardingConfigStructure tests the ForwardingConfig structure
func TestEventForwardingConfigStructure(t *testing.T) {
config := ForwardingConfig{
Enabled: true,
BufferSize: 256,
FlushTime: 5,
}
if !config.Enabled {
t.Fatal("Enabled flag not set")
}
if config.BufferSize != 256 {
t.Fatal("BufferSize not set correctly")
}
if config.FlushTime != 5 {
t.Fatal("FlushTime not set correctly")
}
}
// TestHTTPConfigStructure tests the HTTPConfig structure
func TestHTTPConfigStructure(t *testing.T) {
config := HTTPConfig{
Enabled: true,
URL: "http://localhost:8080",
SSLVerify: true,
Timeout: 30,
RetryCount: 3,
}
if !config.Enabled {
t.Fatal("HTTP Enabled flag not set")
}
if config.URL != "http://localhost:8080" {
t.Fatal("HTTP URL not set correctly")
}
if config.Timeout != 30 {
t.Fatal("HTTP Timeout not set correctly")
}
if config.RetryCount != 3 {
t.Fatal("HTTP RetryCount not set correctly")
}
}
// TestHTTPConfigHeaders tests HTTP headers handling
func TestHTTPConfigHeaders(t *testing.T) {
headers := make(map[string]string)
headers["Content-Type"] = "application/json"
headers["Authorization"] = "Bearer token123"
config := HTTPConfig{
Enabled: true,
Headers: headers,
}
if config.Headers["Content-Type"] != "application/json" {
t.Fatal("Content-Type header not set")
}
if config.Headers["Authorization"] != "Bearer token123" {
t.Fatal("Authorization header not set")
}
}
// TestFileOutputConfigStructure tests the FileOutputConfig structure
func TestFileOutputConfigStructure(t *testing.T) {
config := FileOutputConfig{
Enabled: true,
DirectoryPath: "/var/log/fastfinder",
RotateMinutes: 60,
MaxFileSize: 100,
RetainFiles: 10,
}
if !config.Enabled {
t.Fatal("File output Enabled flag not set")
}
if config.DirectoryPath != "/var/log/fastfinder" {
t.Fatal("Directory path not set correctly")
}
if config.RotateMinutes != 60 {
t.Fatal("Rotate minutes not set correctly")
}
if config.MaxFileSize != 100 {
t.Fatal("Max file size not set correctly")
}
if config.RetainFiles != 10 {
t.Fatal("Retain files count not set correctly")
}
}
// TestEventFiltersStructure tests the EventFilters structure
func TestEventFiltersStructure(t *testing.T) {
filters := EventFilters{
EventTypes: []string{"alert", "error", "scan_complete"},
}
if len(filters.EventTypes) != 3 {
t.Fatal("Event types not set correctly")
}
if filters.EventTypes[0] != "alert" {
t.Fatal("First event type incorrect")
}
}
// TestForwardingConfigDisabled tests disabled event forwarding
func TestForwardingConfigDisabled(t *testing.T) {
config := ForwardingConfig{
Enabled: false,
BufferSize: 0,
FlushTime: 0,
}
if config.Enabled {
t.Fatal("Config should be disabled")
}
}
// TestForwardingConfigWithHTTP tests forwarding config with HTTP enabled
func TestForwardingConfigWithHTTP(t *testing.T) {
config := ForwardingConfig{
Enabled: true,
BufferSize: 512,
FlushTime: 10,
HTTP: HTTPConfig{
Enabled: true,
URL: "https://collector.example.com/events",
},
}
if !config.Enabled {
t.Fatal("Main config should be enabled")
}
if !config.HTTP.Enabled {
t.Fatal("HTTP should be enabled")
}
if config.HTTP.URL != "https://collector.example.com/events" {
t.Fatal("HTTP URL not correct")
}
}
// TestForwardingConfigWithFile tests forwarding config with file output enabled
func TestForwardingConfigWithFile(t *testing.T) {
config := ForwardingConfig{
Enabled: true,
BufferSize: 256,
File: FileOutputConfig{
Enabled: true,
DirectoryPath: "/tmp/events",
RotateMinutes: 30,
},
}
if !config.Enabled {
t.Fatal("Main config should be enabled")
}
if !config.File.Enabled {
t.Fatal("File output should be enabled")
}
if config.File.DirectoryPath != "/tmp/events" {
t.Fatal("File directory path not correct")
}
}
// TestForwardingConfigWithFilters tests forwarding config with event filters
func TestForwardingConfigWithFilters(t *testing.T) {
config := ForwardingConfig{
Enabled: true,
BufferSize: 256,
Filters: EventFilters{
EventTypes: []string{"error", "critical"},
},
}
if len(config.Filters.EventTypes) != 2 {
t.Fatal("Filters event types not set")
}
}
// TestHTTPConfigSSLVerify tests SSL verification flag
func TestHTTPConfigSSLVerify(t *testing.T) {
configWithSSL := HTTPConfig{
Enabled: true,
SSLVerify: true,
}
configWithoutSSL := HTTPConfig{
Enabled: true,
SSLVerify: false,
}
if !configWithSSL.SSLVerify {
t.Fatal("SSL verify should be true")
}
if configWithoutSSL.SSLVerify {
t.Fatal("SSL verify should be false")
}
}
// TestFileOutputConfigRetention tests file retention settings
func TestFileOutputConfigRetention(t *testing.T) {
config := FileOutputConfig{
Enabled: true,
DirectoryPath: "/logs",
RotateMinutes: 1440, // Daily rotation
MaxFileSize: 500, // 500 MB
RetainFiles: 30, // Keep 30 days
}
if config.RotateMinutes != 1440 {
t.Fatal("Daily rotation not set")
}
if config.MaxFileSize != 500 {
t.Fatal("Max file size not set")
}
if config.RetainFiles != 30 {
t.Fatal("Retention period not set")
}
}
// TestEventFiltersMultipleTypes tests multiple event types
func TestEventFiltersMultipleTypes(t *testing.T) {
filters := EventFilters{
EventTypes: []string{
"alert",
"error",
"warning",
"info",
"scan_start",
"scan_complete",
"match_found",
},
}
if len(filters.EventTypes) != 7 {
t.Fatal("Not all event types set")
}
found := false
for _, et := range filters.EventTypes {
if et == "scan_complete" {
found = true
break
}
}
if !found {
t.Fatal("scan_complete event type not found")
}
}
// TestForwardingConfigComplex tests complex configuration with both HTTP and File
func TestForwardingConfigComplex(t *testing.T) {
config := ForwardingConfig{
Enabled: true,
BufferSize: 1024,
FlushTime: 30,
HTTP: HTTPConfig{
Enabled: true,
URL: "https://siem.company.com/ingest",
SSLVerify: true,
Timeout: 60,
RetryCount: 5,
Headers: map[string]string{
"Content-Type": "application/json",
"Authorization": "Bearer xyz123",
"X-API-Key": "secret-key",
},
},
File: FileOutputConfig{
Enabled: true,
DirectoryPath: "/var/log/fastfinder/events",
RotateMinutes: 60,
MaxFileSize: 200,
RetainFiles: 90,
},
Filters: EventFilters{
EventTypes: []string{"error", "critical", "match_found"},
},
}
// Verify all components are properly configured
if !config.Enabled || !config.HTTP.Enabled || !config.File.Enabled {
t.Fatal("All components should be enabled")
}
if len(config.HTTP.Headers) != 3 {
t.Fatal("HTTP headers not set correctly")
}
if len(config.Filters.EventTypes) != 3 {
t.Fatal("Filter event types not set")
}
}