mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-12 19:24:40 +00:00
6a396731eb
Mechanical change with perl+goimports. Changed {Must,}Parse{IP,IPPrefix,IPPort} to their netip variants, then goimports -d . Finally, removed the net/netaddr wrappers, to prevent future use. Updates #5162 Change-Id: I59c0e38b5fbca5a935d701645789cddf3d7863ad Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package packet
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
)
|
|
|
|
func TestTailscaleRejectedHeader(t *testing.T) {
|
|
tests := []struct {
|
|
h TailscaleRejectedHeader
|
|
wantStr string
|
|
}{
|
|
{
|
|
h: TailscaleRejectedHeader{
|
|
IPSrc: netip.MustParseAddr("5.5.5.5"),
|
|
IPDst: netip.MustParseAddr("1.2.3.4"),
|
|
Src: netip.MustParseAddrPort("1.2.3.4:567"),
|
|
Dst: netip.MustParseAddrPort("5.5.5.5:443"),
|
|
Proto: TCP,
|
|
Reason: RejectedDueToACLs,
|
|
},
|
|
wantStr: "TSMP-reject-flow{TCP 1.2.3.4:567 > 5.5.5.5:443}: acl",
|
|
},
|
|
{
|
|
h: TailscaleRejectedHeader{
|
|
IPSrc: netip.MustParseAddr("2::2"),
|
|
IPDst: netip.MustParseAddr("1::1"),
|
|
Src: netip.MustParseAddrPort("[1::1]:567"),
|
|
Dst: netip.MustParseAddrPort("[2::2]:443"),
|
|
Proto: UDP,
|
|
Reason: RejectedDueToShieldsUp,
|
|
},
|
|
wantStr: "TSMP-reject-flow{UDP [1::1]:567 > [2::2]:443}: shields",
|
|
},
|
|
{
|
|
h: TailscaleRejectedHeader{
|
|
IPSrc: netip.MustParseAddr("2::2"),
|
|
IPDst: netip.MustParseAddr("1::1"),
|
|
Src: netip.MustParseAddrPort("[1::1]:567"),
|
|
Dst: netip.MustParseAddrPort("[2::2]:443"),
|
|
Proto: UDP,
|
|
Reason: RejectedDueToIPForwarding,
|
|
MaybeBroken: true,
|
|
},
|
|
wantStr: "TSMP-reject-flow{UDP [1::1]:567 > [2::2]:443}: host-ip-forwarding-unavailable",
|
|
},
|
|
}
|
|
for i, tt := range tests {
|
|
gotStr := tt.h.String()
|
|
if gotStr != tt.wantStr {
|
|
t.Errorf("%v. String = %q; want %q", i, gotStr, tt.wantStr)
|
|
continue
|
|
}
|
|
pkt := make([]byte, tt.h.Len())
|
|
tt.h.Marshal(pkt)
|
|
|
|
var p Parsed
|
|
p.Decode(pkt)
|
|
t.Logf("Parsed: %+v", p)
|
|
t.Logf("Parsed: %s", p.String())
|
|
back, ok := p.AsTailscaleRejectedHeader()
|
|
if !ok {
|
|
t.Errorf("%v. %q (%02x) didn't parse back", i, gotStr, pkt)
|
|
continue
|
|
}
|
|
if back != tt.h {
|
|
t.Errorf("%v. %q parsed back as %q", i, tt.h, back)
|
|
}
|
|
}
|
|
}
|