Skip to content

Commit 39721d8

Browse files
committed
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.
1 parent d22b65e commit 39721d8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

probe/endpoint/nat_internal_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ func TestNat(t *testing.T) {
7171

7272
have := report.MakeReport()
7373
originalID := report.MakeEndpointNodeID("host1", "", "10.0.47.1", "80")
74-
originalNode := report.MakeNodeWith(originalID, map[string]string{
74+
have.Endpoint.AddNode(report.MakeNodeWith(originalID, map[string]string{
7575
"foo": "bar",
76-
})
77-
have.Endpoint.AddNode(originalNode)
78-
fromID := report.MakeEndpointNodeID("host2", "", "2.3.4.5", "22223")
76+
}))
77+
fromID := report.MakeEndpointNodeID("host1", "", "2.3.4.5", "22223")
7978
have.Endpoint.AddNode(report.MakeNodeWith(fromID, nil).WithAdjacent(originalID))
8079

8180
want := have.Copy()
8281
// add nat original destination as a copy of nat reply source
83-
origDstID := report.MakeEndpointNodeID("host1", "", "1.2.3.4", "80")
84-
want.Endpoint.AddNode(originalNode.WithID(origDstID).WithLatests(map[string]string{
82+
wantID := report.MakeEndpointNodeID("host1", "", "1.2.3.4", "80")
83+
want.Endpoint.AddNode(report.MakeNodeWith(wantID, map[string]string{
8584
CopyOf: originalID,
85+
"foo": "bar",
8686
}))
8787

8888
makeNATMapper(ct).applyNAT(have, "host1")
@@ -91,7 +91,7 @@ func TestNat(t *testing.T) {
9191
}
9292
}
9393

94-
// form the PoV of host2
94+
// from the PoV of host2
9595
{
9696
f := conntrack.Conn{
9797
MsgType: conntrack.NfctMsgUpdate,
@@ -117,21 +117,21 @@ func TestNat(t *testing.T) {
117117
}
118118

119119
have := report.MakeReport()
120-
fromID := report.MakeEndpointNodeID("host2", "", "10.0.47.2", "22222")
121-
toID := report.MakeEndpointNodeID("host1", "", "1.2.3.4", "80")
120+
originalID := report.MakeEndpointNodeID("host2", "", "10.0.47.2", "22222")
121+
toID := report.MakeEndpointNodeID("host2", "", "1.2.3.4", "80")
122122
have.Endpoint.AddNode(report.MakeNodeWith(toID, nil))
123-
have.Endpoint.AddNode(report.MakeNodeWith(fromID, map[string]string{
123+
have.Endpoint.AddNode(report.MakeNodeWith(originalID, map[string]string{
124124
"foo": "baz",
125125
}).WithAdjacent(toID))
126126

127127
// add NAT reply destination as a copy of NAT original source
128128
want := have.Copy()
129129
want.Endpoint.AddNode(report.MakeNodeWith(report.MakeEndpointNodeID("host2", "", "2.3.4.5", "22223"), map[string]string{
130-
CopyOf: report.MakeEndpointNodeID("host1", "", "10.0.47.2", "22222"),
130+
CopyOf: originalID,
131131
"foo": "baz",
132132
}).WithAdjacent(toID))
133133

134-
makeNATMapper(ct).applyNAT(have, "host1")
134+
makeNATMapper(ct).applyNAT(have, "host2")
135135
if !reflect.DeepEqual(want, have) {
136136
t.Fatal(test.Diff(want, have))
137137
}

0 commit comments

Comments
 (0)