mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 22:59:58 +00:00
TUN-8762: fix argument order when invoking tracert and modify network info output parsing.
## Summary The windows code path has three bugs: * the -4 and -6 option cannot be passed in the last position * since there are some lines in the command output that are not parsable the collection fails to parse any kind of output * the timeout hop is not correctly parsed This PR also guards the parsing code against empty domains Closes TUN-8762
This commit is contained in:
@@ -20,23 +20,105 @@ func TestDecode(t *testing.T) {
|
||||
name string
|
||||
text string
|
||||
expectedHops []*diagnostic.Hop
|
||||
expectErr bool
|
||||
}{
|
||||
|
||||
{
|
||||
"tracert output",
|
||||
`
|
||||
Tracing route to region2.v2.argotunnel.com [198.41.200.73]
|
||||
over a maximum of 5 hops:
|
||||
|
||||
1 10 ms <1 ms 1 ms 192.168.64.1
|
||||
2 27 ms 14 ms 5 ms 192.168.1.254
|
||||
3 * * * Request timed out.
|
||||
4 * * * Request timed out.
|
||||
5 27 ms 5 ms 5 ms 195.8.30.245
|
||||
|
||||
Trace complete.
|
||||
`,
|
||||
[]*diagnostic.Hop{
|
||||
diagnostic.NewHop(
|
||||
uint8(1),
|
||||
"192.168.64.1",
|
||||
[]time.Duration{
|
||||
time.Duration(10000),
|
||||
time.Duration(1000),
|
||||
time.Duration(1000),
|
||||
},
|
||||
),
|
||||
diagnostic.NewHop(
|
||||
uint8(2),
|
||||
"192.168.1.254",
|
||||
[]time.Duration{
|
||||
time.Duration(27000),
|
||||
time.Duration(14000),
|
||||
time.Duration(5000),
|
||||
},
|
||||
),
|
||||
diagnostic.NewTimeoutHop(uint8(3)),
|
||||
diagnostic.NewTimeoutHop(uint8(4)),
|
||||
diagnostic.NewHop(
|
||||
uint8(5),
|
||||
"195.8.30.245",
|
||||
[]time.Duration{
|
||||
time.Duration(27000),
|
||||
time.Duration(5000),
|
||||
time.Duration(5000),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
"repeated hop index parse failure",
|
||||
`1 12.874 ms 15.517 ms 15.311 ms 172.68.101.121 (172.68.101.121)
|
||||
2 12.874 ms 15.517 ms 15.311 ms 172.68.101.121 (172.68.101.121)
|
||||
someletters * * *`,
|
||||
nil,
|
||||
true,
|
||||
[]*diagnostic.Hop{
|
||||
diagnostic.NewHop(
|
||||
uint8(1),
|
||||
"172.68.101.121 (172.68.101.121)",
|
||||
[]time.Duration{
|
||||
time.Duration(12874),
|
||||
time.Duration(15517),
|
||||
time.Duration(15311),
|
||||
},
|
||||
),
|
||||
diagnostic.NewHop(
|
||||
uint8(2),
|
||||
"172.68.101.121 (172.68.101.121)",
|
||||
[]time.Duration{
|
||||
time.Duration(12874),
|
||||
time.Duration(15517),
|
||||
time.Duration(15311),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
"hop index parse failure",
|
||||
`1 12.874 ms 15.517 ms 15.311 ms 172.68.101.121 (172.68.101.121)
|
||||
2 12.874 ms 15.517 ms 15.311 ms 172.68.101.121 (172.68.101.121)
|
||||
someletters abc ms 0.456 ms 0.789 ms 8.8.8.8 8.8.8.9`,
|
||||
nil,
|
||||
true,
|
||||
[]*diagnostic.Hop{
|
||||
diagnostic.NewHop(
|
||||
uint8(1),
|
||||
"172.68.101.121 (172.68.101.121)",
|
||||
[]time.Duration{
|
||||
time.Duration(12874),
|
||||
time.Duration(15517),
|
||||
time.Duration(15311),
|
||||
},
|
||||
),
|
||||
diagnostic.NewHop(
|
||||
uint8(2),
|
||||
"172.68.101.121 (172.68.101.121)",
|
||||
[]time.Duration{
|
||||
time.Duration(12874),
|
||||
time.Duration(15517),
|
||||
time.Duration(15311),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
"missing rtt",
|
||||
@@ -61,13 +143,12 @@ someletters abc ms 0.456 ms 0.789 ms 8.8.8.8 8.8.8.9`,
|
||||
},
|
||||
),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"simple example ipv4",
|
||||
`1 12.874 ms 15.517 ms 15.311 ms 172.68.101.121 (172.68.101.121)
|
||||
2 12.874 ms 15.517 ms 15.311 ms 172.68.101.121 (172.68.101.121)
|
||||
3 * * *`,
|
||||
3 * * * Request timed out.`,
|
||||
[]*diagnostic.Hop{
|
||||
diagnostic.NewHop(
|
||||
uint8(1),
|
||||
@@ -89,7 +170,6 @@ someletters abc ms 0.456 ms 0.789 ms 8.8.8.8 8.8.8.9`,
|
||||
),
|
||||
diagnostic.NewTimeoutHop(uint8(3)),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"simple example ipv6",
|
||||
@@ -115,7 +195,6 @@ someletters abc ms 0.456 ms 0.789 ms 8.8.8.8 8.8.8.9`,
|
||||
},
|
||||
),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -124,12 +203,8 @@ someletters abc ms 0.456 ms 0.789 ms 8.8.8.8 8.8.8.9`,
|
||||
t.Parallel()
|
||||
|
||||
hops, err := diagnostic.Decode(strings.NewReader(test.text), diagnostic.DecodeLine)
|
||||
if test.expectErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.expectedHops, hops)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.expectedHops, hops)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user