-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathconfig_integration_test.go
More file actions
168 lines (138 loc) · 5.01 KB
/
config_integration_test.go
File metadata and controls
168 lines (138 loc) · 5.01 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
package main
import (
"os"
"os/exec"
"path/filepath"
"testing"
)
// TestConfigurationStandard tests loading a standard (non-encrypted) configuration
func TestConfigurationStandard(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
// Verify basic structure is accessible (paths may be empty in test file)
t.Log("Configuration loaded successfully")
}
// TestConfigurationCiphered tests loading an encrypted (RC4) configuration
func TestConfigurationCiphered(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_ciphered.yml")
// Verify basic structure is accessible (paths may be empty in test file)
t.Log("Ciphered configuration loaded successfully")
}
// TestConfigurationPaths verifies path configuration structure
func TestConfigurationPaths(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
if len(config.Input.Path) > 0 {
// Verify first path is not empty
if config.Input.Path[0] == "" {
t.Fatal("Path should not be empty")
}
}
}
// TestConfigurationContent verifies content patterns (grep, yara, checksum)
func TestConfigurationContent(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
if config.Input.Content.Grep != nil {
// Grep patterns should be readable
for _, pattern := range config.Input.Content.Grep {
if pattern == "" {
t.Fatal("Grep pattern should not be empty")
}
}
}
}
// TestConfigurationOptions verifies options configuration
func TestConfigurationOptions(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
// Options structure should exist (may be all false)
t.Log("Options section loaded successfully")
}
// TestConfigurationOutput verifies output configuration
func TestConfigurationOutput(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
// Output structure should exist
t.Log("Output section loaded successfully")
}
// TestConfigurationEventForwarding verifies event forwarding configuration
func TestConfigurationEventForwarding(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
// Event forwarding section should be accessible
t.Log("Event forwarding section loaded successfully")
}
// TestConfigurationAdvancedParameters verifies advanced parameters
func TestConfigurationAdvancedParameters(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
// Advanced parameters should exist
t.Log("Advanced parameters section loaded successfully")
}
// TestConfigurationMissingRequired tests handling of incomplete config
func TestConfigurationMissingRequired(t *testing.T) {
// Create a minimal temporary config file
tmpFile := filepath.Join(t.TempDir(), "test_config.yml")
tmpContent := `input:
path:
- /tmp
`
os.WriteFile(tmpFile, []byte(tmpContent), 0644)
var config Configuration
config.getConfiguration(tmpFile)
if len(config.Input.Path) == 0 {
t.Fatal("Minimal config should have at least path section")
}
}
// TestConfigurationEmpty tests handling of empty configuration
func TestConfigurationEmpty(t *testing.T) {
if os.Getenv("TEST_CONFIGURATION_EMPTY_SUBPROCESS") == "1" {
tmpFile := os.Getenv("TEST_CONFIGURATION_EMPTY_FILE")
var config Configuration
config.getConfiguration(tmpFile)
return
}
tmpFile := filepath.Join(t.TempDir(), "empty_config.yml")
os.WriteFile(tmpFile, []byte(""), 0644)
cmd := exec.Command(os.Args[0], "-test.run=TestConfigurationEmpty")
cmd.Env = append(os.Environ(), "TEST_CONFIGURATION_EMPTY_SUBPROCESS=1", "TEST_CONFIGURATION_EMPTY_FILE="+tmpFile)
err := cmd.Run()
// We expect an exit error here because LogFatal calls os.Exit(1)
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
t.Log("Empty configuration triggered exit as expected")
return
}
t.Fatalf("process ran with err %v, want exit status 1", err)
}
// TestConfigurationYARAWithRC4 tests YARA section with RC4 encryption
func TestConfigurationYARAWithRC4(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_ciphered.yml")
// Ciphered config should load without panicking
if config.Input.Content.Yara != nil {
t.Log("YARA rules loaded from ciphered configuration")
}
}
// TestConfigurationChecksums tests checksum patterns
func TestConfigurationChecksums(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
if len(config.Input.Content.Checksum) > 0 {
// Verify checksums are readable
for _, cs := range config.Input.Content.Checksum {
if cs == "" {
t.Fatal("Checksum should not be empty")
}
}
}
}
// TestConfigurationMultiplePaths tests multiple path handling
func TestConfigurationMultiplePaths(t *testing.T) {
var config Configuration
config.getConfiguration("tests/config_test_standard.yml")
if len(config.Input.Path) > 1 {
t.Logf("Configuration loaded with %d paths", len(config.Input.Path))
}
}