|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +// TestConfigurationStandard tests loading a standard (non-encrypted) configuration |
| 10 | +func TestConfigurationStandard(t *testing.T) { |
| 11 | + var config Configuration |
| 12 | + config.getConfiguration("tests/config_test_standard.yml") |
| 13 | + |
| 14 | + // Verify basic structure is accessible (paths may be empty in test file) |
| 15 | + t.Log("Configuration loaded successfully") |
| 16 | +} |
| 17 | + |
| 18 | +// TestConfigurationCiphered tests loading an encrypted (RC4) configuration |
| 19 | +func TestConfigurationCiphered(t *testing.T) { |
| 20 | + var config Configuration |
| 21 | + config.getConfiguration("tests/config_test_ciphered.yml") |
| 22 | + |
| 23 | + // Verify basic structure is accessible (paths may be empty in test file) |
| 24 | + t.Log("Ciphered configuration loaded successfully") |
| 25 | +} |
| 26 | + |
| 27 | +// TestConfigurationPaths verifies path configuration structure |
| 28 | +func TestConfigurationPaths(t *testing.T) { |
| 29 | + var config Configuration |
| 30 | + config.getConfiguration("tests/config_test_standard.yml") |
| 31 | + |
| 32 | + if len(config.Input.Path) > 0 { |
| 33 | + // Verify first path is not empty |
| 34 | + if config.Input.Path[0] == "" { |
| 35 | + t.Fatal("Path should not be empty") |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +// TestConfigurationContent verifies content patterns (grep, yara, checksum) |
| 41 | +func TestConfigurationContent(t *testing.T) { |
| 42 | + var config Configuration |
| 43 | + config.getConfiguration("tests/config_test_standard.yml") |
| 44 | + |
| 45 | + if config.Input.Content.Grep != nil { |
| 46 | + // Grep patterns should be readable |
| 47 | + for _, pattern := range config.Input.Content.Grep { |
| 48 | + if pattern == "" { |
| 49 | + t.Fatal("Grep pattern should not be empty") |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// TestConfigurationOptions verifies options configuration |
| 56 | +func TestConfigurationOptions(t *testing.T) { |
| 57 | + var config Configuration |
| 58 | + config.getConfiguration("tests/config_test_standard.yml") |
| 59 | + |
| 60 | + // Options structure should exist (may be all false) |
| 61 | + t.Log("Options section loaded successfully") |
| 62 | +} |
| 63 | + |
| 64 | +// TestConfigurationOutput verifies output configuration |
| 65 | +func TestConfigurationOutput(t *testing.T) { |
| 66 | + var config Configuration |
| 67 | + config.getConfiguration("tests/config_test_standard.yml") |
| 68 | + |
| 69 | + // Output structure should exist |
| 70 | + t.Log("Output section loaded successfully") |
| 71 | +} |
| 72 | + |
| 73 | +// TestConfigurationEventForwarding verifies event forwarding configuration |
| 74 | +func TestConfigurationEventForwarding(t *testing.T) { |
| 75 | + var config Configuration |
| 76 | + config.getConfiguration("tests/config_test_standard.yml") |
| 77 | + |
| 78 | + // Event forwarding section should be accessible |
| 79 | + t.Log("Event forwarding section loaded successfully") |
| 80 | +} |
| 81 | + |
| 82 | +// TestConfigurationAdvancedParameters verifies advanced parameters |
| 83 | +func TestConfigurationAdvancedParameters(t *testing.T) { |
| 84 | + var config Configuration |
| 85 | + config.getConfiguration("tests/config_test_standard.yml") |
| 86 | + |
| 87 | + // Advanced parameters should exist |
| 88 | + t.Log("Advanced parameters section loaded successfully") |
| 89 | +} |
| 90 | + |
| 91 | +// TestConfigurationMissingRequired tests handling of incomplete config |
| 92 | +func TestConfigurationMissingRequired(t *testing.T) { |
| 93 | + // Create a minimal temporary config file |
| 94 | + tmpFile := filepath.Join(t.TempDir(), "test_config.yml") |
| 95 | + tmpContent := `input: |
| 96 | + path: |
| 97 | + - /tmp |
| 98 | +` |
| 99 | + os.WriteFile(tmpFile, []byte(tmpContent), 0644) |
| 100 | + |
| 101 | + var config Configuration |
| 102 | + config.getConfiguration(tmpFile) |
| 103 | + |
| 104 | + if len(config.Input.Path) == 0 { |
| 105 | + t.Fatal("Minimal config should have at least path section") |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +// TestConfigurationEmpty tests handling of empty configuration |
| 110 | +func TestConfigurationEmpty(t *testing.T) { |
| 111 | + tmpFile := filepath.Join(t.TempDir(), "empty_config.yml") |
| 112 | + os.WriteFile(tmpFile, []byte(""), 0644) |
| 113 | + |
| 114 | + var config Configuration |
| 115 | + config.getConfiguration(tmpFile) |
| 116 | + |
| 117 | + // Verify no panic occurred |
| 118 | + t.Log("Empty configuration handled gracefully") |
| 119 | +} |
| 120 | + |
| 121 | +// TestConfigurationYARAWithRC4 tests YARA section with RC4 encryption |
| 122 | +func TestConfigurationYARAWithRC4(t *testing.T) { |
| 123 | + var config Configuration |
| 124 | + config.getConfiguration("tests/config_test_ciphered.yml") |
| 125 | + |
| 126 | + // Ciphered config should load without panicking |
| 127 | + if config.Input.Content.Yara != nil { |
| 128 | + t.Log("YARA rules loaded from ciphered configuration") |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +// TestConfigurationChecksums tests checksum patterns |
| 133 | +func TestConfigurationChecksums(t *testing.T) { |
| 134 | + var config Configuration |
| 135 | + config.getConfiguration("tests/config_test_standard.yml") |
| 136 | + |
| 137 | + if len(config.Input.Content.Checksum) > 0 { |
| 138 | + // Verify checksums are readable |
| 139 | + for _, cs := range config.Input.Content.Checksum { |
| 140 | + if cs == "" { |
| 141 | + t.Fatal("Checksum should not be empty") |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +// TestConfigurationMultiplePaths tests multiple path handling |
| 148 | +func TestConfigurationMultiplePaths(t *testing.T) { |
| 149 | + var config Configuration |
| 150 | + config.getConfiguration("tests/config_test_standard.yml") |
| 151 | + |
| 152 | + if len(config.Input.Path) > 1 { |
| 153 | + t.Logf("Configuration loaded with %d paths", len(config.Input.Path)) |
| 154 | + } |
| 155 | +} |
0 commit comments