TestFTPDecoder tests FTP decoder functionality
(t *testing.T)
| 315 | |
| 316 | // TestFTPDecoder tests FTP decoder functionality |
| 317 | func TestFTPDecoder(t *testing.T) { |
| 318 | if !fileExists(ftpPCAP) { |
| 319 | t.Skip("FTP test PCAP not found:", ftpPCAP) |
| 320 | } |
| 321 | |
| 322 | tmpDir := t.TempDir() |
| 323 | |
| 324 | // Configure file extraction |
| 325 | cfg := file.GetDefaultConfig() |
| 326 | cfg.FileExtraction.Enabled = true |
| 327 | cfg.FileExtraction.Protocols.FTP = true |
| 328 | file.SetGlobalConfig(cfg) |
| 329 | |
| 330 | // Create collector |
| 331 | c := createTestCollector(tmpDir, false) |
| 332 | c.InputFile = ftpPCAP |
| 333 | |
| 334 | // Run capture |
| 335 | err := c.CollectPcap(ftpPCAP) |
| 336 | if err != nil { |
| 337 | t.Fatalf("Capture failed: %v", err) |
| 338 | } |
| 339 | |
| 340 | // Check for FTP audit records |
| 341 | ftpAuditPath := filepath.Join(tmpDir, "FTP.ncap.gz") |
| 342 | if !fileExists(ftpAuditPath) { |
| 343 | t.Log("No FTP audit records created") |
| 344 | return |
| 345 | } |
| 346 | |
| 347 | // Read FTP records |
| 348 | reader, err := netio.Open(ftpAuditPath, defaults.BufferSize) |
| 349 | if err != nil { |
| 350 | t.Fatalf("Failed to open FTP audit records: %v", err) |
| 351 | } |
| 352 | defer reader.Close() |
| 353 | |
| 354 | // Read file header first |
| 355 | header, err := reader.ReadHeader() |
| 356 | if err != nil { |
| 357 | t.Fatalf("Failed to read FTP audit header: %v", err) |
| 358 | } |
| 359 | if header.Type != types.Type_NC_FTP { |
| 360 | t.Fatalf("Expected FTP type, got: %v", header.Type) |
| 361 | } |
| 362 | |
| 363 | var ftpRecord types.FTP |
| 364 | commandCount := 0 |
| 365 | var foundRETR, foundSTOR, foundPORT, foundPASV bool |
| 366 | |
| 367 | for { |
| 368 | err := reader.Next(&ftpRecord) |
| 369 | if err != nil { |
| 370 | if err != io.EOF { |
| 371 | t.Errorf("Error reading FTP record: %v", err) |
| 372 | } |
| 373 | break |
| 374 | } |
nothing calls this directly
no test coverage detected