MCPcopy
hub / github.com/dreadl0ck/netcap / TestFTPDecoder

Function TestFTPDecoder

collector/file_extraction_test.go:317–408  ·  view source on GitHub ↗

TestFTPDecoder tests FTP decoder functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

315
316// TestFTPDecoder tests FTP decoder functionality
317func 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 }

Callers

nothing calls this directly

Calls 10

GetDefaultConfigFunction · 0.92
SetGlobalConfigFunction · 0.92
fileExistsFunction · 0.85
createTestCollectorFunction · 0.85
SkipMethod · 0.80
CollectPcapMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.65
ReadHeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected