mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-27 03:55:36 +00:00
f27b2cf569
The design changed during integration and testing, resulting in the earlier implementation growing in the appc package to be intended now only for the sniproxy implementation. That code is moved to it's final location, and the current App Connector code is now renamed. Updates tailscale/corp#15437 Signed-off-by: James Tucker <james@tailscale.com>
96 lines
3.3 KiB
Go
96 lines
3.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package main
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
"tailscale.com/tailcfg"
|
|
"tailscale.com/types/appctype"
|
|
)
|
|
|
|
func TestMakeConnectorsFromConfig(t *testing.T) {
|
|
tcs := []struct {
|
|
name string
|
|
input *appctype.AppConnectorConfig
|
|
want map[appctype.ConfigID]connector
|
|
}{
|
|
{
|
|
"empty",
|
|
&appctype.AppConnectorConfig{},
|
|
nil,
|
|
},
|
|
{
|
|
"DNAT",
|
|
&appctype.AppConnectorConfig{
|
|
DNAT: map[appctype.ConfigID]appctype.DNATConfig{
|
|
"swiggity_swooty": {
|
|
Addrs: []netip.Addr{netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1")},
|
|
To: []string{"example.org"},
|
|
IP: []tailcfg.ProtoPortRange{{Proto: 0, Ports: tailcfg.PortRange{First: 0, Last: 65535}}},
|
|
},
|
|
},
|
|
},
|
|
map[appctype.ConfigID]connector{
|
|
"swiggity_swooty": {
|
|
Handlers: map[target]handler{
|
|
{
|
|
Dest: netip.MustParsePrefix("100.64.0.1/32"),
|
|
Matching: tailcfg.ProtoPortRange{Proto: 0, Ports: tailcfg.PortRange{First: 0, Last: 65535}},
|
|
}: &tcpRoundRobinHandler{To: []string{"example.org"}, ReachableIPs: []netip.Addr{netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1")}},
|
|
{
|
|
Dest: netip.MustParsePrefix("fd7a:115c:a1e0::1/128"),
|
|
Matching: tailcfg.ProtoPortRange{Proto: 0, Ports: tailcfg.PortRange{First: 0, Last: 65535}},
|
|
}: &tcpRoundRobinHandler{To: []string{"example.org"}, ReachableIPs: []netip.Addr{netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1")}},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"SNIProxy",
|
|
&appctype.AppConnectorConfig{
|
|
SNIProxy: map[appctype.ConfigID]appctype.SNIProxyConfig{
|
|
"swiggity_swooty": {
|
|
Addrs: []netip.Addr{netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1")},
|
|
AllowedDomains: []string{"example.org"},
|
|
IP: []tailcfg.ProtoPortRange{{Proto: 0, Ports: tailcfg.PortRange{First: 0, Last: 65535}}},
|
|
},
|
|
},
|
|
},
|
|
map[appctype.ConfigID]connector{
|
|
"swiggity_swooty": {
|
|
Handlers: map[target]handler{
|
|
{
|
|
Dest: netip.MustParsePrefix("100.64.0.1/32"),
|
|
Matching: tailcfg.ProtoPortRange{Proto: 0, Ports: tailcfg.PortRange{First: 0, Last: 65535}},
|
|
}: &tcpSNIHandler{Allowlist: []string{"example.org"}, ReachableIPs: []netip.Addr{netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1")}},
|
|
{
|
|
Dest: netip.MustParsePrefix("fd7a:115c:a1e0::1/128"),
|
|
Matching: tailcfg.ProtoPortRange{Proto: 0, Ports: tailcfg.PortRange{First: 0, Last: 65535}},
|
|
}: &tcpSNIHandler{Allowlist: []string{"example.org"}, ReachableIPs: []netip.Addr{netip.MustParseAddr("100.64.0.1"), netip.MustParseAddr("fd7a:115c:a1e0::1")}},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
connectors := makeConnectorsFromConfig(tc.input)
|
|
|
|
if diff := cmp.Diff(connectors, tc.want,
|
|
cmpopts.IgnoreFields(tcpRoundRobinHandler{}, "DialContext"),
|
|
cmpopts.IgnoreFields(tcpSNIHandler{}, "DialContext"),
|
|
cmp.Comparer(func(x, y netip.Addr) bool {
|
|
return x == y
|
|
})); diff != "" {
|
|
t.Fatalf("mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|