Skip to content

Commit

Permalink
Fix up NAT mapper test
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
bboreham committed Nov 28, 2018
1 parent d22b65e commit 39721d8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions probe/endpoint/nat_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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))
}
Expand Down

0 comments on commit 39721d8

Please sign in to comment.