diff --git a/internal/openvpn/extract/extract.go b/internal/openvpn/extract/extract.go index b5557e46..f2b88302 100644 --- a/internal/openvpn/extract/extract.go +++ b/internal/openvpn/extract/extract.go @@ -53,6 +53,8 @@ func extractDataFromLines(lines []string) ( func extractDataFromLine(line string) ( ip netip.Addr, port uint16, protocol string, err error, ) { + line = strings.TrimSpace(line) + switch { case strings.HasPrefix(line, "proto "): protocol, err = extractProto(line) diff --git a/internal/openvpn/extract/extract_test.go b/internal/openvpn/extract/extract_test.go index 200bfdb8..f5a4362c 100644 --- a/internal/openvpn/extract/extract_test.go +++ b/internal/openvpn/extract/extract_test.go @@ -62,6 +62,14 @@ func Test_extractDataFromLines(t *testing.T) { Protocol: constants.UDP, }, }, + "leading_whitespace": { + lines: []string{" proto tcp", "\tremote 1.2.3.4 443 tcp"}, + connection: models.Connection{ + IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}), + Port: 443, + Protocol: constants.TCP, + }, + }, } for name, testCase := range testCases {