Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROX-26711: Collector mock server should handle external ips #1901

28 changes: 26 additions & 2 deletions integration-tests/pkg/mock_sensor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,33 @@ func (m *MockSensor) pushEndpoint(containerID string, endpoint *sensorAPI.Networ
// translateAddress is a helper function for converting binary representations
// of network addresses (in the signals) to usable forms for testing
func (m *MockSensor) translateAddress(addr *sensorAPI.NetworkAddress) string {
address := utils.IPAddress{}
ipNetwork := utils.IPNetwork{}

addressData := addr.GetAddressData()
if len(addressData) > 0 {
address = utils.IPFromBytes(addressData)
} else {
// If there is no address data IpNetwork should be set and represent
// a CIDR block or external IP address.
Molter73 marked this conversation as resolved.
Show resolved Hide resolved
ipNetworkData := addr.GetIpNetwork()
if len(ipNetworkData) > 0 {
ipNetwork = utils.IPNetworkFromCIDRBytes(ipNetworkData)
// If the prefix length is 32 this is a regular IP address
// and not a CIDR block
Molter73 marked this conversation as resolved.
Show resolved Hide resolved
if ipNetwork.PrefixLen() == byte(32) {
address = ipNetwork.IP()
ipNetwork = utils.IPNetwork{}
}
}

}

ipPortPair := utils.NetworkPeerID{
Address: utils.IPFromBytes(addr.GetAddressData()),
Port: uint16(addr.GetPort()),
Address: address,
IPNetwork: ipNetwork,
Port: uint16(addr.GetPort()),
}

return ipPortPair.String()
}
Molter73 marked this conversation as resolved.
Show resolved Hide resolved
Loading