Skip to content

Commit d9cc8be

Browse files
committed
Entirely removed types.NetworkInfo
1 parent 037aa91 commit d9cc8be

File tree

4 files changed

+83
-87
lines changed

4 files changed

+83
-87
lines changed

integration-tests/integration_test.go

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"strings"
55
"testing"
66

7+
sensorAPI "github.com/stackrox/rox/generated/internalapi/sensor"
8+
79
"github.com/stretchr/testify/suite"
810

911
"github.com/stackrox/collector/integration-tests/pkg/collector"
@@ -166,13 +168,13 @@ func TestConnectionsAndEndpointsNormal(t *testing.T) {
166168
Server: suites.Container{
167169
Name: "socat-server-0",
168170
Cmd: "socat TCP4-LISTEN:40,reuseaddr,fork - &",
169-
ExpectedNetwork: []types.NetworkInfo{
171+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
170172
{
171-
LocalAddress: ":40",
172-
RemoteAddress: "CLIENT_IP",
173-
Role: "ROLE_SERVER",
174-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
175-
CloseTimestamp: types.NilTimestamp,
173+
LocalAddress: types.CreateNetworkAddress("", "", 40),
174+
RemoteAddress: types.CreateNetworkAddress("", "", 0),
175+
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
176+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
177+
CloseTimestamp: nil,
176178
},
177179
},
178180
ExpectedEndpoints: []types.EndpointInfo{
@@ -189,13 +191,13 @@ func TestConnectionsAndEndpointsNormal(t *testing.T) {
189191
Client: suites.Container{
190192
Name: "socat-client-0",
191193
Cmd: "echo hello | socat - TCP4:SERVER_IP:40",
192-
ExpectedNetwork: []types.NetworkInfo{
194+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
193195
{
194-
LocalAddress: "",
195-
RemoteAddress: "SERVER_IP:40",
196-
Role: "ROLE_CLIENT",
197-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
198-
CloseTimestamp: types.NilTimestamp,
196+
LocalAddress: types.CreateNetworkAddress("", "", 0),
197+
RemoteAddress: types.CreateNetworkAddress("", "", 40),
198+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
199+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
200+
CloseTimestamp: nil,
199201
},
200202
},
201203
ExpectedEndpoints: nil,
@@ -211,13 +213,13 @@ func TestConnectionsAndEndpointsHighLowPorts(t *testing.T) {
211213
Server: suites.Container{
212214
Name: "socat-server-1",
213215
Cmd: "socat TCP4-LISTEN:40000,reuseaddr,fork - &",
214-
ExpectedNetwork: []types.NetworkInfo{
216+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
215217
{
216-
LocalAddress: ":40000",
217-
RemoteAddress: "CLIENT_IP",
218-
Role: "ROLE_SERVER",
219-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
220-
CloseTimestamp: types.NilTimestamp,
218+
LocalAddress: types.CreateNetworkAddress("", "", 40000),
219+
RemoteAddress: types.CreateNetworkAddress("", "", 0),
220+
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
221+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
222+
CloseTimestamp: nil,
221223
},
222224
},
223225
ExpectedEndpoints: []types.EndpointInfo{
@@ -234,13 +236,13 @@ func TestConnectionsAndEndpointsHighLowPorts(t *testing.T) {
234236
Client: suites.Container{
235237
Name: "socat-client-1",
236238
Cmd: "echo hello | socat - TCP4:SERVER_IP:40000,sourceport=10000",
237-
ExpectedNetwork: []types.NetworkInfo{
239+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
238240
{
239-
LocalAddress: "",
240-
RemoteAddress: "SERVER_IP:40000",
241-
Role: "ROLE_CLIENT",
242-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
243-
CloseTimestamp: types.NilTimestamp,
241+
LocalAddress: types.CreateNetworkAddress("", "", 0),
242+
RemoteAddress: types.CreateNetworkAddress("", "", 40000),
243+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
244+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
245+
CloseTimestamp: nil,
244246
},
245247
},
246248
ExpectedEndpoints: nil,
@@ -256,13 +258,13 @@ func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
256258
Server: suites.Container{
257259
Name: "socat-server-2",
258260
Cmd: "socat TCP4-LISTEN:60999,reuseaddr,fork - &",
259-
ExpectedNetwork: []types.NetworkInfo{
261+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
260262
{
261-
LocalAddress: ":60999",
262-
RemoteAddress: "CLIENT_IP",
263-
Role: "ROLE_SERVER",
264-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
265-
CloseTimestamp: types.NilTimestamp,
263+
LocalAddress: types.CreateNetworkAddress("", "", 60999),
264+
RemoteAddress: types.CreateNetworkAddress("", "", 0),
265+
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
266+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
267+
CloseTimestamp: nil,
266268
},
267269
},
268270
ExpectedEndpoints: []types.EndpointInfo{
@@ -279,13 +281,13 @@ func TestConnectionsAndEndpointsServerHigh(t *testing.T) {
279281
Client: suites.Container{
280282
Name: "socat-client-2",
281283
Cmd: "echo hello | socat - TCP4:SERVER_IP:60999",
282-
ExpectedNetwork: []types.NetworkInfo{
284+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
283285
{
284-
LocalAddress: "",
285-
RemoteAddress: "SERVER_IP:60999",
286-
Role: "ROLE_CLIENT",
287-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
288-
CloseTimestamp: types.NilTimestamp,
286+
LocalAddress: types.CreateNetworkAddress("", "", 0),
287+
RemoteAddress: types.CreateNetworkAddress("", "", 60999),
288+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
289+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
290+
CloseTimestamp: nil,
289291
},
290292
},
291293
ExpectedEndpoints: nil,
@@ -301,13 +303,13 @@ func TestConnectionsAndEndpointsSourcePort(t *testing.T) {
301303
Server: suites.Container{
302304
Name: "socat-server-1",
303305
Cmd: "socat TCP4-LISTEN:10000,reuseaddr,fork - &",
304-
ExpectedNetwork: []types.NetworkInfo{
306+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
305307
{
306-
LocalAddress: ":10000",
307-
RemoteAddress: "CLIENT_IP",
308-
Role: "ROLE_SERVER",
309-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
310-
CloseTimestamp: types.NilTimestamp,
308+
LocalAddress: types.CreateNetworkAddress("", "", 10000),
309+
RemoteAddress: types.CreateNetworkAddress("", "", 0),
310+
Role: sensorAPI.ClientServerRole_ROLE_SERVER,
311+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
312+
CloseTimestamp: nil,
311313
},
312314
},
313315
ExpectedEndpoints: []types.EndpointInfo{
@@ -324,13 +326,13 @@ func TestConnectionsAndEndpointsSourcePort(t *testing.T) {
324326
Client: suites.Container{
325327
Name: "socat-client-1",
326328
Cmd: "echo hello | socat - TCP4:SERVER_IP:10000,sourceport=40000",
327-
ExpectedNetwork: []types.NetworkInfo{
329+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
328330
{
329-
LocalAddress: "",
330-
RemoteAddress: "SERVER_IP:10000",
331-
Role: "ROLE_CLIENT",
332-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
333-
CloseTimestamp: types.NilTimestamp,
331+
LocalAddress: types.CreateNetworkAddress("", "", 0),
332+
RemoteAddress: types.CreateNetworkAddress("", "", 10000),
333+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
334+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
335+
CloseTimestamp: nil,
334336
},
335337
},
336338
ExpectedEndpoints: nil,
@@ -362,13 +364,13 @@ func TestConnectionsAndEndpointsUDPNormal(t *testing.T) {
362364
Client: suites.Container{
363365
Name: "socat-client-udp",
364366
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
365-
ExpectedNetwork: []types.NetworkInfo{
367+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
366368
{
367-
LocalAddress: "",
368-
RemoteAddress: "SERVER_IP:53",
369-
Role: "ROLE_CLIENT",
370-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
371-
CloseTimestamp: types.NilTimestamp,
369+
LocalAddress: types.CreateNetworkAddress("", "", 0),
370+
RemoteAddress: types.CreateNetworkAddress("", "", 53),
371+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
372+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
373+
CloseTimestamp: nil,
372374
},
373375
},
374376
ExpectedEndpoints: nil,
@@ -400,13 +402,13 @@ func TestConnectionsAndEndpointsUDPNoReuseaddr(t *testing.T) {
400402
Client: suites.Container{
401403
Name: "socat-client-udp",
402404
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
403-
ExpectedNetwork: []types.NetworkInfo{
405+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
404406
{
405-
LocalAddress: "",
406-
RemoteAddress: "SERVER_IP:53",
407-
Role: "ROLE_CLIENT",
408-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
409-
CloseTimestamp: types.NilTimestamp,
407+
LocalAddress: types.CreateNetworkAddress("", "", 0),
408+
RemoteAddress: types.CreateNetworkAddress("", "", 53),
409+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
410+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
411+
CloseTimestamp: nil,
410412
},
411413
},
412414
ExpectedEndpoints: nil,
@@ -438,13 +440,13 @@ func TestConnectionsAndEndpointsUDPNoFork(t *testing.T) {
438440
Client: suites.Container{
439441
Name: "socat-client-udp",
440442
Cmd: "echo hello | socat - UDP:SERVER_IP:53",
441-
ExpectedNetwork: []types.NetworkInfo{
443+
ExpectedNetwork: []*sensorAPI.NetworkConnection{
442444
{
443-
LocalAddress: "",
444-
RemoteAddress: "SERVER_IP:53",
445-
Role: "ROLE_CLIENT",
446-
SocketFamily: "SOCKET_FAMILY_UNKNOWN",
447-
CloseTimestamp: types.NilTimestamp,
445+
LocalAddress: types.CreateNetworkAddress("", "", 0),
446+
RemoteAddress: types.CreateNetworkAddress("", "", 53),
447+
Role: sensorAPI.ClientServerRole_ROLE_CLIENT,
448+
SocketFamily: sensorAPI.SocketFamily_SOCKET_FAMILY_UNKNOWN,
449+
CloseTimestamp: nil,
448450
},
449451
},
450452
ExpectedEndpoints: nil,

integration-tests/pkg/mock_sensor/expect_conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *MockSensor) ExpectConnections(t *testing.T, containerID string, timeout
2121

2222
to_find := funk.Filter(expected, func(x *sensorAPI.NetworkConnection) bool {
2323
return !s.HasConnection(containerID, x)
24-
}).([]types.NetworkInfo)
24+
}).([]*sensorAPI.NetworkConnection)
2525

2626
if len(to_find) == 0 {
2727
return true
@@ -43,7 +43,7 @@ loop:
4343

4444
to_find = funk.Filter(expected, func(x *sensorAPI.NetworkConnection) bool {
4545
return !s.HasConnection(containerID, x)
46-
}).([]types.NetworkInfo)
46+
}).([]*sensorAPI.NetworkConnection)
4747

4848
if len(to_find) == 0 {
4949
return true

integration-tests/pkg/types/network.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ const (
1212
NilTimestamp = "<nil>"
1313
)
1414

15-
type NetworkInfo struct {
16-
LocalAddress string
17-
RemoteAddress string
18-
Role string
19-
SocketFamily string
20-
CloseTimestamp string
21-
}
22-
2315
type NetworkInfoBatch []*sensorAPI.NetworkConnection
2416

2517
// TranslateAddress is a helper function for converting binary representations

integration-tests/suites/connections_and_endpoints.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"strings"
66
"time"
77

8+
sensorAPI "github.com/stackrox/rox/generated/internalapi/sensor"
9+
810
"github.com/stackrox/collector/integration-tests/pkg/collector"
911
"github.com/stackrox/collector/integration-tests/pkg/common"
1012
"github.com/stackrox/collector/integration-tests/pkg/config"
@@ -18,7 +20,7 @@ type Container struct {
1820
Cmd string
1921
ContainerID string
2022
IP string
21-
ExpectedNetwork []types.NetworkInfo
23+
ExpectedNetwork []*sensorAPI.NetworkConnection
2224
ExpectedEndpoints []types.EndpointInfo
2325
}
2426

@@ -106,11 +108,11 @@ func (s *ConnectionsAndEndpointsTestSuite) TestConnectionsAndEndpoints() {
106108
}
107109
lastNetwork := clientNetworks[nNetwork-1]
108110
lastExpectedNetwork := s.Client.ExpectedNetwork[nExpectedNetwork-1]
109-
expectedLocalAddress := strings.Replace(lastExpectedNetwork.LocalAddress, "CLIENT_IP", s.Client.IP, -1)
110-
expectedRemoteAddress := strings.Replace(lastExpectedNetwork.RemoteAddress, "SERVER_IP", s.Server.IP, -1)
111-
assert.Equal(s.T(), expectedLocalAddress, lastNetwork.LocalAddress)
112-
assert.Equal(s.T(), expectedRemoteAddress, lastNetwork.RemoteAddress)
113-
assert.Equal(s.T(), "ROLE_CLIENT", lastNetwork.Role)
111+
expectedRemoteAddress := types.CreateNetworkAddress(s.Server.IP, "", lastExpectedNetwork.RemoteAddress.Port)
112+
113+
assert.True(s.T(), types.EqualNetworkAddress(lastExpectedNetwork.LocalAddress, lastNetwork.LocalAddress))
114+
assert.True(s.T(), types.EqualNetworkAddress(expectedRemoteAddress, lastNetwork.RemoteAddress))
115+
assert.Equal(s.T(), sensorAPI.ClientServerRole_ROLE_CLIENT, lastNetwork.Role)
114116
assert.Equal(s.T(), lastExpectedNetwork.SocketFamily, lastNetwork.SocketFamily)
115117
}
116118

@@ -133,11 +135,11 @@ func (s *ConnectionsAndEndpointsTestSuite) TestConnectionsAndEndpoints() {
133135
}
134136
lastNetwork := serverNetworks[nNetwork-1]
135137
lastExpectedNetwork := s.Server.ExpectedNetwork[nExpectedNetwork-1]
136-
expectedLocalAddress := strings.Replace(lastExpectedNetwork.LocalAddress, "SERVER_IP", s.Server.IP, -1)
137-
expectedRemoteAddress := strings.Replace(lastExpectedNetwork.RemoteAddress, "CLIENT_IP", s.Client.IP, -1)
138-
assert.Equal(s.T(), expectedLocalAddress, lastNetwork.LocalAddress)
139-
assert.Equal(s.T(), expectedRemoteAddress, lastNetwork.RemoteAddress)
140-
assert.Equal(s.T(), "ROLE_SERVER", lastNetwork.Role)
138+
expectedRemoteAddress := types.CreateNetworkAddress(s.Client.IP, "", lastExpectedNetwork.RemoteAddress.Port)
139+
140+
assert.True(s.T(), types.EqualNetworkAddress(lastExpectedNetwork.LocalAddress, lastNetwork.LocalAddress))
141+
assert.True(s.T(), types.EqualNetworkAddress(expectedRemoteAddress, lastNetwork.RemoteAddress))
142+
assert.Equal(s.T(), sensorAPI.ClientServerRole_ROLE_SERVER, lastNetwork.Role)
141143
assert.Equal(s.T(), lastExpectedNetwork.SocketFamily, lastNetwork.SocketFamily)
142144
}
143145

0 commit comments

Comments
 (0)