mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-01 20:41:28 +02:00
update test to validate event aggregation over tcp, udp, icmp, and icmpv6
Signed-off-by: Dmitri <dmitri.external@netbird.io>
This commit is contained in:
@@ -18,7 +18,8 @@ var pregeneratedUUIDs = func() []uuid.UUID {
|
|||||||
return toret
|
return toret
|
||||||
}()
|
}()
|
||||||
|
|
||||||
func TestTcpAggregation(t *testing.T) {
|
func TestFlowAggregation(t *testing.T) {
|
||||||
|
var protocols = []types.Protocol{types.ICMP, types.ICMPv6, types.TCP, types.UDP}
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
description string
|
description string
|
||||||
events []*types.Event
|
events []*types.Event
|
||||||
@@ -35,7 +36,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeStart,
|
Type: types.TypeStart,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -55,7 +55,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeEnd,
|
Type: types.TypeEnd,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -77,7 +76,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeStart,
|
Type: types.TypeStart,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -105,7 +103,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeStart,
|
Type: types.TypeStart,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -125,7 +122,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeDrop,
|
Type: types.TypeDrop,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -147,7 +143,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeStart,
|
Type: types.TypeStart,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -175,7 +170,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeStart,
|
Type: types.TypeStart,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -197,7 +191,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeStart,
|
Type: types.TypeStart,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -225,7 +218,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeDrop,
|
Type: types.TypeDrop,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -247,7 +239,6 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
Type: types.TypeDrop,
|
Type: types.TypeDrop,
|
||||||
RuleID: []byte("rule-id-1"),
|
RuleID: []byte("rule-id-1"),
|
||||||
Direction: types.Egress,
|
Direction: types.Egress,
|
||||||
Protocol: types.TCP,
|
|
||||||
SourceIP: ipAddr("1.1.1.1"),
|
SourceIP: ipAddr("1.1.1.1"),
|
||||||
SourcePort: 1234,
|
SourcePort: 1234,
|
||||||
DestIP: ipAddr("2.2.2.2"),
|
DestIP: ipAddr("2.2.2.2"),
|
||||||
@@ -265,16 +256,22 @@ func TestTcpAggregation(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, protocol := range protocols {
|
||||||
t.Run(tt.description, func(t *testing.T) {
|
for _, tt := range tests {
|
||||||
store := NewAggregatingMemoryStore()
|
t.Run(tt.description+" "+protocol.String(), func(t *testing.T) {
|
||||||
for _, e := range tt.events {
|
store := NewAggregatingMemoryStore()
|
||||||
store.StoreEvent(e)
|
for _, e := range tt.events {
|
||||||
}
|
e.Protocol = protocol
|
||||||
events := store.GetAggregatedEvents()
|
store.StoreEvent(e)
|
||||||
assert.Len(t, events, len(tt.expected))
|
}
|
||||||
assert.ElementsMatch(t, events, tt.expected)
|
for _, e := range tt.expected {
|
||||||
})
|
e.Protocol = protocol
|
||||||
|
}
|
||||||
|
events := store.GetAggregatedEvents()
|
||||||
|
assert.Len(t, events, len(tt.expected))
|
||||||
|
assert.ElementsMatch(t, events, tt.expected)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user