inlet/flow: add a test to decode IPFIX NAT fields
Some checks are pending
CI / 🤖 Check dependabot status (push) Waiting to run
CI / 🐧 Build and test on Linux (push) Blocked by required conditions
CI / 🍏 Build and test on macOS (push) Blocked by required conditions
CI / 🔍 Upload code coverage (push) Blocked by required conditions
CI / 🔭 Build Go backend (1.24) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (18) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (20) (push) Blocked by required conditions
CI / 🔭 Build JS frontend (22) (push) Blocked by required conditions
CI / ⚖️ Check licenses (push) Waiting to run
CI / 🐋 Build Docker images (push) Blocked by required conditions
CI / 🚀 Publish release (push) Blocked by required conditions

Unfortunately, they are discrete events. 0 packets, 0 bytes. We can't
use them much.
This commit is contained in:
Vincent Bernat
2025-06-09 08:02:56 +02:00
parent bc49f56eca
commit 7be4a5f424
2 changed files with 35 additions and 0 deletions

View File

@@ -629,3 +629,38 @@ func TestDecodeTimestampFromFirstSwitched(t *testing.T) {
}
}
}
func TestDecodeNAT(t *testing.T) {
r := reporter.NewMock(t)
nfdecoder := New(r, decoder.Dependencies{Schema: schema.NewMock(t).EnableAllColumns()}, decoder.Option{TimestampSource: decoder.TimestampSourceUDP})
// The following PCAP is a NAT event, there is no sampling rate, no bytes,
// no packets. We can't do much with it.
data := helpers.ReadPcapL4(t, filepath.Join("testdata", "nat.pcap"))
got := nfdecoder.Decode(decoder.RawFlow{Payload: data, Source: net.ParseIP("127.0.0.1")})
expectedFlows := []*schema.FlowMessage{
{
ExporterAddress: netip.MustParseAddr("::ffff:127.0.0.1"),
SrcAddr: netip.MustParseAddr("::ffff:172.16.100.198"),
DstAddr: netip.MustParseAddr("::ffff:10.89.87.1"),
ProtobufDebug: map[schema.ColumnKey]any{
schema.ColumnSrcPort: 35303,
schema.ColumnDstPort: 53,
schema.ColumnSrcAddrNAT: netip.MustParseAddr("::ffff:10.143.52.29"),
schema.ColumnDstAddrNAT: netip.MustParseAddr("::ffff:10.89.87.1"),
schema.ColumnSrcPortNAT: 35303,
schema.ColumnDstPortNAT: 53,
schema.ColumnEType: helpers.ETypeIPv4,
schema.ColumnProto: 17,
},
},
}
for _, f := range got {
f.TimeReceived = 0
}
if diff := helpers.Diff(got[:1], expectedFlows); diff != "" {
t.Fatalf("Decode() (-got, +want):\n%s", diff)
}
}

Binary file not shown.