From 39721d86198d95bee0cf5a9715bfdb9b02ad5900 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 28 Nov 2018 12:33:06 +0000 Subject: [PATCH] Fix up NAT mapper test - Add SRC and DST NAT flag in status. - The port number was wrong from host1's perspective - it should see the mapped port on host2 not the real port inside the container. - Add nodes at the other end of the connection, like the real probe does. - Pass the local host name to MakeEndpointNodeID as it would be on the real probe. --- probe/endpoint/nat_internal_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/probe/endpoint/nat_internal_test.go b/probe/endpoint/nat_internal_test.go index 6884614e4..a94d55218 100644 --- a/probe/endpoint/nat_internal_test.go +++ b/probe/endpoint/nat_internal_test.go @@ -71,18 +71,18 @@ func TestNat(t *testing.T) { have := report.MakeReport() originalID := report.MakeEndpointNodeID("host1", "", "10.0.47.1", "80") - originalNode := report.MakeNodeWith(originalID, map[string]string{ + have.Endpoint.AddNode(report.MakeNodeWith(originalID, map[string]string{ "foo": "bar", - }) - have.Endpoint.AddNode(originalNode) - fromID := report.MakeEndpointNodeID("host2", "", "2.3.4.5", "22223") + })) + fromID := report.MakeEndpointNodeID("host1", "", "2.3.4.5", "22223") have.Endpoint.AddNode(report.MakeNodeWith(fromID, nil).WithAdjacent(originalID)) want := have.Copy() // add nat original destination as a copy of nat reply source - origDstID := report.MakeEndpointNodeID("host1", "", "1.2.3.4", "80") - want.Endpoint.AddNode(originalNode.WithID(origDstID).WithLatests(map[string]string{ + wantID := report.MakeEndpointNodeID("host1", "", "1.2.3.4", "80") + want.Endpoint.AddNode(report.MakeNodeWith(wantID, map[string]string{ CopyOf: originalID, + "foo": "bar", })) makeNATMapper(ct).applyNAT(have, "host1") @@ -91,7 +91,7 @@ func TestNat(t *testing.T) { } } - // form the PoV of host2 + // from the PoV of host2 { f := conntrack.Conn{ MsgType: conntrack.NfctMsgUpdate, @@ -117,21 +117,21 @@ func TestNat(t *testing.T) { } have := report.MakeReport() - fromID := report.MakeEndpointNodeID("host2", "", "10.0.47.2", "22222") - toID := report.MakeEndpointNodeID("host1", "", "1.2.3.4", "80") + originalID := report.MakeEndpointNodeID("host2", "", "10.0.47.2", "22222") + toID := report.MakeEndpointNodeID("host2", "", "1.2.3.4", "80") have.Endpoint.AddNode(report.MakeNodeWith(toID, nil)) - have.Endpoint.AddNode(report.MakeNodeWith(fromID, map[string]string{ + have.Endpoint.AddNode(report.MakeNodeWith(originalID, map[string]string{ "foo": "baz", }).WithAdjacent(toID)) // add NAT reply destination as a copy of NAT original source want := have.Copy() want.Endpoint.AddNode(report.MakeNodeWith(report.MakeEndpointNodeID("host2", "", "2.3.4.5", "22223"), map[string]string{ - CopyOf: report.MakeEndpointNodeID("host1", "", "10.0.47.2", "22222"), + CopyOf: originalID, "foo": "baz", }).WithAdjacent(toID)) - makeNATMapper(ct).applyNAT(have, "host1") + makeNATMapper(ct).applyNAT(have, "host2") if !reflect.DeepEqual(want, have) { t.Fatal(test.Diff(want, have)) }